Interface Text

All Superinterfaces:
com.mojang.brigadier.Message, StringVisitable
All Known Subinterfaces:
MutableText
All Known Implementing Classes:
BaseText, KeybindText, LiteralText, NbtText, NbtText.BlockNbtText, NbtText.EntityNbtText, NbtText.StorageNbtText, ScoreText, SelectorText, TranslatableText

public interface Text
extends com.mojang.brigadier.Message, StringVisitable
A text. Can be converted to and from JSON format.

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.

See Also:
MutableText
  • Method Details

    • getStyle

      Style getStyle()
      Returns the style of this text.
    • asString

      String asString()
      Returns the string representation of this text itself, excluding siblings.
    • getString

      default String getString()
      Specified by:
      getString in interface com.mojang.brigadier.Message
      Specified by:
      getString in interface StringVisitable
    • asTruncatedString

      default String asTruncatedString​(int length)
      Returns the full string representation of this text, truncated beyond the supplied length.
      Parameters:
      length - the max length allowed for the string representation of the text
    • getSiblings

      List<Text> getSiblings()
      Returns the siblings of this text.
    • copy

      MutableText copy()
      Copies the text itself, excluding the styles or siblings.
    • shallowCopy

      MutableText shallowCopy()
      Copies the text itself, the style, and the siblings.

      A shallow copy is made for the siblings.

    • asOrderedText

      @Environment(CLIENT) OrderedText asOrderedText()
    • visit

      @Environment(CLIENT) default <T> Optional<T> visit​(StringVisitable.StyledVisitor<T> styledVisitor, Style style)
      Supplies this visitable's literal content and contextual style to the visitor.
      Specified by:
      visit in interface StringVisitable
      Parameters:
      styledVisitor - the visitor
      style - the contextual style
      Returns:
      Optional.empty() if the visit finished, or a terminating result from the visitor
    • visit

      default <T> Optional<T> visit​(StringVisitable.Visitor<T> visitor)
      Supplies this visitable's literal content to the visitor.
      Specified by:
      visit in interface StringVisitable
      Parameters:
      visitor - the visitor
      Returns:
      Optional.empty() if the visit finished, or a terminating result from the visitor
    • visitSelf

      @Environment(CLIENT) default <T> Optional<T> visitSelf​(StringVisitable.StyledVisitor<T> visitor, Style style)
      Visits the text itself.
      Parameters:
      visitor - the visitor
      style - the current style
      Returns:
      the visitor's return value
      See Also:
      visit(StyledVisitor, Style)
    • visitSelf

      default <T> Optional<T> visitSelf​(StringVisitable.Visitor<T> visitor)
      Visits the text itself.
      Parameters:
      visitor - the visitor
      Returns:
      the visitor's return value
      See Also:
      visit(Visitor)
    • of

      @Environment(CLIENT) static Text of​(@Nullable String string)
      Creates a literal text with the given string as content.