Serialize full skull item profile data in internal blob

Dieser Commit ist enthalten in:
Nathan Wolf 2015-04-16 07:51:08 -07:00 committet von Thinkofdeath
Ursprung 04afd79178
Commit 845336b511
3 geänderte Dateien mit 51 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -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<String, NBTBase> internalTags) {
if (blockEntityTag != null) {
internalTags.put(BLOCK_ENTITY_TAG.NBT, blockEntityTag);
}
}
@Override
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
super.serialize(builder);

Datei anzeigen

@ -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<String> 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<Enchantment, Integer> buildEnchantments(Map<String, Object> 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<String, NBTBase> internalTags = new HashMap<String, NBTBase>(unhandledTags);
serializeInternal(internalTags);
if (!internalTags.isEmpty()) {
NBTTagCompound internal = new NBTTagCompound();
for (Map.Entry<String, NBTBase> e : unhandledTags.entrySet()) {
for (Map.Entry<String, NBTBase> 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<String, NBTBase> unhandledTags) {
}
static void serializeEnchantments(Map<Enchantment, Integer> enchantments, ImmutableMap.Builder<String, Object> 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,

Datei anzeigen

@ -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<String, Object> 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<String, NBTBase> internalTags) {
if (profile != null) {
NBTTagCompound nbtData = new NBTTagCompound();
GameProfileSerializer.serialize(nbtData, profile);
internalTags.put(SKULL_PROFILE.NBT, nbtData);
}
}
@Override