2015-07-23 22:43:27 +02:00
|
|
|
From 31d25787ca265f644141847830548922e666faed 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-07-23 22:43:27 +02:00
|
|
|
index dcb9252..eaaa6a1 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
|
2015-04-16 12:19:45 +02:00
|
|
|
@@ -217,6 +217,8 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-08-25 23:30:52 +02:00
|
|
|
static final ItemMetaKey ATTRIBUTES_UUID_LOW = new ItemMetaKey("UUIDLeast");
|
2015-02-15 02:52:33 +01:00
|
|
|
@Specific(Specific.To.NBT)
|
2015-02-18 11:24:40 +01:00
|
|
|
static final ItemMetaKey HIDEFLAGS = new ItemMetaKey("HideFlags", "ItemFlags");
|
2015-02-15 02:52:33 +01:00
|
|
|
+ @Specific(Specific.To.NBT)
|
2014-08-25 23:30:52 +02:00
|
|
|
+ static final ItemMetaKey UNBREAKABLE = new ItemMetaKey("Unbreakable"); // Spigot
|
|
|
|
|
|
|
|
private String displayName;
|
|
|
|
private List<String> lore;
|
2015-04-16 12:19:45 +02:00
|
|
|
@@ -246,6 +248,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|
|
|
this.repairCost = meta.repairCost;
|
2015-02-15 02:52:33 +01:00
|
|
|
this.hideFlag = meta.hideFlag;
|
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) {
|
2015-04-16 12:19:45 +02:00
|
|
|
@@ -446,6 +449,12 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-12-19 00:33:08 +01:00
|
|
|
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) {
|
2015-04-16 12:19:45 +02:00
|
|
|
@@ -498,6 +507,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2015-02-15 02:52:33 +01:00
|
|
|
}
|
2014-08-25 23:30:52 +02:00
|
|
|
}
|
2015-04-16 12:19:45 +02:00
|
|
|
|
2014-08-25 23:30:52 +02:00
|
|
|
+ // Spigot start
|
|
|
|
+ Boolean unbreakable = SerializableMeta.getObject( Boolean.class, map, UNBREAKABLE.BUKKIT, true );
|
|
|
|
+ if ( unbreakable != null )
|
|
|
|
+ {
|
|
|
|
+ spigot.setUnbreakable( unbreakable );
|
|
|
|
+ }
|
|
|
|
+ // Spigot end
|
2015-04-16 12:19:45 +02:00
|
|
|
+
|
|
|
|
String internal = SerializableMeta.getString(map, "internal", true);
|
|
|
|
if (internal != null) {
|
|
|
|
ByteArrayInputStream buf = new ByteArrayInputStream(Base64.decodeBase64(internal));
|
2015-06-09 01:16:01 +02:00
|
|
|
@@ -552,6 +569,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2015-01-18 19:17:11 +01:00
|
|
|
}
|
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-06-09 01:16:01 +02:00
|
|
|
@@ -611,7 +636,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-08-25 23:30:52 +02:00
|
|
|
|
|
|
|
@Overridden
|
|
|
|
boolean isEmpty() {
|
2015-04-16 12:19:45 +02:00
|
|
|
- return !(hasDisplayName() || hasEnchants() || hasLore() || hasRepairCost() || !unhandledTags.isEmpty() || hideFlag != 0);
|
|
|
|
+ return !(hasDisplayName() || hasEnchants() || hasLore() || hasRepairCost() || !unhandledTags.isEmpty() || hideFlag != 0 || spigot.isUnbreakable()); // Spigot
|
2014-08-25 23:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getDisplayName() {
|
2015-06-09 01:16:01 +02:00
|
|
|
@@ -769,7 +794,8 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2015-04-16 12:19:45 +02:00
|
|
|
&& (this.hasLore() ? that.hasLore() && this.lore.equals(that.lore) : !that.hasLore())
|
2014-12-19 00:33:08 +01:00
|
|
|
&& (this.hasRepairCost() ? that.hasRepairCost() && this.repairCost == that.repairCost : !that.hasRepairCost())
|
2015-02-15 02:55:54 +01:00
|
|
|
&& (this.unhandledTags.equals(that.unhandledTags))
|
2015-02-15 02:52:33 +01:00
|
|
|
- && (this.hideFlag == that.hideFlag);
|
|
|
|
+ && (this.hideFlag == that.hideFlag)
|
|
|
|
+ && (this.spigot.isUnbreakable() == that.spigot.isUnbreakable()); // Spigot
|
2014-08-25 23:30:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-06-09 01:16:01 +02:00
|
|
|
@@ -796,6 +822,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2014-08-25 23:30:52 +02:00
|
|
|
hash = 61 * hash + (hasRepairCost() ? this.repairCost : 0);
|
2015-02-15 02:55:54 +01:00
|
|
|
hash = 61 * hash + unhandledTags.hashCode();
|
2015-02-15 02:52:33 +01:00
|
|
|
hash = 61 * hash + hideFlag;
|
2015-01-18 19:23:17 +01:00
|
|
|
+ hash = 61 * hash + (spigot.isUnbreakable() ? 1231 : 1237); // Spigot
|
2014-08-25 23:30:52 +02:00
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2015-06-09 01:16:01 +02:00
|
|
|
@@ -839,6 +866,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2015-01-18 19:17:11 +01:00
|
|
|
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
|
|
|
|
2015-02-15 02:52:33 +01:00
|
|
|
Set<String> hideFlags = new HashSet<String>();
|
|
|
|
for (ItemFlag hideFlagEnum : getItemFlags()) {
|
2015-06-09 01:16:01 +02:00
|
|
|
@@ -930,6 +965,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
2015-01-18 19:17:11 +01:00
|
|
|
synchronized (HANDLED_TAGS) {
|
|
|
|
if (HANDLED_TAGS.isEmpty()) {
|
|
|
|
HANDLED_TAGS.addAll(Arrays.asList(
|
2015-02-15 02:55:54 +01:00
|
|
|
+ UNBREAKABLE.NBT, // Spigot
|
|
|
|
DISPLAY.NBT,
|
|
|
|
REPAIR.NBT,
|
2015-04-16 12:19:45 +02:00
|
|
|
ENCHANTMENTS.NBT,
|
2015-07-23 22:43:27 +02:00
|
|
|
@@ -957,6 +993,19 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
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-05-09 22:23:26 +02:00
|
|
|
2.1.4
|
2014-08-25 23:30:52 +02:00
|
|
|
|