From 9379ebb33df41100033ff3ed198fb50ada6194b4 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 6 Jul 2024 07:35:06 +0100 Subject: [PATCH] make the server watcher list command look better --- .../command/serverwatcher/ListSubCommand.java | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/main/java/cc/fascinated/bat/features/minecraft/command/serverwatcher/ListSubCommand.java b/src/main/java/cc/fascinated/bat/features/minecraft/command/serverwatcher/ListSubCommand.java index e42ec6f..b52a4de 100644 --- a/src/main/java/cc/fascinated/bat/features/minecraft/command/serverwatcher/ListSubCommand.java +++ b/src/main/java/cc/fascinated/bat/features/minecraft/command/serverwatcher/ListSubCommand.java @@ -13,9 +13,15 @@ import lombok.NonNull; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction; +import org.apache.catalina.Server; import org.springframework.stereotype.Component; import xyz.mcutils.models.server.ServerPlatform; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + /** * @author Fascinated (fascinated7) */ @@ -29,18 +35,23 @@ public class ListSubCommand extends BatCommand { public void execute(BatGuild guild, @NonNull BatUser user, @NonNull MessageChannel channel, Member member, @NonNull SlashCommandInteraction event) { MinecraftProfile profile = guild.getMinecraftProfile(); + Map> watchers = new HashMap<>(); + for (ServerWatcher server : profile.getServerWatchers()) { + watchers.computeIfAbsent(server.getPlatform(), k -> new ArrayList<>()).add(server); + } EmbedDescriptionBuilder description = new EmbedDescriptionBuilder("Server Watcher"); description.appendLine("Here is a list of all the servers being watched", false); description.emptyLine(); - for (ServerWatcher server : profile.getServerWatchers()) { - int platformDefaultPort = server.getPlatform() == ServerPlatform.JAVA ? 25565 : 19132; - String hostname = server.getHostname() + (server.getPort() != platformDefaultPort ? ":" + server.getPort() : ""); - description.appendLine("`%s` (%s) - %s".formatted( - hostname, - EnumUtils.getEnumName(server.getPlatform()), - server.getChannel().getAsMention() - ), true); + for (Map.Entry> entry : watchers.entrySet()) { + description.appendLine("**%s**".formatted(EnumUtils.getEnumName(entry.getKey())), false); + for (ServerWatcher server : entry.getValue()) { + description.appendLine("`%s` - %s".formatted( + server.getHostname(), + server.getChannel().getAsMention() + ), true); + } + description.emptyLine(); } event.replyEmbeds(EmbedUtils.successEmbed()