Add 2 more ItemUtils
Einige Prüfungen sind fehlgeschlagen
SteamWarCI Build failed

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2022-06-08 12:20:50 +02:00
Ursprung bba42ec3a4
Commit 4507516f45

Datei anzeigen

@ -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);
}
}