Allow to count multiple servers.

This commit is contained in:
filoghost 2015-01-03 17:34:36 +01:00
parent 52d9940926
commit 0704693810
2 changed files with 32 additions and 9 deletions

View File

@ -55,15 +55,15 @@ public class BungeeServerTracker {
return info; return info;
} }
public static String getPlayersOnline(String server) { public static int getPlayersOnline(String server) {
BungeeServerInfo info = trackedServers.get(server); BungeeServerInfo info = trackedServers.get(server);
if (info != null) { if (info != null) {
info.updateLastRequest(); info.updateLastRequest();
return String.valueOf(info.getOnlinePlayers()); return info.getOnlinePlayers();
} else { } else {
// It was not tracked, add it. // It was not tracked, add it.
track(server); track(server);
return "0"; return 0;
} }
} }

View File

@ -165,14 +165,37 @@ public class PlaceholdersManager {
final String serverName = extractArgumentFromPlaceholder(matcher); final String serverName = extractArgumentFromPlaceholder(matcher);
BungeeServerTracker.track(serverName); // Track this server. BungeeServerTracker.track(serverName); // Track this server.
// Add it to tracked servers. if (serverName.contains(",")) {
bungeeReplacers.put(matcher.group(), new PlaceholderReplacer() {
@Override String[] split = serverName.split(",");
public String update() { for (int i = 0; i < split.length; i++) {
return BungeeServerTracker.getPlayersOnline(serverName); split[i] = split[i].trim();
} }
});
final String[] serversToTrack = split;
// Add it to tracked servers.
bungeeReplacers.put(matcher.group(), new PlaceholderReplacer() {
@Override
public String update() {
int count = 0;
for (String serverToTrack : serversToTrack) {
count += BungeeServerTracker.getPlayersOnline(serverToTrack);
}
return String.valueOf(count);
}
});
} else {
// Normal, single tracked server.
bungeeReplacers.put(matcher.group(), new PlaceholderReplacer() {
@Override
public String update() {
return String.valueOf(BungeeServerTracker.getPlayersOnline(serverName));
}
});
}
} }
// BungeeCord max players pattern. // BungeeCord max players pattern.