From 71e6fcf23ecf4a9524c6cc20987feb314fbdecf8 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Sat, 25 Jul 2026 12:18:40 +0200 Subject: [PATCH 1/2] chore(deps): add junit params dependency --- build.gradle.kts | 1 + settings.gradle.kts | 1 + 2 files changed, 2 insertions(+) diff --git a/build.gradle.kts b/build.gradle.kts index c3f8da0..c38619d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -26,6 +26,7 @@ dependencies { testImplementation(libs.cyano) testImplementation(libs.adventure) testImplementation(libs.junit.api) + testImplementation(libs.junit.params) testImplementation(libs.junit.platform.launcher) testImplementation(libs.mockito.core) testImplementation(libs.mockito.junit) diff --git a/settings.gradle.kts b/settings.gradle.kts index 5f0d637..c779c98 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -35,6 +35,7 @@ dependencyResolutionManagement { library("mockito.core", "org.mockito", "mockito-core").withoutVersion() library("mockito.junit", "org.mockito", "mockito-junit-jupiter").withoutVersion() library("junit.platform.launcher", "org.junit.platform", "junit-platform-launcher").withoutVersion() + library("junit.params", "org.junit.jupiter", "junit-jupiter-params").withoutVersion() } } } From faad6f2bb88047b0acc33fb4f8ec3e926e1e53a8 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Sat, 25 Jul 2026 12:20:12 +0200 Subject: [PATCH 2/2] feat(color): add method to translate a ColorData to a TeamColor --- .../theevilreaper/xerus/api/ColorData.java | 43 ++++++++++++++++--- .../xerus/api/ColorDataTest.java | 15 +++++++ 2 files changed, 51 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/theevilreaper/xerus/api/ColorData.java b/src/main/java/net/theevilreaper/xerus/api/ColorData.java index 88af91e..20f9cca 100644 --- a/src/main/java/net/theevilreaper/xerus/api/ColorData.java +++ b/src/main/java/net/theevilreaper/xerus/api/ColorData.java @@ -3,14 +3,18 @@ import net.kyori.adventure.text.format.NamedTextColor; import net.minestom.server.color.Color; import net.minestom.server.color.DyeColor; +import net.minestom.server.color.TeamColor; import net.minestom.server.item.Material; +import java.util.EnumMap; +import java.util.Map; + /** * Represents a mapping of visual color variants using text color, dye color, block material, and a string identifier. * Each constant aligns with a specific base color and can be used to harmonize visual elements across different systems. * * @author theEvilReaper - * @version 1.6.0 + * @version 1.7.0 * @since 1.0.0 */ @SuppressWarnings("java:S3252") @@ -40,14 +44,14 @@ public enum ColorData { /** Aligns with the dark gray color. */ DARK_GRAY(NamedTextColor.DARK_GRAY, DyeColor.GRAY, Material.GRAY_WOOL, "colorDarkGray"), - /** Aligns with the green color. */ - GREEN(NamedTextColor.DARK_GREEN, DyeColor.GREEN, Material.GREEN_WOOL, "colorGreen"), + /** Aligns with the dark green color. */ + DARK_GREEN(NamedTextColor.DARK_GREEN, DyeColor.GREEN, Material.GREEN_WOOL, "colorGreen"), - /** Aligns with the light green color. */ - LIGHT_GREEN(NamedTextColor.GREEN, DyeColor.LIME, Material.LIME_WOOL, "colorLime"), + /** Aligns with the green color. */ + GREEN(NamedTextColor.GREEN, DyeColor.LIME, Material.LIME_WOOL, "colorLime"), - /** Aligns with the purple color. */ - PURPLE(NamedTextColor.DARK_PURPLE, DyeColor.PURPLE, Material.PURPLE_WOOL, "colorPurple"), + /** Aligns with the dark purple color. */ + DARK_PURPLE(NamedTextColor.DARK_PURPLE, DyeColor.PURPLE, Material.PURPLE_WOOL, "colorPurple"), /** Aligns with the light purple color. */ LIGHT_PURPLE(NamedTextColor.LIGHT_PURPLE, DyeColor.MAGENTA, Material.MAGENTA_WOOL, "colorMagenta"), @@ -67,6 +71,20 @@ public enum ColorData { //Reduce defensive copies from the array, because values() returns each call a new array! private static final ColorData[] VALUES = values(); + private static final Map TEAM_COLOR_CACHE = new EnumMap<>(ColorData.class); + + static { + for (ColorData colorData : VALUES) { + TeamColor mapped = TeamColor.fromName(colorData.chatColor.toString()); + if (mapped == null) { + throw new ExceptionInInitializerError( + "No TeamColor mapping found for ColorData " + colorData.name() + ); + } + TEAM_COLOR_CACHE.put(colorData, mapped); + } + } + private final NamedTextColor chatColor; private final DyeColor dyeColor; private final Material material; @@ -132,6 +150,17 @@ public Color getColor() { return this.dyeColor.color(); } + /** + * Returns the matching {@link TeamColor} for this entry, resolved via the underlying + * {@link NamedTextColor} rather than the enum name to avoid mismatches + * (e.g. this enum's {@code DARK_GREEN} maps to {@link NamedTextColor#DARK_GREEN}). + * + * @return the underlying teamColor + */ + public TeamColor toTeamColor() { + return TEAM_COLOR_CACHE.get(this); + } + /** * Returns an array which contains all given color data values. * Please use this method because it reduces defensive copies from the array, diff --git a/src/test/java/net/theevilreaper/xerus/api/ColorDataTest.java b/src/test/java/net/theevilreaper/xerus/api/ColorDataTest.java index bb88b75..ce5c839 100644 --- a/src/test/java/net/theevilreaper/xerus/api/ColorDataTest.java +++ b/src/test/java/net/theevilreaper/xerus/api/ColorDataTest.java @@ -3,8 +3,11 @@ import net.kyori.adventure.text.format.NamedTextColor; import net.minestom.server.color.Color; import net.minestom.server.color.DyeColor; +import net.minestom.server.color.TeamColor; import net.minestom.server.item.Material; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; import static org.junit.jupiter.api.Assertions.*; @@ -26,4 +29,16 @@ void testAquaData() { void testLength() { assertSame(16, ColorData.getValues().length); } + + @ParameterizedTest + @EnumSource(ColorData.class) + void testToTeamColorMatchesChatColor(ColorData colorData) { + TeamColor teamColor = colorData.toTeamColor(); + NamedTextColor chatColor = colorData.getChatColor(); + + assertNotNull(teamColor); + assertEquals(chatColor.red(), teamColor.red()); + assertEquals(chatColor.green(), teamColor.green()); + assertEquals(chatColor.blue(), teamColor.blue()); + } }