diff --git a/build.gradle.kts b/build.gradle.kts index 210fcc8..c672dcd 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,7 +14,7 @@ taboolib { name("Zaphkiel").optional(true) } contributors { - name("小白") + name("xbaimiao") } } install("common") diff --git a/gradle.properties b/gradle.properties index 312955a..fe73617 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=com.github.xbaimiao.shoppro -version=1.2.2 +version=1.2.3 diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/ShopPro.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/ShopPro.kt index 3078a5e..43010f2 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/ShopPro.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/ShopPro.kt @@ -25,9 +25,12 @@ object ShopPro : Plugin(), KtorStat { val itemLoaderManager = ItemLoaderManager() override fun onActive() { - KtorPluginsBukkit.init(BukkitPlugin.getInstance(), this) - info("$userId 感谢您的使用") - stat() + val userId = kotlin.runCatching { userId }.getOrNull() + if (userId != null) { + KtorPluginsBukkit.init(BukkitPlugin.getInstance(), this) + info("$userId 感谢您的使用") + stat() + } ShopManager.load() DiyCurrency.load() database = if (config.getBoolean("mysql.enable")) MysqlDatabase(config) else SQLiteDatabase() 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 38bf228..0442495 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 @@ -1,6 +1,9 @@ package com.github.xbaimiao.shoppro.core.shop +import com.github.xbaimiao.shoppro.core.item.Item +import com.github.xbaimiao.shoppro.core.item.ShopItem import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack abstract class Shop { @@ -25,4 +28,8 @@ abstract class Shop { abstract fun open(player: Player) + abstract fun getItems(): Collection + + abstract fun sellItem(player: Player, shopItem: ShopItem, itemStack: ItemStack): Boolean + } \ 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 0a84cd7..21c6aaf 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 @@ -12,6 +12,7 @@ import com.github.xbaimiao.shoppro.util.Util.replacePapi import org.bukkit.Bukkit import org.bukkit.configuration.Configuration import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack import taboolib.common.platform.function.info import taboolib.module.chat.colored import taboolib.module.ui.ClickType @@ -147,6 +148,10 @@ class ShopImpl(private val configuration: Configuration) : Shop() { } } + override fun getItems(): Collection { + return items.toList() + } + private fun checkBuyLimit(amount: Int, item: ShopItem, player: Player) { if (item.isLimit()) { if (ShopPro.database.getPlayerAlreadyData(player, item).buy >= item.getLimitPlayer(player)) { @@ -201,6 +206,60 @@ class ShopImpl(private val configuration: Configuration) : Shop() { } } + override fun sellItem(player: Player, shopItem: ShopItem, itemStack: ItemStack): Boolean { + val amount = itemStack.amount + if (shopItem.isLimit()) { + if (ShopPro.database.getPlayerAlreadyData(player, shopItem).sell >= shopItem.getLimitPlayer(player)) { + player.sendLang("sell-limit-player", shopItem.getLimitPlayer(player)) + ShopPro.config.getString("the_voice_of_failure")?.let { + player.playSound(player.location, it, 100f, 1f) + } + return false + } + if (ShopPro.database.getServerAlreadyData(shopItem).sell >= shopItem.limitServer) { + player.sendLang("sell-limit-server", shopItem.limitServer) + ShopPro.config.getString("the_voice_of_failure")?.let { + player.playSound(player.location, it, 100f, 1f) + } + return false + } + if (ShopPro.database.getPlayerAlreadyData( + player, + shopItem + ).sell + amount > shopItem.getLimitPlayer(player) + ) { + sell( + (shopItem.getLimitPlayer(player) - ShopPro.database.getPlayerAlreadyData( + player, + shopItem + ).sell).toInt(), + shopItem, + player + ) + return false + } + if (ShopPro.database.getServerAlreadyData(shopItem).sell + amount > shopItem.limitServer) { + sell( + (shopItem.limitServer - ShopPro.database.getServerAlreadyData(shopItem).sell).toInt(), + shopItem, + player + ) + return false + } + } + if (!shopItem.equal(itemStack)) { + error("!item.equal(itemStack)") + } + shopItem.currency.giveMoney(player, shopItem.price * amount) + Bukkit.getPluginManager().callEvent(ShopProSellEvent(shopItem, amount, player)) + ShopPro.database.addAmount(shopItem, player, LimitData(0L, amount.toLong())) + player.sendLang("sell-item", amount, shopItem.name, shopItem.price * amount) + ShopPro.config.getString("the_voice_of_success")?.let { + player.playSound(player.location, it, 100f, 1f) + } + return true + } + private fun checkSellLimit(amount: Int, item: ShopItem, player: Player) { if (item.isLimit()) { if (ShopPro.database.getPlayerAlreadyData(player, item).sell >= item.getLimitPlayer(player)) {