mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-27 04:55:47 +01:00
e4d10a6d67
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: 122289ff Add FaceAttachable interface to handle Grindstone facing in common with Switches a6db750e SPIGOT-5647: ZombieVillager entity should have getVillagerType() CraftBukkit Changes:bbe3d58e
SPIGOT-5650: Lectern.setPage(int) causes a NullPointerException3075579f
Add FaceAttachable interface to handle Grindstone facing in common with Switches95bd4238
SPIGOT-5647: ZombieVillager entity should have getVillagerType()4d975ac3
SPIGOT-5617: setBlockData does not work when NotPlayEvent is called by redstone current
82 lines
3.8 KiB
Diff
82 lines
3.8 KiB
Diff
From 47537f82a6f5a0de4bb3d6e1a1ee09fa1135683a Mon Sep 17 00:00:00 2001
|
|
From: Hugo Manrique <hugmanrique@gmail.com>
|
|
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 a41be8fdae..d5e8a7ee6d 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftItemStack.java
|
|
@@ -553,7 +553,7 @@ public final class CraftItemStack extends ItemStack {
|
|
|
|
@Override
|
|
public boolean hasItemMeta() {
|
|
- return hasItemMeta(handle) && !CraftItemFactory.instance().equals(getItemMeta(), null);
|
|
+ return hasItemMeta(handle) && (handle.getDamage() != 0 || (handle.getTag() != null && handle.getTag().map.size() >= (handle.getTag().hasKey(CraftMetaItem.DAMAGE.NBT) ? 2 : 1))); // Paper - keep 1.12 CraftBukkit behavior without calling getItemMeta
|
|
}
|
|
|
|
static boolean hasItemMeta(net.minecraft.server.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 3a82bede7c..d731418397 100644
|
|
--- a/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
|
|
+++ b/src/test/java/org/bukkit/craftbukkit/inventory/ItemMetaTest.java
|
|
@@ -2,10 +2,9 @@ package org.bukkit.craftbukkit.inventory;
|
|
|
|
import static org.hamcrest.Matchers.*;
|
|
import static org.junit.Assert.*;
|
|
-import java.util.ArrayList;
|
|
-import java.util.Arrays;
|
|
-import java.util.List;
|
|
-import java.util.UUID;
|
|
+
|
|
+import java.util.*;
|
|
+
|
|
import com.destroystokyo.paper.inventory.meta.ArmorStandMeta; // Paper
|
|
import net.minecraft.server.Block;
|
|
import net.minecraft.server.IRegistry;
|
|
@@ -97,6 +96,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(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);
|
|
--
|
|
2.25.1
|
|
|