public final class ComponentBuilder extends Object
ComponentBuilder simplifies creating basic messages by allowing the use of a chainable builder.
new ComponentBuilder("Hello ").color(ChatColor.RED).
append("World").color(ChatColor.BLUE). append("!").bold(true).create();
All methods (excluding append(String) and create() work on
the last part appended to the builder, so in the example above "Hello " would
be ChatColor.RED and "World" would be
ChatColor.BLUE but "!" would be bold and
ChatColor.BLUE because append copies the previous
part's formatting
| Modifier and Type | Class and Description |
|---|---|
static class |
ComponentBuilder.FormatRetention |
static interface |
ComponentBuilder.Joiner
Functional interface to join additional components to a ComponentBuilder.
|
| Constructor and Description |
|---|
ComponentBuilder(BaseComponent component)
Creates a ComponentBuilder with the given component as the first part.
|
ComponentBuilder(ComponentBuilder original)
Creates a ComponentBuilder from the other given ComponentBuilder to clone
it.
|
ComponentBuilder(String text)
Creates a ComponentBuilder with the given text as the first part.
|
| Modifier and Type | Method and Description |
|---|---|
ComponentBuilder |
append(BaseComponent component)
Appends a component to the builder and makes it the current target for
formatting.
|
ComponentBuilder |
append(BaseComponent[] components)
Appends the components to the builder and makes the last element the
current target for formatting.
|
ComponentBuilder |
append(BaseComponent[] components,
ComponentBuilder.FormatRetention retention)
Appends the components to the builder and makes the last element the
current target for formatting.
|
ComponentBuilder |
append(BaseComponent component,
ComponentBuilder.FormatRetention retention)
Appends a component to the builder and makes it the current target for
formatting.
|
ComponentBuilder |
append(ComponentBuilder.Joiner joiner)
Allows joining additional components to this builder using the given
ComponentBuilder.Joiner and ComponentBuilder.FormatRetention.ALL. |
ComponentBuilder |
append(ComponentBuilder.Joiner joiner,
ComponentBuilder.FormatRetention retention)
Allows joining additional components to this builder using the given
ComponentBuilder.Joiner. |
ComponentBuilder |
append(String text)
Appends the text to the builder and makes it the current target for
formatting.
|
ComponentBuilder |
append(String text,
ComponentBuilder.FormatRetention retention)
Appends the text to the builder and makes it the current target for
formatting.
|
ComponentBuilder |
appendLegacy(String text)
Parse text to BaseComponent[] with colors and format, appends the text to
the builder and makes it the current target for formatting.
|
ComponentBuilder |
bold(boolean bold)
Sets whether the current part is bold.
|
ComponentBuilder |
color(ChatColor color)
Sets the color of the current part.
|
BaseComponent[] |
create()
Returns the components needed to display the message created by this
builder.
|
ComponentBuilder |
event(ClickEvent clickEvent)
Sets the click event for the current part.
|
ComponentBuilder |
event(HoverEvent hoverEvent)
Sets the hover event for the current part.
|
ComponentBuilder |
insertion(String insertion)
Sets the insertion text for the current part.
|
ComponentBuilder |
italic(boolean italic)
Sets whether the current part is italic.
|
ComponentBuilder |
obfuscated(boolean obfuscated)
Sets whether the current part is obfuscated.
|
ComponentBuilder |
reset()
Sets the current part back to normal settings.
|
ComponentBuilder |
retain(ComponentBuilder.FormatRetention retention)
Retains only the specified formatting.
|
ComponentBuilder |
strikethrough(boolean strikethrough)
Sets whether the current part is strikethrough.
|
ComponentBuilder |
underlined(boolean underlined)
Sets whether the current part is underlined.
|
public ComponentBuilder(ComponentBuilder original)
original - the original for the new ComponentBuilder.public ComponentBuilder(String text)
text - the first text elementpublic ComponentBuilder(BaseComponent component)
component - the first component elementpublic ComponentBuilder append(BaseComponent component)
component - the component to appendpublic ComponentBuilder append(BaseComponent component, ComponentBuilder.FormatRetention retention)
component - the component to appendretention - the formatting to retainpublic ComponentBuilder append(BaseComponent[] components)
components - the components to appendpublic ComponentBuilder append(BaseComponent[] components, ComponentBuilder.FormatRetention retention)
components - the components to appendretention - the formatting to retainpublic ComponentBuilder append(String text)
text - the text to appendpublic ComponentBuilder appendLegacy(String text)
text - the text to appendpublic ComponentBuilder append(String text, ComponentBuilder.FormatRetention retention)
text - the text to appendretention - the formatting to retainpublic ComponentBuilder append(ComponentBuilder.Joiner joiner)
ComponentBuilder.Joiner and ComponentBuilder.FormatRetention.ALL.
Simply executes the provided joiner on this instance to facilitate a
chain pattern.joiner - joiner used for operationpublic ComponentBuilder append(ComponentBuilder.Joiner joiner, ComponentBuilder.FormatRetention retention)
ComponentBuilder.Joiner.
Simply executes the provided joiner on this instance to facilitate a
chain pattern.joiner - joiner used for operationretention - the formatting to retainpublic ComponentBuilder color(ChatColor color)
color - the new colorpublic ComponentBuilder bold(boolean bold)
bold - whether this part is boldpublic ComponentBuilder italic(boolean italic)
italic - whether this part is italicpublic ComponentBuilder underlined(boolean underlined)
underlined - whether this part is underlinedpublic ComponentBuilder strikethrough(boolean strikethrough)
strikethrough - whether this part is strikethroughpublic ComponentBuilder obfuscated(boolean obfuscated)
obfuscated - whether this part is obfuscatedpublic ComponentBuilder insertion(String insertion)
insertion - the insertion textpublic ComponentBuilder event(ClickEvent clickEvent)
clickEvent - the click eventpublic ComponentBuilder event(HoverEvent hoverEvent)
hoverEvent - the hover eventpublic ComponentBuilder reset()
public ComponentBuilder retain(ComponentBuilder.FormatRetention retention)
retention - the formatting to retainpublic BaseComponent[] create()
Copyright © 2015–2019 WaterfallMC. All rights reserved.