From a37c867d0af58e1c3caec8b5851489faa4fa2866 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E7=99=BD?= <3104026189@qq.com> Date: Mon, 15 May 2023 19:49:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=BA=97=E6=94=AF=E6=8C=81zap?= =?UTF-8?q?=E7=89=A9=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/xbaimiao/shoppro/core/item/Item.kt | 3 +- .../shoppro/core/item/ItemLoaderManager.kt | 6 +-- .../xbaimiao/shoppro/core/item/ShopItem.kt | 7 ++- .../shoppro/core/item/impl/HeadShopItem.kt | 5 +- .../shoppro/core/item/impl/ItemImpl.kt | 4 +- .../core/item/impl/ItemsAdderShopItem.kt | 6 +-- .../shoppro/core/item/impl/VanillaShopItem.kt | 10 ++-- .../shoppro/core/item/impl/ZapItem.kt | 52 +++++++++++++++++++ .../xbaimiao/shoppro/core/shop/ShopImpl.kt | 2 +- src/main/resources/niinnee/buy-gui.yml | 0 src/main/resources/niinnee/sell-gui.yml | 0 src/main/resources/shops/limit-buy.yml | 27 +++++++++- 12 files changed, 98 insertions(+), 24 deletions(-) create mode 100644 src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ZapItem.kt create mode 100644 src/main/resources/niinnee/buy-gui.yml create mode 100644 src/main/resources/niinnee/sell-gui.yml diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/Item.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/Item.kt index fa503b8..31dc5b3 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/Item.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/Item.kt @@ -4,7 +4,6 @@ import com.github.xbaimiao.shoppro.core.shop.Shop import com.github.xbaimiao.shoppro.core.shop.ShopManager import org.bukkit.Bukkit import org.bukkit.Material -import org.bukkit.configuration.ConfigurationSection import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack import org.bukkit.permissions.Permission @@ -22,7 +21,7 @@ interface Item { val shop: Shop fun isCommodity(): Boolean - fun buildItem(): ItemStack + fun buildItem(player: Player): ItemStack fun update(player: Player): ItemStack fun exeCommands(player: Player, amount: Int) { diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ItemLoaderManager.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ItemLoaderManager.kt index 0eebcd0..9dc29bd 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ItemLoaderManager.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ItemLoaderManager.kt @@ -1,9 +1,6 @@ package com.github.xbaimiao.shoppro.core.item -import com.github.xbaimiao.shoppro.core.item.impl.HeadShopItem -import com.github.xbaimiao.shoppro.core.item.impl.ItemImpl -import com.github.xbaimiao.shoppro.core.item.impl.ItemsAdderShopItem -import com.github.xbaimiao.shoppro.core.item.impl.VanillaShopItem +import com.github.xbaimiao.shoppro.core.item.impl.* class ItemLoaderManager { @@ -14,6 +11,7 @@ class ItemLoaderManager { itemLoaders.add(ItemImpl) itemLoaders.add(ItemsAdderShopItem) itemLoaders.add(HeadShopItem) + itemLoaders.add(ZapItem) } fun getVanillaShop(): ItemLoader = VanillaShopItem.Companion 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 d4484c3..bc3308d 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 @@ -69,7 +69,10 @@ abstract class ShopItem( return true } - abstract fun vanillaItem(): ItemStack + /** + * 构建发送给玩家的物品 + */ + abstract fun vanillaItem(player: Player): ItemStack abstract fun equal(itemStack: ItemStack): Boolean @@ -88,7 +91,7 @@ abstract class ShopItem( } else { ShopPro.database.getServerAlreadyData(this).sell } - val item = buildItem().modifyLore { + val item = buildItem(player).modifyLore { val newLore = ArrayList() for (line in this) { var newLine = line.replace("\${name}", name) diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/HeadShopItem.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/HeadShopItem.kt index 6e41762..1c84101 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/HeadShopItem.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/HeadShopItem.kt @@ -6,6 +6,7 @@ import com.github.xbaimiao.shoppro.core.item.ShopItem import com.github.xbaimiao.shoppro.core.shop.Shop import org.bukkit.Material import org.bukkit.configuration.ConfigurationSection +import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack import taboolib.library.xseries.XMaterial import taboolib.library.xseries.parseToMaterial @@ -26,7 +27,7 @@ class HeadShopItem( head = headString.substring(5) } - override fun vanillaItem(): ItemStack { + override fun vanillaItem(player: Player): ItemStack { return taboolib.platform.util.buildItem(material) { skullTexture = ItemBuilder.SkullTexture(head, UUID.randomUUID()) } @@ -36,7 +37,7 @@ class HeadShopItem( return itemStack.itemMeta?.hasLore() == false && itemStack.type == item } - override fun buildItem(): ItemStack { + override fun buildItem(player: Player): ItemStack { return taboolib.platform.util.buildItem(material) { this.name = this@HeadShopItem.name this.lore.addAll(this@HeadShopItem.lore) diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ItemImpl.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ItemImpl.kt index e31a044..bdf43b1 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ItemImpl.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ItemImpl.kt @@ -47,7 +47,7 @@ class ItemImpl( return false } - override fun buildItem(): ItemStack { + override fun buildItem(player: Player): ItemStack { return taboolib.platform.util.buildItem(material) { this.name = this@ItemImpl.name this.lore.addAll(this@ItemImpl.lore) @@ -59,7 +59,7 @@ class ItemImpl( } override fun update(player: Player): ItemStack { - val item = buildItem().modifyLore { + val item = buildItem(player).modifyLore { val newLore = ArrayList() for (line in this) { newLore.add(line.replacePapi(player)) diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ItemsAdderShopItem.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ItemsAdderShopItem.kt index 1dae085..11f1468 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ItemsAdderShopItem.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ItemsAdderShopItem.kt @@ -4,9 +4,9 @@ import com.github.xbaimiao.shoppro.core.item.Item import com.github.xbaimiao.shoppro.core.item.ItemLoader import com.github.xbaimiao.shoppro.core.item.ShopItem import com.github.xbaimiao.shoppro.core.shop.Shop -import com.github.xbaimiao.shoppro.core.vault.CurrencyType import org.bukkit.Material import org.bukkit.configuration.ConfigurationSection +import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack import taboolib.library.xseries.XMaterial @@ -33,13 +33,13 @@ class ItemsAdderShopItem( return false } - override fun vanillaItem(): ItemStack { + override fun vanillaItem(player: Player): ItemStack { return taboolib.platform.util.buildItem(material) { this.customModelData = custom } } - override fun buildItem(): ItemStack { + override fun buildItem(player: Player): ItemStack { return taboolib.platform.util.buildItem(material) { this.name = this@ItemsAdderShopItem.name this.lore.addAll(this@ItemsAdderShopItem.lore) diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/VanillaShopItem.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/VanillaShopItem.kt index 584a515..a68e0e0 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/VanillaShopItem.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/VanillaShopItem.kt @@ -4,16 +4,14 @@ import com.github.xbaimiao.shoppro.core.item.Item import com.github.xbaimiao.shoppro.core.item.ItemLoader import com.github.xbaimiao.shoppro.core.item.ShopItem import com.github.xbaimiao.shoppro.core.shop.Shop -import com.github.xbaimiao.shoppro.core.vault.CurrencyType import org.bukkit.configuration.ConfigurationSection +import org.bukkit.entity.Player import org.bukkit.inventory.ItemStack import taboolib.platform.util.hasLore -class VanillaShopItem( - itemSetting: ItemSetting -) : ShopItem(itemSetting) { +open class VanillaShopItem(itemSetting: ItemSetting) : ShopItem(itemSetting) { - override fun vanillaItem(): ItemStack { + override fun vanillaItem(player: Player): ItemStack { return taboolib.platform.util.buildItem(material) } @@ -21,7 +19,7 @@ class VanillaShopItem( return itemStack.type == material && !itemStack.hasLore() } - override fun buildItem(): ItemStack { + override fun buildItem(player: Player): ItemStack { return taboolib.platform.util.buildItem(material) { this.name = this@VanillaShopItem.name this.lore.addAll(this@VanillaShopItem.lore) diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ZapItem.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ZapItem.kt new file mode 100644 index 0000000..e5e0f22 --- /dev/null +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/impl/ZapItem.kt @@ -0,0 +1,52 @@ +package com.github.xbaimiao.shoppro.core.item.impl + +import com.github.xbaimiao.shoppro.core.item.Item +import com.github.xbaimiao.shoppro.core.item.ItemLoader +import com.github.xbaimiao.shoppro.core.shop.Shop +import ink.ptms.zaphkiel.Zaphkiel +import org.bukkit.Bukkit +import org.bukkit.Material +import org.bukkit.configuration.ConfigurationSection +import org.bukkit.entity.Player +import org.bukkit.inventory.ItemStack + +/** + * @author 小白 + * @date 2023/5/15 17:59 + **/ +class ZapItem( + private val zapItem: ink.ptms.zaphkiel.api.Item, + itemSetting: ItemSetting +) : VanillaShopItem(itemSetting) { + + override val material: Material + get() = zapItem.buildItemStack(null).type + + override fun vanillaItem(player: Player): ItemStack { + return zapItem.buildItemStack(player) + } + + override fun equal(itemStack: ItemStack): Boolean { + val item = Zaphkiel.api().getItemHandler().getItem(itemStack) ?: return false + return item.id == zapItem.id + } + + companion object : ItemLoader() { + override val prefix: String = "Zaphkiel" + + override fun formSection(char: Char, section: ConfigurationSection, shop: Shop): Item { + if (Bukkit.getPluginManager().plugins.find { it.name.lowercase() == "Zaphkiel".lowercase() } == null) { + error("Zaphkiel Plugin not found") + } + val zapId = section.getString("material")!!.substring(prefix.length + 1) + val item = Zaphkiel.api().getItemManager().getItem(zapId) ?: error("ZapItem $zapId not found") + return ZapItem(item, section.toItemSetting(char, shop)) + } + + override fun parseToMaterial(section: ConfigurationSection): Material { + return Material.AIR + } + + } + +} \ 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 7aba0aa..6a21981 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 @@ -172,7 +172,7 @@ class ShopImpl(private val configuration: Configuration) : Shop() { private fun buy(amount: Int, item: ShopItem, player: Player) { if (item.currency.takeMoney(player, item.price * amount)) { if (item.vanilla) { - val vanilla = item.vanillaItem() + val vanilla = item.vanillaItem(player) vanilla.amount = amount player.giveItem(vanilla) } diff --git a/src/main/resources/niinnee/buy-gui.yml b/src/main/resources/niinnee/buy-gui.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/niinnee/sell-gui.yml b/src/main/resources/niinnee/sell-gui.yml new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/shops/limit-buy.yml b/src/main/resources/shops/limit-buy.yml index 88f320d..7ae2ef9 100644 --- a/src/main/resources/shops/limit-buy.yml +++ b/src/main/resources/shops/limit-buy.yml @@ -7,7 +7,7 @@ title: "系统出售商店" # 物品摆放顺序 slots: - 'NNNNNNNNN' - - 'NAB N' + - 'NABC N' - 'NNNNNNNNN' items: N: @@ -71,4 +71,27 @@ items: # 关闭此选项 可只执行命令 不给原版物品 vanilla: false commands: - - '[console] ia give %player% 物品 ${amount}' \ No newline at end of file + - '[console] ia give %player% 物品 ${amount}' + # Zaphkiel物品示范 + C: + material: 'Zaphkiel:example_sword' + name: 'Zaphkiel物品' + # 每日限购买 + limit: 5000 + # 每个玩家限购买 + limit-player: 500 + # 物品金额 + price: 2 + lore: + - '&e| &7这里可以购买&6 ${name}' + - '&e| &7购买单价 &6${price}' + - '&e| &7你的余额 &6${money}' + - '' + - '&e|&6 左击 &7购买 &6单个' + - '&e|&6 右击 &7购买 &6一组 &7需要 &6${price64}' + - '' + - '&e| &7限买公示:' + - '&e| &7每人限制购买: ${limit}' + - '&e| &7全服限制购买: ${allLimit}' + - '&e| &7您已购买: ${limit-player}' + - '&e| &7全服剩余: ${limit-server}' \ No newline at end of file