From a4534f9704f59469d4445c6529e66206123e3cf0 Mon Sep 17 00:00:00 2001 From: funnyboy-roks Date: Sun, 23 Nov 2025 18:06:10 -0600 Subject: [PATCH 1/7] use m4 to generate ComponentColor.java --- .github/workflows/check.yml | 19 ++ .../componentutils/ComponentColor.java | 25 +- .../componentutils/ComponentColor.java.m4 | 298 ++++++++++++++++++ 3 files changed, 328 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/check.yml create mode 100644 src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..9f7b468 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,19 @@ +name: build + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + component-color: + runs-on: 'ubuntu-latest' + steps: + - uses: actions/checkout@v5 + + - name: run m4 + run: m4 -P src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 > src/main/java/net/farlandsmc/componentutils/ComponentColor.java + + - name: check diff + run: git diff --quiet -- src/main/java/net/farlandsmc/componentutils/ComponentColor.java diff --git a/src/main/java/net/farlandsmc/componentutils/ComponentColor.java b/src/main/java/net/farlandsmc/componentutils/ComponentColor.java index cc75b25..403f3d9 100644 --- a/src/main/java/net/farlandsmc/componentutils/ComponentColor.java +++ b/src/main/java/net/farlandsmc/componentutils/ComponentColor.java @@ -1,3 +1,7 @@ + +// NOTE: This file is generated from ComponentColor.java.m4 +// Generate with `m4 -P src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 > src/main/java/net/farlandsmc/componentutils/ComponentColor.java` + package net.farlandsmc.componentutils; import net.kyori.adventure.text.Component; @@ -67,8 +71,7 @@ public static Component darkBlue(String format, Object... values) { } /** - * Generate a component with the colour of DARK_BLUE using {@link ComponentUtils#format} with the format of - * {@code {}} + * Generate a component with the colour of DARK_BLUE using {@link ComponentUtils#format} with the format of {@code {}} * * @param obj The object to format */ @@ -109,8 +112,7 @@ public static Component darkGreen(String format, Object... values) { } /** - * Generate a component with the colour of DARK_GREEN using {@link ComponentUtils#format} with the format of - * {@code {}} + * Generate a component with the colour of DARK_GREEN using {@link ComponentUtils#format} with the format of {@code {}} * * @param obj The object to format */ @@ -151,8 +153,7 @@ public static Component darkAqua(String format, Object... values) { } /** - * Generate a component with the colour of DARK_AQUA using {@link ComponentUtils#format} with the format of - * {@code {}} + * Generate a component with the colour of DARK_AQUA using {@link ComponentUtils#format} with the format of {@code {}} * * @param obj The object to format */ @@ -193,8 +194,7 @@ public static Component darkRed(String format, Object... values) { } /** - * Generate a component with the colour of DARK_RED using {@link ComponentUtils#format} with the format of - * {@code {}} + * Generate a component with the colour of DARK_RED using {@link ComponentUtils#format} with the format of {@code {}} * * @param obj The object to format */ @@ -235,8 +235,7 @@ public static Component darkPurple(String format, Object... values) { } /** - * Generate a component with the colour of DARK_PURPLE using {@link ComponentUtils#format} with the format of - * {@code {}} + * Generate a component with the colour of DARK_PURPLE using {@link ComponentUtils#format} with the format of {@code {}} * * @param obj The object to format */ @@ -359,8 +358,7 @@ public static Component darkGray(String format, Object... values) { } /** - * Generate a component with the colour of DARK_GRAY using {@link ComponentUtils#format} with the format of - * {@code {}} + * Generate a component with the colour of DARK_GRAY using {@link ComponentUtils#format} with the format of {@code {}} * * @param obj The object to format */ @@ -565,8 +563,7 @@ public static Component lightPurple(String format, Object... values) { } /** - * Generate a component with the colour of LIGHT_PURPLE using {@link ComponentUtils#format} with the format of - * {@code {}} + * Generate a component with the colour of LIGHT_PURPLE using {@link ComponentUtils#format} with the format of {@code {}} * * @param obj The object to format */ diff --git a/src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 b/src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 new file mode 100644 index 0000000..bc6b8ef --- /dev/null +++ b/src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 @@ -0,0 +1,298 @@ +m4_dnl vim:ft=java +m4_changecom(`//', `') +// NOTE: This file is generated from ComponentColor.java.m4 +// Generate with `m4 -P src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 > src/main/java/net/farlandsmc/componentutils/ComponentColor.java` + +package net.farlandsmc.componentutils; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.Style; +import net.kyori.adventure.text.format.TextColor; + +import org.bukkit.Color; +import org.jetbrains.annotations.Contract; + +import static net.farlandsmc.componentutils.ComponentUtils.format; +import static net.kyori.adventure.text.format.NamedTextColor.*; + +public class ComponentColor { + + // Note: All methods are annotated with `@Contract(pure = true)` so IDEs warn about unused results (same effect as @CheckReturnValue) +m4_define(`implColor', ` + /** + * Generate a component with the colour of $1. + * + * @param format The text to use for the format, uses {@link ComponentUtils#format} + * @param values The values to use for the format + */ + @Contract(pure = true) + public static Component $2(String format, Object... values) { + return format(format, values).color($1); + } + + /** + * Generate a component with the colour of $1 using {@link ComponentUtils#format} with the format of {@code {}} + * + * @param obj The object to format + */ + @Contract(pure = true) + public static Component $2(Object obj) { + return $2("{}", obj); + } + + /** + * Generate a component with the colour of $1 + * + * @param str The string to use + */ + @Contract(pure = true) + public static Component $2(String str) { + return Component.text(str).color($1); + } + + /** + * Wrap a component with the colour of $1 + * + * @param comp The Component to wrap + */ + @Contract(pure = true) + public static Component $2(Component comp) { + return Component.empty().append(comp).color($1); + }')m4_dnl +implColor(`BLACK', black) +implColor(`DARK_BLUE', darkBlue) +implColor(`DARK_GREEN', darkGreen) +implColor(`DARK_AQUA', darkAqua) +implColor(`DARK_RED', darkRed) +implColor(`DARK_PURPLE', darkPurple) +implColor(`GOLD', gold) +implColor(`GRAY', gray) +implColor(`DARK_GRAY', darkGray) +implColor(`BLUE', blue) +implColor(`GREEN', green) +implColor(`AQUA', aqua) +implColor(`RED', red) +implColor(`LIGHT_PURPLE', lightPurple) +implColor(`YELLOW', yellow) +implColor(`WHITE', white) + + /** + * Generate a component with the specified + * + * @param col The colour to use + * @param format The text to use for the format, uses `{@link ComponentUtils#format}' + * @param values The values to use for the format + */ + @Contract(pure = true) + public static Component color(TextColor col, String format, Object... values) { + return format(format, values).color(col); + } + + /** + * Generate a component with the colour specified using `{@link ComponentUtils#format}' with the format of {@code {}} + * + * @param col The colour to use + * @param obj The object to format + */ + @Contract(pure = true) + public static Component color(TextColor col, Object obj) { + return color(col, "{}", obj); + } + + /** + * Generate a component with the colour provided + * + * @param col The colour to use + * @param str The string to use + */ + @Contract(pure = true) + public static Component color(TextColor col, String str) { + return Component.text(str).color(col); + } + + /** + * Wrap a component with the colour provided + * + * @param comp The Component to wrap + */ + @Contract(pure = true) + public static Component color(TextColor col, Component comp) { + return Component.empty().append(comp).color(col); + } + + /** + * Generate a component with the specified + * + * @param col The colour to use + * @param format The text to use for the format, uses `{@link ComponentUtils#format}' + * @param values The values to use for the format + */ + @Contract(pure = true) + public static Component color(Color col, String format, Object... values) { + return format(format, values).color(TextColor.color(col.asRGB())); + } + + /** + * Generate a component with the colour specified using `{@link ComponentUtils#format}' with the format of {@code {}} + * + * @param col The colour to use + * @param obj The object to format + */ + @Contract(pure = true) + public static Component color(Color col, Object obj) { + return color(TextColor.color(col.asRGB()), "{}", obj); + } + + /** + * Generate a component with the colour provided + * + * @param col The colour to use + * @param str The string to use + */ + @Contract(pure = true) + public static Component color(Color col, String str) { + return Component.text(str).color(TextColor.color(col.asRGB())); + } + + /** + * Wrap a component with the colour provided + * + * @param comp The Component to wrap + */ + @Contract(pure = true) + public static Component color(Color col, Component comp) { + return Component.empty().append(comp).color(TextColor.color(col.asRGB())); + } + + /** + * Generate a component with the specified + * + * @param col The colour to use + * @param format The text to use for the format, uses {@link ComponentUtils#format} + * @param values The values to use for the format + */ + @Contract(pure = true) + public static Component color(java.awt.Color col, String format, Object... values) { + return format(format, values).color(TextColor.color(col.getRGB())); + } + + /** + * Generate a component with the colour specified using {@link ComponentUtils#format} with the format of {@code {}} + * + * @param col The colour to use + * @param obj The object to format + */ + @Contract(pure = true) + public static Component color(java.awt.Color col, Object obj) { + return color(TextColor.color(col.getRGB()), "{}", obj); + } + + /** + * Generate a component with the colour provided + * + * @param col The colour to use + * @param str The string to use + */ + @Contract(pure = true) + public static Component color(java.awt.Color col, String str) { + return Component.text(str).color(TextColor.color(col.getRGB())); + } + + /** + * Wrap a component with the colour provided + * + * @param comp The Component to wrap + */ + @Contract(pure = true) + public static Component color(java.awt.Color col, Component comp) { + return Component.empty().append(comp).color(TextColor.color(col.getRGB())); + } + + /** + * Generate a component with the specified + * + * @param col The colour to use (Parsed with {@link FLUtils#parseColor(String)}) + * @param format The text to use for the format, uses {@link ComponentUtils#format} + * @param values The values to use for the format + */ + @Contract(pure = true) + public static Component color(String col, String format, Object... values) { + return format(format, values).color(Utils.parseColor(col)); + } + + /** + * Generate a component with the colour specified using {@link ComponentUtils#format} with the format of {@code {}} + * + * @param col The colour to use (Parsed with {@link FLUtils#parseColor(String)}) + * @param obj The object to format + */ + @Contract(pure = true) + public static Component color(String col, Object obj) { + return color(col, "{}", obj); + } + + /** + * Generate a component with the colour provided + * + * @param col The colour to use (Parsed with {@link FLUtils#parseColor(String)}) + * @param str The string to use + */ + @Contract(pure = true) + public static Component color(String col, String str) { + return Component.text(str).color(Utils.parseColor(col)); + } + + /** + * Wrap a component with the colour provided + * + * @param comp The Component to wrap + */ + @Contract(pure = true) + public static Component color(String col, Component comp) { + return Component.empty().append(comp).color(Utils.parseColor(col)); + } + + /** + * Generate a component with the specified style + * + * @param style The style to use + * @param format The text to use for the format, uses {@link ComponentUtils#format} + * @param values The values to use for the format + */ + @Contract(pure = true) + public static Component style(Style style, String format, Object... values) { + return format(format, values).style(style); + } + + /** + * Generate a component with the style specified using {@link ComponentUtils#format} with the format of {@code {}} + * + * @param style The colour to use + * @param obj The object to format + */ + @Contract(pure = true) + public static Component style(Style style, Object obj) { + return style(style, "{}", obj); + } + + /** + * Generate a component with the style provided + * + * @param style The style to use + * @param str The string to use + */ + @Contract(pure = true) + public static Component style(Style style, String str) { + return Component.text(str).style(style); + } + + /** + * Wrap a component with the style provided + * + * @param comp The Component to wrap + */ + @Contract(pure = true) + public static Component style(Style style, Component comp) { + return Component.empty().append(comp).style(style); + } +} From 99e22a7c497bc17e096f03a294e60504d57edc18 Mon Sep 17 00:00:00 2001 From: funnyboy-roks Date: Sun, 23 Nov 2025 18:09:10 -0600 Subject: [PATCH 2/7] update check name --- .github/workflows/check.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 9f7b468..b38c8fa 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -1,4 +1,4 @@ -name: build +name: check on: push: From 3163e313cf1445cff674064ab901e7b0434fb2e2 Mon Sep 17 00:00:00 2001 From: funnyboy-roks Date: Sun, 23 Nov 2025 18:09:50 -0600 Subject: [PATCH 3/7] test CI --- .../java/net/farlandsmc/componentutils/ComponentColor.java.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 b/src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 index bc6b8ef..bb7db3e 100644 --- a/src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 +++ b/src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 @@ -17,7 +17,7 @@ import static net.kyori.adventure.text.format.NamedTextColor.*; public class ComponentColor { - // Note: All methods are annotated with `@Contract(pure = true)` so IDEs warn about unused results (same effect as @CheckReturnValue) + // Note: Methods are annotated with `@Contract(pure = true)` so IDEs warn about unused results (same effect as @CheckReturnValue) m4_define(`implColor', ` /** * Generate a component with the colour of $1. From fd5ccf63ffb129de59546d504f22af14f16337d5 Mon Sep 17 00:00:00 2001 From: funnyboy-roks Date: Sun, 23 Nov 2025 18:16:25 -0600 Subject: [PATCH 4/7] add error reporting to CI --- .github/workflows/check.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index b38c8fa..ccb9872 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -16,4 +16,12 @@ jobs: run: m4 -P src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 > src/main/java/net/farlandsmc/componentutils/ComponentColor.java - name: check diff - run: git diff --quiet -- src/main/java/net/farlandsmc/componentutils/ComponentColor.java + run: | + git diff --quiet -- src/main/java/net/farlandsmc/componentutils/ComponentColor.java + local status=$? + if [ status -ne 0 ]; then + echo '::error file=src/main/java/net/farlandsmc/componentutils/ComponentColor.java,title=Update ComponentColor.java::ComponentColor.java is out of date with ComponentColor.java.m4! Update it with m4 -P src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 > src/main/java/net/farlandsmc/componentutils/ComponentColor.java.' + exit $status + else + echo 'No diff' + fi From fe46c3583c5d0b0cfa2aa2543748a364ddd30e29 Mon Sep 17 00:00:00 2001 From: funnyboy-roks Date: Sun, 23 Nov 2025 18:18:13 -0600 Subject: [PATCH 5/7] fix error reporting in CI --- .github/workflows/check.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index ccb9872..89a1548 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -17,6 +17,7 @@ jobs: - name: check diff run: | + set +e git diff --quiet -- src/main/java/net/farlandsmc/componentutils/ComponentColor.java local status=$? if [ status -ne 0 ]; then From 69acdb6cf96e49b97f5abc93f809fed6770de051 Mon Sep 17 00:00:00 2001 From: funnyboy-roks Date: Sun, 23 Nov 2025 18:19:06 -0600 Subject: [PATCH 6/7] fix CI --- .github/workflows/check.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 89a1548..252f046 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -19,8 +19,8 @@ jobs: run: | set +e git diff --quiet -- src/main/java/net/farlandsmc/componentutils/ComponentColor.java - local status=$? - if [ status -ne 0 ]; then + status=$? + if [ $status -ne 0 ]; then echo '::error file=src/main/java/net/farlandsmc/componentutils/ComponentColor.java,title=Update ComponentColor.java::ComponentColor.java is out of date with ComponentColor.java.m4! Update it with m4 -P src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 > src/main/java/net/farlandsmc/componentutils/ComponentColor.java.' exit $status else From f79ad9368535be7beb19fb53f1cca9860007444a Mon Sep 17 00:00:00 2001 From: funnyboy-roks Date: Sun, 23 Nov 2025 18:20:22 -0600 Subject: [PATCH 7/7] unbreak ci --- .../java/net/farlandsmc/componentutils/ComponentColor.java.m4 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 b/src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 index bb7db3e..bc6b8ef 100644 --- a/src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 +++ b/src/main/java/net/farlandsmc/componentutils/ComponentColor.java.m4 @@ -17,7 +17,7 @@ import static net.kyori.adventure.text.format.NamedTextColor.*; public class ComponentColor { - // Note: Methods are annotated with `@Contract(pure = true)` so IDEs warn about unused results (same effect as @CheckReturnValue) + // Note: All methods are annotated with `@Contract(pure = true)` so IDEs warn about unused results (same effect as @CheckReturnValue) m4_define(`implColor', ` /** * Generate a component with the colour of $1.