2015-01-18 19:17:11 +01:00
|
|
|
From 0eaa3a328cc7659f59ae42d9625283bbf42b42b5 Mon Sep 17 00:00:00 2001
|
2014-08-25 23:30:52 +02:00
|
|
|
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
|
2015-01-18 19:17:11 +01:00
|
|
|
index fef0971..64639b9 100644
|
2014-08-25 23:30:52 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2014-12-19 00:33:08 +01:00
|
|
|
@@ -207,6 +207,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-08-25 23:30:52 +02:00
|
|
|
static final ItemMetaKey ATTRIBUTES_UUID_HIGH = new ItemMetaKey("UUIDMost");
|
|
|
|
@Specific(Specific.To.NBT)
|
|
|
|
static final ItemMetaKey ATTRIBUTES_UUID_LOW = new ItemMetaKey("UUIDLeast");
|
|
|
|
+ static final ItemMetaKey UNBREAKABLE = new ItemMetaKey("Unbreakable"); // Spigot
|
|
|
|
|
|
|
|
private String displayName;
|
|
|
|
private List<String> lore;
|
2014-12-19 00:33:08 +01:00
|
|
|
@@ -237,6 +238,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-08-25 23:30:52 +02:00
|
|
|
this.repairCost = meta.repairCost;
|
|
|
|
this.attributes = meta.attributes;
|
2014-12-19 00:33:08 +01:00
|
|
|
this.unhandledTags.putAll(meta.unhandledTags);
|
2014-08-25 23:30:52 +02:00
|
|
|
+ spigot.setUnbreakable( meta.spigot.isUnbreakable() ); // Spigot
|
|
|
|
}
|
|
|
|
|
|
|
|
CraftMetaItem(NBTTagCompound tag) {
|
2014-12-19 00:33:08 +01:00
|
|
|
@@ -436,6 +438,12 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
|
|
unhandledTags.put(key, tag.get(key));
|
|
|
|
}
|
2014-08-25 23:30:52 +02:00
|
|
|
}
|
|
|
|
+ // Spigot start
|
|
|
|
+ if ( tag.hasKey( UNBREAKABLE.NBT ) )
|
|
|
|
+ {
|
|
|
|
+ spigot.setUnbreakable( tag.getBoolean( UNBREAKABLE.NBT ) );
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
}
|
|
|
|
|
|
|
|
static Map<Enchantment, Integer> buildEnchantments(NBTTagCompound tag, ItemMetaKey key) {
|
2014-12-19 00:33:08 +01:00
|
|
|
@@ -476,6 +484,13 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-08-25 23:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
attributes = null;
|
|
|
|
+ // Spigot start
|
|
|
|
+ Boolean unbreakable = SerializableMeta.getObject( Boolean.class, map, UNBREAKABLE.BUKKIT, true );
|
|
|
|
+ if ( unbreakable != null )
|
|
|
|
+ {
|
|
|
|
+ spigot.setUnbreakable( unbreakable );
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
}
|
|
|
|
|
|
|
|
static Map<Enchantment, Integer> buildEnchantments(Map<String, Object> map, ItemMetaKey key) {
|
2015-01-18 19:17:11 +01:00
|
|
|
@@ -507,6 +522,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
|
|
}
|
2014-08-25 23:30:52 +02:00
|
|
|
|
|
|
|
applyEnchantments(enchantments, itemTag, ENCHANTMENTS);
|
2015-01-18 19:17:11 +01:00
|
|
|
+
|
2014-08-25 23:30:52 +02:00
|
|
|
+ // Spigot start
|
|
|
|
+ if ( spigot.isUnbreakable() )
|
|
|
|
+ {
|
|
|
|
+ itemTag.setBoolean( UNBREAKABLE.NBT, true );
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
+
|
2015-01-18 19:17:11 +01:00
|
|
|
|
2014-08-25 23:30:52 +02:00
|
|
|
if (hasRepairCost()) {
|
|
|
|
itemTag.setInt(REPAIR.NBT, repairCost);
|
2015-01-18 19:17:11 +01:00
|
|
|
@@ -570,7 +593,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-08-25 23:30:52 +02:00
|
|
|
|
|
|
|
@Overridden
|
|
|
|
boolean isEmpty() {
|
2014-12-19 00:33:08 +01:00
|
|
|
- return !(hasDisplayName() || hasEnchants() || hasLore() || hasAttributes() || hasRepairCost() || !unhandledTags.isEmpty());
|
|
|
|
+ return !(hasDisplayName() || hasEnchants() || hasLore() || hasAttributes() || hasRepairCost() || !unhandledTags.isEmpty() || spigot.isUnbreakable()); // Spigot
|
2014-08-25 23:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getDisplayName() {
|
2015-01-18 19:17:11 +01:00
|
|
|
@@ -695,7 +718,8 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-08-25 23:30:52 +02:00
|
|
|
&& (this.hasLore() ? that.hasLore() && this.lore.equals(that.lore) : !that.hasLore())
|
|
|
|
&& (this.hasAttributes() ? that.hasAttributes() && this.attributes.equals(that.attributes) : !that.hasAttributes())
|
2014-12-19 00:33:08 +01:00
|
|
|
&& (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost())
|
|
|
|
- && (this.unhandledTags.equals(that.unhandledTags));
|
|
|
|
+ && (this.unhandledTags.equals(that.unhandledTags))
|
|
|
|
+ && this.spigot.isUnbreakable() == that.spigot.isUnbreakable(); // Spigot
|
2014-08-25 23:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-01-18 19:17:11 +01:00
|
|
|
@@ -722,6 +746,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-08-25 23:30:52 +02:00
|
|
|
hash = 61 * hash + (hasAttributes() ? this.attributes.hashCode() : 0);
|
|
|
|
hash = 61 * hash + (hasRepairCost() ? this.repairCost : 0);
|
2014-12-19 00:33:08 +01:00
|
|
|
hash = 61 * hash + unhandledTags.hashCode();
|
2015-01-18 19:17:11 +01:00
|
|
|
++ hash = 61 * hash + (spigot.isUnbreakable() ? 1231 : 1237); // Spigot
|
2014-08-25 23:30:52 +02:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2015-01-18 19:17:11 +01:00
|
|
|
@@ -764,6 +789,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
|
|
if (hasRepairCost()) {
|
2014-08-25 23:30:52 +02:00
|
|
|
builder.put(REPAIR.BUKKIT, repairCost);
|
|
|
|
}
|
2015-01-18 19:17:11 +01:00
|
|
|
+
|
2014-08-25 23:30:52 +02:00
|
|
|
+ // Spigot start
|
|
|
|
+ if ( spigot.isUnbreakable() )
|
|
|
|
+ {
|
|
|
|
+ builder.put( UNBREAKABLE.BUKKIT, true );
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
|
|
|
+
|
2015-01-18 19:17:11 +01:00
|
|
|
|
2014-08-25 23:30:52 +02:00
|
|
|
return builder;
|
|
|
|
}
|
2015-01-18 19:17:11 +01:00
|
|
|
@@ -828,6 +861,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,
|
|
|
|
ATTRIBUTES.NBT,
|
|
|
|
@@ -848,11 +882,23 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
|
|
}
|
|
|
|
return HANDLED_TAGS;
|
|
|
|
}
|
|
|
|
- }
|
2014-08-25 23:30:52 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
--
|
2015-01-18 19:17:11 +01:00
|
|
|
1.9.5.msysgit.0
|
2014-08-25 23:30:52 +02:00
|
|
|
|