Search in sources :

Example 1 with ResolvedChatStyle

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();
}
Also used : ITextComponent(net.minecraft.util.text.ITextComponent) ResolvedChatStyle(org.spongepowered.common.text.ResolvedChatStyle) TextStyle(org.spongepowered.api.text.format.TextStyle) Style(net.minecraft.util.text.Style) ResolvedChatStyle(org.spongepowered.common.text.ResolvedChatStyle)

Aggregations

ITextComponent (net.minecraft.util.text.ITextComponent)1 Style (net.minecraft.util.text.Style)1 TextStyle (org.spongepowered.api.text.format.TextStyle)1 ResolvedChatStyle (org.spongepowered.common.text.ResolvedChatStyle)1