From 843d9c3509ed145312b099ebf3273384b79605e4 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Fri, 18 Jul 2025 17:09:30 +0200 Subject: [PATCH] ItemStackAdapter for Json: deserialized json cannot contains both old and new data. When both are present (because old server needs the old one), keeping only the new data. --- .../fr/pandacube/lib/paper/json/ItemStackAdapter.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/json/ItemStackAdapter.java b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/json/ItemStackAdapter.java index 1aa5606..648b040 100644 --- a/pandalib-paper/src/main/java/fr/pandacube/lib/paper/json/ItemStackAdapter.java +++ b/pandalib-paper/src/main/java/fr/pandacube/lib/paper/json/ItemStackAdapter.java @@ -41,6 +41,7 @@ import java.util.Map; return context.deserialize(jsonObj, ConfigurationSerializable.class); + if (jsonObj.has("meta") && jsonObj.get("meta") instanceof JsonObject metaJson && !metaJson.has(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { @@ -50,6 +51,16 @@ import java.util.Map; Map map = context.deserialize(jsonObj, MAP_STR_OBJ_TYPE.getType()); fixDeserializationVersion(map); map.remove("meta"); + + // the deserialized json may contain older data compatible with pre 1.21.5 but not compatible after. + // if it contains both old and new data, delete the old one introduced for compatibility + if (map.containsKey("DataVersion")) { // it uses the new DataVersion data + map.remove("v"); + } + if (map.containsKey("id")) { + map.remove("type"); + } + ItemStack is = ItemStack.deserialize(map); Class metaClass = is.getItemMeta().getClass();