public interface Text extends com.mojang.brigadier.Message, StringVisitable
Each text has a tree structure, embodying all its siblings
. To iterate contents in the text and all
its siblings, call visit
methods.
This interface does not expose mutation operations. For mutation,
refer to MutableText
.
MutableText
Modifier and Type | Interface and Description |
---|---|
static class |
Text.Serializer
A JSON serializer for
Text . |
StringVisitable.StyledVisitor<T>, StringVisitable.Visitor<T>
EMPTY, TERMINATE_VISIT
Modifier and Type | Method and Description |
---|---|
OrderedText |
asOrderedText() |
String |
asString()
Returns the string representation of this text itself, excluding siblings.
|
default String |
asTruncatedString(int length)
Returns the full string representation of this text, truncated beyond
the supplied
length . |
MutableText |
copy()
Copies the text itself, excluding the styles or siblings.
|
List<Text> |
getSiblings()
Returns the siblings of this text.
|
default String |
getString() |
Style |
getStyle()
Returns the style of this text.
|
static Text |
of(String string)
Creates a literal text with the given string as content.
|
MutableText |
shallowCopy()
Copies the text itself, the style, and the siblings.
|
default <T> Optional<T> |
visit(StringVisitable.StyledVisitor<T> styledVisitor,
Style style)
Supplies this visitable's literal content and contextual style to
the visitor.
|
default <T> Optional<T> |
visit(StringVisitable.Visitor<T> visitor)
Supplies this visitable's literal content to the visitor.
|
default <T> Optional<T> |
visitSelf(StringVisitable.StyledVisitor<T> visitor,
Style style)
Visits the text itself.
|
default <T> Optional<T> |
visitSelf(StringVisitable.Visitor<T> visitor)
Visits the text itself.
|
concat, concat, plain, styled
Style getStyle()
String asString()
default String getString()
getString
in interface com.mojang.brigadier.Message
getString
in interface StringVisitable
default String asTruncatedString(int length)
length
.length
- the max length allowed for the string representation of the textMutableText copy()
MutableText shallowCopy()
A shallow copy is made for the siblings.
@Environment(value=CLIENT) OrderedText asOrderedText()
@Environment(value=CLIENT) default <T> Optional<T> visit(StringVisitable.StyledVisitor<T> styledVisitor, Style style)
visit
in interface StringVisitable
styledVisitor
- the visitorstyle
- the contextual styleOptional.empty()
if the visit finished, or a terminating
result from the visitor
default <T> Optional<T> visit(StringVisitable.Visitor<T> visitor)
visit
in interface StringVisitable
visitor
- the visitorOptional.empty()
if the visit finished, or a terminating
result from the visitor
@Environment(value=CLIENT) default <T> Optional<T> visitSelf(StringVisitable.StyledVisitor<T> visitor, Style style)
visitor
- the visitorstyle
- the current styleStringVisitable.visit(StyledVisitor, Style)
default <T> Optional<T> visitSelf(StringVisitable.Visitor<T> visitor)
visitor
- the visitorStringVisitable.visit(Visitor)