mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-08 11:24:11 +01:00
Fix serializing unhandled NBT + add unit test with unhandled NBT
By: md_5 <git@md-5.net>
This commit is contained in:
parent
683f54a1e7
commit
6992843028
2 changed files with 4 additions and 2 deletions
|
@ -280,7 +280,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||||
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
|
private static final CraftPersistentDataTypeRegistry DATA_TYPE_REGISTRY = new CraftPersistentDataTypeRegistry();
|
||||||
|
|
||||||
private NBTTagCompound internalTag;
|
private NBTTagCompound internalTag;
|
||||||
private final Map<String, NBTBase> unhandledTags = new HashMap<String, NBTBase>();
|
final Map<String, NBTBase> unhandledTags = new HashMap<String, NBTBase>(); // Visible for testing only
|
||||||
private CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY);
|
private CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(DATA_TYPE_REGISTRY);
|
||||||
|
|
||||||
private int version = CraftMagicNumbers.INSTANCE.getDataVersion(); // Internal use only
|
private int version = CraftMagicNumbers.INSTANCE.getDataVersion(); // Internal use only
|
||||||
|
@ -1259,7 +1259,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream buf = new ByteArrayOutputStream();
|
ByteArrayOutputStream buf = new ByteArrayOutputStream();
|
||||||
NBTCompressedStreamTools.writeCompressed(internal, buf);
|
NBTCompressedStreamTools.writeCompressed(internal, buf);
|
||||||
builder.put("internal", Base64.getEncoder().encode(buf.toByteArray()));
|
builder.put("internal", Base64.getEncoder().encodeToString(buf.toByteArray()));
|
||||||
} 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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import java.nio.ByteBuffer;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagString;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.NamespacedKey;
|
import org.bukkit.NamespacedKey;
|
||||||
|
@ -148,6 +149,7 @@ public class DeprecatedItemMetaCustomValueTest extends AbstractTestingBase {
|
||||||
|
|
||||||
private CraftMetaItem createComplexItemMeta() {
|
private CraftMetaItem createComplexItemMeta() {
|
||||||
CraftMetaItem itemMeta = (CraftMetaItem) createNewItemMeta();
|
CraftMetaItem itemMeta = (CraftMetaItem) createNewItemMeta();
|
||||||
|
itemMeta.unhandledTags.put("unhandled-test", NBTTagString.valueOf("test"));
|
||||||
itemMeta.setDisplayName("Item Display Name");
|
itemMeta.setDisplayName("Item Display Name");
|
||||||
|
|
||||||
itemMeta.getCustomTagContainer().setCustomTag(requestKey("custom-long"), ItemTagType.LONG, 4L); //Add random primitive values
|
itemMeta.getCustomTagContainer().setCustomTag(requestKey("custom-long"), ItemTagType.LONG, 4L); //Add random primitive values
|
||||||
|
|
Loading…
Reference in a new issue