mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-12-23 00:47:39 +01:00
Use correct deserialization method in SerializerVersion#toComponent (#3795)
MCStructs has multiple methods for parsing jsons depending on the version, we should use them correctly in our wrapper to support all possible cases of components.
This commit is contained in:
parent
128e191132
commit
fb434a79bd
@ -93,11 +93,11 @@ public final class ComponentUtil {
|
||||
}
|
||||
|
||||
public static @Nullable JsonElement convertJson(@Nullable final JsonElement element, final SerializerVersion from, final SerializerVersion to) {
|
||||
return element != null ? convert(from, to, from.jsonSerializer.deserialize(element)) : null;
|
||||
return element != null ? convert(from, to, from.toComponent(element)) : null;
|
||||
}
|
||||
|
||||
public static @Nullable JsonElement convertJson(@Nullable final String json, final SerializerVersion from, final SerializerVersion to) {
|
||||
return json != null ? convert(from, to, from.jsonSerializer.deserializeReader(json)) : null;
|
||||
return json != null ? convert(from, to, from.toComponent(json)) : null;
|
||||
}
|
||||
|
||||
private static JsonElement convert(final SerializerVersion from, final SerializerVersion to, final ATextComponent component) {
|
||||
|
@ -77,7 +77,13 @@ public enum SerializerVersion {
|
||||
}
|
||||
|
||||
public ATextComponent toComponent(final String json) {
|
||||
return jsonSerializer.deserializeReader(json);
|
||||
if (ordinal() >= SerializerVersion.V1_20_3.ordinal()) {
|
||||
return jsonSerializer.deserializeParser(json);
|
||||
} else if (ordinal() >= SerializerVersion.V1_9.ordinal()) {
|
||||
return jsonSerializer.deserializeReader(json);
|
||||
} else {
|
||||
return jsonSerializer.deserialize(json);
|
||||
}
|
||||
}
|
||||
|
||||
public ATextComponent toComponent(final Tag tag) {
|
||||
|
Loading…
Reference in New Issue
Block a user