use of com.imaginarycode.minecraft.redisbungee.RedisBungee in project BungeeTabListPlus by CodeCrafter47.
the class RedisPlayerManager method updatePlayers.
private void updatePlayers() {
Set<UUID> playersOnline;
try {
playersOnline = RedisBungee.getApi().getPlayersOnline();
} catch (Throwable th) {
if (!redisBungeeAPIError) {
logger.log(Level.WARNING, "Error using RedisBungee API", th);
redisBungeeAPIError = true;
}
return;
}
redisBungeeAPIError = false;
// fetch names for new players
Map<UUID, String> uuidToNameMap = new Object2ObjectOpenHashMap<>();
for (UUID uuid : playersOnline) {
if (!byUUID.containsKey(uuid) && ProxyServer.getInstance().getPlayer(uuid) == null) {
try {
uuidToNameMap.put(uuid, RedisBungee.getApi().getNameFromUuid(uuid));
} catch (Throwable ex) {
logger.log(Level.WARNING, "Error while using RedisBungee API", ex);
}
}
}
redisConnectionSuccessful = true;
try {
mainThread.submit(() -> {
// remove players which have gone offline
for (Iterator<UUID> iterator = byUUID.keySet().iterator(); iterator.hasNext(); ) {
UUID uuid = iterator.next();
if (!playersOnline.contains(uuid) || ProxyServer.getInstance().getPlayer(uuid) != null) {
RedisPlayer redisPlayer = byUUID.get(uuid);
iterator.remove();
listeners.forEach(listener -> listener.onPlayerRemoved(redisPlayer));
}
}
// add new players
for (UUID uuid : uuidToNameMap.keySet()) {
if (!byUUID.containsKey(uuid) && ProxyServer.getInstance().getPlayer(uuid) == null) {
RedisPlayer redisPlayer = new RedisPlayer(uuid, uuidToNameMap.get(uuid));
byUUID.put(uuid, redisPlayer);
listeners.forEach(listener -> listener.onPlayerAdded(redisPlayer));
}
}
}).sync();
} catch (InterruptedException ignored) {
}
}
Aggregations