Shift + 右击 一键出售背包内物品已完成

This commit is contained in:
小白
2022-09-10 15:46:33 +08:00
parent 2b3ce52758
commit 66fe1f5676
4 changed files with 34 additions and 6 deletions
@@ -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
}
}
@@ -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<String>()
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()
@@ -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 {
+1
View File
@@ -1,5 +1,6 @@
# 请勿修改此项
date: 0
# 启用mysql
mysql:
enable: false
host: localhost