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

@ -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<ItemTag> getAppliedNBT(@NotNull BooleanData data) {
ArrayList<ItemTag> a = new ArrayList<>();
if (((BooleanData) data).isEnabled()) { a.add(new ItemTag(getNBTPath(), true)); }
return a;
}
@NotNull
@Override
public ArrayList<ItemTag> getAppliedNBT(@NotNull BooleanData data) {
ArrayList<ItemTag> a = new ArrayList<>();
if (data.isEnabled()) {
a.add(new ItemTag(getNBTPath(), true));
}
return a;
}
@Override
public void whenLoaded(@NotNull ReadMMOItem mmoitem) {
ArrayList<ItemTag> 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<ItemTag> 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<ItemTag> storedTags) {
@Nullable
@Override
public BooleanData getLoadedNBT(@NotNull ArrayList<ItemTag> 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";
}
}