mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-20 15:57:49 +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<>();
|
worldsOnlinePlayersReplacers = new HashMap<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String worldName = extractArgumentFromPlaceholder(matcher);
|
final String worldsNames = extractArgumentFromPlaceholder(matcher);
|
||||||
worldsOnlinePlayersReplacers.put(matcher.group(), () -> {
|
|
||||||
return WorldPlayerCounterTask.getCount(worldName);
|
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(worldsToTrack);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Normal, single tracked world.
|
||||||
|
worldsOnlinePlayersReplacers.put(matcher.group(), () -> {
|
||||||
|
return WorldPlayerCounterTask.getCount(worldsNames);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BungeeCord online pattern.
|
// BungeeCord online pattern.
|
||||||
|
@ -43,8 +43,22 @@ public class WorldPlayerCounterTask implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getCount(String world) {
|
public static String getCount(String[] worldsNames) {
|
||||||
Integer count = worlds.get(world);
|
int total = 0;
|
||||||
return count != null ? count.toString() : "[World \"" + world + "\" not found]";
|
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