public abstract class Text extends Object implements TextRepresentable
Text is primarily used for sending formatted chat messages to players, but also in other places like books or signs.
Text instances can be either directly created through the available
constructor or using the TextBuilder
available through one of the
Texts.builder()
methods, which is the recommended way.
Texts.builder()
,
TextBuilder
,
Text.Literal
,
Text.Translatable
,
Text.Selector
,
Text.Score
Modifier and Type | Class and Description |
---|---|
static class |
Text.Literal
|
static class |
Text.Placeholder
Represents a
Text placeholder that can be replaced with another
Text by Texts.format(Text, java.util.Map) . |
static class |
Text.Score
Represents a
Text displaying the current score of a player. |
static class |
Text.Selector
Represents a
Text containing a selector that will be replaced by
the names of the matching entities on the client. |
static class |
Text.Translatable
Represents a
Text containing a Translation identifier
that gets translated into the current locale on the client. |
Modifier and Type | Field and Description |
---|---|
protected ImmutableList<Text> |
children |
protected Iterable<Text> |
childrenIterable
|
protected Optional<ClickAction<?>> |
clickAction |
protected TextFormat |
format |
protected Optional<HoverAction<?>> |
hoverAction |
protected Optional<ShiftClickAction<?>> |
shiftClickAction |
Modifier and Type | Method and Description |
---|---|
abstract TextBuilder |
builder()
Returns a new
TextBuilder with the content, formatting and
actions of this text. |
boolean |
equals(Object o) |
ImmutableList<Text> |
getChildren()
Returns the immutable list of children appended after the content of this
Text . |
Optional<ClickAction<?>> |
getClickAction()
Returns the
ClickAction executed on the client when this
Text gets clicked. |
TextColor |
getColor()
Returns the color of this
Text . |
TextFormat |
getFormat()
Returns the format of this
Text . |
Optional<HoverAction<?>> |
getHoverAction()
Returns the
HoverAction executed on the client when this
Text gets hovered. |
Optional<ShiftClickAction<?>> |
getShiftClickAction()
Returns the
ShiftClickAction executed on the client when this
Text gets shift-clicked. |
TextStyle |
getStyle()
Returns the style of this
Text . |
int |
hashCode() |
String |
toString() |
Text |
toText()
Gets the textual representation of this instance for its usage in other
Text objects. |
Iterable<Text> |
withChildren()
Returns an immutable
Iterable over this text and all of its
children. |
protected final TextFormat format
protected final ImmutableList<Text> children
protected final Optional<ClickAction<?>> clickAction
protected final Optional<HoverAction<?>> hoverAction
protected final Optional<ShiftClickAction<?>> shiftClickAction
public final TextFormat getFormat()
Text
.public final TextColor getColor()
Text
.public final TextStyle getStyle()
Text
. This will return a compound
TextStyle
if multiple different styles have been set.public final ImmutableList<Text> getChildren()
Text
.public final Iterable<Text> withChildren()
Iterable
over this text and all of its
children. This is recursive, the children of the children will be also
included.public final Optional<ClickAction<?>> getClickAction()
ClickAction
executed on the client when this
Text
gets clicked.Optional.absent()
if
not setpublic final Optional<HoverAction<?>> getHoverAction()
HoverAction
executed on the client when this
Text
gets hovered.Optional.absent()
if
not setpublic final Optional<ShiftClickAction<?>> getShiftClickAction()
ShiftClickAction
executed on the client when this
Text
gets shift-clicked.Optional.absent()
if not setpublic abstract TextBuilder builder()
TextBuilder
with the content, formatting and
actions of this text. This can be used to edit an otherwise immutable
Text
instance.public final Text toText()
TextRepresentable
Text
objects. This may but does not need to include
hover texts
or other actions
. This
method is basically the toString()
equivalent
for Text
s.toText
in interface TextRepresentable