public interface Text
extends com.mojang.brigadier.Message
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. |
static interface |
Text.StyledVisitor<T>
A visitor for text content and a contextual
Style. |
static interface |
Text.Visitor<T>
A visitor for text content.
|
| Modifier and Type | Field and Description |
|---|---|
static Optional<Unit> |
TERMINATE_VISIT
An
Optional that indicates a text visitor should be terminated. |
| Modifier and Type | Method and Description |
|---|---|
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()
Returns the full string representation of this text, including siblings.
|
Style |
getStyle()
Returns the style of this text.
|
MutableText |
shallowCopy()
Copies the text itself, the style, and the siblings.
|
default <T> Optional<T> |
visit(Text.StyledVisitor<T> visitor,
Style style)
Visits the code points of in each
partial string
representation of text and its siblings, applying the formatting
codes within. |
default <T> Optional<T> |
visit(Text.Visitor<T> visitor)
Visits this text and its siblings.
|
default <T> Optional<T> |
visitSelf(Text.StyledVisitor<T> visitor,
Style style)
Visits the text itself.
|
default <T> Optional<T> |
visitSelf(Text.Visitor<T> visitor)
Visits the text itself.
|
Style getStyle()
String asString()
default String getString()
getString in interface com.mojang.brigadier.Messagedefault 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) default <T> Optional<T> visit(Text.StyledVisitor<T> visitor, Style style)
partial string
representation of text and its siblings, applying the formatting
codes within.
The visit is in forward direction.
visitor - the styled text visitorstyle - the starting styletrue if the full string was visited, or false indicating
the visitor terminated half-wayvisit(Text.StyledVisitor, Style)default <T> Optional<T> visit(Text.Visitor<T> visitor)
When the visitor returns a non-empty
optional during visit, the visit is immediately terminated and the
result is returned.
visitor - the text visitorOptional.empty() if the
visitor always returned Optional.empty().@Environment(value=CLIENT) default <T> Optional<T> visitSelf(Text.StyledVisitor<T> visitor, Style style)
visitor - the visitorstyle - the current stylevisit(StyledVisitor, Style)default <T> Optional<T> visitSelf(Text.Visitor<T> visitor)
visitor - the visitorvisit(Visitor)