From be9cf916e2fc76c42e23d9ae0095d55aad326040 Mon Sep 17 00:00:00 2001 From: mnfu Date: Tue, 30 Jun 2026 19:23:21 -0400 Subject: [PATCH] Update to 26.2 - move some logic around and stop using ChatFormatting class in SetCommand.java in favor of TextColor class and the internal MinecraftColor.java - adjust the normalization logic of color inputs, they all now save as "#00FFFF" format, instead of previously where you could see "FFFF" saved. --- gradle.properties | 13 ++--- .../mnfu/clantag/commands/MinecraftColor.java | 11 ++++ .../mnfu/clantag/commands/SetCommand.java | 54 ++++++++++--------- 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/gradle.properties b/gradle.properties index 00e5866..8413769 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,16 +2,17 @@ org.gradle.jvmargs=-Xmx1G # Fabric Properties # check these on https://modmuss50.me/fabric.html -minecraft_version=26.1 -loader_version=0.18.4 -loom_version=1.15-SNAPSHOT +minecraft_version=26.2 +loader_version=0.19.3 +loom_version=1.17-SNAPSHOT # Mod Properties -mod_version=1.1.1+26.1 +mod_version=1.1.1+26.2 maven_group=mnfu archives_base_name=ClanTag # Dependencies # check this on https://modmuss50.me/fabric.html -fabric_api_version=0.144.3+26.1 -placeholder_api_version=3.0.0-beta.2+26.1 +fabric_api_version=0.153.0+26.2 +# https://maven.nucleoid.xyz/eu/pb4/placeholder-api/ +placeholder_api_version=3.1.0-beta.1+26.2 sqlite_jdbc_version=3.51.2.0 fabric_permissions_api=0.7.0 \ No newline at end of file diff --git a/src/main/java/mnfu/clantag/commands/MinecraftColor.java b/src/main/java/mnfu/clantag/commands/MinecraftColor.java index ed88099..1ec9d84 100644 --- a/src/main/java/mnfu/clantag/commands/MinecraftColor.java +++ b/src/main/java/mnfu/clantag/commands/MinecraftColor.java @@ -1,6 +1,7 @@ package mnfu.clantag.commands; import java.util.Arrays; +import java.util.List; import java.util.Locale; import java.util.Map; import java.util.stream.Collectors; @@ -34,6 +35,16 @@ public int getColor() { return color; } + public String getKey() { + return name().toLowerCase(Locale.ROOT); + } + + public static List getKeys() { + return Arrays.stream(values()) + .map(MinecraftColor::getKey) + .toList(); + } + /** "Dark Aqua", "Light Purple", etc */ public String getDisplayName() { String[] parts = name().toLowerCase(Locale.ROOT).split("_"); diff --git a/src/main/java/mnfu/clantag/commands/SetCommand.java b/src/main/java/mnfu/clantag/commands/SetCommand.java index e50c040..8a1ab8d 100644 --- a/src/main/java/mnfu/clantag/commands/SetCommand.java +++ b/src/main/java/mnfu/clantag/commands/SetCommand.java @@ -3,24 +3,22 @@ import com.mojang.brigadier.arguments.StringArgumentType; import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.context.CommandContext; +import com.mojang.serialization.DataResult; import mnfu.clantag.Clan; import mnfu.clantag.ClanManager; import mnfu.clantag.ClanManager.JoinPolicy; import net.minecraft.commands.Commands; import net.minecraft.commands.CommandSourceStack; -import net.minecraft.server.level.ServerPlayer; -import net.minecraft.network.chat.MutableComponent; -import net.minecraft.network.chat.Style; +import net.minecraft.network.chat.*; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TextColor; -import net.minecraft.ChatFormatting; +import net.minecraft.server.level.ServerPlayer; +import java.awt.*; import java.util.Collection; -import java.util.Locale; public class SetCommand { private final ClanManager clanManager; - private final Collection colorNames = ChatFormatting.getNames(true, false); + private final Collection colorNames = MinecraftColor.getKeys(); public SetCommand(ClanManager clanManager) { this.clanManager = clanManager; @@ -35,6 +33,7 @@ public LiteralArgumentBuilder build() { for (String c : colorNames) { builder.suggest(c); } + builder.suggest("reset"); return builder.buildFuture(); }) .executes(this::executeColor) @@ -76,17 +75,20 @@ private int executeColor(CommandContext context) { String newColor = StringArgumentType.getString(context, "newColorNameOrHex"); if (newColor == null || newColor.isEmpty()) return 0; + newColor = newColor.trim(); - ChatFormatting formatting = ChatFormatting.getByName(newColor); - if (formatting != null && formatting.isColor()) { - newColor = "#" + Integer.toHexString(formatting.getColor()).toUpperCase(Locale.ROOT); - } else if (newColor.matches("(?i)^#?[0-9a-f]{1,6}$")) { - newColor = "#" + newColor.replaceFirst("^#", "").toUpperCase(Locale.ROOT); - } else if ("reset".equalsIgnoreCase(newColor)) { - newColor = "#" + Integer.toHexString(ChatFormatting.WHITE.getColor()).toUpperCase(Locale.ROOT); + if (newColor.equalsIgnoreCase("reset")) { + newColor = String.format("#%06X", TextColor.WHITE.getValue()); + } else if (newColor.matches("^[0-9a-fA-F]{1,6}$")) { + newColor = String.format("#%06X", Integer.parseInt(newColor, 16)); } else { - context.getSource().sendFailure(Component.literal(newColor + " is not a valid hex color or minecraft color.")); - return 0; + DataResult result = TextColor.parseColor(newColor); + if (result.isError()) { + context.getSource().sendFailure(Component.literal(newColor + " is not a valid hex color or minecraft color.")); + return 0; + } + TextColor color = result.result().orElseThrow(); + newColor = String.format("#%06X", color.getValue()); } String oldColor = clan.hexColor(); @@ -100,11 +102,11 @@ private int executeColor(CommandContext context) { TextColor oldClanTextColor = TextColor.parseColor(oldColor).getOrThrow(); TextColor newClanTextColor = TextColor.parseColor(newColor).getOrThrow(); - message.append(Component.literal("Updated clan color from ").withStyle(ChatFormatting.GRAY)) + message.append(Component.literal("Updated clan color from ").withColor(TextColor.GRAY)) .append(Component.literal(colorDisplayName(oldColor)).setStyle(Style.EMPTY.withColor(oldClanTextColor))) - .append(Component.literal(" to ").withStyle(ChatFormatting.GRAY)) + .append(Component.literal(" to ").withColor(TextColor.GRAY)) .append(Component.literal(colorDisplayName(newColor)).setStyle(Style.EMPTY.withColor(newClanTextColor))) - .append(Component.literal("!").withStyle(ChatFormatting.GRAY)); + .append(Component.literal("!").withColor((TextColor.GRAY))); context.getSource().sendSystemMessage(message); return 1; @@ -126,11 +128,11 @@ private int executeAccess(CommandContext context, JoinPolicy clanManager.changePolicy(clan.name(), newPolicy); MutableComponent message = Component.empty() - .append(Component.literal("Updated clan access from ").withStyle(ChatFormatting.GRAY)) + .append(Component.literal("Updated clan access from ").withColor(TextColor.GRAY)) .append(accessText(oldPolicy != JoinPolicy.OPEN)) - .append(Component.literal(" to ").withStyle(ChatFormatting.GRAY)) + .append(Component.literal(" to ").withColor(TextColor.GRAY)) .append(accessText(newPolicy != JoinPolicy.OPEN)) - .append(Component.literal("!").withStyle(ChatFormatting.GRAY)); + .append(Component.literal("!").withColor(TextColor.GRAY)); context.getSource().sendSystemMessage(message); return 1; @@ -149,7 +151,7 @@ private int executeAccessToggle(CommandContext context) { private MutableComponent accessText(boolean closed) { return Component.literal(closed ? "Invite Only" : "Open") - .withStyle(closed ? ChatFormatting.RED : ChatFormatting.GREEN); + .withColor(closed ? TextColor.RED : TextColor.GREEN); } private int executeName(CommandContext context) { @@ -176,11 +178,11 @@ private int executeName(CommandContext context) { } TextColor clanTextColor = TextColor.parseColor(clan.hexColor()).getOrThrow(); - MutableComponent message = Component.literal("Updated clan name from ").withStyle(ChatFormatting.GRAY) + MutableComponent message = Component.literal("Updated clan name from ").withColor(TextColor.GRAY) .append(Component.literal(clan.name()).setStyle(Style.EMPTY.withColor(clanTextColor))) - .append(Component.literal(" to ").withStyle(ChatFormatting.GRAY)) + .append(Component.literal(" to ").withColor(TextColor.GRAY)) .append(Component.literal(newClanName).setStyle(Style.EMPTY.withColor(clanTextColor))) - .append(Component.literal("!").withStyle(ChatFormatting.GRAY)); + .append(Component.literal("!").withColor(TextColor.GRAY)); context.getSource().sendSystemMessage(message); return 1;