From 672b9b6c219d5e46cec0b774a4347bb126b4f137 Mon Sep 17 00:00:00 2001 From: Jules Date: Thu, 20 Jun 2024 23:18:52 -0700 Subject: [PATCH] Fixed 'Unbreakable' not working in 1.20.5+ --- .../java/net/Indyuce/mmoitems/ItemStats.java | 2 +- ...abilityBar.java => HideDurabilityBar.java} | 6 +- .../Indyuce/mmoitems/stat/Unbreakable.java | 86 ++++++++++--------- 3 files changed, 50 insertions(+), 44 deletions(-) rename MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/{DurabilityBar.java => HideDurabilityBar.java} (55%) diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java index 5c4a6f1d..d81dbd48 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/ItemStats.java @@ -120,7 +120,7 @@ public class ItemStats { TWO_HANDED = new BooleanStat("TWO_HANDED", Material.IRON_INGOT, "Two Handed", new String[]{"If set to true, a player will be", "significantly slower if holding two", "items, one being Two Handed."}, new String[]{"handheld"}), REQUIRED_BIOMES = new RequiredBiomes(), DROP_ON_DEATH = new DisableDeathDrop(), - DURABILITY_BAR = new DurabilityBar(), + HIDE_DURABILITY_BAR = new HideDurabilityBar(), // Extra Attributes (1.20.2+) MAX_ABSORPTION = new MaxAbsorption(), diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DurabilityBar.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/HideDurabilityBar.java similarity index 55% rename from MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DurabilityBar.java rename to MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/HideDurabilityBar.java index 101c1109..42518226 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/DurabilityBar.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/HideDurabilityBar.java @@ -3,9 +3,9 @@ package net.Indyuce.mmoitems.stat; import net.Indyuce.mmoitems.stat.type.BooleanStat; import org.bukkit.Material; -public class DurabilityBar extends BooleanStat { - public DurabilityBar() { +public class HideDurabilityBar extends BooleanStat { + public HideDurabilityBar() { super("DURABILITY_BAR", Material.DAMAGED_ANVIL, "Hide Durability Bar", - new String[] { "Enable this to have the green bar", "hidden when using custom durability." }, new String[] { "!block", "all"}); + new String[] { "Enable this to have the green bar", "hidden when using &ncustom&7 durability.", "Does not work when using vanilla durability." }, new String[] { "!block", "all"}); } } diff --git a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Unbreakable.java b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Unbreakable.java index 96aca987..1966ccaf 100644 --- a/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Unbreakable.java +++ b/MMOItems-API/src/main/java/net/Indyuce/mmoitems/stat/Unbreakable.java @@ -15,54 +15,60 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; public class Unbreakable extends BooleanStat { - public Unbreakable() { - super("UNBREAKABLE", Material.ANVIL, "Unbreakable", new String[] { "Infinite durability if set to true." }, new String[0]); - } + public Unbreakable() { + super("UNBREAKABLE", Material.ANVIL, "Unbreakable", new String[]{"Infinite durability if set to true."}, new String[0]); + } - @Override - public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) { - if (((BooleanData) data).isEnabled()) { + @Override + public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) { + if (data.isEnabled()) { - // Hide unbreakable if - item.addItemTag(getAppliedNBT(data)); - item.getMeta().addItemFlags(ItemFlag.HIDE_UNBREAKABLE); - } - } + // Hide unbreakable if + item.getMeta().setUnbreakable(true); + item.addItemTag(getAppliedNBT(data)); // Save for backwards compatibility + item.getMeta().addItemFlags(ItemFlag.HIDE_UNBREAKABLE); + } + } - @NotNull - @Override - public ArrayList getAppliedNBT(@NotNull BooleanData data) { - ArrayList a = new ArrayList<>(); - if (((BooleanData) data).isEnabled()) { a.add(new ItemTag(getNBTPath(), true)); } - return a; - } + @NotNull + @Override + public ArrayList getAppliedNBT(@NotNull BooleanData data) { + ArrayList a = new ArrayList<>(); + if (data.isEnabled()) { + a.add(new ItemTag(getNBTPath(), true)); + } + return a; + } - @Override - public void whenLoaded(@NotNull ReadMMOItem mmoitem) { - ArrayList rTags = new ArrayList<>(); - if (mmoitem.getNBT().hasTag(getNBTPath())) - rTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.BOOLEAN)); - StatData data = getLoadedNBT(rTags); - if (data != null) { mmoitem.setData(this, data);} - } + @Override + public void whenLoaded(@NotNull ReadMMOItem mmoitem) { + ArrayList rTags = new ArrayList<>(); + if (mmoitem.getNBT().hasTag(getNBTPath())) + rTags.add(ItemTag.getTagAtPath(getNBTPath(), mmoitem.getNBT(), SupportedNBTTagValues.BOOLEAN)); + StatData data = getLoadedNBT(rTags); + if (data != null) { + mmoitem.setData(this, data); + } + } - @Nullable - @Override - public BooleanData getLoadedNBT(@NotNull ArrayList storedTags) { + @Nullable + @Override + public BooleanData getLoadedNBT(@NotNull ArrayList storedTags) { - ItemTag uTag = ItemTag.getTagAtPath(getNBTPath(), storedTags); + ItemTag uTag = ItemTag.getTagAtPath(getNBTPath(), storedTags); - if (uTag != null) { + if (uTag != null) { - // As Boolean - return new BooleanData((boolean) uTag.getValue()); - } + // As Boolean + return new BooleanData((boolean) uTag.getValue()); + } - return null; - } + return null; + } - @Override - @NotNull public String getNBTPath() { - return "Unbreakable"; - } + @Override + @NotNull + public String getNBTPath() { + return "Unbreakable"; + } }