From e9297fab4741d66536e29722c041c8234f5ac891 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 26 Jun 2021 10:22:55 +0200 Subject: [PATCH 1/2] Add ListCommand --- src/de/steamwar/bungeecore/BungeeCore.java | 1 + .../bungeecore/commands/ListCommand.java | 71 +++++++++++++++++++ 2 files changed, 72 insertions(+) create mode 100644 src/de/steamwar/bungeecore/commands/ListCommand.java diff --git a/src/de/steamwar/bungeecore/BungeeCore.java b/src/de/steamwar/bungeecore/BungeeCore.java index 2344d56..8b78cb6 100644 --- a/src/de/steamwar/bungeecore/BungeeCore.java +++ b/src/de/steamwar/bungeecore/BungeeCore.java @@ -121,6 +121,7 @@ public class BungeeCore extends Plugin { new UnIgnoreCommand(); new PollresultCommand(); new ResourcereloadCommand(); + new ListCommand(); if(!EVENT_MODE){ new WebregisterCommand(); diff --git a/src/de/steamwar/bungeecore/commands/ListCommand.java b/src/de/steamwar/bungeecore/commands/ListCommand.java new file mode 100644 index 0000000..6ab37f0 --- /dev/null +++ b/src/de/steamwar/bungeecore/commands/ListCommand.java @@ -0,0 +1,71 @@ +/* + * 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.commands; + +import de.steamwar.bungeecore.Servertype; +import de.steamwar.bungeecore.Subserver; +import net.md_5.bungee.api.CommandSender; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.config.ServerInfo; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.connection.Server; + +import java.util.ArrayList; +import java.util.List; +import java.util.TreeMap; +import java.util.stream.Collectors; + +public class ListCommand extends BasicCommand { + + public ListCommand() { + super("list", ""); + } + + private final TreeMap> playerMap = new TreeMap<>(); + + private synchronized void updateCustomTablist(){ + //Calculate server-player-map + playerMap.clear(); + for (ProxiedPlayer player : ProxyServer.getInstance().getPlayers()) { + Server pserver = player.getServer(); + if (pserver == null) //Happens temporarily + continue; + + ServerInfo server = pserver.getInfo(); + String serverName = server.getName(); + + Subserver subserver = Subserver.getSubserver(server); + if (subserver != null && subserver.getType() == Servertype.BAUSERVER) { + playerMap.computeIfAbsent("Bau", s -> new ArrayList<>()).add(player); + } else { + playerMap.computeIfAbsent(serverName, s -> new ArrayList<>()).add(player); + } + } + playerMap.forEach((server, players) -> players.sort((proxiedPlayer, t1) -> proxiedPlayer.getName().compareToIgnoreCase(t1.getName()))); + } + + @Override + public void execute(CommandSender commandSender, String[] strings) { + updateCustomTablist(); + for (String server : playerMap.navigableKeySet()) { + commandSender.sendMessage("§e" + server + "§8: §7" + playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", "))); + } + } +} From c253709f4ac074bf5f2413f6b8e011fbe5070920 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 26 Jun 2021 10:27:59 +0200 Subject: [PATCH 2/2] Update ListCommand to multilang --- src/de/steamwar/bungeecore/commands/ListCommand.java | 6 +++++- src/de/steamwar/messages/BungeeCore.properties | 1 + 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/de/steamwar/bungeecore/commands/ListCommand.java b/src/de/steamwar/bungeecore/commands/ListCommand.java index 6ab37f0..b5d2f2d 100644 --- a/src/de/steamwar/bungeecore/commands/ListCommand.java +++ b/src/de/steamwar/bungeecore/commands/ListCommand.java @@ -19,6 +19,7 @@ package de.steamwar.bungeecore.commands; +import de.steamwar.bungeecore.Message; import de.steamwar.bungeecore.Servertype; import de.steamwar.bungeecore.Subserver; import net.md_5.bungee.api.CommandSender; @@ -65,7 +66,10 @@ public class ListCommand extends BasicCommand { public void execute(CommandSender commandSender, String[] strings) { updateCustomTablist(); for (String server : playerMap.navigableKeySet()) { - commandSender.sendMessage("§e" + server + "§8: §7" + playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", "))); + if (server.equals("Bau")) { + server = Message.parse("TABLIST_BAU", commandSender); + } + Message.send("LIST_COMMAND", commandSender, server, playerMap.get(server).stream().map(CommandSender::getName).collect(Collectors.joining(", "))); } } } diff --git a/src/de/steamwar/messages/BungeeCore.properties b/src/de/steamwar/messages/BungeeCore.properties index a92b7c5..dd74cdb 100644 --- a/src/de/steamwar/messages/BungeeCore.properties +++ b/src/de/steamwar/messages/BungeeCore.properties @@ -480,6 +480,7 @@ TABLIST_PHASE_1=§8Teamspeak: §eSteam§8War.de TABLIST_PHASE_2=§8Discord: §8https://§eSteam§8War.de/discord TABLIST_PHASE_DEFAULT=§8Website: https://§eSteam§8War.de TABLIST_BAU=Bau +LIST_COMMAND=§e{0}§8: §7{1} #EventStarter EVENT_FIGHT_BROADCAST=§7Hier §eklicken §7für den Kampf §{0}{1} §8vs §{2}{3}