Bukkit Color and Gradient Utilities
ColorUtils provides color utilities for PaperMC and Bukkit plugin development, including Adventure text gradients, image color extraction, hexadecimal conversion, and random Bukkit colors.
The utility works primarily with Bukkit Color, java.awt.Color, BufferedImage, and Adventure Component objects.
Generate gradient text
Section titled “Generate gradient text”generateGradientText(String text, Color start, Color end)
Section titled “generateGradientText(String text, Color start, Color end)”Creates an Adventure Component whose characters transition from one Bukkit color to another.
Color start = Color.fromRGB(255, 0, 0);Color end = Color.fromRGB(0, 0, 255);
Component text = ColorUtils.generateGradientText( "Hello Reedwork!", start, end);The start color is applied to the beginning of the text and the end color to the end.
Because the result is an Adventure Component, it can be sent directly to a player:
player.sendMessage( ColorUtils.generateGradientText( "Hello Reedwork!", Color.fromRGB(255, 0, 0), Color.fromRGB(0, 255, 255) ));This is useful for colorful messages, titles, command feedback, and other Adventure-based text.
Extract colors from an image
Section titled “Extract colors from an image”extractTwoColors(BufferedImage image)
Section titled “extractTwoColors(BufferedImage image)”Analyzes a BufferedImage and returns two signal colors detected in the image.
BufferedImage image = ImageIO.read(file);
Color[] colors = ColorUtils.extractTwoColors(image);
Color first = colors[0];Color second = colors[1];The returned colors can be used as a palette for other operations.
For example, they can become the endpoints of a text gradient:
Color[] colors = ColorUtils.extractTwoColors(image);
Component gradient = ColorUtils.generateGradientText( "Welcome!", colors[0], colors[1]);
player.sendMessage(gradient);If the image does not provide enough suitable colors, the utility generates additional random colors before determining the result.
Convert a Bukkit color to hexadecimal
Section titled “Convert a Bukkit color to hexadecimal”colorToHex(org.bukkit.Color color)
Section titled “colorToHex(org.bukkit.Color color)”Converts a Bukkit Color into a hexadecimal RGB string.
Color color = Color.fromRGB(255, 128, 64);
String hex = ColorUtils.colorToHex(color);The resulting value is:
#ff8040Only the RGB channels are included in the resulting hexadecimal value.
Convert an AWT color to hexadecimal
Section titled “Convert an AWT color to hexadecimal”colorToHex(java.awt.Color color)
Section titled “colorToHex(java.awt.Color color)”ColorUtils also supports java.awt.Color.
java.awt.Color color = new java.awt.Color(64, 128, 255);
String hex = ColorUtils.colorToHex(color);The resulting value is:
#4080ffThe RGB channels are converted into hexadecimal notation.
Generate a random Bukkit color
Section titled “Generate a random Bukkit color”randomColor()
Section titled “randomColor()”Creates a random Bukkit Color.
Color color = ColorUtils.randomColor();Each RGB channel is generated independently.
This allows the method to generate colors across the available RGB range.
Combine color extraction and gradients
Section titled “Combine color extraction and gradients”The color utilities can be combined to create image-based visual effects.
For example, an image can provide two colors that become the endpoints of an Adventure text gradient:
Color[] colors = ColorUtils.extractTwoColors(image);
Component gradient = ColorUtils.generateGradientText( "Welcome!", colors[0], colors[1]);
player.sendMessage(gradient);The process has two separate steps:
extractTwoColors(...)determines the color palette.generateGradientText(...)applies the colors to Adventure text.
For more control over selecting the strongest colors from your own collection, see ColorfulnessFinder.
generateGradientText(String text, Color start, Color end)
Section titled “generateGradientText(String text, Color start, Color end)”Creates an Adventure component with a gradient between two Bukkit colors.
| Parameter | Type | Description |
|---|---|---|
text |
String |
The text to color. |
start |
Color |
The color at the beginning of the text. |
end |
Color |
The color at the end of the text. |
Returns an Adventure Component containing the gradient-colored text.
extractTwoColors(BufferedImage image)
Section titled “extractTwoColors(BufferedImage image)”Extracts two signal colors from an image.
| Parameter | Type | Description |
|---|---|---|
image |
BufferedImage |
The image to analyze. |
Returns an array containing two Color values.
colorToHex(org.bukkit.Color color)
Section titled “colorToHex(org.bukkit.Color color)”Converts a Bukkit color into hexadecimal notation.
| Parameter | Type | Description |
|---|---|---|
color |
Color |
The Bukkit color to convert. |
Returns a hexadecimal RGB string such as #ff8040.
colorToHex(java.awt.Color color)
Section titled “colorToHex(java.awt.Color color)”Converts an AWT color into hexadecimal notation.
| Parameter | Type | Description |
|---|---|---|
color |
java.awt.Color |
The AWT color to convert. |
Returns a hexadecimal RGB string such as #4080ff.
randomColor()
Section titled “randomColor()”Generates a random Bukkit color.
Returns a randomly generated Bukkit Color.
Related utilities
Section titled “Related utilities”For selecting the strongest colors from a collection, see ColorfulnessFinder.
For the complete collection of Reedwork utilities, see the PaperMC Plugin Utilities.