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.
This commit is contained in:
@@ -41,6 +41,7 @@ import java.util.Map;
|
|||||||
return context.deserialize(jsonObj, ConfigurationSerializable.class);
|
return context.deserialize(jsonObj, ConfigurationSerializable.class);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (jsonObj.has("meta")
|
if (jsonObj.has("meta")
|
||||||
&& jsonObj.get("meta") instanceof JsonObject metaJson
|
&& jsonObj.get("meta") instanceof JsonObject metaJson
|
||||||
&& !metaJson.has(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
|
&& !metaJson.has(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) {
|
||||||
@@ -50,6 +51,16 @@ import java.util.Map;
|
|||||||
Map<String, Object> map = context.deserialize(jsonObj, MAP_STR_OBJ_TYPE.getType());
|
Map<String, Object> map = context.deserialize(jsonObj, MAP_STR_OBJ_TYPE.getType());
|
||||||
fixDeserializationVersion(map);
|
fixDeserializationVersion(map);
|
||||||
map.remove("meta");
|
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);
|
ItemStack is = ItemStack.deserialize(map);
|
||||||
|
|
||||||
Class<? extends ItemMeta> metaClass = is.getItemMeta().getClass();
|
Class<? extends ItemMeta> metaClass = is.getItemMeta().getClass();
|
||||||
|
Reference in New Issue
Block a user