From 8df0c0ae2ea7375009ad8e28cd2d699a6ed15a26 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 24 Apr 2024 15:47:47 +0200 Subject: [PATCH] Catch component parsing exceptions separately instead of failing the entire item --- .../BlockItemPacketRewriter1_20_5.java | 29 ++++++++++++++++--- .../viaversion/util/ComponentUtil.java | 9 +----- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java index c4cc7a9c4..fb0ded1aa 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java @@ -1089,11 +1089,23 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter loreTag = displayTag.getListTag("Lore", StringTag.class); if (loreTag != null) { // Apply limit as per new network codec. Some servers send these lores to do trickery with shaders - data.set(StructuredDataKey.LORE, loreTag.stream().limit(256).map(t -> jsonToTag(connection, t)).toArray(Tag[]::new)); + try { + data.set(StructuredDataKey.LORE, loreTag.stream().limit(256).map(t -> jsonToTag(connection, t)).toArray(Tag[]::new)); + } catch (final Exception ignored) { + // No lore if any one of them fail to parse + } } final NumberTag colorTag = displayTag.getNumberTag("color"); diff --git a/common/src/main/java/com/viaversion/viaversion/util/ComponentUtil.java b/common/src/main/java/com/viaversion/viaversion/util/ComponentUtil.java index e84c4bce6..98a0297ad 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/ComponentUtil.java +++ b/common/src/main/java/com/viaversion/viaversion/util/ComponentUtil.java @@ -110,14 +110,7 @@ public final class ComponentUtil { if (json == null) { return null; } - - try { - final ATextComponent component = from.jsonSerializer.deserialize(json); - return to.toTag(component); - } catch (final Exception e) { - Via.getPlatform().getLogger().log(Level.SEVERE, "Error converting component: " + json, e); - return new StringTag(""); - } + return to.toTag(from.jsonSerializer.deserialize(json)); } public static @Nullable JsonElement convertJson(@Nullable final JsonElement element, final SerializerVersion from, final SerializerVersion to) {