diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java index 1ac157a..6c9f02d 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungee.java @@ -6,7 +6,9 @@ */ package com.imaginarycode.minecraft.redisbungee; +import com.google.common.collect.HashMultimap; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Multimap; import com.google.common.io.ByteStreams; import net.md_5.bungee.api.ServerPing; import net.md_5.bungee.api.config.ServerInfo; @@ -55,6 +57,16 @@ public final class RedisBungee extends Plugin implements Listener { return configuration; } + static Multimap serversToPlayers() { + Multimap serverToPlayers = HashMultimap.create(); + for (String p : RedisBungee.getApi().getPlayersOnline()) { + ServerInfo si = RedisBungee.getApi().getServerFor(p); + if (si != null) + serverToPlayers.put(si.getName(), p); + } + return serverToPlayers; + } + final int getCount() { int c = plugin.getProxy().getOnlineCount(); if (pool != null) { @@ -91,6 +103,10 @@ public final class RedisBungee extends Plugin implements Listener { return ImmutableSet.copyOf(players); } + final Set getPlayersOnServer(String server) { + return new HashSet<>(serversToPlayers().get(server)); + } + final ServerInfo getServerFor(String name) { ServerInfo server = null; if (plugin.getProxy().getPlayer(name) != null) return plugin.getProxy().getPlayer(name).getServer().getInfo(); @@ -169,7 +185,7 @@ public final class RedisBungee extends Plugin implements Listener { public void run() { Jedis rsc = pool.getResource(); try { - rsc.set("server:" + configuration.getString("server-id")+ ":playerCount", String.valueOf(getProxy().getOnlineCount())); + rsc.set("server:" + configuration.getString("server-id") + ":playerCount", String.valueOf(getProxy().getOnlineCount())); } finally { pool.returnResource(rsc); } diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java index 61dc4eb..3c3c87e 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeAPI.java @@ -6,13 +6,12 @@ */ package com.imaginarycode.minecraft.redisbungee; +import lombok.NonNull; import net.md_5.bungee.api.config.ServerInfo; import java.net.InetAddress; import java.util.Set; -import lombok.NonNull; - /** * This class exposes some internal RedisBungee functions. You obtain an instance of this object by invoking {@link RedisBungee#getApi()}. * @@ -68,6 +67,15 @@ public class RedisBungeeAPI { return plugin.getPlayers(); } + /** + * Get a list of players on the server with the given name. + * @param server a server name + * @return a Set with all players found on this server + */ + public final Set getPlayersOnServer(@NonNull String server) { + return plugin.getPlayersOnServer(server); + } + /** * Convenience method: Checks if the specified player is online. * diff --git a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java index bd08c99..f8e9e23 100644 --- a/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java +++ b/src/main/java/com/imaginarycode/minecraft/redisbungee/RedisBungeeCommands.java @@ -7,7 +7,6 @@ package com.imaginarycode.minecraft.redisbungee; import com.google.common.base.Joiner; -import com.google.common.collect.HashMultimap; import com.google.common.collect.Multimap; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; @@ -48,12 +47,7 @@ class RedisBungeeCommands { .append(" player(s) are currently online.").create(); if (args.length > 0 && args[0].equals("showall")) { if (RedisBungee.getConfiguration().getBoolean("canonical-glist", true)) { - Multimap serverToPlayers = HashMultimap.create(); - for (String p : RedisBungee.getApi().getPlayersOnline()) { - ServerInfo si = RedisBungee.getApi().getServerFor(p); - if (si != null) - serverToPlayers.put(si.getName(), p); - } + Multimap serverToPlayers = RedisBungee.serversToPlayers(); for (String server : new TreeSet<>(serverToPlayers.keySet())) { TextComponent serverName = new TextComponent(); serverName.setColor(ChatColor.GREEN);