mirror of
https://github.com/proxiodev/RedisBungee.git
synced 2026-05-03 11:40:29 +00:00
Add /plist command and plural player count.
This commit is contained in:
@@ -40,6 +40,7 @@ import net.md_5.bungee.api.plugin.Command;
|
||||
import java.net.InetAddress;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -59,6 +60,10 @@ class RedisBungeeCommands {
|
||||
private static final BaseComponent[] NO_COMMAND_SPECIFIED =
|
||||
new ComponentBuilder("You must specify a command to be run.").color(ChatColor.RED).create();
|
||||
|
||||
private static String playerPlural(int num) {
|
||||
return num == 1 ? num + " player is" : num + " players are";
|
||||
}
|
||||
|
||||
public static class GlistCommand extends Command {
|
||||
private final RedisBungee plugin;
|
||||
|
||||
@@ -73,8 +78,8 @@ class RedisBungeeCommands {
|
||||
@Override
|
||||
public void run() {
|
||||
int count = RedisBungee.getApi().getPlayerCount();
|
||||
BaseComponent[] playersOnline = new ComponentBuilder("").color(ChatColor.YELLOW).append(String.valueOf(count))
|
||||
.append(" player(s) are currently online.").create();
|
||||
BaseComponent[] playersOnline = new ComponentBuilder("").color(ChatColor.YELLOW)
|
||||
.append(playerPlural(count) + " currently online.").create();
|
||||
if (args.length > 0 && args[0].equals("showall")) {
|
||||
Multimap<String, UUID> serverToPlayers = RedisBungee.getApi().getServerToPlayers();
|
||||
Multimap<String, String> human = HashMultimap.create();
|
||||
@@ -304,4 +309,55 @@ class RedisBungeeCommands {
|
||||
sender.sendMessage(textComponent);
|
||||
}
|
||||
}
|
||||
|
||||
public static class PlistCommand extends Command {
|
||||
private final RedisBungee plugin;
|
||||
|
||||
PlistCommand(RedisBungee plugin) {
|
||||
super("plist", "redisbungee.command.plist", "redisbungee", "rplist");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void execute(final CommandSender sender, final String[] args) {
|
||||
plugin.getProxy().getScheduler().runAsync(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String proxy = args.length >= 1 ? args[0] : RedisBungee.getConfiguration().getServerId();
|
||||
if (!plugin.getServerIds().contains(proxy)) {
|
||||
sender.sendMessage(new ComponentBuilder(proxy + " is not a valid proxy. See /serverids for valid proxies.").color(ChatColor.RED).create());
|
||||
return;
|
||||
}
|
||||
Set<UUID> players = RedisBungee.getApi().getPlayersOnProxy(proxy);
|
||||
BaseComponent[] playersOnline = new ComponentBuilder("").color(ChatColor.YELLOW)
|
||||
.append(playerPlural(players.size()) + " currently on proxy " + proxy + ".").create();
|
||||
if (args.length >= 2 && args[1].equals("showall")) {
|
||||
Multimap<String, UUID> serverToPlayers = RedisBungee.getApi().getServerToPlayers();
|
||||
Multimap<String, String> human = HashMultimap.create();
|
||||
for (Map.Entry<String, UUID> entry : serverToPlayers.entries()) {
|
||||
if (players.contains(entry.getValue())) {
|
||||
human.put(entry.getKey(), plugin.getUuidTranslator().getNameFromUuid(entry.getValue(), false));
|
||||
}
|
||||
}
|
||||
for (String server : new TreeSet<>(human.keySet())) {
|
||||
TextComponent serverName = new TextComponent();
|
||||
serverName.setColor(ChatColor.RED);
|
||||
serverName.setText("[" + server + "] ");
|
||||
TextComponent serverCount = new TextComponent();
|
||||
serverCount.setColor(ChatColor.YELLOW);
|
||||
serverCount.setText("(" + serverToPlayers.get(server).size() + "): ");
|
||||
TextComponent serverPlayers = new TextComponent();
|
||||
serverPlayers.setColor(ChatColor.WHITE);
|
||||
serverPlayers.setText(Joiner.on(", ").join(human.get(server)));
|
||||
sender.sendMessage(serverName, serverCount, serverPlayers);
|
||||
}
|
||||
sender.sendMessage(playersOnline);
|
||||
} else {
|
||||
sender.sendMessage(playersOnline);
|
||||
sender.sendMessage(new ComponentBuilder("To see all players online, use /plist " + proxy + " showall.").color(ChatColor.YELLOW).create());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user