make the server watcher list command look better
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m13s
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 1m13s
This commit is contained in:
parent
bbbbce557b
commit
9379ebb33d
@ -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<ServerPlatform, List<ServerWatcher>> 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<ServerPlatform, List<ServerWatcher>> 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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user