SteamWar/BungeeCore
Archiviert
13
2

Add ListCommand

Dieser Commit ist enthalten in:
yoyosource 2021-07-30 16:10:48 +02:00
Ursprung c0ef12829b
Commit d476fd12bd
3 geänderte Dateien mit 48 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -112,6 +112,7 @@ public class SteamwarDiscordBot {
addCommand(commands, new BanCommand()); addCommand(commands, new BanCommand());
addCommand(commands, new WhoisCommand()); addCommand(commands, new WhoisCommand());
addCommand(commands, new TeamCommand()); addCommand(commands, new TeamCommand());
addCommand(commands, new ListCommand());
commands.complete(); commands.complete();
} }

Datei anzeigen

@ -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 <https://www.gnu.org/licenses/>.
*/
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();
}
}

Datei anzeigen

@ -22,6 +22,7 @@ package de.steamwar.bungeecore.commands;
import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Message;
import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Servertype;
import de.steamwar.bungeecore.Subserver; import de.steamwar.bungeecore.Subserver;
import lombok.Getter;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.ProxyServer; import net.md_5.bungee.api.ProxyServer;
import net.md_5.bungee.api.config.ServerInfo; import net.md_5.bungee.api.config.ServerInfo;
@ -39,9 +40,10 @@ public class ListCommand extends BasicCommand {
super("list", ""); super("list", "");
} }
private final TreeMap<String, List<ProxiedPlayer>> playerMap = new TreeMap<>(); @Getter
private static final TreeMap<String, List<ProxiedPlayer>> playerMap = new TreeMap<>();
private synchronized void updateCustomTablist(){ public static synchronized void updateCustomTablist(){
//Calculate server-player-map //Calculate server-player-map
playerMap.clear(); playerMap.clear();
for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) { for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) {