Interface Formatter<T>

Type Parameters:
T - formatter result type

public interface Formatter<T>
Shared contract implemented by the PrismaticAPI.legacy() and PrismaticAPI.adventure() facades.

Both facades use the same Prismatic parsing pipeline and only differ in the type they emit: legacy output returns strings, while Adventure output returns components.

Since:
1.4.0
  • Method Summary

    Modifier and Type
    Method
    Description
    applyColor(Color color, String string, boolean legacy)
    Applies a single color to the beginning of a string.
    applyGradient(String string, Color start, Color end, boolean legacy)
    Applies a per-character gradient between two colors.
    applyRainbow(String string, float saturation, boolean legacy)
    Applies a per-character rainbow effect.
    default T
    colorize(String string)
    Parses and colorizes a string without player context.
    colorize(@Nullable org.bukkit.entity.Player player, String string)
    Parses and colorizes a string using the full Prismatic pipeline for a specific player context.
    default net.md_5.bungee.api.ChatColor
    Parses a color token into a chat color.
    net.md_5.bungee.api.ChatColor
    fromString(String string, boolean legacy)
    Converts a bare six-digit hexadecimal RGB value into a chat color.
    @Nullable String
    Returns the last color code found in the formatted representation of a string.
    @Nullable String
    Returns the first color code found in the formatted representation of a string.
    boolean
    Determines whether the formatted representation of a string starts with a color code.
    stripAll(String string)
    Removes Bukkit colors, Bukkit special formatting, MiniMessage tags and Prismatic RGB syntax from a string.
    Removes standard Bukkit color codes from a string.
    Removes MiniMessage formatting tags from a string.
    stripRGB(String string)
    Removes Prismatic RGB, gradient and rainbow syntax from a string while leaving legacy Bukkit codes untouched.
    Removes Bukkit special formatting codes from a string.
  • Method Details

    • fromString

      net.md_5.bungee.api.ChatColor fromString(String string, boolean legacy)
      Converts a bare six-digit hexadecimal RGB value into a chat color.

      When legacy is false, the exact RGB value is preserved. When legacy is true, the result is downsampled to the nearest legacy Bukkit color.

      Parameters:
      string - six-digit hexadecimal RGB value without a leading #
      legacy - whether to downsample the resulting color to the legacy palette
      Returns:
      the parsed chat color
      Throws:
      NumberFormatException - if string is not a valid six-digit hexadecimal RGB value
    • fromString

      default net.md_5.bungee.api.ChatColor fromString(String string)
      Parses a color token into a chat color.

      This overload accepts plain legacy codes such as a, prefixed legacy codes such as &a or §a, exact RGB values such as ff8800, and compact hex tokens such as &xff8800. Blank input falls back to ChatColor.WHITE.

      Parameters:
      string - color token to parse
      Returns:
      the parsed chat color, or white when the input is blank or unrecognized
    • applyColor

      T applyColor(Color color, String string, boolean legacy)
      Applies a single color to the beginning of a string.
      Parameters:
      color - color to prepend
      string - text to receive the color
      legacy - whether to use the nearest legacy Bukkit color instead of exact RGB
      Returns:
      the colorized output
    • applyGradient

      T applyGradient(String string, Color start, Color end, boolean legacy)
      Applies a per-character gradient between two colors.
      Parameters:
      string - text to colorize
      start - gradient start color
      end - gradient end color
      legacy - whether to downsample each generated step to the legacy Bukkit palette
      Returns:
      the gradient-colored output
    • applyRainbow

      T applyRainbow(String string, float saturation, boolean legacy)
      Applies a per-character rainbow effect.
      Parameters:
      string - text to colorize
      saturation - rainbow saturation/brightness factor used to generate the palette
      legacy - whether to downsample each generated step to the legacy Bukkit palette
      Returns:
      the rainbow-colored output
    • colorize

      T colorize(@Nullable @Nullable org.bukkit.entity.Player player, String string)
      Parses and colorizes a string using the full Prismatic pipeline for a specific player context.

      If the player supports hex colors, RGB output is preserved. Otherwise the result is downsampled to legacy-safe colors.

      Parameters:
      player - player used to resolve runtime color capabilities, or null to force the conservative legacy fallback
      string - text to parse and colorize
      Returns:
      the formatted output
    • colorize

      default T colorize(String string)
      Parses and colorizes a string without player context.

      This delegates to colorize(Player, String) with a null player, which means the formatting pipeline uses the conservative legacy fallback because no player capability information is available.

      Parameters:
      string - text to parse and colorize
      Returns:
      the formatted output
    • stripBukkit

      String stripBukkit(String string)
      Removes standard Bukkit color codes from a string.
      Parameters:
      string - text to clean
      Returns:
      the string without standard Bukkit color codes
    • stripSpecial

      String stripSpecial(String string)
      Removes Bukkit special formatting codes from a string.
      Parameters:
      string - text to clean
      Returns:
      the string without Bukkit special formatting codes
    • stripRGB

      String stripRGB(String string)
      Removes Prismatic RGB, gradient and rainbow syntax from a string while leaving legacy Bukkit codes untouched.
      Parameters:
      string - text to clean
      Returns:
      the string without Prismatic RGB syntax
    • stripMiniMessage

      String stripMiniMessage(String string)
      Removes MiniMessage formatting tags from a string.
      Parameters:
      string - text to clean
      Returns:
      the string without MiniMessage tags
    • stripAll

      String stripAll(String string)
      Removes Bukkit colors, Bukkit special formatting, MiniMessage tags and Prismatic RGB syntax from a string.
      Parameters:
      string - text to clean
      Returns:
      the fully stripped plain-text string
    • startsWithColor

      boolean startsWithColor(String string)
      Determines whether the formatted representation of a string starts with a color code.
      Parameters:
      string - text to inspect
      Returns:
      true if the formatted output begins with a color code
    • getStartColor

      @Nullable @Nullable String getStartColor(String string)
      Returns the first color code found in the formatted representation of a string.
      Parameters:
      string - text to inspect
      Returns:
      the first detected color code, or null if none is present
    • getEndColor

      @Nullable @Nullable String getEndColor(String string)
      Returns the last color code found in the formatted representation of a string.
      Parameters:
      string - text to inspect
      Returns:
      the last detected color code, or null if none is present