Interface Format<T>

Type Parameters:
T - the type of the result produced when this format is applied
All Known Subinterfaces:
BiFormat<T,R>, ContextualFormat<T>, PlainFormat<T>, StringFormat, TextFormat<T>

public interface Format<T>
Defines the contract for a single text‐based format.

A Format encapsulates:

  • Method Summary

    Modifier and Type
    Method
    Description
    default T
    accept(String string)
    Transform the given text using this format without any player context.
    accept(org.bukkit.entity.Player player, String string)
    Transform the given text using this format in the context of a single Player.
    @NotNull String
    Obtain the regex pattern string used to identify this format within input text.
    default boolean
    Check whether the input contains at least one occurrence of this format.
    default @NotNull Matcher
    matcher(String string)
    Create a Matcher for this format against the provided input.
    default String
    Strip all substrings matching this format from the input text.
    default @NotNull String
    Convert the given result into a formatted representation.
  • Method Details

    • getRegex

      @NotNull @NotNull String getRegex()
      Obtain the regex pattern string used to identify this format within input text.

      This string is automatically wrapped into a Pattern by matcher(String). Patterns should use non-greedy quantifiers (e.g. ".+?") to avoid over-matching.

      Returns:
      a valid Java regex, annotated with Regex to denote its purpose
    • matcher

      @NotNull default @NotNull Matcher matcher(String string)
      Create a Matcher for this format against the provided input.
      Parameters:
      string - the text to match against (never null)
      Returns:
      a Matcher configured with getRegex() on string
    • isFormatted

      default boolean isFormatted(String string)
      Check whether the input contains at least one occurrence of this format.
      Parameters:
      string - text in which to search for format markers
      Returns:
      true if at least one match is found; false otherwise
    • removeFormat

      default String removeFormat(String string)
      Strip all substrings matching this format from the input text.

      This default implementation simply finds each match via matcher(String) and removes it. Implementations with more complex needs or performance constraints are encouraged to override this method with a tailored removal algorithm.

      Parameters:
      string - the original text containing format markers
      Returns:
      a new string with all matching substrings removed
    • accept

      @NotNull T accept(org.bukkit.entity.Player player, String string)
      Transform the given text using this format in the context of a single Player.

      Implementations must override this method to perform the desired transformation based on the raw input string and optionally the player context.

      Parameters:
      player - the player context (may be null)
      string - the text to transform (never null)
      Returns:
      the result of applying this format
    • accept

      @NotNull default T accept(String string)
      Transform the given text using this format without any player context.
      Parameters:
      string - the text to transform (never null)
      Returns:
      the result of applying this format
    • toFormattedString

      @NotNull default @NotNull String toFormattedString(T result)
      Convert the given result into a formatted representation.

      This method is intended to be overridden by subclasses to provide specific formatting logic. The default implementation throws an UnsupportedOperationException.

      Parameters:
      result - the object to format (never null)
      Returns:
      the formatted string
      Throws:
      UnsupportedOperationException - if not overridden