diff --git a/BauSystem_Main/src/de/steamwar/bausystem/utils/ItemUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/utils/ItemUtils.java index 3dba79d1..ee4b93aa 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/utils/ItemUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/utils/ItemUtils.java @@ -33,21 +33,30 @@ public class ItemUtils { private final NamespacedKey ITEM_KEY = SWUtils.getNamespaceKey("bau_item"); public boolean isItem(ItemStack itemStack, String tag) { - if (itemStack == null) { - return false; - } - ItemMeta meta = itemStack.getItemMeta(); - if (meta == null) { - return false; - } - PersistentDataContainer container = meta.getPersistentDataContainer(); - if (!container.has(ITEM_KEY, PersistentDataType.STRING)) { - return false; - } - return tag.equals(container.get(ITEM_KEY, PersistentDataType.STRING)); + String value = getTag(itemStack, ITEM_KEY); + return value != null && value.equals(tag); } public void setItem(ItemStack itemStack, String tag) { + setTag(itemStack, ITEM_KEY, tag); + } + + public String getTag(ItemStack itemStack, NamespacedKey key) { + if (itemStack == null) { + return null; + } + ItemMeta meta = itemStack.getItemMeta(); + if (meta == null) { + return null; + } + PersistentDataContainer container = meta.getPersistentDataContainer(); + if (!container.has(key, PersistentDataType.STRING)) { + return null; + } + return container.get(ITEM_KEY, PersistentDataType.STRING) + } + + public void setTag(ItemStack itemStack, NamespacedKey key, String value) { if (itemStack == null) { return; } @@ -55,8 +64,7 @@ public class ItemUtils { if (meta == null) { return; } - meta.getPersistentDataContainer().set(ITEM_KEY, PersistentDataType.STRING, tag); + meta.getPersistentDataContainer().set(key, PersistentDataType.STRING, value); itemStack.setItemMeta(meta); } - }