/** * Creates a TextComponent with formatting and text from the passed * component * * @param textComponent the component to copy from */ public TextComponent(TextComponent textComponent) { super( textComponent ); setText( textComponent.getText() ); }
@Override public JsonElement serialize(TextComponent src, Type typeOfSrc, JsonSerializationContext context) { List<BaseComponent> extra = src.getExtra(); JsonObject object = new JsonObject(); if ( src.hasFormatting() || ( extra != null && !extra.isEmpty() ) ) { serialize( object, src, context ); } object.addProperty( "text", src.getText() ); return object; } }
/** * Creates a TextComponent with formatting and text from the passed * component * * @param textComponent the component to copy from */ public TextComponent(TextComponent textComponent) { super( textComponent ); setText( textComponent.getText() ); }
@Override public JsonElement serialize(TextComponent src, Type typeOfSrc, JsonSerializationContext context) { List<BaseComponent> extra = src.getExtra(); JsonObject object = new JsonObject(); if ( src.hasFormatting() || ( extra != null && !extra.isEmpty() ) ) { serialize( object, src, context ); } object.addProperty( "text", src.getText() ); return object; } }
final String originalTxt = textComponent.getText();
/** * Retains only the specified formatting. Text is not modified. * * @param retention the formatting to retain * @return this ComponentBuilder for chaining */ public ComponentBuilder retain(FormatRetention retention) { BaseComponent previous = current; switch ( retention ) { case NONE: current = new TextComponent( current.getText() ); break; case ALL: // No changes are required break; case EVENTS: current = new TextComponent( current.getText() ); current.setInsertion( previous.getInsertion() ); current.setClickEvent( previous.getClickEvent() ); current.setHoverEvent( previous.getHoverEvent() ); break; case FORMATTING: current.setClickEvent( null ); current.setHoverEvent( null ); break; } return this; }