mirror of
https://gitlab.com/phoenix-dvpmt/mmoitems.git
synced 2024-12-22 04:37:42 +01:00
Fixed 'Unbreakable' not working in 1.20.5+
This commit is contained in:
parent
90520347fb
commit
672b9b6c21
@ -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(),
|
||||
|
@ -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"});
|
||||
}
|
||||
}
|
@ -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";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user