From 2a088c08ed5873524b92727bb35fb86fa9a9e049 Mon Sep 17 00:00:00 2001 From: EnZaXD Date: Thu, 30 May 2024 22:55:03 +0200 Subject: [PATCH] Handle edge cases when converting legacy components (#3896) --- .../viaversion/viaversion/util/ComponentUtil.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) 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 5517a921e..45778bbe3 100644 --- a/common/src/main/java/com/viaversion/viaversion/util/ComponentUtil.java +++ b/common/src/main/java/com/viaversion/viaversion/util/ComponentUtil.java @@ -155,18 +155,16 @@ public final class ComponentUtil { public static String legacyToJsonString(final String message, final boolean itemData) { final ATextComponent component = LegacyStringDeserializer.parse(message, true); - if (itemData && hasStyle(component)) { - component.setParentStyle(new Style().setItalic(false)); + if (itemData) { + TextUtils.iterateAll(component, c -> { + if (!c.getStyle().isEmpty()) { + c.setParentStyle(new Style().setItalic(false)); + } + }); } return SerializerVersion.V1_12.toString(component); } - public static boolean hasStyle(final ATextComponent component) { - final boolean[] hasStyle = {false}; - TextUtils.iterateAll(component, c -> hasStyle[0] |= !c.getStyle().isEmpty()); - return hasStyle[0]; - } - public static String jsonToLegacy(final String value) { return TextComponentSerializer.V1_12.deserializeReader(value).asLegacyFormatString(); }