/** * Creates a ComponentBuilder with the given text as the first part. * * @param text the first text element */ public ComponentBuilder(String text) { current = new TextComponent( text ); }
/** * Creates a duplicate of this TextComponent. * * @return the duplicate of this TextComponent. */ @Override public BaseComponent duplicate() { return new TextComponent( this ); }
public static String toString(BaseComponent... components) { if ( components.length == 1 ) { return gson.toJson( components[0] ); } else { return gson.toJson( new TextComponent( components ) ); } }
@Deprecated public ServerPing(Protocol version, Players players, String description, Favicon favicon) { this( version, players, new TextComponent( TextComponent.fromLegacyText( description ) ), favicon ); }
@Deprecated public void setDescription(String description) { this.description = new TextComponent( TextComponent.fromLegacyText( description ) ); }
/** * 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 ) ); }
/** * 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 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; }
@Override public TextComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { TextComponent component = new TextComponent(); JsonObject object = json.getAsJsonObject(); deserialize( object, component, context ); component.setText( object.get( "text" ).getAsString() ); return component; }
@Override public BaseComponent deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { if ( json.isJsonPrimitive() ) { return new TextComponent( json.getAsString() ); } JsonObject object = json.getAsJsonObject(); if ( object.has( "translate" ) ) { return context.deserialize( json, TranslatableComponent.class ); } if ( object.has( "keybind" ) ) { return context.deserialize( json, KeybindComponent.class ); } if ( object.has( "score" ) ) { return context.deserialize( json, ScoreComponent.class ); } if ( object.has( "selector" ) ) { return context.deserialize( json, SelectorComponent.class ); } return context.deserialize( json, TextComponent.class ); } }
@Deprecated public ServerPing(Protocol version, Players players, String description, String favicon) { this( version, players, new TextComponent( TextComponent.fromLegacyText( description ) ), favicon == null ? null : Favicon.create( favicon ) ); }
/** * Creates a translatable component with the passed substitutions * * @see #translate * @see #setWith(java.util.List) * @param translate the translation key * @param with the {@link java.lang.String}s and * {@link net.md_5.bungee.api.chat.BaseComponent}s to use into the * translation */ public TranslatableComponent(String translate, Object... with) { setTranslate( translate ); if ( with != null && with.length != 0 ) { List<BaseComponent> temp = new ArrayList<BaseComponent>(); for ( Object w : with ) { if ( w instanceof BaseComponent ) { temp.add( (BaseComponent) w ); } else { temp.add( new TextComponent( String.valueOf( w ) ) ); } } setWith( temp ); } }
TextComponent component = new TextComponent(); Matcher matcher = url.matcher( message ); component = new TextComponent( old ); old.setText( builder.toString() ); builder = new StringBuilder(); format = defaultColor; default: component = new TextComponent(); component.setColor( format ); break; component = new TextComponent( old ); old.setText( builder.toString() ); builder = new StringBuilder(); component = new TextComponent( old ); String urlString = message.substring( i, pos ); component.setText( urlString );
new TextComponent( "" ) };
@Override public void sendMessage(ChatMessageType position, BaseComponent message) { message = ChatComponentTransformer.getInstance().transform( this, message )[0]; // Action bar doesn't display the new JSON formattings, legacy works - send it using this for now if ( position == ChatMessageType.ACTION_BAR ) { sendMessage( position, ComponentSerializer.toString( new TextComponent( BaseComponent.toLegacyText( message ) ) ) ); } else { sendMessage( position, ComponentSerializer.toString( message ) ); } }
@Override public void sendMessage(ChatMessageType position, BaseComponent... message) { // transform score components message = ChatComponentTransformer.getInstance().transform( this, message ); // Action bar doesn't display the new JSON formattings, legacy works - send it using this for now if ( position == ChatMessageType.ACTION_BAR ) { sendMessage( position, ComponentSerializer.toString( new TextComponent( BaseComponent.toLegacyText( message ) ) ) ); } else { sendMessage( position, ComponentSerializer.toString( message ) ); } }
player.disconnect( new TextComponent( kickReason ) );
new TextComponent( TextComponent.fromLegacyText( listener.getMotd() ) ), (Favicon) null );
TextComponent serverTextComponent = new TextComponent( first ? server.getName() : ", " + server.getName() ); int count = server.getPlayers().size(); serverTextComponent.setHoverEvent( new HoverEvent( HoverEvent.Action.SHOW_TEXT,
public static TextComponent getNotificationLevelUpTextComponent(PrimarySkillType skill, int levelsGained, int currentLevel) { TextComponent textComponent = new TextComponent(LocaleLoader.getString("Overhaul.Levelup", LocaleLoader.getString("Overhaul.Name."+StringUtils.getCapitalized(skill.toString())), levelsGained, currentLevel)); return textComponent; }