mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-29 20:27:42 +01:00
Handle multiple worlds in "world" placeholder
This commit is contained in:
parent
bef2ed58a6
commit
b589749c24
@ -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.
|
||||
|
@ -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]";
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user