Archiviert
13
0

Add Unbreakable to ItemMeta

Dieser Commit ist enthalten in:
md_5 2016-11-22 14:35:54 +11:00
Ursprung 7359112e8c
Commit a64b99c95a

Datei anzeigen

@ -211,12 +211,15 @@ class CraftMetaItem implements ItemMeta, Repairable {
static final ItemMetaKey ATTRIBUTES_UUID_LOW = new ItemMetaKey("UUIDLeast"); static final ItemMetaKey ATTRIBUTES_UUID_LOW = new ItemMetaKey("UUIDLeast");
@Specific(Specific.To.NBT) @Specific(Specific.To.NBT)
static final ItemMetaKey HIDEFLAGS = new ItemMetaKey("HideFlags", "ItemFlags"); static final ItemMetaKey HIDEFLAGS = new ItemMetaKey("HideFlags", "ItemFlags");
@Specific(Specific.To.NBT)
static final ItemMetaKey UNBREAKABLE = new ItemMetaKey("Unbreakable");
private String displayName; private String displayName;
private List<String> lore; private List<String> lore;
private Map<Enchantment, Integer> enchantments; private Map<Enchantment, Integer> enchantments;
private int repairCost; private int repairCost;
private int hideFlag; private int hideFlag;
private boolean unbreakable;
private static final Set<String> HANDLED_TAGS = Sets.newHashSet(); private static final Set<String> HANDLED_TAGS = Sets.newHashSet();
@ -239,6 +242,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
this.repairCost = meta.repairCost; this.repairCost = meta.repairCost;
this.hideFlag = meta.hideFlag; this.hideFlag = meta.hideFlag;
this.unbreakable = meta.unbreakable;
this.unhandledTags.putAll(meta.unhandledTags); this.unhandledTags.putAll(meta.unhandledTags);
} }
@ -270,6 +274,9 @@ class CraftMetaItem implements ItemMeta, Repairable {
if (tag.hasKey(HIDEFLAGS.NBT)) { if (tag.hasKey(HIDEFLAGS.NBT)) {
hideFlag = tag.getInt(HIDEFLAGS.NBT); hideFlag = tag.getInt(HIDEFLAGS.NBT);
} }
if (tag.hasKey(UNBREAKABLE.NBT)) {
unbreakable = tag.getBoolean(UNBREAKABLE.NBT);
}
if (tag.get(ATTRIBUTES.NBT) instanceof NBTTagList) { if (tag.get(ATTRIBUTES.NBT) instanceof NBTTagList) {
NBTTagList save = null; NBTTagList save = null;
@ -371,6 +378,11 @@ class CraftMetaItem implements ItemMeta, Repairable {
} }
} }
Boolean unbreakable = SerializableMeta.getObject(Boolean.class, map, UNBREAKABLE.BUKKIT, true);
if (unbreakable != null) {
setUnbreakable(unbreakable);
}
String internal = SerializableMeta.getString(map, "internal", true); String internal = SerializableMeta.getString(map, "internal", true);
if (internal != null) { if (internal != null) {
ByteArrayInputStream buf = new ByteArrayInputStream(Base64.decodeBase64(internal)); ByteArrayInputStream buf = new ByteArrayInputStream(Base64.decodeBase64(internal));
@ -430,6 +442,10 @@ class CraftMetaItem implements ItemMeta, Repairable {
itemTag.setInt(REPAIR.NBT, repairCost); itemTag.setInt(REPAIR.NBT, repairCost);
} }
if (isUnbreakable()) {
itemTag.setBoolean(UNBREAKABLE.NBT, unbreakable);
}
for (Map.Entry<String, NBTBase> e : unhandledTags.entrySet()) { for (Map.Entry<String, NBTBase> e : unhandledTags.entrySet()) {
itemTag.set(e.getKey(), e.getValue()); itemTag.set(e.getKey(), e.getValue());
} }
@ -484,7 +500,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
@Overridden @Overridden
boolean isEmpty() { boolean isEmpty() {
return !(hasDisplayName() || hasEnchants() || hasLore() || hasRepairCost() || !unhandledTags.isEmpty() || hideFlag != 0); return !(hasDisplayName() || hasEnchants() || hasLore() || hasRepairCost() || !unhandledTags.isEmpty() || hideFlag != 0 || isUnbreakable());
} }
public String getDisplayName() { public String getDisplayName() {
@ -609,6 +625,16 @@ class CraftMetaItem implements ItemMeta, Repairable {
repairCost = cost; repairCost = cost;
} }
@Override
public boolean isUnbreakable() {
return unbreakable;
}
@Override
public void setUnbreakable(boolean unbreakable) {
this.unbreakable = unbreakable;
}
@Override @Override
public final boolean equals(Object object) { public final boolean equals(Object object) {
if (object == null) { if (object == null) {
@ -635,7 +661,8 @@ class CraftMetaItem implements ItemMeta, Repairable {
&& (this.hasLore() ? that.hasLore() && this.lore.equals(that.lore) : !that.hasLore()) && (this.hasLore() ? that.hasLore() && this.lore.equals(that.lore) : !that.hasLore())
&& (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost()) && (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost())
&& (this.unhandledTags.equals(that.unhandledTags)) && (this.unhandledTags.equals(that.unhandledTags))
&& (this.hideFlag == that.hideFlag); && (this.hideFlag == that.hideFlag)
&& (this.isUnbreakable() == that.isUnbreakable());
} }
/** /**
@ -662,6 +689,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
hash = 61 * hash + (hasRepairCost() ? this.repairCost : 0); hash = 61 * hash + (hasRepairCost() ? this.repairCost : 0);
hash = 61 * hash + unhandledTags.hashCode(); hash = 61 * hash + unhandledTags.hashCode();
hash = 61 * hash + hideFlag; hash = 61 * hash + hideFlag;
hash = 61 * hash + (isUnbreakable() ? 1231 : 1237);
return hash; return hash;
} }
@ -677,6 +705,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
clone.enchantments = new HashMap<Enchantment, Integer>(this.enchantments); clone.enchantments = new HashMap<Enchantment, Integer>(this.enchantments);
} }
clone.hideFlag = this.hideFlag; clone.hideFlag = this.hideFlag;
clone.unbreakable = this.unbreakable;
return clone; return clone;
} catch (CloneNotSupportedException e) { } catch (CloneNotSupportedException e) {
throw new Error(e); throw new Error(e);
@ -714,6 +743,10 @@ class CraftMetaItem implements ItemMeta, Repairable {
builder.put(HIDEFLAGS.BUKKIT, hideFlags); builder.put(HIDEFLAGS.BUKKIT, hideFlags);
} }
if (isUnbreakable()) {
builder.put(UNBREAKABLE.BUKKIT, unbreakable);
}
final Map<String, NBTBase> internalTags = new HashMap<String, NBTBase>(unhandledTags); final Map<String, NBTBase> internalTags = new HashMap<String, NBTBase>(unhandledTags);
serializeInternal(internalTags); serializeInternal(internalTags);
if (!internalTags.isEmpty()) { if (!internalTags.isEmpty()) {
@ -800,6 +833,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
REPAIR.NBT, REPAIR.NBT,
ENCHANTMENTS.NBT, ENCHANTMENTS.NBT,
HIDEFLAGS.NBT, HIDEFLAGS.NBT,
UNBREAKABLE.NBT,
CraftMetaMap.MAP_SCALING.NBT, CraftMetaMap.MAP_SCALING.NBT,
CraftMetaPotion.POTION_EFFECTS.NBT, CraftMetaPotion.POTION_EFFECTS.NBT,
CraftMetaPotion.DEFAULT_POTION.NBT, CraftMetaPotion.DEFAULT_POTION.NBT,