From b0c3d22cec6621521b42b8ba1c7187382761e308 Mon Sep 17 00:00:00 2001 From: Esoteric Enderman Date: Mon, 28 Oct 2024 23:03:38 +0000 Subject: [PATCH] Update custom item code --- .../minecraft/plugins/library/item/CustomItem.kt | 15 +++++---------- .../plugins/library/item/CustomItemManager.kt | 10 +++------- 2 files changed, 8 insertions(+), 17 deletions(-) diff --git a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItem.kt b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItem.kt index 3370694..54c24a7 100644 --- a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItem.kt +++ b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItem.kt @@ -15,9 +15,9 @@ abstract class CustomItem(private val plugin: CustomItemPlugin, private val item plugin.customItemManager.addCustomItem(itemId, this) } - protected abstract fun generateCustomItem(baseCustomItem: ItemStack?, player: Player?): ItemStack + protected abstract fun generateCustomItem(baseCustomItem: ItemStack, player: Player): ItemStack - fun getCustomItem(player: Player?): ItemStack { + fun getCustomItem(player: Player): ItemStack { val item = ItemStack(material) item.editMeta { meta: ItemMeta -> meta.persistentDataContainer.set( @@ -26,6 +26,7 @@ abstract class CustomItem(private val plugin: CustomItemPlugin, private val item itemId ) } + return generateCustomItem(item, player) } @@ -38,15 +39,9 @@ abstract class CustomItem(private val plugin: CustomItemPlugin, private val item return false } - val dataContainerItemIdValue = - itemStack.itemMeta.persistentDataContainer.get(plugin.customItemManager.customItemIdKey, PersistentDataType.STRING) - ?: return false + val dataContainerItemIdValue = itemStack.itemMeta.persistentDataContainer.get(plugin.customItemManager.customItemIdKey, PersistentDataType.STRING) ?: return false - return try { - itemId === dataContainerItemIdValue - } catch (exception: IllegalArgumentException) { - false - } + return itemId == dataContainerItemIdValue } fun give(player: Player) { diff --git a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItemManager.kt b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItemManager.kt index e0dfdcf..e2465d6 100644 --- a/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItemManager.kt +++ b/lib/src/main/kotlin/foundation/esoteric/minecraft/plugins/library/item/CustomItemManager.kt @@ -4,16 +4,12 @@ import org.bukkit.NamespacedKey import org.bukkit.entity.Player import org.bukkit.plugin.java.JavaPlugin -class CustomItemManager(private val plugin: JavaPlugin) { +class CustomItemManager(plugin: JavaPlugin) { private val customItemMap: MutableMap = HashMap() val customItemIdKey: NamespacedKey = NamespacedKey(plugin, "custom_item_id") - fun getPlugin(): JavaPlugin { - return plugin - } - fun addCustomItem(itemId: String, customItem: CustomItem) { customItemMap[itemId] = customItem } @@ -22,7 +18,7 @@ class CustomItemManager(private val plugin: JavaPlugin) { return customItemMap[itemId] } - fun giveCustomItem(itemId: String, player: Player?) { - customItemMap[itemId]!!.give(player!!) + fun giveCustomItem(itemId: String, player: Player) { + customItemMap[itemId]!!.give(player) } }