3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-19 14:30:16 +01:00

Change ComponentUtil#jsonToLegacy validation to match Vanilla

MC 1.14 validates both lore and display name properly when reading it, this doesn't matter for ViaVersion where the server doesn't send a json and we build it (and the client never sends invalid data to us). But it is important for ViaBackwards to handle invalid sent json properly like MC does.
Dieser Commit ist enthalten in:
FlorianMichael 2024-06-02 21:19:39 +02:00
Ursprung 82452dbdfe
Commit 6714f8c7d2
2 geänderte Dateien mit 10 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -260,7 +260,7 @@ public class ItemPacketRewriter1_14 extends ItemRewriter<ClientboundPackets1_13,
if (item.tag() == null) return item; if (item.tag() == null) return item;
// Display Name now uses JSON // Lore now uses JSON
CompoundTag display = item.tag().getCompoundTag("display"); CompoundTag display = item.tag().getCompoundTag("display");
if (display != null) { if (display != null) {
ListTag<StringTag> lore = display.getListTag("Lore", StringTag.class); ListTag<StringTag> lore = display.getListTag("Lore", StringTag.class);

Datei anzeigen

@ -19,6 +19,7 @@ package com.viaversion.viaversion.util;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.viaversion.nbt.tag.CompoundTag; import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.StringTag; import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag; import com.viaversion.nbt.tag.Tag;
@ -165,8 +166,14 @@ public final class ComponentUtil {
return SerializerVersion.V1_12.toString(component); return SerializerVersion.V1_12.toString(component);
} }
public static String jsonToLegacy(final String value) { public static @Nullable String jsonToLegacy(final String value) {
return TextComponentSerializer.V1_12.deserializeReader(value).asLegacyFormatString(); try {
final ATextComponent component = TextComponentSerializer.V1_12.deserializeReader(value);
if (component == null) return null;
return component.asLegacyFormatString();
} catch (final JsonParseException e) {
return null;
}
} }
public static String jsonToLegacy(final JsonElement value) { public static String jsonToLegacy(final JsonElement value) {