diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java index 32d461a312..d60686d624 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBlockState.java @@ -4,6 +4,7 @@ import com.google.common.base.Objects; import com.google.common.collect.ImmutableMap; import java.util.Map; import net.minecraft.server.BlockJukeBox; +import net.minecraft.server.NBTBase; import net.minecraft.server.NBTTagCompound; import net.minecraft.server.TileEntity; import net.minecraft.server.TileEntityBanner; @@ -96,6 +97,20 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta } } + @Override + void deserializeInternal(NBTTagCompound tag) { + if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, 10)) { + blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT); + } + } + + @Override + void serializeInternal(final Map internalTags) { + if (blockEntityTag != null) { + internalTags.put(BLOCK_ENTITY_TAG.NBT, blockEntityTag); + } + } + @Override ImmutableMap.Builder serialize(ImmutableMap.Builder builder) { super.serialize(builder); diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index 8b18e1f344..5f123e32dc 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -376,16 +376,12 @@ class CraftMetaItem implements ItemMeta, Repairable { ByteArrayInputStream buf = new ByteArrayInputStream(Base64.decodeBase64(internal)); try { NBTTagCompound tag = NBTCompressedStreamTools.a(buf); + deserializeInternal(tag); Set keys = tag.c(); for (String key : keys) { if (!getHandledTags().contains(key)) { unhandledTags.put(key, tag.get(key)); } - if (key.equals(CraftMetaBlockState.BLOCK_ENTITY_TAG.NBT) && this instanceof CraftMetaBlockState) { - if (tag.hasKeyOfType(key, 10)) { - ((CraftMetaBlockState) this).blockEntityTag = tag.getCompound(key); - } - } } } catch (IOException ex) { Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex); @@ -393,6 +389,9 @@ class CraftMetaItem implements ItemMeta, Repairable { } } + void deserializeInternal(NBTTagCompound tag) { + } + static Map buildEnchantments(Map map, ItemMetaKey key) { Map ench = SerializableMeta.getObject(Map.class, map, key.BUKKIT, true); if (ench == null) { @@ -715,17 +714,13 @@ class CraftMetaItem implements ItemMeta, Repairable { builder.put(HIDEFLAGS.BUKKIT, hideFlags); } - if (!unhandledTags.isEmpty() || this instanceof CraftMetaBlockState) { + final Map internalTags = new HashMap(unhandledTags); + serializeInternal(internalTags); + if (!internalTags.isEmpty()) { NBTTagCompound internal = new NBTTagCompound(); - for (Map.Entry e : unhandledTags.entrySet()) { + for (Map.Entry e : internalTags.entrySet()) { internal.set(e.getKey(), e.getValue()); } - if (this instanceof CraftMetaBlockState) { - CraftMetaBlockState bs = ((CraftMetaBlockState) this); - if (bs.blockEntityTag != null) { - internal.set(CraftMetaBlockState.BLOCK_ENTITY_TAG.NBT, bs.blockEntityTag); - } - } try { ByteArrayOutputStream buf = new ByteArrayOutputStream(); NBTCompressedStreamTools.a(internal, buf); @@ -738,6 +733,9 @@ class CraftMetaItem implements ItemMeta, Repairable { return builder; } + void serializeInternal(final Map unhandledTags) { + } + static void serializeEnchantments(Map enchantments, ImmutableMap.Builder builder, ItemMetaKey key) { if (enchantments == null || enchantments.isEmpty()) { return; @@ -804,6 +802,7 @@ class CraftMetaItem implements ItemMeta, Repairable { CraftMetaMap.MAP_SCALING.NBT, CraftMetaPotion.POTION_EFFECTS.NBT, CraftMetaSkull.SKULL_OWNER.NBT, + CraftMetaSkull.SKULL_PROFILE.NBT, CraftMetaBlockState.BLOCK_ENTITY_TAG.NBT, CraftMetaBook.BOOK_TITLE.NBT, CraftMetaBook.BOOK_AUTHOR.NBT, diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java index 89912bcf5f..ead8a98c93 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java @@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.inventory; import java.util.Map; import net.minecraft.server.GameProfileSerializer; +import net.minecraft.server.NBTBase; import net.minecraft.server.NBTTagCompound; import org.bukkit.Material; @@ -15,6 +16,10 @@ import com.mojang.authlib.GameProfile; @DelegateDeserialization(SerializableMeta.class) class CraftMetaSkull extends CraftMetaItem implements SkullMeta { + + @ItemMetaKey.Specific(ItemMetaKey.Specific.To.NBT) + static final ItemMetaKey SKULL_PROFILE = new ItemMetaKey("SkullProfile"); + static final ItemMetaKey SKULL_OWNER = new ItemMetaKey("SkullOwner", "skull-owner"); static final int MAX_OWNER_LENGTH = 16; @@ -41,7 +46,25 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { CraftMetaSkull(Map map) { super(map); - setOwner(SerializableMeta.getString(map, SKULL_OWNER.BUKKIT, true)); + if (profile == null) { + setOwner(SerializableMeta.getString(map, SKULL_OWNER.BUKKIT, true)); + } + } + + @Override + void deserializeInternal(NBTTagCompound tag) { + if (tag.hasKeyOfType(SKULL_PROFILE.NBT, 10)) { + profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_PROFILE.NBT)); + } + } + + @Override + void serializeInternal(final Map internalTags) { + if (profile != null) { + NBTTagCompound nbtData = new NBTTagCompound(); + GameProfileSerializer.serialize(nbtData, profile); + internalTags.put(SKULL_PROFILE.NBT, nbtData); + } } @Override