From 50fbc3f190390b75d3a58612e4c42a9f5c09d556 Mon Sep 17 00:00:00 2001 From: md_5 Date: Mon, 14 Jan 2019 10:20:24 +1100 Subject: [PATCH] SPIGOT-4576: Fix attributes in itemstack internal data being lost --- .../bukkit/craftbukkit/inventory/CraftMetaBlockState.java | 2 ++ .../org/bukkit/craftbukkit/inventory/CraftMetaItem.java | 6 +++++- .../org/bukkit/craftbukkit/inventory/CraftMetaSkull.java | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java index 0585d240c9..f96f6af038 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java @@ -111,6 +111,8 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta @Override void deserializeInternal(NBTTagCompound tag, Object context) { + super.deserializeInternal(tag, context); + if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT); } diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index 7784284a34..32942ff248 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -385,7 +385,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable { static Multimap buildModifiers(NBTTagCompound tag, ItemMetaKey key) { Multimap modifiers = HashMultimap.create(); - if (!tag.hasKey(key.NBT)) { + if (!tag.hasKeyOfType(key.NBT, CraftMagicNumbers.NBT.TAG_LIST)) { return modifiers; } NBTTagList mods = tag.getList(key.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND); @@ -504,6 +504,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable { } void deserializeInternal(NBTTagCompound tag, Object context) { + // SPIGOT-4576: Need to migrate from internal to proper data + if (tag.hasKeyOfType(ATTRIBUTES.NBT, CraftMagicNumbers.NBT.TAG_LIST)) { + this.attributeModifiers = buildModifiers(tag, ATTRIBUTES); + } } static Map buildEnchantments(Map map, ItemMetaKey key) { diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java index bedb01cbc4..27f4d7761e 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java @@ -58,6 +58,8 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { @Override void deserializeInternal(NBTTagCompound tag, Object context) { + super.deserializeInternal(tag, context); + if (tag.hasKeyOfType(SKULL_PROFILE.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_PROFILE.NBT)); }