diff --git a/jitpack.yml b/jitpack.yml new file mode 100644 index 0000000..1e41e00 --- /dev/null +++ b/jitpack.yml @@ -0,0 +1,2 @@ +jdk: + - openjdk17 \ No newline at end of file diff --git a/pom.xml b/pom.xml index c1ed439..c256037 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ DEV - 17 + 1.8 UTF-8 src @@ -223,12 +223,6 @@ 2.20.1 provided - - org.geysermc.geyser - api - 2.2.2-SNAPSHOT - provided - org.geysermc.floodgate api diff --git a/src/me/rockyhawk/commandpanels/api/Panel.java b/src/me/rockyhawk/commandpanels/api/Panel.java index 3f76df3..9edad2f 100644 --- a/src/me/rockyhawk/commandpanels/api/Panel.java +++ b/src/me/rockyhawk/commandpanels/api/Panel.java @@ -99,7 +99,7 @@ public class Panel{ } try { //add NBT to item and return the ItemStack - return plugin.nbt.setNBT(s, "CommandPanelsHotbar", panelName + ":" + slot); + return plugin.nbt.setNBT(s, "CommandPanelsHotbar", "string", panelName + ":" + slot); }catch(Exception e) { //return air if null return new ItemStack(Material.AIR); diff --git a/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java b/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java index 653c037..63a6dac 100644 --- a/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java +++ b/src/me/rockyhawk/commandpanels/classresources/ItemCreation.java @@ -191,10 +191,10 @@ public class ItemCreation { } if(itemSection.contains("nbt")){ - plugin.nbt.applyNBTRecursively("", itemSection, s, p, panel, position); + plugin.nbt.applyNBTRecursively("", itemSection.getConfigurationSection("nbt"), s, p, panel, position); } if(addNBT){ - plugin.nbt.setNBT(s, "CommandPanelsItem", "true"); + plugin.nbt.setNBT(s, "CommandPanelsItem","boolean", "true"); } if (itemSection.contains("enchanted")) { diff --git a/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java b/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java index b297e1c..dd426ca 100644 --- a/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java +++ b/src/me/rockyhawk/commandpanels/classresources/placeholders/Placeholders.java @@ -140,19 +140,23 @@ public class Placeholders { } } - //placeholder to check if an item has NBT %cp-nbt-slot:key% - if(identifier.startsWith("nbt-")) { + //placeholder to check if an item has NBT %cp-nbt-slot:type:key% + if (identifier.startsWith("nbt-")) { try { String slot_key = identifier.replace("nbt-", ""); - String value; - value = plugin.nbt.getNBT(p.getOpenInventory().getTopInventory().getItem((int)Double.parseDouble(slot_key.split(":")[0])),slot_key.split(":")[1]); - if(value.isEmpty()){ - value = "empty"; - } - return value; - }catch (Exception ex){ - plugin.debug(ex,p); - return ""; + Object value; + value = plugin.nbt.getNBT( + p.getOpenInventory().getTopInventory().getItem( + (int) Double.parseDouble(slot_key.split(":")[0]) + ), + slot_key.split(":")[2], + slot_key.split(":")[1] + ); + // Convert any object type to a string, handle null explicitly if desired + return value == null ? "empty" : String.valueOf(value); + } catch (Exception ex) { + plugin.debug(ex, p); + return ""; // Consider returning "error" or some other indicative string } } diff --git a/src/me/rockyhawk/commandpanels/ioclasses/nbt/NBTManager.java b/src/me/rockyhawk/commandpanels/ioclasses/nbt/NBTManager.java index a4a403f..d618786 100644 --- a/src/me/rockyhawk/commandpanels/ioclasses/nbt/NBTManager.java +++ b/src/me/rockyhawk/commandpanels/ioclasses/nbt/NBTManager.java @@ -1,17 +1,13 @@ package me.rockyhawk.commandpanels.ioclasses.nbt; -import de.tr7zw.changeme.nbtapi.NBT; import de.tr7zw.changeme.nbtapi.NBTItem; import me.rockyhawk.commandpanels.CommandPanels; import me.rockyhawk.commandpanels.api.Panel; import me.rockyhawk.commandpanels.openpanelsmanager.PanelPosition; -import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -import java.util.Objects; - public class NBTManager { CommandPanels plugin; public NBTManager(CommandPanels pl) { @@ -25,26 +21,77 @@ public class NBTManager { return nbtitem1.equals(nbtitem2); } - public ItemStack setNBT(ItemStack item, String key, String value) { - if (item != null) { - NBT.modify(item, nbt -> { - nbt.setString(key, value); - }); + public ItemStack setNBT(ItemStack item, String key, String type, String value) { + type = type.toLowerCase(); + if (item == null) { + throw new IllegalArgumentException("ItemStack cannot be null"); } + NBTItem nbtItem = new NBTItem(item); + + switch (type.toLowerCase()) { + case "byte": + nbtItem.setByte(key, Byte.valueOf(value)); + break; + case "boolean": + nbtItem.setBoolean(key, Boolean.valueOf(value)); + break; + case "short": + nbtItem.setShort(key, Short.valueOf(value)); + break; + case "integer": + nbtItem.setInteger(key, Integer.valueOf(value)); + break; + case "long": + nbtItem.setLong(key, Long.valueOf(value)); + break; + case "float": + nbtItem.setFloat(key, Float.valueOf(value)); + break; + case "double": + nbtItem.setDouble(key, Double.valueOf(value)); + break; + case "string": + nbtItem.setString(key, value); + break; + default: + throw new IllegalArgumentException("Unsupported NBT type: " + type); + } + item.setItemMeta(nbtItem.getItem().getItemMeta()); return item; } + public Object getNBT(ItemStack item, String key, String type) { + type = type.toLowerCase(); + NBTItem nbtItem = new NBTItem(item); + switch(type.toLowerCase()) { + case "byte": + return nbtItem.getByte(key); + case "boolean": + return nbtItem.getBoolean(key); + case "short": + return nbtItem.getShort(key); + case "integer": + return nbtItem.getInteger(key); + case "long": + return nbtItem.getLong(key); + case "float": + return nbtItem.getFloat(key); + case "double": + return nbtItem.getDouble(key); + case "string": + return nbtItem.getString(key); + default: + throw new IllegalArgumentException("Unsupported NBT type: " + type); + } + } + public boolean hasNBT(ItemStack item, String key){ NBTItem nbti = new NBTItem(item); return nbti.hasTag(key); } - public String getNBT(ItemStack item, String key){ - NBTItem nbti = new NBTItem(item); - if(!nbti.hasNBTData()) return ""; - return nbti.getString(key); - } - + //nbt will be assigned with the value "string_value_1 + //which uses the type "String" and value "value_1" public void applyNBTRecursively(String path, ConfigurationSection section, ItemStack s, Player p, Panel panel, PanelPosition position) { for (String key : section.getKeys(true)) { String fullPath = path.isEmpty() ? key : path + "." + key; @@ -53,8 +100,11 @@ public class NBTManager { applyNBTRecursively(fullPath, section.getConfigurationSection(key), s, p, panel, position); } else { // Set the NBT tag at this level - String value = plugin.tex.attachPlaceholders(panel, position, p, section.getString(key)); - s = plugin.nbt.setNBT(s, fullPath, value); + String wholeValue = plugin.tex.attachPlaceholders(panel, position, p, section.getString(key)); + int firstUnderscore = wholeValue.indexOf("_"); + String type = wholeValue.substring(0, firstUnderscore); + String value = wholeValue.substring(firstUnderscore + 1); + s = plugin.nbt.setNBT(s, fullPath, type, value); } } } diff --git a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java index 140cac9..ab5788c 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/HotbarItemLoader.java @@ -36,7 +36,7 @@ public class HotbarItemLoader { if(stationaryItems.get(p.getUniqueId()).list.containsKey(String.valueOf(slot))){ if(openPanel) { try { - if (!plugin.nbt.getNBT(p.getInventory().getItem(slot), "CommandPanelsHotbar").split(":")[1].equals(String.valueOf(slot))) { + if (!String.valueOf(plugin.nbt.getNBT(p.getInventory().getItem(slot), "CommandPanelsHotbar", "string")).split(":")[1].equals(String.valueOf(slot))) { return false; } }catch(Exception ex){ @@ -64,7 +64,7 @@ public class HotbarItemLoader { //return true if found public boolean itemCheckExecute(ItemStack invItem, Player p, boolean openPanel, boolean stationaryOnly){ try { - if (Objects.equals(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar"), "")) { + if (Objects.equals(String.valueOf(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar", "string")), "")) { return false; } }catch(IllegalArgumentException | NullPointerException nu){ @@ -73,13 +73,13 @@ public class HotbarItemLoader { for(Panel panel : plugin.panelList) { if(stationaryOnly){ try { - if (plugin.nbt.getNBT(invItem, "CommandPanelsHotbar").split(":")[1].equals("-1")) { + if (String.valueOf(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar", "string")).split(":")[1].equals("-1")) { continue; } }catch(NullPointerException | IllegalArgumentException ignore){} } if(panel.hasHotbarItem()){ - if(plugin.nbt.getNBT(invItem,"CommandPanelsHotbar").split(":")[0].equals(panel.getName())){ + if(String.valueOf(plugin.nbt.getNBT(invItem, "CommandPanelsHotbar", "string")).split(":")[0].equals(panel.getName())){ if(openPanel) { //only open panel automatically if there are no commands and if world is not disabled if(!plugin.panelPerms.isPanelWorldEnabled(p,panel.getConfig())){ @@ -120,9 +120,9 @@ public class HotbarItemLoader { stationaryItems.put(p.getUniqueId(),new HotbarPlayerManager()); for(int i = 0; i <= 35; i++){ try { - if (!Objects.equals(plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar"), "")) { + if (!Objects.equals(String.valueOf(plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar", "string")), "")) { //do not remove items that are not stationary - if(!plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar").endsWith("-1")) { + if(!String.valueOf(plugin.nbt.getNBT(p.getInventory().getItem(i), "CommandPanelsHotbar","string")).endsWith("-1")) { p.getInventory().setItem(i, new ItemStack(Material.AIR)); } } diff --git a/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java b/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java index 62c6785..0e3ab10 100644 --- a/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java +++ b/src/me/rockyhawk/commandpanels/openwithitem/UtilsOpenWithItem.java @@ -110,9 +110,9 @@ public class UtilsOpenWithItem implements Listener { try { for (ItemStack s : new ArrayList<>(e.getDrops())) { try { - if (!plugin.nbt.getNBT(s, "CommandPanelsHotbar").isEmpty()) { + if (!String.valueOf(plugin.nbt.getNBT(s, "CommandPanelsHotbar", "string")).isEmpty()) { //do not remove items that are not stationary - if (!plugin.nbt.getNBT(s, "CommandPanelsHotbar").endsWith("-1")) { + if (!String.valueOf(plugin.nbt.getNBT(s, "CommandPanelsHotbar", "string")).endsWith("-1")) { e.getDrops().remove(s); } }