diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandSellAll.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandSellAll.kt index 9694f22..e6f610f 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandSellAll.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandSellAll.kt @@ -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) { - var didSell = false + val items = mutableMapOf() 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")) - } } } diff --git a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandSellHandall.kt b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandSellHandall.kt index c06d155..86b1c4c 100644 --- a/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandSellHandall.kt +++ b/eco-core/core-plugin/src/main/kotlin/com/willfp/ecoshop/commands/CommandSellHandall.kt @@ -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() + 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)) { - player.sendMessage("not-sellable") - return - } else { + items[i] = itemStack + } + + val sold = items.values.sell(player) + if (sold.size == items.size) { + player.sendMessage("not-sellable") + } else { + for (i in items.keys) { player.inventory.clear(i) } }