Handle multiple worlds in "world" placeholder

This commit is contained in:
filoghost 2020-04-11 20:01:30 +02:00
parent bef2ed58a6
commit b589749c24
2 changed files with 38 additions and 7 deletions

View File

@ -156,10 +156,27 @@ public class PlaceholdersManager {
worldsOnlinePlayersReplacers = new HashMap<>();
}
final String worldName = extractArgumentFromPlaceholder(matcher);
final String worldsNames = extractArgumentFromPlaceholder(matcher);
if (worldsNames.contains(",")) {
String[] split = worldsNames.split(",");
for (int i = 0; i < split.length; i++) {
split[i] = split[i].trim();
}
final String[] worldsToTrack = split;
// Add it to tracked worlds.
worldsOnlinePlayersReplacers.put(matcher.group(), () -> {
return WorldPlayerCounterTask.getCount(worldName);
return WorldPlayerCounterTask.getCount(worldsToTrack);
});
} else {
// Normal, single tracked world.
worldsOnlinePlayersReplacers.put(matcher.group(), () -> {
return WorldPlayerCounterTask.getCount(worldsNames);
});
}
}
// BungeeCord online pattern.

View File

@ -43,8 +43,22 @@ public class WorldPlayerCounterTask implements Runnable {
}
}
public static String getCount(String world) {
Integer count = worlds.get(world);
return count != null ? count.toString() : "[World \"" + world + "\" not found]";
public static String getCount(String[] worldsNames) {
int total = 0;
for (String worldName : worldsNames) {
Integer count = worlds.get(worldName);
if (count == null) {
return "[World \"" + worldName + "\" not found]";
}
total += count;
}
return String.valueOf(total);
}
public static String getCount(String worldName) {
Integer count = worlds.get(worldName);
return count != null ? count.toString() : "[World \"" + worldName + "\" not found]";
}
}