mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 03:25:11 +01:00
Fixup ComponentUtil#legacyToJsonString behavior on items with styles (#3868)
This commit is contained in:
parent
659bee771b
commit
9547cf160d
@ -30,6 +30,7 @@ import net.lenni0451.mcstructs.text.events.hover.AHoverEvent;
|
|||||||
import net.lenni0451.mcstructs.text.events.hover.impl.TextHoverEvent;
|
import net.lenni0451.mcstructs.text.events.hover.impl.TextHoverEvent;
|
||||||
import net.lenni0451.mcstructs.text.serializer.LegacyStringDeserializer;
|
import net.lenni0451.mcstructs.text.serializer.LegacyStringDeserializer;
|
||||||
import net.lenni0451.mcstructs.text.serializer.TextComponentSerializer;
|
import net.lenni0451.mcstructs.text.serializer.TextComponentSerializer;
|
||||||
|
import net.lenni0451.mcstructs.text.utils.TextUtils;
|
||||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -151,12 +152,18 @@ public final class ComponentUtil {
|
|||||||
|
|
||||||
public static String legacyToJsonString(final String message, final boolean itemData) {
|
public static String legacyToJsonString(final String message, final boolean itemData) {
|
||||||
final ATextComponent component = LegacyStringDeserializer.parse(message, true);
|
final ATextComponent component = LegacyStringDeserializer.parse(message, true);
|
||||||
if (itemData) {
|
if (itemData && hasStyle(component)) {
|
||||||
component.setParentStyle(new Style().setItalic(false));
|
component.setParentStyle(new Style().setItalic(false));
|
||||||
}
|
}
|
||||||
return SerializerVersion.V1_12.toString(component);
|
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) {
|
public static String jsonToLegacy(final String value) {
|
||||||
return TextComponentSerializer.V1_12.deserializeReader(value).asLegacyFormatString();
|
return TextComponentSerializer.V1_12.deserializeReader(value).asLegacyFormatString();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user