Archiviert
13
0
Dieses Repository wurde am 2024-12-25 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
Paper-Old/CraftBukkit-Patches/0150-Added-isUnbreakable-and-setUnbreakable-to-ItemMeta.patch

144 Zeilen
5.3 KiB
Diff

2015-04-09 05:18:56 +02:00
From c3630ed22b3e4d670baa8cb35a33312eb90f8437 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
2015-03-24 21:45:15 +01:00
index 9b1ab44..bef5ff2 100644
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
2015-03-24 21:45:15 +01:00
@@ -213,6 +213,8 @@ class CraftMetaItem implements ItemMeta, Repairable {
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)
+ static final ItemMetaKey UNBREAKABLE = new ItemMetaKey("Unbreakable"); // Spigot
private String displayName;
private List<String> lore;
2015-03-24 21:45:15 +01:00
@@ -245,6 +247,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
this.attributes = meta.attributes;
2015-02-15 02:52:33 +01:00
this.hideFlag = meta.hideFlag;
this.unhandledTags.putAll(meta.unhandledTags);
+ spigot.setUnbreakable( meta.spigot.isUnbreakable() ); // Spigot
}
CraftMetaItem(NBTTagCompound tag) {
2015-03-24 21:45:15 +01:00
@@ -447,6 +450,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) {
2015-03-24 21:45:15 +01:00
@@ -500,6 +509,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
2015-02-15 02:52:33 +01:00
}
}
}
2015-02-15 02:52:33 +01:00
+
+ // 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-03-24 21:45:15 +01:00
@@ -535,6 +552,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
2015-01-18 19:17:11 +01:00
}
applyEnchantments(enchantments, itemTag, ENCHANTMENTS);
2015-01-18 19:17:11 +01:00
+
+ // Spigot start
+ if ( spigot.isUnbreakable() )
+ {
+ itemTag.setBoolean( UNBREAKABLE.NBT, true );
+ }
+ // Spigot end
+
2015-01-18 19:17:11 +01:00
if (hasRepairCost()) {
itemTag.setInt(REPAIR.NBT, repairCost);
2015-03-24 21:45:15 +01:00
@@ -598,7 +623,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
@Overridden
boolean isEmpty() {
2015-02-15 02:52:33 +01:00
- return !(hasDisplayName() || hasEnchants() || hasLore() || hasAttributes() || hasRepairCost() || !unhandledTags.isEmpty() || hideFlag != 0);
+ return !(hasDisplayName() || hasEnchants() || hasLore() || hasAttributes() || hasRepairCost() || !unhandledTags.isEmpty() || hideFlag != 0 || spigot.isUnbreakable()); // Spigot
}
public String getDisplayName() {
2015-03-24 21:45:15 +01:00
@@ -761,7 +786,8 @@ class CraftMetaItem implements ItemMeta, Repairable {
&& (this.hasAttributes() ? that.hasAttributes() && this.attributes.equals(that.attributes) : !that.hasAttributes())
&& (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
}
/**
2015-03-24 21:45:15 +01:00
@@ -789,6 +815,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
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
return hash;
}
2015-03-24 21:45:15 +01:00
@@ -832,6 +859,14 @@ class CraftMetaItem implements ItemMeta, Repairable {
2015-01-18 19:17:11 +01:00
if (hasRepairCost()) {
builder.put(REPAIR.BUKKIT, repairCost);
}
2015-01-18 19:17:11 +01: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-03-24 21:45:15 +01:00
@@ -904,6 +939,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,
ATTRIBUTES.NBT,
2015-03-24 21:45:15 +01:00
@@ -929,6 +965,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.0