Improved /sell all and /sell handall

This commit is contained in:
Auxilor
2022-12-05 13:08:41 +00:00
parent 06a668e0e8
commit a19a90110a
2 changed files with 28 additions and 12 deletions

View File

@@ -2,8 +2,11 @@ package com.willfp.ecoshop.commands
import com.willfp.eco.core.EcoPlugin import com.willfp.eco.core.EcoPlugin
import com.willfp.eco.core.command.impl.PluginCommand 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.sell
import com.willfp.ecoshop.shop.shopItem
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
class CommandSellAll(plugin: EcoPlugin) : PluginCommand( class CommandSellAll(plugin: EcoPlugin) : PluginCommand(
plugin, plugin,
@@ -12,19 +15,25 @@ class CommandSellAll(plugin: EcoPlugin) : PluginCommand(
true true
) { ) {
override fun onExecute(player: Player, args: List<String>) { override fun onExecute(player: Player, args: List<String>) {
var didSell = false val items = mutableMapOf<Int, ItemStack>()
for (i in 0..35) { for (i in 0..35) {
val itemStack = player.inventory.getItem(i) val itemStack = player.inventory.getItem(i) ?: continue
if (itemStack?.sell(player) == true) { if (!itemStack.isSellable(player)) {
didSell = true 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) player.inventory.clear(i)
} }
} }
if (!didSell) {
player.sendMessage(plugin.langYml.getMessage("no-sellable"))
}
} }
} }

View File

@@ -5,6 +5,7 @@ import com.willfp.eco.core.command.impl.PluginCommand
import com.willfp.ecoshop.shop.sell import com.willfp.ecoshop.shop.sell
import com.willfp.ecoshop.shop.shopItem import com.willfp.ecoshop.shop.shopItem
import org.bukkit.entity.Player import org.bukkit.entity.Player
import org.bukkit.inventory.ItemStack
class CommandSellHandall(plugin: EcoPlugin) : PluginCommand( class CommandSellHandall(plugin: EcoPlugin) : PluginCommand(
plugin, plugin,
@@ -20,6 +21,8 @@ class CommandSellHandall(plugin: EcoPlugin) : PluginCommand(
return return
} }
val items = mutableMapOf<Int, ItemStack>()
for (i in 0..35) { for (i in 0..35) {
val itemStack = player.inventory.getItem(i) val itemStack = player.inventory.getItem(i)
@@ -27,10 +30,14 @@ class CommandSellHandall(plugin: EcoPlugin) : PluginCommand(
continue continue
} }
if (!itemStack.sell(player)) { items[i] = itemStack
player.sendMessage("not-sellable") }
return
} else { 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) player.inventory.clear(i)
} }
} }