mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-27 04:25:12 +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.
This commit is contained in:
parent
82452dbdfe
commit
6714f8c7d2
@ -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);
|
||||||
|
@ -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) {
|
||||||
|
Loading…
Reference in New Issue
Block a user