diff --git a/gradle.properties b/gradle.properties index ffc8aba..00b25c2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=com.github.xbaimiao.shoppro -version=1.0.6 +version=1.0.7 diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/Commands.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/Commands.kt index 6a14258..7c7abfe 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/core/Commands.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/Commands.kt @@ -1,6 +1,7 @@ package com.github.xbaimiao.shoppro.core import com.github.xbaimiao.shoppro.ShopPro +import com.github.xbaimiao.shoppro.core.shop.Shop import com.github.xbaimiao.shoppro.core.shop.ShopManager import org.bukkit.Bukkit import org.bukkit.command.CommandSender @@ -41,6 +42,37 @@ object Commands { } } + @CommandBody + val sellAll = subCommand { + dynamic("name") { + suggestion { _, _ -> + ShopManager.shops.map { it.getName() } + } + execute { sender, _, argument -> + val shop = ShopManager.shops.first { it.getName() == argument } + sellAll(sender, shop) + } + dynamic("玩家", permission = "admin") { + suggestion { _, _ -> + onlinePlayers.map { it.name } + } + execute { _, 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") val resetLimit = subCommand { execute { sender, _, _ -> diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/shop/Shop.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/shop/Shop.kt index 067d5fb..03ec651 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/core/shop/Shop.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/shop/Shop.kt @@ -21,6 +21,9 @@ abstract class Shop { abstract fun getName(): String + abstract fun sellAll(player: Player) + abstract fun open(player: Player) + } \ No newline at end of file diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/shop/ShopImpl.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/shop/ShopImpl.kt index 5ed7343..eaca5b6 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/core/shop/ShopImpl.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/shop/ShopImpl.kt @@ -65,6 +65,20 @@ class ShopImpl(private val configuration: Configuration) : Shop() { return configuration.getString("name")!!.colored() } + override fun sellAll(player: Player) { + if (getType() != ShopType.SELL) { + throw RuntimeException("此商店非出售商店") + } + items.filterIsInstance().forEach { shopItem -> + val amount = player.inventory.howManyItems { + shopItem.equal(it) + } + if (amount >= 0) { + sell(amount, shopItem, player) + } + } + } + override fun open(player: Player) { player.openMenu(getTitle(player)) { rows(slots.size) diff --git a/src/main/resources/lang/zh_CN.yml b/src/main/resources/lang/zh_CN.yml index 74b3832..cbf85fa 100644 --- a/src/main/resources/lang/zh_CN.yml +++ b/src/main/resources/lang/zh_CN.yml @@ -7,5 +7,6 @@ buy-limit-player: "&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}" not-money: "&7[&e&l!&7] 你没有足够的钱" +sell-all-error: "&7[&e&l!&7] 此商店非出售商店" reload: "&7[&e&l!&7] 重载完成" reset: "&7[&e&l!&7] 限购数据重置成功"