Fixed 'Unbreakable' not working in 1.20.5+

This commit is contained in:
Jules 2024-06-20 23:18:52 -07:00
parent 90520347fb
commit 672b9b6c21
3 changed files with 50 additions and 44 deletions

View File

@ -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(),

View File

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

View File

@ -21,10 +21,11 @@ public class Unbreakable extends BooleanStat {
@Override
public void whenApplied(@NotNull ItemStackBuilder item, @NotNull BooleanData data) {
if (((BooleanData) data).isEnabled()) {
if (data.isEnabled()) {
// Hide unbreakable if
item.addItemTag(getAppliedNBT(data));
item.getMeta().setUnbreakable(true);
item.addItemTag(getAppliedNBT(data)); // Save for backwards compatibility
item.getMeta().addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
}
}
@ -33,7 +34,9 @@ public class Unbreakable extends BooleanStat {
@Override
public ArrayList<ItemTag> getAppliedNBT(@NotNull BooleanData data) {
ArrayList<ItemTag> a = new ArrayList<>();
if (((BooleanData) data).isEnabled()) { a.add(new ItemTag(getNBTPath(), true)); }
if (data.isEnabled()) {
a.add(new ItemTag(getNBTPath(), true));
}
return a;
}
@ -43,7 +46,9 @@ public class Unbreakable extends BooleanStat {
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);}
if (data != null) {
mmoitem.setData(this, data);
}
}
@Nullable
@ -62,7 +67,8 @@ public class Unbreakable extends BooleanStat {
}
@Override
@NotNull public String getNBTPath() {
@NotNull
public String getNBTPath() {
return "Unbreakable";
}
}