Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Incorrect serialisation or deserialisation causes not deserializable ItemStacks

Open Brokkonaut opened this issue 1 year ago • 2 comments

Expected behavior

Be able to load the serialized ItemStack from yaml

Observed/Actual behavior

The following exception: https://cpaste.de/xisomajoto.sql

Steps/models to reproduce

The ItemStack is modified like this:

        ItemMeta itemMeta = item.getItemMeta();
        PersistentDataContainer persistentDataContainer = itemMeta.getPersistentDataContainer();
        // String content = new JSONArray(activeArmorParticleNamesList).toString();
        String content = "[\"UnicornParticle\",\"TotemParticle\",\"AngelParticle\",\"ColorSwitchParticle\"]"
        persistentDataContainer.set(plugin.getAddedParticlesNamespacedKey(), PersistentDataType.STRING, content);
        item.setItemMeta(itemMeta);

Now I am now serializing and then deserializing the ItemStack like this:

        YamlConfiguration conf = new YamlConfiguration();
        conf.set("item", item2);
        YamlConfiguration conf2 = new YamlConfiguration();
        try {
            conf2.loadFromString(conf.saveToString());
        } catch (Exception e) {
            Bukkit.getLogger().log(Level.SEVERE, conf.saveToString(), e);
        }

Plugin and Datapack List

n/a

Paper version

git-Paper-"38be4f8" (MC: 1.19.4) (Implementing API version 1.19.4-R0.1-SNAPSHOT) (Git: 38be4f8)

Other

No response

Brokkonaut avatar Mar 27 '23 05:03 Brokkonaut

This is likely an upstream issue down to how the PDC is serialised into the yaml format; easy fix would be to just store the encoded NBT rather than being stupid about it and trying to store structured data which cares about type info into a system which doesn't even understand types

electronicboy avatar Mar 27 '23 05:03 electronicboy

To give a little more context, the broken and not good bukkit serialization system tries to deserialize that string as a list since it looks like [item1, item2].

Machine-Maker avatar Mar 27 '23 19:03 Machine-Maker