java.lang.Object
nl.pim16aap2.animatedarchitecture.core.text.Text
All Implemented Interfaces:
CharSequence

public class Text extends Object implements CharSequence
Represents a piece of text with styled sections.
  • Constructor Details

  • Method Details

    • getLength

      public int getLength()
      Gets the length of the raw text without any styles applied to it.
      Returns:
      The length of the raw text without any styles applied to it.
    • subsection

      @Contract("_, _ -> this") public Text subsection(int start, int end)
      Gets a subsection from this Text.

      See StringBuilder.substring(int, int).

      Any styles/decorators that have at least 1 character inside this range will be copied.

      Parameters:
      start - The beginning index, inclusive.
      end - The ending index, exclusive.
      Returns:
      The Text in the given range.
    • append

      @Contract("_ -> this") public Text append(String text)
      Appends some unstyled text to the current text.
      Parameters:
      text - The unstyled text to add.
      Returns:
      The current Text instance.
    • append

      @Contract("_, _ -> this") public Text append(String text, TextArgument... arguments)
      Appends some unstyled text to the current text.
      Parameters:
      text - The unstyled text to add.
      Returns:
      The current Text instance.
    • append

      @Contract("_ -> this") public Text append(char ch)
      Appends some unstyled character to the current text.
      Parameters:
      ch - The unstyled character to add.
      Returns:
      The current Text instance.
    • append

      @Contract("_, _ -> this") public Text append(String text, @Nullable @Nullable TextType type)
      Appends some styled text to the current text.
      Parameters:
      text - The text to add.
      type - The TextType of the text to add. This is used by any potential decorators to add styling and such to the text.
      Returns:
      The current Text instance.
    • append

      @Contract("_, _, _ -> this") public Text append(String text, @Nullable @Nullable TextType type, TextArgument... arguments)
      Appends some styled text to the current text.
      Parameters:
      text - The text to add.
      type - The TextType of the text to add. This is used by any potential decorators to add styling and such to the text.
      arguments - The text arguments to use for variable substitution into the input text.
      Returns:
      The current Text instance.
    • append

      @Contract("_, _, _ -> this") @SafeVarargs public final Text append(String text, @Nullable @Nullable TextType type, Function<TextArgumentFactory,TextArgument>... argumentRetrievers)
      Appends some styled text to the current text.
      Parameters:
      text - The text to add.
      type - The TextType of the text to add. This is used by any potential decorators to add styling and such to the text.
      argumentRetrievers - Retrievers for text arguments to use for variable substitution into the input text.
      Returns:
      The current Text instance.
    • append

      @Contract("_, _, _ -> this") public Text append(String text, @Nullable @Nullable TextComponent component, TextArgument... arguments)
      Appends some styled text to the current text with some optional argument.

      For example "Hello, {0}".

      See MessageFormat.

      Parameters:
      text - The text to add.
      component - The TextComponent to use for the text that is being added.
      arguments - The arguments to use to format the text.
      Returns:
      The current Text instance.
    • append

      @Contract("_, _, _ -> this") @SafeVarargs public final Text append(String text, @Nullable @Nullable TextComponent component, Function<TextArgumentFactory,TextArgument>... argumentRetrievers)
      Appends some styled text to the current text with some optional argument.

      For example "Hello, {0}".

      See MessageFormat.

      Parameters:
      text - The text to add.
      component - The TextComponent to use for the text that is being added.
      argumentRetrievers - Retrievers for text arguments to use for variable substitution into the input text.
      Returns:
      The current Text instance.
    • newTextArgument

      public TextArgument newTextArgument(Object argument, TextType type)
      Creates a new TextArgument with a given input String and text type.

      This method is a shortcut for creating a new text argument using the input String and ITextComponentFactory.newComponent(TextType).

      Parameters:
      argument - The argument to use for the TextArgument.
      type - The text type to use for the TextComponent.
      Returns:
      The new text argument.
    • newClickableTextArgument

      public TextArgument newClickableTextArgument(Object argument, @Nullable @Nullable TextType type, String command, @Nullable @Nullable String info)
      Creates a new text argument for clickable texts.

      This method is a shortcut for creating a new argument using the input text and ITextComponentFactory.newClickableTextComponent(TextType, String, String).

      Parameters:
      argument - The argument to use for the TextArgument.
      type - The TextType of the text to add. This is used by any potential decorators to add styling and such to the text.
      command - The command to execute when this text is clicked.
      info - The optional information String explaining what clicking the text will do.
      Returns:
      The new text component if one was created or null if no specific decoration should be applied to the text.
    • appendClickableText

      @Contract("_, _, _, _ -> this") public Text appendClickableText(String text, @Nullable @Nullable TextType type, String command, @Nullable @Nullable String info)
      Attempts to add clickable text.

      The clickable text will execute a command when clicked.

      The result depends on the capabilities of both the registered ITextComponentFactory and the ITextRenderer.

      Parameters:
      text - The text to add.
      type - The TextType of the text to add. This is used by any potential decorators to add styling and such to the text.
      command - The command to execute when this text is clicked.
      info - The optional information String explaining what clicking the text will do.
      Returns:
      The current Text instance.
    • prepend

      @Contract("_ -> this") public Text prepend(Text other)
      Prepends another Text object to this object, so the other text is placed before the current one.

      The other Text instance is not modified.

      Parameters:
      other - The Text to insert before the current Text.
      Returns:
      The current Text instance.
    • append

      @Contract("_ -> this") public Text append(Text other)
      Appends another Text object to this one.

      The other Text object will not be modified.

      Parameters:
      other - The other Text instance to append to the current one.
      Returns:
      The current Text instance.
    • render

      public <T> T render(ITextRenderer<T> renderer)
      Renders this text using the provided text renderer.

      All sections of this Text object are processed by the renderer.

      Type Parameters:
      T - The output type of the renderer.
      Parameters:
      renderer - The renderer to use.
      Returns:
      The output of the renderer after processing this Text object.
    • length

      public int length()
      Specified by:
      length in interface CharSequence
    • charAt

      public char charAt(int index)
      Specified by:
      charAt in interface CharSequence
    • subSequence

      public CharSequence subSequence(int start, int end)
      Specified by:
      subSequence in interface CharSequence
    • toString

      public String toString()
      Specified by:
      toString in interface CharSequence
      Overrides:
      toString in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getTextComponentFactory

      public ITextComponentFactory getTextComponentFactory()
      The factory for the TextComponent instance used by this Text.
    • getTextArgumentFactory

      public TextArgumentFactory getTextArgumentFactory()
      The factory for TextArguments.