use of com.loohp.interactivechat.libs.net.kyori.adventure.text.TextComponent in project InteractiveChat-DiscordSRV-Addon by LOOHP.
the class CharacterDataArray method fromComponent.
public static CharacterDataArray fromComponent(Component component, boolean legacyRGB) {
List<CharacterData> data = new LinkedList<>();
StringBuilder sb = new StringBuilder();
component = ComponentFlattening.flatten(component);
for (Component each : component.children()) {
Key font = each.style().font();
if (font == null) {
font = Key.key("minecraft:default");
}
TextColor color = each.color();
if (color == null) {
color = NamedTextColor.WHITE;
}
List<TextDecoration> decorations = each.decorations().entrySet().stream().filter(entry -> entry.getValue().equals(State.TRUE)).map(entry -> entry.getKey()).collect(Collectors.toList());
String content;
if (each instanceof TextComponent) {
content = ChatColorUtils.filterIllegalColorCodes(((TextComponent) each).content(), legacyRGB);
} else {
content = ChatColorUtils.filterIllegalColorCodes(PlainTextComponentSerializer.plainText().serialize(each), legacyRGB);
}
if (content.isEmpty()) {
continue;
}
CharacterData characterData = new CharacterData(font, color, decorations);
for (char c : content.toCharArray()) {
data.add(characterData);
sb.append(c);
}
}
return new CharacterDataArray(sb.toString().toCharArray(), data.toArray(new CharacterData[data.size()]));
}
Aggregations