/** * Copies the events and formatting of a BaseComponent. Already set * formatting will be replaced. * * @param component the component to copy from */ public void copyFormatting(BaseComponent component) { copyFormatting( component, FormatRetention.ALL, true ); }
/** * Copies the events and formatting of a BaseComponent. * * @param component the component to copy from * @param replace if already set formatting should be replaced by the new * component */ public void copyFormatting(BaseComponent component, boolean replace) { copyFormatting( component, FormatRetention.ALL, replace ); }
/** * Appends a component to the builder and makes it the current target for * formatting. You can specify the amount of formatting retained from * previous part. * * @param component the component to append * @param retention the formatting to retain * @return this ComponentBuilder for chaining */ public ComponentBuilder append(BaseComponent component, FormatRetention retention) { parts.add( current ); BaseComponent previous = current; current = component.duplicate(); current.copyFormatting( previous, retention, false ); return this; }
/** * Appends the text to the builder and makes it the current target for * formatting. You can specify the amount of formatting retained from * previous part. * * @param text the text to append * @param retention the formatting to retain * @return this ComponentBuilder for chaining */ public ComponentBuilder append(String text, FormatRetention retention) { parts.add( current ); BaseComponent old = current; current = new TextComponent( text ); current.copyFormatting( old, retention, false ); return this; }
/** * Appends the components to the builder and makes the last element the * current target for formatting. You can specify the amount of formatting * retained from previous part. * * @param components the components to append * @param retention the formatting to retain * @return this ComponentBuilder for chaining */ public ComponentBuilder append(BaseComponent[] components, FormatRetention retention) { Preconditions.checkArgument( components.length != 0, "No components to append" ); BaseComponent previous = current; for ( BaseComponent component : components ) { parts.add( current ); current = component.duplicate(); current.copyFormatting( previous, retention, false ); } return this; }
BaseComponent(BaseComponent old) { copyFormatting( old, FormatRetention.ALL, true ); if ( old.getExtra() != null ) { for ( BaseComponent extra : old.getExtra() ) { addExtra( extra.duplicate() ); } } }