From 66fe1f5676bcf750ba5c0bfef4a1ecc21be0ae9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD?= <67080574+xbaimiao@users.noreply.github.com> Date: Sat, 10 Sep 2022 15:46:33 +0800 Subject: [PATCH] =?UTF-8?q?Shift=20+=20=E5=8F=B3=E5=87=BB=20=E4=B8=80?= =?UTF-8?q?=E9=94=AE=E5=87=BA=E5=94=AE=E8=83=8C=E5=8C=85=E5=86=85=E7=89=A9?= =?UTF-8?q?=E5=93=81=E5=B7=B2=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/com/github/xbaimiao/shoppro/Util.kt | 16 +++++++++++++++- .../xbaimiao/shoppro/core/item/ShopItem.kt | 12 +++++++++--- .../xbaimiao/shoppro/core/shop/ShopImpl.kt | 11 +++++++++-- src/main/resources/config.yml | 1 + 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/Util.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/Util.kt index 2e26eb7..d4c3244 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/Util.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/Util.kt @@ -1,8 +1,10 @@ package com.github.xbaimiao.shoppro +import org.bukkit.inventory.Inventory +import org.bukkit.inventory.ItemStack +import taboolib.platform.util.isNotAir import java.text.DecimalFormat - object Util { fun Double.format(): Double { @@ -10,4 +12,16 @@ object Util { return df.format(this).toDouble() } + fun Inventory.howManyItems(func: (item: ItemStack) -> Boolean): Int { + var amount = 0 + for (itemStack in this) { + if (itemStack.isNotAir()) { + if (func.invoke(itemStack)) { + amount += itemStack.amount + } + } + } + return amount + } + } \ No newline at end of file diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ShopItem.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ShopItem.kt index 4539d84..c955c6d 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ShopItem.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ShopItem.kt @@ -1,6 +1,8 @@ package com.github.xbaimiao.shoppro.core.item import com.github.xbaimiao.shoppro.ShopPro +import com.github.xbaimiao.shoppro.Util.format +import com.github.xbaimiao.shoppro.Util.howManyItems import com.github.xbaimiao.shoppro.core.shop.Shop import me.clip.placeholderapi.PlaceholderAPI import org.bukkit.entity.Player @@ -36,19 +38,23 @@ abstract class ShopItem : Item { } else { ShopPro.database.getServerAlreadyData(this).sell } - val priceAll = "正在开发" val item = buildItem().modifyLore { val newLore = ArrayList() for (line in this) { - val newLine = line.replace("\${name}", name) + var newLine = line.replace("\${name}", name) .replace("\${price}", price.toString()) .replace("\${money}", vault.getMoney(player).toString()) .replace("\${price64}", (price * 64).toString()) .replace("\${limit}", limitPlayer.toString()) - .replace("\${priceAll}", priceAll.toString()) .replace("\${allLimit}", limitServer.toString()) .replace("\${limit-player}", playerLimit.toString()) .replace("\${limit-server}", (limitServer - serverLimit).toString()) + if (shop.getType() == Shop.ShopType.SELL) { + val priceAll = (player.inventory.howManyItems { + this@ShopItem.equal(it) + } * price).format() + newLine = newLine.replace("\${priceAll}", priceAll.toString()) + } newLore.add(PlaceholderAPI.setPlaceholders(player, newLine)) } this.clear() 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 52aa8b6..e46bee4 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 @@ -1,6 +1,7 @@ package com.github.xbaimiao.shoppro.core.shop import com.github.xbaimiao.shoppro.ShopPro +import com.github.xbaimiao.shoppro.Util.howManyItems import com.github.xbaimiao.shoppro.api.ShopProBuyEvent import com.github.xbaimiao.shoppro.api.ShopProSellEvent import com.github.xbaimiao.shoppro.core.database.LimitData @@ -106,7 +107,7 @@ class ShopImpl(private val configuration: Configuration) : Shop() { val amount = when (event.clickEvent().click) { org.bukkit.event.inventory.ClickType.LEFT -> 1 org.bukkit.event.inventory.ClickType.RIGHT -> 64 - else -> 1 + else -> return@onClick } buy(amount, item, player) event.currentItem?.let { @@ -122,7 +123,13 @@ class ShopImpl(private val configuration: Configuration) : Shop() { val amount = when (event.clickEvent().click) { org.bukkit.event.inventory.ClickType.LEFT -> 1 org.bukkit.event.inventory.ClickType.RIGHT -> 64 - else -> 1 + org.bukkit.event.inventory.ClickType.SHIFT_RIGHT -> { + player.inventory.howManyItems { + item.equal(it) + } + } + + else -> return@onClick } sell(amount, item, player) event.currentItem?.let { diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 0ecd14e..d155fea 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,6 @@ # 请勿修改此项 date: 0 +# 启用mysql mysql: enable: false host: localhost