/** * Parse text to BaseComponent[] with colors and format, appends the text to * the builder and makes it the current target for formatting. The component * will have all the formatting from previous part. * * @param text the text to append * @return this ComponentBuilder for chaining */ public ComponentBuilder appendLegacy(String text) { return append( TextComponent.fromLegacyText( text ) ); }
/** * Adds a text substitution to the component. The text will inherit this * component's formatting * * @param text the text to substitute */ public void addWith(String text) { addWith( new TextComponent( text ) ); }
/** * Appends a text element to the component. The text will inherit this * component's formatting * * @param text the text to append */ public void addExtra(String text) { addExtra( new TextComponent( text ) ); }
void toLegacyText(StringBuilder builder) { if ( extra != null ) { for ( BaseComponent e : extra ) { e.toLegacyText( builder ); } } } }
/** * Sets the click event for the current part. * * @param clickEvent the click event * @return this ComponentBuilder for chaining */ public ComponentBuilder event(ClickEvent clickEvent) { current.setClickEvent( clickEvent ); return this; }
/** * Sets whether the current part is bold. * * @param bold whether this part is bold * @return this ComponentBuilder for chaining */ public ComponentBuilder bold(boolean bold) { current.setBold( bold ); return this; }
/** * Creates a duplicate of this TranslatableComponent. * * @return the duplicate of this TranslatableComponent. */ @Override public BaseComponent duplicate() { return new TranslatableComponent( this ); }
/** * Sets whether the current part is obfuscated. * * @param obfuscated whether this part is obfuscated * @return this ComponentBuilder for chaining */ public ComponentBuilder obfuscated(boolean obfuscated) { current.setObfuscated( obfuscated ); return this; }
/** * Sets the insertion text for the current part. * * @param insertion the insertion text * @return this ComponentBuilder for chaining */ public ComponentBuilder insertion(String insertion) { current.setInsertion( insertion ); return this; }
/** * Sets the current part back to normal settings. Only text is kept. * * @return this ComponentBuilder for chaining */ public ComponentBuilder reset() { return retain( FormatRetention.NONE ); }
/** * Creates a selector component from the original to clone it. * * @param original the original for the new selector component */ public SelectorComponent(SelectorComponent original) { super( original ); setSelector( original.getSelector() ); }
/** * Creates a keybind component from the original to clone it. * * @param original the original for the new keybind component. */ public KeybindComponent(KeybindComponent original) { super( original ); setKeybind( original.getKeybind() ); }
void toPlainText(StringBuilder builder) { if ( extra != null ) { for ( BaseComponent e : extra ) { e.toPlainText( builder ); } } }
/** * Sets whether the current part is italic. * * @param italic whether this part is italic * @return this ComponentBuilder for chaining */ public ComponentBuilder italic(boolean italic) { current.setItalic( italic ); return this; }
@Override public SelectorComponent duplicate() { return new SelectorComponent( this ); }
@Override public BaseComponent duplicate() { return new KeybindComponent( this ); }
@Override public ScoreComponent duplicate() { return new ScoreComponent( this ); }
/** * Creates a keybind component with the passed internal keybind value. * * @param keybind the keybind value * @see Keybinds */ public KeybindComponent(String keybind) { setKeybind( keybind ); }
/** * Converts a {@link Title} to 3 instances of {@link TitleMessage}. * * @param title the title to convert * @return 3 messages: the first sets the title, the second sets the subtitle, and the third * sets the fade/stay/fade durations */ public static TitleMessage[] fromTitle(Title title) { TextMessage titleMessage = asTextMessage(BaseComponent.toLegacyText(title.getTitle())); TextMessage subTitleMessage = title.getSubtitle() != null ? asTextMessage( BaseComponent.toLegacyText(title.getSubtitle())) : asTextMessage(null); return new TitleMessage[]{ new TitleMessage(Action.TITLE, titleMessage), new TitleMessage(Action.SUBTITLE, subTitleMessage), new TitleMessage(Action.TIMES, title.getFadeIn(), title.getStay(), title .getFadeOut()) }; }