Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 11 additions & 0 deletions src/main/java/mnfu/clantag/commands/MinecraftColor.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -34,6 +35,16 @@ public int getColor() {
return color;
}

public String getKey() {
return name().toLowerCase(Locale.ROOT);
}

public static List<String> getKeys() {
return Arrays.stream(values())
.map(MinecraftColor::getKey)
.toList();
}

/** "Dark Aqua", "Light Purple", etc */
public String getDisplayName() {
String[] parts = name().toLowerCase(Locale.ROOT).split("_");
Expand Down
54 changes: 28 additions & 26 deletions src/main/java/mnfu/clantag/commands/SetCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> colorNames = ChatFormatting.getNames(true, false);
private final Collection<String> colorNames = MinecraftColor.getKeys();

public SetCommand(ClanManager clanManager) {
this.clanManager = clanManager;
Expand All @@ -35,6 +33,7 @@ public LiteralArgumentBuilder<CommandSourceStack> build() {
for (String c : colorNames) {
builder.suggest(c);
}
builder.suggest("reset");
return builder.buildFuture();
})
.executes(this::executeColor)
Expand Down Expand Up @@ -76,17 +75,20 @@ private int executeColor(CommandContext<CommandSourceStack> 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<TextColor> 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();
Expand All @@ -100,11 +102,11 @@ private int executeColor(CommandContext<CommandSourceStack> 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;
Expand All @@ -126,11 +128,11 @@ private int executeAccess(CommandContext<CommandSourceStack> 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;
Expand All @@ -149,7 +151,7 @@ private int executeAccessToggle(CommandContext<CommandSourceStack> 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<CommandSourceStack> context) {
Expand All @@ -176,11 +178,11 @@ private int executeName(CommandContext<CommandSourceStack> 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;
Expand Down
Loading