add API
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@ taboolib {
|
|||||||
name("Zaphkiel").optional(true)
|
name("Zaphkiel").optional(true)
|
||||||
}
|
}
|
||||||
contributors {
|
contributors {
|
||||||
name("小白")
|
name("xbaimiao")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
install("common")
|
install("common")
|
||||||
|
|||||||
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
group=com.github.xbaimiao.shoppro
|
group=com.github.xbaimiao.shoppro
|
||||||
version=1.2.2
|
version=1.2.3
|
||||||
|
|||||||
@@ -25,9 +25,12 @@ object ShopPro : Plugin(), KtorStat {
|
|||||||
val itemLoaderManager = ItemLoaderManager()
|
val itemLoaderManager = ItemLoaderManager()
|
||||||
|
|
||||||
override fun onActive() {
|
override fun onActive() {
|
||||||
|
val userId = kotlin.runCatching { userId }.getOrNull()
|
||||||
|
if (userId != null) {
|
||||||
KtorPluginsBukkit.init(BukkitPlugin.getInstance(), this)
|
KtorPluginsBukkit.init(BukkitPlugin.getInstance(), this)
|
||||||
info("$userId 感谢您的使用")
|
info("$userId 感谢您的使用")
|
||||||
stat()
|
stat()
|
||||||
|
}
|
||||||
ShopManager.load()
|
ShopManager.load()
|
||||||
DiyCurrency.load()
|
DiyCurrency.load()
|
||||||
database = if (config.getBoolean("mysql.enable")) MysqlDatabase(config) else SQLiteDatabase()
|
database = if (config.getBoolean("mysql.enable")) MysqlDatabase(config) else SQLiteDatabase()
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
package com.github.xbaimiao.shoppro.core.shop
|
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.entity.Player
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
|
|
||||||
abstract class Shop {
|
abstract class Shop {
|
||||||
|
|
||||||
@@ -25,4 +28,8 @@ abstract class Shop {
|
|||||||
|
|
||||||
abstract fun open(player: Player)
|
abstract fun open(player: Player)
|
||||||
|
|
||||||
|
abstract fun getItems(): Collection<Item>
|
||||||
|
|
||||||
|
abstract fun sellItem(player: Player, shopItem: ShopItem, itemStack: ItemStack): Boolean
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -12,6 +12,7 @@ import com.github.xbaimiao.shoppro.util.Util.replacePapi
|
|||||||
import org.bukkit.Bukkit
|
import org.bukkit.Bukkit
|
||||||
import org.bukkit.configuration.Configuration
|
import org.bukkit.configuration.Configuration
|
||||||
import org.bukkit.entity.Player
|
import org.bukkit.entity.Player
|
||||||
|
import org.bukkit.inventory.ItemStack
|
||||||
import taboolib.common.platform.function.info
|
import taboolib.common.platform.function.info
|
||||||
import taboolib.module.chat.colored
|
import taboolib.module.chat.colored
|
||||||
import taboolib.module.ui.ClickType
|
import taboolib.module.ui.ClickType
|
||||||
@@ -147,6 +148,10 @@ class ShopImpl(private val configuration: Configuration) : Shop() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getItems(): Collection<Item> {
|
||||||
|
return items.toList()
|
||||||
|
}
|
||||||
|
|
||||||
private fun checkBuyLimit(amount: Int, item: ShopItem, player: Player) {
|
private fun checkBuyLimit(amount: Int, item: ShopItem, player: Player) {
|
||||||
if (item.isLimit()) {
|
if (item.isLimit()) {
|
||||||
if (ShopPro.database.getPlayerAlreadyData(player, item).buy >= item.getLimitPlayer(player)) {
|
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) {
|
private fun checkSellLimit(amount: Int, item: ShopItem, player: Player) {
|
||||||
if (item.isLimit()) {
|
if (item.isLimit()) {
|
||||||
if (ShopPro.database.getPlayerAlreadyData(player, item).sell >= item.getLimitPlayer(player)) {
|
if (ShopPro.database.getPlayerAlreadyData(player, item).sell >= item.getLimitPlayer(player)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user