aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0231-Don-t-call-getItemMeta-on-hasItemMeta.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/server/0231-Don-t-call-getItemMeta-on-hasItemMeta.patch')
-rw-r--r--patches/server/0231-Don-t-call-getItemMeta-on-hasItemMeta.patch64
1 files changed, 64 insertions, 0 deletions
diff --git a/patches/server/0231-Don-t-call-getItemMeta-on-hasItemMeta.patch b/patches/server/0231-Don-t-call-getItemMeta-on-hasItemMeta.patch
new file mode 100644
index 0000000000..bb60be7331
--- /dev/null
+++ b/patches/server/0231-Don-t-call-getItemMeta-on-hasItemMeta.patch
@@ -0,0 +1,64 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Hugo Manrique <[email protected]>
+Date: Thu, 26 Jul 2018 14:10:23 +0200
+Subject: [PATCH] Don't call getItemMeta on hasItemMeta
+
+Spigot 1.13 checks if any field (which are manually copied from the ItemStack's "tag" NBT tag) on the ItemMeta class of an ItemStack is set.
+
+We could just check if the "tag" NBT tag is empty, albeit that would break some plugins. The only general tag added on 1.13 is "Damage", and we can just check if the "tag" NBT tag contains any other tag that's not "Damage" (https://minecraft.gamepedia.com/Player.dat_format#Item_structure) making the `hasItemStack` method behave as before.
+
+Returns true if getDamage() == 0 or has damage tag or other tag is set.
+Check the `ItemMetaTest#testTaggedButNotMeta` method to see how this method behaves.
+
+diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+index ca75f84d2beeef0636fc7032297bf038d13d97e0..f3abcd5949011eaef3d1ba68f4cc0751042d2834 100644
+--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
++++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
+@@ -588,7 +588,7 @@ public final class CraftItemStack extends ItemStack {
+
+ @Override
+ public boolean hasItemMeta() {
+- return CraftItemStack.hasItemMeta(this.handle) && !CraftItemFactory.instance().equals(this.getItemMeta(), null);
++ return CraftItemStack.hasItemMeta(this.handle) && (this.handle.getDamageValue() != 0 || (this.handle.getTag() != null && this.handle.getTag().tags.size() >= (this.handle.getTag().contains(CraftMetaItem.DAMAGE.NBT) ? 2 : 1))); // Paper - keep 1.12 CraftBukkit behavior without calling getItemMeta
+ }
+
+ static boolean hasItemMeta(net.minecraft.world.item.ItemStack item) {
+diff --git a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
+index f3a0578f53863dd0866b4c2cb957a30fa3bc6cc5..44bc92bea0fa0742ef861e16eba3e57d9c6e49ce 100644
+--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
++++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
+@@ -99,6 +99,34 @@ public class ItemMetaTest extends AbstractTestingBase {
+ assertThat(itemMeta.hasConflictingEnchant(null), is(false));
+ }
+
++ // Paper start
++ private void testItemMeta(ItemStack stack) {
++ assertThat("Should not have ItemMeta", stack.hasItemMeta(), is(false));
++
++ stack.setDurability((short) 0);
++ assertThat("ItemStack with zero durability should not have ItemMeta", stack.hasItemMeta(), is(false));
++
++ stack.setDurability((short) 2);
++ assertThat("ItemStack with non-zero durability should have ItemMeta", stack.hasItemMeta(), is(true));
++
++ stack.setLore(java.util.Collections.singletonList("Lore"));
++ assertThat("ItemStack with lore and durability should have ItemMeta", stack.hasItemMeta(), is(true));
++
++ stack.setDurability((short) 0);
++ assertThat("ItemStack with lore should have ItemMeta", stack.hasItemMeta(), is(true));
++
++ stack.setLore(null);
++ }
++
++ @Test
++ public void testHasItemMeta() {
++ ItemStack itemStack = new ItemStack(Material.SHEARS);
++
++ testItemMeta(itemStack);
++ testItemMeta(CraftItemStack.asCraftCopy(itemStack));
++ }
++ // Paper end
++
+ @Test
+ public void testConflictingStoredEnchantment() {
+ EnchantmentStorageMeta itemMeta = (EnchantmentStorageMeta) Bukkit.getItemFactory().getItemMeta(Material.ENCHANTED_BOOK);