3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-27 16:40:10 +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.
Dieser Commit ist enthalten in:
EnZaXD 2024-04-19 17:05:07 +02:00 committet von GitHub
Ursprung 128e191132
Commit fb434a79bd
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
2 geänderte Dateien mit 9 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -93,11 +93,11 @@ public final class ComponentUtil {
} }
public static @Nullable JsonElement convertJson(@Nullable final JsonElement element, final SerializerVersion from, final SerializerVersion to) { 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) { 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) { private static JsonElement convert(final SerializerVersion from, final SerializerVersion to, final ATextComponent component) {

Datei anzeigen

@ -77,7 +77,13 @@ public enum SerializerVersion {
} }
public ATextComponent toComponent(final String json) { 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) { public ATextComponent toComponent(final Tag tag) {