143 lines
5.4 KiB
Diff
143 lines
5.4 KiB
Diff
From fcff84cefce17a4b1ce7d468a6e5a868e972e5c0 Mon Sep 17 00:00:00 2001
|
|
From: libraryaddict <redwarfare@live.com>
|
|
Date: Fri, 22 Aug 2014 05:35:16 -0400
|
|
Subject: [PATCH] Added isUnbreakable and setUnbreakable to ItemMeta
|
|
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
index 88b197d..bc35387 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
@@ -217,6 +217,8 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
static final ItemMetaKey ATTRIBUTES_UUID_LOW = new ItemMetaKey("UUIDLeast");
|
|
@Specific(Specific.To.NBT)
|
|
static final ItemMetaKey HIDEFLAGS = new ItemMetaKey("HideFlags", "ItemFlags");
|
|
+ @Specific(Specific.To.NBT)
|
|
+ static final ItemMetaKey UNBREAKABLE = new ItemMetaKey("Unbreakable"); // Spigot
|
|
|
|
private String displayName;
|
|
private List<String> lore;
|
|
@@ -246,6 +248,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
this.repairCost = meta.repairCost;
|
|
this.hideFlag = meta.hideFlag;
|
|
this.unhandledTags.putAll(meta.unhandledTags);
|
|
+ spigot.setUnbreakable( meta.spigot.isUnbreakable() ); // Spigot
|
|
}
|
|
|
|
CraftMetaItem(NBTTagCompound tag) {
|
|
@@ -446,6 +449,12 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
unhandledTags.put(key, tag.get(key));
|
|
}
|
|
}
|
|
+ // Spigot start
|
|
+ if ( tag.hasKey( UNBREAKABLE.NBT ) )
|
|
+ {
|
|
+ spigot.setUnbreakable( tag.getBoolean( UNBREAKABLE.NBT ) );
|
|
+ }
|
|
+ // Spigot end
|
|
}
|
|
|
|
static Map<Enchantment, Integer> buildEnchantments(NBTTagCompound tag, ItemMetaKey key) {
|
|
@@ -498,6 +507,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
}
|
|
}
|
|
|
|
+ // Spigot start
|
|
+ Boolean unbreakable = SerializableMeta.getObject( Boolean.class, map, UNBREAKABLE.BUKKIT, true );
|
|
+ if ( unbreakable != null )
|
|
+ {
|
|
+ spigot.setUnbreakable( unbreakable );
|
|
+ }
|
|
+ // Spigot end
|
|
+
|
|
String internal = SerializableMeta.getString(map, "internal", true);
|
|
if (internal != null) {
|
|
ByteArrayInputStream buf = new ByteArrayInputStream(Base64.decodeBase64(internal));
|
|
@@ -552,6 +569,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
}
|
|
|
|
applyEnchantments(enchantments, itemTag, ENCHANTMENTS);
|
|
+
|
|
+ // Spigot start
|
|
+ if ( spigot.isUnbreakable() )
|
|
+ {
|
|
+ itemTag.setBoolean( UNBREAKABLE.NBT, true );
|
|
+ }
|
|
+ // Spigot end
|
|
+
|
|
|
|
if (hasRepairCost()) {
|
|
itemTag.setInt(REPAIR.NBT, repairCost);
|
|
@@ -611,7 +636,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
|
|
@Overridden
|
|
boolean isEmpty() {
|
|
- return !(hasDisplayName() || hasEnchants() || hasLore() || hasRepairCost() || !unhandledTags.isEmpty() || hideFlag != 0);
|
|
+ return !(hasDisplayName() || hasEnchants() || hasLore() || hasRepairCost() || !unhandledTags.isEmpty() || hideFlag != 0 || spigot.isUnbreakable()); // Spigot
|
|
}
|
|
|
|
public String getDisplayName() {
|
|
@@ -769,7 +794,8 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
&& (this.hasLore() ? that.hasLore() && this.lore.equals(that.lore) : !that.hasLore())
|
|
&& (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost())
|
|
&& (this.unhandledTags.equals(that.unhandledTags))
|
|
- && (this.hideFlag == that.hideFlag);
|
|
+ && (this.hideFlag == that.hideFlag)
|
|
+ && (this.spigot.isUnbreakable() == that.spigot.isUnbreakable()); // Spigot
|
|
}
|
|
|
|
/**
|
|
@@ -796,6 +822,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
hash = 61 * hash + (hasRepairCost() ? this.repairCost : 0);
|
|
hash = 61 * hash + unhandledTags.hashCode();
|
|
hash = 61 * hash + hideFlag;
|
|
+ hash = 61 * hash + (spigot.isUnbreakable() ? 1231 : 1237); // Spigot
|
|
return hash;
|
|
}
|
|
|
|
@@ -839,6 +866,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
if (hasRepairCost()) {
|
|
builder.put(REPAIR.BUKKIT, repairCost);
|
|
}
|
|
+
|
|
+ // Spigot start
|
|
+ if ( spigot.isUnbreakable() )
|
|
+ {
|
|
+ builder.put( UNBREAKABLE.BUKKIT, true );
|
|
+ }
|
|
+ // Spigot end
|
|
+
|
|
|
|
Set<String> hideFlags = new HashSet<String>();
|
|
for (ItemFlag hideFlagEnum : getItemFlags()) {
|
|
@@ -930,6 +965,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
synchronized (HANDLED_TAGS) {
|
|
if (HANDLED_TAGS.isEmpty()) {
|
|
HANDLED_TAGS.addAll(Arrays.asList(
|
|
+ UNBREAKABLE.NBT, // Spigot
|
|
DISPLAY.NBT,
|
|
REPAIR.NBT,
|
|
ENCHANTMENTS.NBT,
|
|
@@ -956,6 +992,19 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
// Spigot start
|
|
private final Spigot spigot = new Spigot()
|
|
{
|
|
+ private boolean unbreakable;
|
|
+
|
|
+ @Override
|
|
+ public void setUnbreakable(boolean setUnbreakable)
|
|
+ {
|
|
+ unbreakable = setUnbreakable;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public boolean isUnbreakable()
|
|
+ {
|
|
+ return unbreakable;
|
|
+ }
|
|
};
|
|
|
|
@Override
|
|
--
|
|
2.1.4
|
|
|