From 69928430286aa07d7a93e4ba975f609c410a878a Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Tue, 23 Nov 2021 12:35:42 +1100 Subject: [PATCH] Fix serializing unhandled NBT + add unit test with unhandled NBT By: md_5 --- .../java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java | 4 ++-- .../inventory/DeprecatedItemMetaCustomValueTest.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java index 6f62f67fd6..574470b59c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java @@ -280,7 +280,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry(); private NBTTagCompound internalTag; - private final Map unhandledTags = new HashMap(); + final Map unhandledTags = new HashMap(); // Visible for testing only private CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY); private int version = CraftMagicNumbers.INSTANCE.getDataVersion(); // Internal use only @@ -1259,7 +1259,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta { try { ByteArrayOutputStream buf = new ByteArrayOutputStream(); NBTCompressedStreamTools.writeCompressed(internal, buf); - builder.put("internal", Base64.getEncoder().encode(buf.toByteArray())); + builder.put("internal", Base64.getEncoder().encodeToString(buf.toByteArray())); } catch (IOException ex) { Logger.getLogger(CraftMetaItem.class.getName()).log(Level.SEVERE, null, ex); } diff --git a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java index b075749edf..6c447cda2f 100644 --- a/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java +++ b/paper-server/src/test/java/org/bukkit/craftbukkit/inventory/DeprecatedItemMetaCustomValueTest.java @@ -7,6 +7,7 @@ import java.nio.ByteBuffer; import java.util.Map; import java.util.UUID; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagString; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -148,6 +149,7 @@ public class DeprecatedItemMetaCustomValueTest extends AbstractTestingBase { private CraftMetaItem createComplexItemMeta() { CraftMetaItem itemMeta = (CraftMetaItem) createNewItemMeta(); + itemMeta.unhandledTags.put("unhandled-test", NBTTagString.valueOf("test")); itemMeta.setDisplayName("Item Display Name"); itemMeta.getCustomTagContainer().setCustomTag(requestKey("custom-long"), ItemTagType.LONG, 4L); //Add random primitive values