mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-18 23:07:34 +01:00
Allow to count multiple servers.
This commit is contained in:
parent
52d9940926
commit
0704693810
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user