Skip to content

Commit 9547cf1

Browse files
Fixup ComponentUtil#legacyToJsonString behavior on items with styles (#3868)
1 parent 659bee7 commit 9547cf1

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

common/src/main/java/com/viaversion/viaversion/util/ComponentUtil.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import net.lenni0451.mcstructs.text.events.hover.impl.TextHoverEvent;
3131
import net.lenni0451.mcstructs.text.serializer.LegacyStringDeserializer;
3232
import net.lenni0451.mcstructs.text.serializer.TextComponentSerializer;
33+
import net.lenni0451.mcstructs.text.utils.TextUtils;
3334
import org.checkerframework.checker.nullness.qual.Nullable;
3435

3536
/**
@@ -151,12 +152,18 @@ public static String legacyToJsonString(final String message) {
151152

152153
public static String legacyToJsonString(final String message, final boolean itemData) {
153154
final ATextComponent component = LegacyStringDeserializer.parse(message, true);
154-
if (itemData) {
155+
if (itemData && hasStyle(component)) {
155156
component.setParentStyle(new Style().setItalic(false));
156157
}
157158
return SerializerVersion.V1_12.toString(component);
158159
}
159160

161+
public static boolean hasStyle(final ATextComponent component) {
162+
final boolean[] hasStyle = {false};
163+
TextUtils.iterateAll(component, c -> hasStyle[0] |= !c.getStyle().isEmpty());
164+
return hasStyle[0];
165+
}
166+
160167
public static String jsonToLegacy(final String value) {
161168
return TextComponentSerializer.V1_12.deserializeReader(value).asLegacyFormatString();
162169
}

0 commit comments

Comments
 (0)