Package me.croabeast.prismatic
Class PrismaticAPI
java.lang.Object
me.croabeast.prismatic.PrismaticAPI
A utility class that provides methods for color manipulation and text formatting.
PrismaticAPI offers functionality to convert hexadecimal color codes to Bukkit ChatColor
objects, create gradients and rainbow effects, and process strings for color codes.
It supports both legacy color formatting and modern RGB color support, adapting based on the server version
or player client.
Key features include:
- Mapping of AWT
Colorobjects to BukkitChatColorusing a predefined color map. - Conversion of hex strings into
ChatColorviafromString(String, boolean). - Creation of gradient and rainbow color arrays for dynamic text effects.
- Methods to apply these color effects to strings and to strip color formatting.
- Handling of legacy formatting by selecting the closest available color if needed.
Example usage:
// Colorize a message for a specific player:
String coloredMessage = PrismaticAPI.colorize(player, "invalid input: '&aHello', world!");
// Apply a gradient effect to a string:
String gradientText = PrismaticAPI.applyGradient("Gradient Text", new Color(255, 0, 0), new Color(0, 0, 255), false);
// Strip all color codes from a string:
String plainText = PrismaticAPI.stripAll("invalid input: '&aColored' invalid input: '&bText'");
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapplyColor(Color color, String string, boolean isLegacy) Prepends a given string with theChatColorcorresponding to the provided color.applyGradient(String string, Color start, Color end, boolean isLegacy) Applies a gradient color effect to the given string.applyRainbow(String string, float saturation, boolean isLegacy) Applies a rainbow color effect to the given string.Colorizes the given string without any player context.Colorizes the given string by applying all registeredColorPatterneffects.net.md_5.bungee.api.ChatColorfromString(String string, boolean isLegacy) Converts a hexadecimal color string into aChatColor.@Nullable StringgetLastColor(String string) Retrieves the last color code found in the provided string.booleanstartsWithColor(String string) Checks if the provided string starts with a valid color code.Strips all types of color and formatting codes from the provided string.stripBukkit(String string) Strips Bukkit color codes (e.g.Strips RGB color codes applied byColorPatternimplementations from the provided string.stripSpecial(String string) Strips special formatting codes (e.g.
-
Constructor Details
-
PrismaticAPI
public PrismaticAPI()
-
-
Method Details
-
fromString
Converts a hexadecimal color string into aChatColor.- Parameters:
string- the hexadecimal color code (without the leading '#' character)isLegacy- iftrue, legacy color mode is used- Returns:
- the resulting
ChatColor
-
applyColor
Prepends a given string with theChatColorcorresponding to the provided color.- Parameters:
color- the color to applystring- the string to colorizeisLegacy- iftrue, legacy color mode is used- Returns:
- the colorized string
-
applyGradient
Applies a gradient color effect to the given string.- Parameters:
string- the string to apply the gradient tostart- the starting color of the gradientend- the ending color of the gradientisLegacy- iftrue, legacy color mode is used- Returns:
- the string with a gradient effect applied
-
applyRainbow
Applies a rainbow color effect to the given string.- Parameters:
string- the string to apply the rainbow effect tosaturation- the saturation level for the rainbow (0.0 to 1.0)isLegacy- iftrue, legacy color mode is used- Returns:
- the string with a rainbow effect applied
-
colorize
Colorizes the given string by applying all registeredColorPatterneffects.The method determines if legacy color formatting is needed based on the server version and player client. Finally, it translates alternate color codes using Bukkit's translation method.
- Parameters:
player- the player for whom the colorization context is applied (may benull)string- the string to colorize- Returns:
- the colorized string
-
colorize
Colorizes the given string without any player context.- Parameters:
string- the string to colorize- Returns:
- the colorized string
-
stripBukkit
Strips Bukkit color codes (e.g.&a,§b) from the provided string.- Parameters:
string- the string from which to remove color codes- Returns:
- the string without Bukkit color codes
-
stripSpecial
Strips special formatting codes (e.g. magic, bold, etc.) from the provided string.- Parameters:
string- the string from which to remove special formatting- Returns:
- the string without special formatting codes
-
stripRGB
Strips RGB color codes applied byColorPatternimplementations from the provided string.- Parameters:
string- the string from which to remove RGB color codes- Returns:
- the string without RGB color codes
-
stripAll
Strips all types of color and formatting codes from the provided string.- Parameters:
string- the string from which to remove all formatting- Returns:
- the plain string without any color or formatting codes
-
startsWithColor
Checks if the provided string starts with a valid color code.- Parameters:
string- the string to check- Returns:
trueif the string starts with a color code;falseotherwise
-
getLastColor
Retrieves the last color code found in the provided string.- Parameters:
string- the string to search for color codes- Returns:
- the last color code as a
String, ornullif none is found
-