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;
}
public static String getPlayersOnline(String server) {
public static int getPlayersOnline(String server) {
BungeeServerInfo info = trackedServers.get(server);
if (info != null) {
info.updateLastRequest();
return String.valueOf(info.getOnlinePlayers());
return info.getOnlinePlayers();
} else {
// It was not tracked, add it.
track(server);
return "0";
return 0;
}
}

View File

@ -165,14 +165,37 @@ public class PlaceholdersManager {
final String serverName = extractArgumentFromPlaceholder(matcher);
BungeeServerTracker.track(serverName); // Track this server.
if (serverName.contains(",")) {
String[] split = serverName.split(",");
for (int i = 0; i < split.length; i++) {
split[i] = split[i].trim();
}
final String[] serversToTrack = split;
// Add it to tracked servers.
bungeeReplacers.put(matcher.group(), new PlaceholderReplacer() {
@Override
public String update() {
return BungeeServerTracker.getPlayersOnline(serverName);
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.