Search in sources :

Example 1 with RedisBungee

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) {
    }
}
Also used : DataCache(de.codecrafter47.data.api.DataCache) Player(de.codecrafter47.taboverlay.config.player.Player) EventExecutor(io.netty.util.concurrent.EventExecutor) java.util(java.util) DataStreamUtils(codecrafter47.bungeetablistplus.common.network.DataStreamUtils) PubSubMessageEvent(com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent) Level(java.util.logging.Level) BungeePlayer(codecrafter47.bungeetablistplus.player.BungeePlayer) ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) ByteArrayDataInput(com.google.common.io.ByteArrayDataInput) BungeeData(de.codecrafter47.data.bungee.api.BungeeData) BTLPBungeeDataKeys(codecrafter47.bungeetablistplus.data.BTLPBungeeDataKeys) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) Listener(net.md_5.bungee.api.plugin.Listener) BTLPDataTypes(codecrafter47.bungeetablistplus.data.BTLPDataTypes) RedisPlayer(codecrafter47.bungeetablistplus.player.RedisPlayer) DataKey(de.codecrafter47.data.api.DataKey) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) IOException(java.io.IOException) RedisBungee(com.imaginarycode.minecraft.redisbungee.RedisBungee) ProxyServer(net.md_5.bungee.api.ProxyServer) Logger(java.util.logging.Logger) Sets(com.google.common.collect.Sets) PlayerProvider(de.codecrafter47.taboverlay.config.player.PlayerProvider) TypeAdapterRegistry(codecrafter47.bungeetablistplus.common.network.TypeAdapterRegistry) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) BukkitData(de.codecrafter47.data.bukkit.api.BukkitData) DataKeyRegistry(de.codecrafter47.data.api.DataKeyRegistry) SpongeData(de.codecrafter47.data.sponge.api.SpongeData) ReferenceOpenHashSet(it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet) ByteStreams(com.google.common.io.ByteStreams) MinecraftData(de.codecrafter47.data.minecraft.api.MinecraftData) BTLPDataKeys(codecrafter47.bungeetablistplus.common.BTLPDataKeys) BungeeTabListPlus(codecrafter47.bungeetablistplus.BungeeTabListPlus) EventHandler(net.md_5.bungee.event.EventHandler) Object2ObjectOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap) RedisPlayer(codecrafter47.bungeetablistplus.player.RedisPlayer)

Aggregations

BungeeTabListPlus (codecrafter47.bungeetablistplus.BungeeTabListPlus)1 BTLPDataKeys (codecrafter47.bungeetablistplus.common.BTLPDataKeys)1 DataStreamUtils (codecrafter47.bungeetablistplus.common.network.DataStreamUtils)1 TypeAdapterRegistry (codecrafter47.bungeetablistplus.common.network.TypeAdapterRegistry)1 BTLPBungeeDataKeys (codecrafter47.bungeetablistplus.data.BTLPBungeeDataKeys)1 BTLPDataTypes (codecrafter47.bungeetablistplus.data.BTLPDataTypes)1 BungeePlayer (codecrafter47.bungeetablistplus.player.BungeePlayer)1 RedisPlayer (codecrafter47.bungeetablistplus.player.RedisPlayer)1 Sets (com.google.common.collect.Sets)1 ByteArrayDataInput (com.google.common.io.ByteArrayDataInput)1 ByteArrayDataOutput (com.google.common.io.ByteArrayDataOutput)1 ByteStreams (com.google.common.io.ByteStreams)1 RedisBungee (com.imaginarycode.minecraft.redisbungee.RedisBungee)1 PubSubMessageEvent (com.imaginarycode.minecraft.redisbungee.events.PubSubMessageEvent)1 DataCache (de.codecrafter47.data.api.DataCache)1 DataKey (de.codecrafter47.data.api.DataKey)1 DataKeyRegistry (de.codecrafter47.data.api.DataKeyRegistry)1 BukkitData (de.codecrafter47.data.bukkit.api.BukkitData)1 BungeeData (de.codecrafter47.data.bungee.api.BungeeData)1 MinecraftData (de.codecrafter47.data.minecraft.api.MinecraftData)1