Skip to content

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.

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.

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.

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:

#ff8040

Only the RGB channels are included in the resulting hexadecimal value.

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:

#4080ff

The RGB channels are converted into hexadecimal notation.

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.

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:

  1. extractTwoColors(...) determines the color palette.
  2. 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.

Extracts two signal colors from an image.

Parameter Type Description
image BufferedImage The image to analyze.

Returns an array containing two Color values.

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.

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.

Generates a random Bukkit color.

Returns a randomly generated Bukkit Color.

For selecting the strongest colors from a collection, see ColorfulnessFinder.

For the complete collection of Reedwork utilities, see the PaperMC Plugin Utilities.