更新一件出售身上所有物品

This commit is contained in:
小白
2022-10-02 14:15:03 +08:00
parent 9d3444af01
commit 3fefb62a8b
5 changed files with 51 additions and 1 deletions
+1 -1
View File
@@ -1,2 +1,2 @@
group=com.github.xbaimiao.shoppro group=com.github.xbaimiao.shoppro
version=1.0.6 version=1.0.7
@@ -1,6 +1,7 @@
package com.github.xbaimiao.shoppro.core package com.github.xbaimiao.shoppro.core
import com.github.xbaimiao.shoppro.ShopPro import com.github.xbaimiao.shoppro.ShopPro
import com.github.xbaimiao.shoppro.core.shop.Shop
import com.github.xbaimiao.shoppro.core.shop.ShopManager import com.github.xbaimiao.shoppro.core.shop.ShopManager
import org.bukkit.Bukkit import org.bukkit.Bukkit
import org.bukkit.command.CommandSender import org.bukkit.command.CommandSender
@@ -41,6 +42,37 @@ object Commands {
} }
} }
@CommandBody
val sellAll = subCommand {
dynamic("name") {
suggestion<CommandSender> { _, _ ->
ShopManager.shops.map { it.getName() }
}
execute<Player> { sender, _, argument ->
val shop = ShopManager.shops.first { it.getName() == argument }
sellAll(sender, shop)
}
dynamic("玩家", permission = "admin") {
suggestion<CommandSender> { _, _ ->
onlinePlayers.map { it.name }
}
execute<CommandSender> { _, context, argument ->
val player = Bukkit.getPlayerExact(argument)!!
val shop = ShopManager.shops.first { it.getName() == context.argument(-1) }
sellAll(player, shop)
}
}
}
}
private fun sellAll(player: Player, shop: Shop) {
if (shop.getType() != Shop.ShopType.SELL) {
player.sendLang("sell-all-error")
return
}
shop.sellAll(player)
}
@CommandBody(permission = "admin") @CommandBody(permission = "admin")
val resetLimit = subCommand { val resetLimit = subCommand {
execute<CommandSender> { sender, _, _ -> execute<CommandSender> { sender, _, _ ->
@@ -21,6 +21,9 @@ abstract class Shop {
abstract fun getName(): String abstract fun getName(): String
abstract fun sellAll(player: Player)
abstract fun open(player: Player) abstract fun open(player: Player)
} }
@@ -65,6 +65,20 @@ class ShopImpl(private val configuration: Configuration) : Shop() {
return configuration.getString("name")!!.colored() return configuration.getString("name")!!.colored()
} }
override fun sellAll(player: Player) {
if (getType() != ShopType.SELL) {
throw RuntimeException("此商店非出售商店")
}
items.filterIsInstance<ShopItem>().forEach { shopItem ->
val amount = player.inventory.howManyItems {
shopItem.equal(it)
}
if (amount >= 0) {
sell(amount, shopItem, player)
}
}
}
override fun open(player: Player) { override fun open(player: Player) {
player.openMenu<Basic>(getTitle(player)) { player.openMenu<Basic>(getTitle(player)) {
rows(slots.size) rows(slots.size)
+1
View File
@@ -7,5 +7,6 @@ buy-limit-player: "&7[&e&l!&7] 此物品每人每日限制购买{0}个,今日购
buy-limit-server: "&7[&e&l!&7] 此物品全服每日限制购买{0}个,今日购买限制" buy-limit-server: "&7[&e&l!&7] 此物品全服每日限制购买{0}个,今日购买限制"
buy-item: "&7[&e&l!&7] 你购买了§6 {0}个 §7{1} §7花费了§6 {2}" buy-item: "&7[&e&l!&7] 你购买了§6 {0}个 §7{1} §7花费了§6 {2}"
not-money: "&7[&e&l!&7] 你没有足够的钱" not-money: "&7[&e&l!&7] 你没有足够的钱"
sell-all-error: "&7[&e&l!&7] 此商店非出售商店"
reload: "&7[&e&l!&7] 重载完成" reload: "&7[&e&l!&7] 重载完成"
reset: "&7[&e&l!&7] 限购数据重置成功" reset: "&7[&e&l!&7] 限购数据重置成功"