Class PrismaticAPI
This class exposes two facades backed by the same parser and color engine:
legacy() returns plain strings containing Bukkit-compatible color codes and is always safe
to use, while adventure() returns Adventure components when the Adventure runtime is available.
The top-level methods on this class are retained for source compatibility with older PrismaticAPI
versions and delegate to legacy().
The shared pipeline understands legacy color codes, multiple RGB syntaxes, gradients, rainbows and, when Adventure MiniMessage is present at runtime, MiniMessage tags that coexist with Prismatic tags.
-
Method Summary
Modifier and TypeMethodDescriptionstatic Formatter<net.kyori.adventure.text.Component> Returns the Adventure formatter facade when the required Adventure classes are present at runtime.static StringapplyColor(Color color, String string, boolean legacy) Applies a single color to the beginning of a string.static StringapplyGradient(String string, Color start, Color end, boolean legacy) Applies a per-character gradient between two colors.static StringapplyRainbow(String string, float saturation, boolean legacy) Applies a per-character rainbow effect.static ChatComponent<?> chatComponent(String message) Creates a mutable interactive chat component.static StringParses and colorizes a string using the conservative no-player fallback.static StringParses and colorizes a string using the full Prismatic pipeline for a specific player context.static net.md_5.bungee.api.ChatColorfromString(String string) Parses a color token into aChatColor.static net.md_5.bungee.api.ChatColorfromString(String string, boolean legacy) Converts a bare six-digit hexadecimal RGB value into aChatColor.static @Nullable StringgetEndColor(String string) Returns the last color code found in the formatted representation of a string.static @Nullable StringgetStartColor(String string) Returns the first color code found in the formatted representation of a string.static booleanChecks whether the Adventure facade can be used safely at runtime.legacy()Returns the always-safe legacy formatter facade.static MultiComponentmultiComponent(String message) Creates a mutable multi-component that can parse click and hover markup.static booleanstartsWithColor(String string) Determines whether the formatted representation of a string starts with a color code.static StringRemoves Bukkit colors, Bukkit special formatting, MiniMessage tags and Prismatic RGB syntax from a string.static StringstripBukkit(String string) Removes standard Bukkit color codes from a string.static StringstripMiniMessage(String string) Removes MiniMessage formatting tags from a string.static StringRemoves Prismatic RGB, gradient and rainbow syntax from a string while leaving legacy Bukkit codes untouched.static StringstripSpecial(String string) Removes Bukkit special formatting codes from a string.
-
Method Details
-
legacy
Returns the always-safe legacy formatter facade.The returned formatter produces
stringscontaining Bukkit/Bungee color codes and does not require Adventure to exist at runtime.- Returns:
- formatter that produces legacy strings
- Since:
- 1.4.0
-
adventure
Returns the Adventure formatter facade when the required Adventure classes are present at runtime.This facade produces
componentsfrom the same Prismatic parsing pipeline used bylegacy(). CallisAdventureAvailable()before invoking this method when Adventure is an optional dependency in the consuming plugin.- Returns:
- formatter that produces Adventure components
- Throws:
IllegalStateException- if Adventure or MiniMessage is not available at runtime- Since:
- 1.4.0
-
isAdventureAvailable
public static boolean isAdventureAvailable()Checks whether the Adventure facade can be used safely at runtime.The check validates the presence of the Adventure component API, MiniMessage and the legacy serializer classes required by PrismaticAPI's Adventure bridge.
- Returns:
truewhen the Adventure formatter can be created safely- Since:
- 1.4.0
-
chatComponent
Creates a mutable interactive chat component.The component compiles to Bungee/Spigot
BaseComponentoutput and uses the Prismatic legacy formatter by default.- Parameters:
message- raw message- Returns:
- new chat component
- Since:
- 1.5.0
-
multiComponent
Creates a mutable multi-component that can parse click and hover markup.The supported markup is
<action:"argument">text</text>or<action:"argument"|action:"argument">text</text>.- Parameters:
message- raw or formatted message- Returns:
- new multi-component
- Since:
- 1.5.0
-
fromString
Converts a bare six-digit hexadecimal RGB value into aChatColor.When
legacyisfalse, the returned color preserves the exact RGB value. Whenlegacyistrue, the value is downsampled to the nearest legacy Bukkit color.- Parameters:
string- six-digit hexadecimal RGB value without a leading#legacy- whether to downsample the result to the legacy Bukkit palette- Returns:
- the resulting chat color
- Throws:
NumberFormatException- ifstringis not a valid six-digit hexadecimal RGB value
-
fromString
Parses a color token into aChatColor.This overload accepts plain legacy codes such as
a, prefixed legacy codes such as&aor§a, exact RGB values such asff8800, and compact hex tokens such as&xff8800. Blank input falls back toChatColor.WHITE.- Parameters:
string- color token to parse- Returns:
- the parsed chat color, or white when the input is blank or unrecognized
-
applyColor
Applies a single color to the beginning of a string.- Parameters:
color- color to prependstring- text to receive the colorlegacy- whether to use the nearest legacy Bukkit color instead of exact RGB- Returns:
- the colorized string
-
applyGradient
Applies a per-character gradient between two colors.Existing special format codes such as bold or italic are preserved while visible characters are recolored across the gradient.
- Parameters:
string- text to colorizestart- gradient start colorend- gradient end colorlegacy- whether to downsample each generated step to the legacy Bukkit palette- Returns:
- the gradient-colored string
-
applyRainbow
Applies a per-character rainbow effect.- Parameters:
string- text to colorizesaturation- rainbow saturation/brightness factor used to generate the palettelegacy- whether to downsample each generated step to the legacy Bukkit palette- Returns:
- the rainbow-colored string
-
colorize
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 converted to legacy-safe colors. When Adventure MiniMessage is available at runtime, MiniMessage tags are handled before Prismatic tags are restored into the final output.
- Parameters:
player- player used to resolve runtime color capabilities, ornullto force the conservative legacy fallbackstring- text to parse and colorize- Returns:
- the final formatted string
-
colorize
Parses and colorizes a string using the conservative no-player fallback.This overload delegates to
colorize(Player, String)with anullplayer, which means the result is treated as legacy-safe output because no player capability information is available.- Parameters:
string- text to parse and colorize- Returns:
- the formatted legacy-safe string
-
stripBukkit
Removes standard Bukkit color codes from a string.This targets color codes such as
&a,§cand the compactxhex prefix. It does not remove Prismatic gradient/rainbow tags.- Parameters:
string- text to clean- Returns:
- the string without standard Bukkit color codes
-
stripSpecial
Removes Bukkit special formatting codes from a string.This includes styles such as bold, italic, underline, obfuscated and reset markers.
- Parameters:
string- text to clean- Returns:
- the string without Bukkit special formatting codes
-
stripRGB
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
Removes MiniMessage formatting tags from a string.- Parameters:
string- text to clean- Returns:
- the string without MiniMessage tags
-
stripAll
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
Determines whether the formatted representation of a string starts with a color code.The inspection is performed against the conservative legacy rendering used by
colorize(String).- Parameters:
string- text to inspect- Returns:
trueif the formatted output begins with a color code
-
getStartColor
Returns the first color code found in the formatted representation of a string.The returned value is based on the conservative legacy rendering used by
colorize(String)and is typically a section-sign color code such as§a.- Parameters:
string- text to inspect- Returns:
- the first detected color code, or
nullif none is present
-
getEndColor
Returns the last color code found in the formatted representation of a string.The returned value is based on the conservative legacy rendering used by
colorize(String)and is typically a section-sign color code such as§a.- Parameters:
string- text to inspect- Returns:
- the last detected color code, or
nullif none is present
-