Tidy up new color classes

This commit is contained in:
Kieran Wallbanks 2021-03-24 12:51:31 +00:00
parent 9490f1f9da
commit 1fe159636b
2 changed files with 13 additions and 28 deletions

View File

@ -123,23 +123,6 @@ public class Color implements RGBLike {
return (rgb << 8) + blue;
}
/**
* Shorthand method for {@link #mixWith(Color...)}. This method converts each dye
* color to a color and then mixes this color with the new colors.
*
* @param dyeColors the dye colors
*/
public void mixWith(@NotNull DyeColor... dyeColors) {
Validate.noNullElements(dyeColors, "Colors cannot be null");
Color[] colors = new Color[dyeColors.length];
for (int i = 0; i < colors.length; i++) {
colors[i] = dyeColors[i].getColor();
}
this.mixWith(colors);
}
/**
* Mixes this color with a series of other colors, as if they were combined in a
* crafting table. This function works out the average of each RGB component and then
@ -149,18 +132,18 @@ public class Color implements RGBLike {
*
* @param colors the colors
*/
public void mixWith(@NotNull Color... colors) {
public void mixWith(@NotNull RGBLike... colors) {
Validate.noNullElements(colors, "Colors cannot be null");
// store the current highest component
int max = Math.max(Math.max(this.red, this.green), this.blue);
// now combine all of the color components, adding to the max
for (Color color : colors) {
this.red += color.getRed();
this.green += color.getGreen();
this.blue += color.getBlue();
max += Math.max(Math.max(color.getRed(), color.getGreen()), color.getBlue());
for (RGBLike color : colors) {
this.red += color.red();
this.green += color.green();
this.blue += color.blue();
max += Math.max(Math.max(color.red(), color.green()), color.blue());
}
// work out the averages

View File

@ -3,6 +3,8 @@ package net.minestom.server.color;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.util.RGBLike;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
/**
@ -34,21 +36,21 @@ public enum TeamColor implements RGBLike {
}
/**
* Gets the text color equivalent to this team color, if any.
* Gets the text color equivalent to this team color.
*
* @return the text color
*/
public @Nullable TextColor getTextColor() {
public @NotNull TextColor getTextColor() {
return this.color;
}
/**
* Gets the color equivalent to this team color, if any.
* Gets the color equivalent to this team color.
*
* @return the color
*/
public @Nullable Color getColor() {
return this.color == null ? null : new Color(this.color);
public @NotNull Color getColor() {
return new Color(this.color);
}
/**