From ce99c11707a68f90f73a09d74319f049001c8301 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 19:21:16 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=A4=B4=E9=A2=85=E8=A3=85?= =?UTF-8?q?=E9=A5=B0=E5=95=86=E5=BA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../shoppro/core/item/HeadShopItem.kt | 50 +++++++++++++++++++ .../github/xbaimiao/shoppro/core/item/Item.kt | 2 + .../shoppro/core/item/ItemsAdderShopItem.kt | 1 - .../xbaimiao/shoppro/core/shop/ShopImpl.kt | 18 ++++++- 5 files changed, 70 insertions(+), 3 deletions(-) create mode 100644 src/main/kotlin/com/github/xbaimiao/shoppro/core/item/HeadShopItem.kt diff --git a/gradle.properties b/gradle.properties index 1bd0147..11acfbb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,2 +1,2 @@ group=com.github.xbaimiao.shoppro -version=1.0.1 \ No newline at end of file +version=1.0.2 \ No newline at end of file diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/HeadShopItem.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/HeadShopItem.kt new file mode 100644 index 0000000..7a9bd50 --- /dev/null +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/HeadShopItem.kt @@ -0,0 +1,50 @@ +package com.github.xbaimiao.shoppro.core.item + +import com.github.xbaimiao.shoppro.core.shop.Shop +import org.bukkit.Material +import org.bukkit.inventory.ItemStack +import taboolib.library.xseries.XMaterial +import taboolib.platform.util.ItemBuilder +import java.util.* + +class HeadShopItem( + override val key: Char, + headString: String, + override val price: Double, + override val limitServer: Long, + override val limitPlayer: Long, + override val name: String, + override val lore: List, + override val vanilla: Boolean, + override val commands: List, + override val shop: Shop, + val item: Material +) : ShopItem() { + + override val material: Material = XMaterial.PLAYER_HEAD.parseMaterial()!! + + val head: String + + init { + head = headString.substring(5) + } + + override fun vanillaItem(): ItemStack { + return taboolib.platform.util.buildItem(material) { + skullTexture = ItemBuilder.SkullTexture(head, UUID.randomUUID()) + } + } + + override fun equal(itemStack: ItemStack): Boolean { + return itemStack.itemMeta?.hasLore() == false && itemStack.type == item + } + + override fun buildItem(): ItemStack { + return taboolib.platform.util.buildItem(material) { + this.name = this@HeadShopItem.name + this.lore.addAll(this@HeadShopItem.lore) + skullTexture = ItemBuilder.SkullTexture(head, UUID.randomUUID()) + } + } + +} \ No newline at end of file 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 a61fed5..dce4728 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 @@ -45,6 +45,8 @@ interface Item { override fun hasPermission(p0: Permission) = true override fun hasPermission(p0: String) = true }, command.substring(5)) + } else if (command == "close" || command.startsWith("[close]")) { + player.closeInventory() } } } diff --git a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ItemsAdderShopItem.kt b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ItemsAdderShopItem.kt index 867520c..fb1f187 100644 --- a/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ItemsAdderShopItem.kt +++ b/src/main/kotlin/com/github/xbaimiao/shoppro/core/item/ItemsAdderShopItem.kt @@ -22,7 +22,6 @@ class ItemsAdderShopItem( val custom: Int - init { iaMaterial.split(":").let { strings -> material = XMaterial.matchXMaterial(strings[1]).get().parseMaterial()!! 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 a5ed532..9e15e7a 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 @@ -48,6 +48,22 @@ class ShopImpl(private val configuration: Configuration) : Shop() { this ) ) + } else if (materialString.startsWith("HEAD:")) { + items.add( + HeadShopItem( + key[0], + section.getString("$key.material")!!, + section.getDouble("$key.price"), + section.getLong("$key.limit"), + section.getLong("$key.limit-player"), + section.getString("$key.name")!!.colored(), + section.getStringList("$key.lore").colored(), + section.getBoolean("$key.vanilla", true), + section.getStringList("$key.commands"), + this, + section.getString("item")!!.parseToMaterial() + ) + ) } else { items.add( VanillaShopItem( @@ -67,7 +83,7 @@ class ShopImpl(private val configuration: Configuration) : Shop() { } else { items.add( ItemImpl( - section.getString("$key.material")!!.parseToMaterial(), + section.getString("$key.material")!!, section.getStringList("$key.lore").colored(), section.getString("$key.name")!!.colored(), key[0],