Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-18 12:30:06 +01:00
Serialize full skull item profile data in internal blob
Dieser Commit ist enthalten in:
Ursprung
04afd79178
Commit
845336b511
@ -4,6 +4,7 @@ import com.google.common.base.Objects;
|
|||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import net.minecraft.server.BlockJukeBox;
|
import net.minecraft.server.BlockJukeBox;
|
||||||
|
import net.minecraft.server.NBTBase;
|
||||||
import net.minecraft.server.NBTTagCompound;
|
import net.minecraft.server.NBTTagCompound;
|
||||||
import net.minecraft.server.TileEntity;
|
import net.minecraft.server.TileEntity;
|
||||||
import net.minecraft.server.TileEntityBanner;
|
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
|
@Override
|
||||||
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
|
ImmutableMap.Builder<String, Object> serialize(ImmutableMap.Builder<String, Object> builder) {
|
||||||
super.serialize(builder);
|
super.serialize(builder);
|
||||||
|
@ -376,16 +376,12 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||||||
ByteArrayInputStream buf = new ByteArrayInputStream(Base64.decodeBase64(internal));
|
ByteArrayInputStream buf = new ByteArrayInputStream(Base64.decodeBase64(internal));
|
||||||
try {
|
try {
|
||||||
NBTTagCompound tag = NBTCompressedStreamTools.a(buf);
|
NBTTagCompound tag = NBTCompressedStreamTools.a(buf);
|
||||||
|
deserializeInternal(tag);
|
||||||
Set<String> keys = tag.c();
|
Set<String> keys = tag.c();
|
||||||
for (String key : keys) {
|
for (String key : keys) {
|
||||||
if (!getHandledTags().contains(key)) {
|
if (!getHandledTags().contains(key)) {
|
||||||
unhandledTags.put(key, tag.get(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) {
|
} catch (IOException ex) {
|
||||||
Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, 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) {
|
static Map<Enchantment, Integer> buildEnchantments(Map<String, Object> map, ItemMetaKey key) {
|
||||||
Map<?, ?> ench = SerializableMeta.getObject(Map.class, map, key.BUKKIT, true);
|
Map<?, ?> ench = SerializableMeta.getObject(Map.class, map, key.BUKKIT, true);
|
||||||
if (ench == null) {
|
if (ench == null) {
|
||||||
@ -715,17 +714,13 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||||||
builder.put(HIDEFLAGS.BUKKIT, hideFlags);
|
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();
|
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());
|
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 {
|
try {
|
||||||
ByteArrayOutputStream buf = new ByteArrayOutputStream();
|
ByteArrayOutputStream buf = new ByteArrayOutputStream();
|
||||||
NBTCompressedStreamTools.a(internal, buf);
|
NBTCompressedStreamTools.a(internal, buf);
|
||||||
@ -738,6 +733,9 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void serializeInternal(final Map<String, NBTBase> unhandledTags) {
|
||||||
|
}
|
||||||
|
|
||||||
static void serializeEnchantments(Map<Enchantment, Integer> enchantments, ImmutableMap.Builder<String, Object> builder, ItemMetaKey key) {
|
static void serializeEnchantments(Map<Enchantment, Integer> enchantments, ImmutableMap.Builder<String, Object> builder, ItemMetaKey key) {
|
||||||
if (enchantments == null || enchantments.isEmpty()) {
|
if (enchantments == null || enchantments.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
@ -804,6 +802,7 @@ class CraftMetaItem implements ItemMeta, Repairable {
|
|||||||
CraftMetaMap.MAP_SCALING.NBT,
|
CraftMetaMap.MAP_SCALING.NBT,
|
||||||
CraftMetaPotion.POTION_EFFECTS.NBT,
|
CraftMetaPotion.POTION_EFFECTS.NBT,
|
||||||
CraftMetaSkull.SKULL_OWNER.NBT,
|
CraftMetaSkull.SKULL_OWNER.NBT,
|
||||||
|
CraftMetaSkull.SKULL_PROFILE.NBT,
|
||||||
CraftMetaBlockState.BLOCK_ENTITY_TAG.NBT,
|
CraftMetaBlockState.BLOCK_ENTITY_TAG.NBT,
|
||||||
CraftMetaBook.BOOK_TITLE.NBT,
|
CraftMetaBook.BOOK_TITLE.NBT,
|
||||||
CraftMetaBook.BOOK_AUTHOR.NBT,
|
CraftMetaBook.BOOK_AUTHOR.NBT,
|
||||||
|
@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.inventory;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import net.minecraft.server.GameProfileSerializer;
|
import net.minecraft.server.GameProfileSerializer;
|
||||||
|
import net.minecraft.server.NBTBase;
|
||||||
import net.minecraft.server.NBTTagCompound;
|
import net.minecraft.server.NBTTagCompound;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
@ -15,6 +16,10 @@ import com.mojang.authlib.GameProfile;
|
|||||||
|
|
||||||
@DelegateDeserialization(SerializableMeta.class)
|
@DelegateDeserialization(SerializableMeta.class)
|
||||||
class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
|
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 ItemMetaKey SKULL_OWNER = new ItemMetaKey("SkullOwner", "skull-owner");
|
||||||
static final int MAX_OWNER_LENGTH = 16;
|
static final int MAX_OWNER_LENGTH = 16;
|
||||||
|
|
||||||
@ -41,8 +46,26 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
|
|||||||
|
|
||||||
CraftMetaSkull(Map<String, Object> map) {
|
CraftMetaSkull(Map<String, Object> map) {
|
||||||
super(map);
|
super(map);
|
||||||
|
if (profile == null) {
|
||||||
setOwner(SerializableMeta.getString(map, SKULL_OWNER.BUKKIT, true));
|
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
|
@Override
|
||||||
void applyToItem(NBTTagCompound tag) {
|
void applyToItem(NBTTagCompound tag) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren