From 7f330ae1297162a4b64fe870baff5153aa4e830c Mon Sep 17 00:00:00 2001 From: Jules Date: Wed, 19 Jun 2024 17:52:41 -0700 Subject: [PATCH] Removed some usages of NBTTags --- .../net/Indyuce/mmoitems/gui/ItemBrowser.java | 19 ++++++++++--------- .../mmoitems/gui/edition/AbilityEdition.java | 16 +++++++--------- .../gui/edition/AbilityListEdition.java | 15 +++++++-------- .../gui/edition/CommandListEdition.java | 13 ++++++++----- .../mmoitems/gui/edition/ItemEdition.java | 13 +++++++------ .../gui/edition/ParticlesEdition.java | 16 ++++++++-------- .../Indyuce/mmoitems/stat/RequiredLevel.java | 6 ++---- 7 files changed, 49 insertions(+), 49 deletions(-) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java index 70fa90ee..06f728d6 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/ItemBrowser.java @@ -1,7 +1,6 @@ package net.Indyuce.mmoitems.gui; import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.api.util.ui.SilentNumbers; @@ -13,10 +12,7 @@ import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.gui.edition.ItemEdition; import net.Indyuce.mmoitems.stat.BrowserDisplayIDX; import net.Indyuce.mmoitems.util.MMOUtils; -import org.bukkit.Bukkit; -import org.bukkit.ChatColor; -import org.bukkit.Material; -import org.bukkit.Sound; +import org.bukkit.*; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; @@ -24,6 +20,7 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataType; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -41,6 +38,7 @@ public class ItemBrowser extends PluginInventory { private static final int[] slotsAlt = {1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 14, 15, 16, 19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34}; private static final String CUSTOM_RP_DOWNLOAD_LINK = "https://www.dropbox.com/s/90w9pvdbfeyxu94/MICustomBlockPack.zip?dl=1"; + private static final NamespacedKey TYPE_ID_KEY = new NamespacedKey(MMOItems.plugin, "TypeId"); public ItemBrowser(Player player) { this(player, null); @@ -85,7 +83,7 @@ public class ItemBrowser extends PluginInventory { int items = MMOItems.plugin.getTemplates().getTemplates(currentType).size(); // Display how many items are in the type - ItemStack item = currentType.getItem(); + final ItemStack item = currentType.getItem(); item.setAmount(Math.max(1, Math.min(64, items))); ItemMeta meta = item.getItemMeta(); AdventureUtils.setDisplayName(meta, String.format("&a%s&8 (click to browse)", currentType.getName())); @@ -93,10 +91,11 @@ public class ItemBrowser extends PluginInventory { List lore = new ArrayList<>(); lore.add(String.format("&7&oThere %s %s &7&oitem%s in this type.", items == 1 ? "is" : "are", items < 1 ? "&c&ono" : "&6&o" + items, items == 1 ? "" : "s")); AdventureUtils.setLore(meta, lore); + meta.getPersistentDataContainer().set(TYPE_ID_KEY, PersistentDataType.STRING, currentType.getId()); item.setItemMeta(meta); // Set item - inv.setItem(slots[n++], NBTItem.get(item).addTag(new ItemTag("typeId", currentType.getId())).toItem()); + inv.setItem(slots[n++], item); } // Fill remainder slots with 'No Type' notice @@ -363,8 +362,10 @@ public class ItemBrowser extends PluginInventory { MythicLib.plugin.getVersion().getWrapper().sendJson(getPlayer(), "[{\"text\":\"Click to download!\",\"color\":\"green\",\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + CUSTOM_RP_DOWNLOAD_LINK + "\"},\"hoverEvent\":{\"action\":\"show_text\",\"value\":[\"\",{\"text\":\"Click to download via Dropbox\",\"italic\":true,\"color\":\"white\"}]}}]"); getPlayer().closeInventory(); - } else if (type == null && !item.getItemMeta().getDisplayName().equals(ChatColor.RED + "- No type -")) - new ItemBrowser(getPlayer(), MMOItems.plugin.getTypes().get(NBTItem.get(item).getString("typeId"))).open(); + } else if (type == null && !item.getItemMeta().getDisplayName().equals(ChatColor.RED + "- No type -")) { + final String typeId = item.getItemMeta().getPersistentDataContainer().get(TYPE_ID_KEY, PersistentDataType.STRING); + new ItemBrowser(getPlayer(), MMOItems.plugin.getTypes().get(typeId)).open(); + } } String id = NBTItem.get(item).getString("MMOITEMS_ITEM_ID"); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java index c24332e9..f7d87484 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityEdition.java @@ -1,8 +1,6 @@ package net.Indyuce.mmoitems.gui.edition; -import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.UtilityMethods; -import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.skill.trigger.TriggerType; import net.Indyuce.mmoitems.ItemStats; @@ -14,12 +12,14 @@ import net.Indyuce.mmoitems.skill.RegisteredSkill; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataType; import java.text.DecimalFormat; import java.util.ArrayList; @@ -32,6 +32,7 @@ public class AbilityEdition extends EditionInventory { private static final DecimalFormat MODIFIER_FORMAT = new DecimalFormat("0.###"); private static final int[] slots = { 23, 24, 25, 32, 33, 34, 41, 42, 43, 50, 51, 52 }; + private static final NamespacedKey ABILITY_MOD_KEY = new NamespacedKey(MMOItems.plugin, "AbilityModifier"); public AbilityEdition(Player player, MMOItemTemplate template, String configKey) { super(player, template); @@ -98,7 +99,7 @@ public class AbilityEdition extends EditionInventory { if (ability != null) { ConfigurationSection section = getEditedSection().getConfigurationSection("ability." + configKey); for (String modifier : ability.getHandler().getModifiers()) { - ItemStack modifierItem = new ItemStack(Material.GRAY_DYE); + final ItemStack modifierItem = new ItemStack(Material.GRAY_DYE); ItemMeta modifierItemMeta = modifierItem.getItemMeta(); modifierItemMeta.setDisplayName(ChatColor.GREEN + UtilityMethods.caseOnWords(modifier.toLowerCase().replace("-", " "))); List modifierItemLore = new ArrayList<>(); @@ -119,11 +120,9 @@ public class AbilityEdition extends EditionInventory { modifierItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Click to change this value."); modifierItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to reset."); modifierItemMeta.setLore(modifierItemLore); + modifierItemMeta.getPersistentDataContainer().set(ABILITY_MOD_KEY, PersistentDataType.STRING, modifier); modifierItem.setItemMeta(modifierItemMeta); - modifierItem = MythicLib.plugin.getVersion().getWrapper().getNBTItem(modifierItem).addTag(new ItemTag("abilityModifier", modifier)) - .toItem(); - inventory.setItem(slots[n++], modifierItem); } } @@ -190,9 +189,8 @@ public class AbilityEdition extends EditionInventory { return; } - String tag = MythicLib.plugin.getVersion().getWrapper().getNBTItem(item).getString("abilityModifier"); - if (tag.equals("")) - return; + final String tag = item.getItemMeta().getPersistentDataContainer().get(ABILITY_MOD_KEY, PersistentDataType.STRING); + if (tag == null || tag.equals("")) return; if (event.getAction() == InventoryAction.PICKUP_ALL) new StatEdition(this, ItemStats.ABILITIES, configKey, tag).enable("Write in the chat the value you want."); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityListEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityListEdition.java index d41e7c91..2be016a8 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityListEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/AbilityListEdition.java @@ -1,8 +1,6 @@ package net.Indyuce.mmoitems.gui.edition; -import io.lumine.mythic.lib.MythicLib; import io.lumine.mythic.lib.UtilityMethods; -import io.lumine.mythic.lib.api.item.ItemTag; import io.lumine.mythic.lib.api.util.AltChar; import io.lumine.mythic.lib.skill.trigger.TriggerType; import net.Indyuce.mmoitems.MMOItems; @@ -12,17 +10,20 @@ import net.Indyuce.mmoitems.skill.RegisteredSkill; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataType; import java.util.ArrayList; import java.util.List; public class AbilityListEdition extends EditionInventory { private static final int[] slots = { 19, 20, 21, 22, 23, 24, 25 }; + private static final NamespacedKey CONFIG_KEY = new NamespacedKey(MMOItems.plugin, "ConfigKey"); public AbilityListEdition(Player player, MMOItemTemplate template) { super(player, template); @@ -52,7 +53,7 @@ public class AbilityListEdition extends EditionInventory { castMode = null; } - ItemStack abilityItem = new ItemStack(Material.BLAZE_POWDER); + final ItemStack abilityItem = new ItemStack(Material.BLAZE_POWDER); ItemMeta abilityItemMeta = abilityItem.getItemMeta(); abilityItemMeta.setDisplayName(ability != null ? ChatColor.GREEN + ability.getName() : ChatColor.RED + "! No Ability Selected !"); List abilityItemLore = new ArrayList<>(); @@ -80,10 +81,9 @@ public class AbilityListEdition extends EditionInventory { abilityItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Left click to edit."); abilityItemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove."); abilityItemMeta.setLore(abilityItemLore); + abilityItemMeta.getPersistentDataContainer().set(CONFIG_KEY, PersistentDataType.STRING, key); abilityItem.setItemMeta(abilityItemMeta); - abilityItem = MythicLib.plugin.getVersion().getWrapper().getNBTItem(abilityItem).addTag(new ItemTag("configKey", key)).toItem(); - inventory.setItem(slots[n++], abilityItem); } @@ -130,9 +130,8 @@ public class AbilityListEdition extends EditionInventory { } } - String tag = MythicLib.plugin.getVersion().getWrapper().getNBTItem(item).getString("configKey"); - if (tag.equals("")) - return; + final String tag = item.getItemMeta().getPersistentDataContainer().get(CONFIG_KEY, PersistentDataType.STRING); + if (tag == null || tag.equals("")) return; if (event.getAction() == InventoryAction.PICKUP_ALL) new AbilityEdition(player, template, tag).open(this); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/CommandListEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/CommandListEdition.java index b39f3f99..c6fd91ba 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/CommandListEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/CommandListEdition.java @@ -11,17 +11,20 @@ import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataType; import java.util.ArrayList; import java.util.List; public class CommandListEdition extends EditionInventory { private static final int[] slots = { 19, 20, 21, 22, 23, 24, 25, 28, 29, 33, 34, 37, 38, 42, 43 }; + private static final NamespacedKey CONFIG_KEY = new NamespacedKey(MMOItems.plugin, "ConfigKey"); public CommandListEdition(Player player, MMOItemTemplate template) { super(player, template); @@ -44,7 +47,7 @@ public class CommandListEdition extends EditionInventory { boolean console = getEditedSection().getBoolean("commands." + key + ".console"), op = getEditedSection().getBoolean("commands." + key + ".op"); - ItemStack item = new ItemStack(Material.COMPARATOR); + final ItemStack item = new ItemStack(Material.COMPARATOR); ItemMeta itemMeta = item.getItemMeta(); itemMeta.setDisplayName(format == null || format.equals("") ? ChatColor.RED + "No Format" : ChatColor.GREEN + format); List itemLore = new ArrayList<>(); @@ -55,9 +58,10 @@ public class CommandListEdition extends EditionInventory { itemLore.add(""); itemLore.add(ChatColor.YELLOW + AltChar.listDash + " Right click to remove."); itemMeta.setLore(itemLore); + itemMeta.getPersistentDataContainer().set(CONFIG_KEY, PersistentDataType.STRING, key); item.setItemMeta(itemMeta); - inventory.setItem(slots[n++], NBTItem.get(item).addTag(new ItemTag("configKey", key)).toItem()); + inventory.setItem(slots[n++], item); } ItemStack glass = new ItemStack(Material.GRAY_STAINED_GLASS_PANE); @@ -90,9 +94,8 @@ public class CommandListEdition extends EditionInventory { return; } - String tag = MythicLib.plugin.getVersion().getWrapper().getNBTItem(item).getString("configKey"); - if (tag.equals("")) - return; + final String tag = item.getItemMeta().getPersistentDataContainer().get(CONFIG_KEY, PersistentDataType.STRING); + if (tag == null || tag.equals("")) return; if (event.getAction() == InventoryAction.PICKUP_HALF) { if (getEditedSection().contains("commands") && getEditedSection().getConfigurationSection("commands").contains(tag)) { diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java index d21c340f..c13c2696 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ItemEdition.java @@ -1,8 +1,6 @@ package net.Indyuce.mmoitems.gui.edition; import io.lumine.mythic.lib.MythicLib; -import io.lumine.mythic.lib.api.item.ItemTag; -import io.lumine.mythic.lib.api.item.NBTItem; import net.Indyuce.mmoitems.MMOItems; import net.Indyuce.mmoitems.api.item.template.MMOItemTemplate; import net.Indyuce.mmoitems.stat.type.InternalStat; @@ -10,11 +8,13 @@ import net.Indyuce.mmoitems.stat.type.ItemStat; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.entity.Player; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataType; import java.util.ArrayList; import java.util.Arrays; @@ -23,6 +23,7 @@ import java.util.stream.Collectors; public class ItemEdition extends EditionInventory { private static final int[] slots = {19, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, 32, 33, 34, 37, 38, 39, 40, 41, 42, 43}; + private static final NamespacedKey STAT_ID_KEY = new NamespacedKey(MMOItems.plugin,"StatId"); public ItemEdition(Player player, MMOItemTemplate template) { super(player, template); @@ -57,9 +58,10 @@ public class ItemEdition extends EditionInventory { stat.whenDisplayed(lore, getEventualStatData(stat)); + meta.getPersistentDataContainer().set(STAT_ID_KEY, PersistentDataType.STRING, stat.getId()); meta.setLore(lore); item.setItemMeta(meta); - inventory.setItem(slots[n++], MythicLib.plugin.getVersion().getWrapper().getNBTItem(item).addTag(new ItemTag("guiStat", stat.getId())).toItem()); + inventory.setItem(slots[n++], item); } ItemStack glass = new ItemStack(Material.GRAY_STAINED_GLASS_PANE); @@ -103,9 +105,8 @@ public class ItemEdition extends EditionInventory { refreshInventory(); } - final String tag = NBTItem.get(item).getString("guiStat"); - if (tag.isEmpty()) - return; + final String tag = item.getItemMeta().getPersistentDataContainer().get(STAT_ID_KEY, PersistentDataType.STRING); + if (tag == null || tag.isEmpty()) return; // Check for OP stats final ItemStat edited = MMOItems.plugin.getStats().get(tag); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ParticlesEdition.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ParticlesEdition.java index 8633476f..d299f52f 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ParticlesEdition.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/gui/edition/ParticlesEdition.java @@ -1,8 +1,6 @@ package net.Indyuce.mmoitems.gui.edition; import io.lumine.mythic.lib.UtilityMethods; -import io.lumine.mythic.lib.api.item.ItemTag; -import io.lumine.mythic.lib.api.item.NBTItem; import io.lumine.mythic.lib.api.util.AltChar; import net.Indyuce.mmoitems.ItemStats; import net.Indyuce.mmoitems.MMOItems; @@ -12,6 +10,7 @@ import net.Indyuce.mmoitems.particle.api.ParticleType; import net.Indyuce.mmoitems.util.MMOUtils; import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.NamespacedKey; import org.bukkit.Particle; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.entity.Player; @@ -19,12 +18,15 @@ import org.bukkit.event.inventory.InventoryAction; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import org.bukkit.persistence.PersistentDataType; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.List; public class ParticlesEdition extends EditionInventory { + private static final NamespacedKey PATTERN_MODIFIED_KEY = new NamespacedKey(MMOItems.plugin, "PatternModifierId"); + public ParticlesEdition(Player player, MMOItemTemplate template) { super(player, template); } @@ -67,7 +69,7 @@ public class ParticlesEdition extends EditionInventory { if (particleType != null) { ConfigurationSection psection = getEditedSection().getConfigurationSection("item-particles"); for (String modifier : particleType.getModifiers()) { - ItemStack modifierItem = new ItemStack(Material.GRAY_DYE); + final ItemStack modifierItem = new ItemStack(Material.GRAY_DYE); ItemMeta modifierItemMeta = modifierItem.getItemMeta(); modifierItemMeta.setDisplayName(ChatColor.GREEN + UtilityMethods.caseOnWords(modifier.toLowerCase().replace("-", " "))); List modifierItemLore = new ArrayList<>(); @@ -78,10 +80,9 @@ public class ParticlesEdition extends EditionInventory { modifierItemLore.add(ChatColor.GRAY + "Current Value: " + ChatColor.GOLD + (psection.contains(modifier) ? psection.getDouble(modifier) : particleType.getModifier(modifier))); modifierItemMeta.setLore(modifierItemLore); + modifierItemMeta.getPersistentDataContainer().set(PATTERN_MODIFIED_KEY, PersistentDataType.STRING, modifier); modifierItem.setItemMeta(modifierItemMeta); - modifierItem = NBTItem.get(modifierItem).addTag(new ItemTag("patternModifierId", modifier)).toItem(); - inventory.setItem(slots[n++], modifierItem); } } @@ -201,9 +202,8 @@ public class ParticlesEdition extends EditionInventory { } } - String tag = NBTItem.get(item).getString("patternModifierId"); - if (tag.equals("")) - return; + final String tag = item.getItemMeta().getPersistentDataContainer().get(PATTERN_MODIFIED_KEY, PersistentDataType.STRING); + if (tag == null || tag.equals("")) return; if (event.getAction() == InventoryAction.PICKUP_ALL) new StatEdition(this, ItemStats.ITEM_PARTICLES, tag).enable("Write in the chat the value you want."); diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredLevel.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredLevel.java index 0c932019..6d4a5c00 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredLevel.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/RequiredLevel.java @@ -37,12 +37,10 @@ public class RequiredLevel extends DoubleStat implements ItemRestriction { @Override public void whenApplied(@NotNull ItemStackBuilder item, @NotNull DoubleData data) { + final int lvl = (int) data.getValue(); + if (lvl <= 0) return; - // Lore Management - int lvl = (int) data.getValue(); item.getLore().insert(getPath(), DoubleStat.formatPath(getPath(), getGeneralStatFormat(), false, false, lvl)); - - // Insert NBT item.addItemTag(getAppliedNBT(data)); }