Improved /sell all and /sell handall
This commit is contained in:
@@ -2,8 +2,11 @@ package com.willfp.ecoshop.commands
|
||||
|
||||
import com.willfp.eco.core.EcoPlugin
|
||||
import com.willfp.eco.core.command.impl.PluginCommand
|
||||
import com.willfp.ecoshop.shop.isSellable
|
||||
import com.willfp.ecoshop.shop.sell
|
||||
import com.willfp.ecoshop.shop.shopItem
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class CommandSellAll(plugin: EcoPlugin) : PluginCommand(
|
||||
plugin,
|
||||
@@ -12,19 +15,25 @@ class CommandSellAll(plugin: EcoPlugin) : PluginCommand(
|
||||
true
|
||||
) {
|
||||
override fun onExecute(player: Player, args: List<String>) {
|
||||
var didSell = false
|
||||
val items = mutableMapOf<Int, ItemStack>()
|
||||
|
||||
for (i in 0..35) {
|
||||
val itemStack = player.inventory.getItem(i)
|
||||
val itemStack = player.inventory.getItem(i) ?: continue
|
||||
|
||||
if (itemStack?.sell(player) == true) {
|
||||
didSell = true
|
||||
if (!itemStack.isSellable(player)) {
|
||||
continue
|
||||
}
|
||||
|
||||
items[i] = itemStack
|
||||
}
|
||||
|
||||
val sold = items.values.sell(player)
|
||||
if (sold.size == items.size) {
|
||||
player.sendMessage("no-sellable")
|
||||
} else {
|
||||
for (i in items.keys) {
|
||||
player.inventory.clear(i)
|
||||
}
|
||||
}
|
||||
|
||||
if (!didSell) {
|
||||
player.sendMessage(plugin.langYml.getMessage("no-sellable"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.willfp.eco.core.command.impl.PluginCommand
|
||||
import com.willfp.ecoshop.shop.sell
|
||||
import com.willfp.ecoshop.shop.shopItem
|
||||
import org.bukkit.entity.Player
|
||||
import org.bukkit.inventory.ItemStack
|
||||
|
||||
class CommandSellHandall(plugin: EcoPlugin) : PluginCommand(
|
||||
plugin,
|
||||
@@ -20,6 +21,8 @@ class CommandSellHandall(plugin: EcoPlugin) : PluginCommand(
|
||||
return
|
||||
}
|
||||
|
||||
val items = mutableMapOf<Int, ItemStack>()
|
||||
|
||||
for (i in 0..35) {
|
||||
val itemStack = player.inventory.getItem(i)
|
||||
|
||||
@@ -27,10 +30,14 @@ class CommandSellHandall(plugin: EcoPlugin) : PluginCommand(
|
||||
continue
|
||||
}
|
||||
|
||||
if (!itemStack.sell(player)) {
|
||||
items[i] = itemStack
|
||||
}
|
||||
|
||||
val sold = items.values.sell(player)
|
||||
if (sold.size == items.size) {
|
||||
player.sendMessage("not-sellable")
|
||||
return
|
||||
} else {
|
||||
for (i in items.keys) {
|
||||
player.inventory.clear(i)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user