Developer API
Add ChatColor as a dependency in your project to interact with player color data programmatically.
Obtaining the API Instance
To use the API, obtain an instance of the ChatColorAPI from the main plugin class.
ChatColor plugin = (ChatColor) Bukkit.getPluginManager().getPlugin("ChatColor");
if (plugin != null) {
ChatColorAPI api = plugin.getChatColorAPI();
// Your API calls here
}
API Methods
Set a Player's Color
// Set a solid color by key
api.setColor(player, "red");
// Set a gradient by key
api.setGradient(player, "sunset");
// Set a pattern by key
api.setPattern(player, "rainbow");
Reset a Player's Color
// Remove all active color settings for a player
api.resetColor(player);
Get Player Data
// Get data by UUID
PlayerColorData data = api.getPlayerData(player.getUniqueId());
if (data != null) {
String type = data.getColorType(); // "SOLID", "GRADIENT", "PATTERN", or "NONE"
String key = data.getColorKey();
String tag = data.getColorTag();
}
Apply Color to Text
Apply a player's active selection to a string and return it as a Kyori Adventure Component.
Component coloredText = api.applyColorToText(player, "Hello, world!");