From 82322fe06c1331a4fc0d31b062ed633c99fce004 Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 25 Dec 2019 10:05:11 +1100 Subject: [PATCH] SPIGOT-5426: isSimilar for player heads fails --- .../craftbukkit/inventory/CraftMetaSkull.java | 36 ++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java index 961e2cc5b0..bb48da6056 100644 --- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java +++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java @@ -26,6 +26,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { static final int MAX_OWNER_LENGTH = 16; private GameProfile profile; + private NBTTagCompound serializedProfile; CraftMetaSkull(CraftMetaItem meta) { super(meta); @@ -33,16 +34,16 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { return; } CraftMetaSkull skullMeta = (CraftMetaSkull) meta; - this.profile = skullMeta.profile; + this.setProfile(skullMeta.profile); } CraftMetaSkull(NBTTagCompound tag) { super(tag); if (tag.hasKeyOfType(SKULL_OWNER.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { - profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_OWNER.NBT)); + this.setProfile(GameProfileSerializer.deserialize(tag.getCompound(SKULL_OWNER.NBT))); } else if (tag.hasKeyOfType(SKULL_OWNER.NBT, CraftMagicNumbers.NBT.TAG_STRING) && !tag.getString(SKULL_OWNER.NBT).isEmpty()) { - profile = new GameProfile(null, tag.getString(SKULL_OWNER.NBT)); + this.setProfile(new GameProfile(null, tag.getString(SKULL_OWNER.NBT))); } } @@ -58,30 +59,31 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { super.deserializeInternal(tag, context); if (tag.hasKeyOfType(SKULL_PROFILE.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { - profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_PROFILE.NBT)); + this.setProfile(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); + internalTags.put(SKULL_PROFILE.NBT, serializedProfile); } } + private void setProfile(GameProfile profile) { + this.profile = profile; + this.serializedProfile = (profile == null) ? null : GameProfileSerializer.serialize(new NBTTagCompound(), profile); + } + @Override void applyToItem(NBTTagCompound tag) { super.applyToItem(tag); if (profile != null) { // Fill in textures - profile = TileEntitySkull.b(profile); + setProfile(TileEntitySkull.b(profile)); - NBTTagCompound owner = new NBTTagCompound(); - GameProfileSerializer.serialize(owner, profile); - tag.set(SKULL_OWNER.NBT, owner); + tag.set(SKULL_OWNER.NBT, serializedProfile); } } @@ -152,9 +154,9 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { } if (name == null) { - profile = null; + setProfile(null); } else { - profile = new GameProfile(null, name); + setProfile(new GameProfile(null, name)); } return true; @@ -163,11 +165,11 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { @Override public boolean setOwningPlayer(OfflinePlayer owner) { if (owner == null) { - profile = null; + setProfile(null); } else if (owner instanceof CraftPlayer) { - profile = ((CraftPlayer) owner).getProfile(); + setProfile(((CraftPlayer) owner).getProfile()); } else { - profile = new GameProfile(owner.getUniqueId(), owner.getName()); + setProfile(new GameProfile(owner.getUniqueId(), owner.getName())); } return true; @@ -192,7 +194,7 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta { CraftMetaSkull that = (CraftMetaSkull) meta; // SPIGOT-5403: equals does not check properties - return (this.profile != null ? that.profile != null && this.profile.equals(that.profile) && this.profile.getProperties().equals(that.profile.getProperties()) : that.profile == null); + return (this.profile != null ? that.profile != null && this.serializedProfile.equals(that.serializedProfile) : that.profile == null); } return true; }