From d476fd12bd40a84245f1cf2809186a4f953a7052 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 30 Jul 2021 16:10:48 +0200 Subject: [PATCH] Add ListCommand --- .../bungeecore/bot/SteamwarDiscordBot.java | 1 + .../bungeecore/bot/commands/ListCommand.java | 43 +++++++++++++++++++ .../bungeecore/commands/ListCommand.java | 6 ++- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 src/de/steamwar/bungeecore/bot/commands/ListCommand.java diff --git a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java index 11a4ac6..6f9bae3 100644 --- a/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java +++ b/src/de/steamwar/bungeecore/bot/SteamwarDiscordBot.java @@ -112,6 +112,7 @@ public class SteamwarDiscordBot { addCommand(commands, new BanCommand()); addCommand(commands, new WhoisCommand()); addCommand(commands, new TeamCommand()); + addCommand(commands, new ListCommand()); commands.complete(); } diff --git a/src/de/steamwar/bungeecore/bot/commands/ListCommand.java b/src/de/steamwar/bungeecore/bot/commands/ListCommand.java new file mode 100644 index 0000000..2050180 --- /dev/null +++ b/src/de/steamwar/bungeecore/bot/commands/ListCommand.java @@ -0,0 +1,43 @@ +/* + * This file is a part of the SteamWar software. + * + * Copyright (C) 2020 SteamWar.de-Serverteam + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package de.steamwar.bungeecore.bot.commands; + +import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; + +import java.util.stream.Collectors; + +public class ListCommand extends BasicDiscordCommand { + + public ListCommand() { + super("list", "Gebe eine Liste aller online Spieler"); + } + + @Override + public void run(SlashCommandEvent event) { + de.steamwar.bungeecore.commands.ListCommand.updateCustomTablist(); + EmbedBuilder embedBuilder = new EmbedBuilder(); + embedBuilder.setTitle("List"); + de.steamwar.bungeecore.commands.ListCommand.getPlayerMap().forEach((s, proxiedPlayers) -> { + embedBuilder.addField(s, proxiedPlayers.stream().map(player -> "`" + player.getName() + "`").collect(Collectors.joining(", ")), true); + }); + event.replyEmbeds(embedBuilder.build()).setEphemeral(true).complete(); + } +} diff --git a/src/de/steamwar/bungeecore/commands/ListCommand.java b/src/de/steamwar/bungeecore/commands/ListCommand.java index b5d2f2d..b7a4a63 100644 --- a/src/de/steamwar/bungeecore/commands/ListCommand.java +++ b/src/de/steamwar/bungeecore/commands/ListCommand.java @@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands; import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; +import lombok.Getter; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.config.ServerInfo; @@ -39,9 +40,10 @@ public class ListCommand extends BasicCommand { super("list", ""); } - private final TreeMap> playerMap = new TreeMap<>(); + @Getter + private static final TreeMap> playerMap = new TreeMap<>(); - private synchronized void updateCustomTablist(){ + public static synchronized void updateCustomTablist(){ //Calculate server-player-map playerMap.clear(); for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {