use of org.spongepowered.common.text.ResolvedChatStyle in project SpongeCommon by SpongePowered.
the class MixinTextComponentBase method toLegacy.
@Override
public String toLegacy(char code) {
StringBuilder builder = new StringBuilder();
ResolvedChatStyle current = null;
Style previous = null;
for (ITextComponent component : withChildren()) {
Style newStyle = component.getStyle();
ResolvedChatStyle style = resolve(current, previous, newStyle);
previous = newStyle;
if (current == null || (current.color != style.color) || (current.bold && !style.bold) || (current.italic && !style.italic) || (current.underlined && !style.underlined) || (current.strikethrough && !style.strikethrough) || (current.obfuscated && !style.obfuscated)) {
if (style.color != null) {
apply(builder, code, style.color);
} else if (current != null) {
apply(builder, code, RESET);
}
apply(builder, code, BOLD, style.bold);
apply(builder, code, ITALIC, style.italic);
apply(builder, code, UNDERLINE, style.underlined);
apply(builder, code, STRIKETHROUGH, style.strikethrough);
apply(builder, code, OBFUSCATED, style.obfuscated);
} else {
apply(builder, code, BOLD, current.bold != style.bold);
apply(builder, code, ITALIC, current.italic != style.italic);
apply(builder, code, UNDERLINE, current.underlined != style.underlined);
apply(builder, code, STRIKETHROUGH, current.strikethrough != style.strikethrough);
apply(builder, code, OBFUSCATED, current.obfuscated != style.obfuscated);
}
current = style;
builder.append(component.getUnformattedComponentText());
}
return builder.toString();
}
Aggregations