Search in sources :

Example 1 with PingStoreTransaction

use of com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction in project Plan by plan-player-analytics.

the class BungeePingCounter method run.

@Override
public void run() {
    long time = System.currentTimeMillis();
    Iterator<Map.Entry<UUID, Long>> starts = startRecording.entrySet().iterator();
    while (starts.hasNext()) {
        Map.Entry<UUID, Long> start = starts.next();
        if (time >= start.getValue()) {
            addPlayer(start.getKey());
            starts.remove();
        }
    }
    Iterator<Map.Entry<UUID, List<DateObj<Integer>>>> iterator = playerHistory.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<UUID, List<DateObj<Integer>>> entry = iterator.next();
        UUID uuid = entry.getKey();
        List<DateObj<Integer>> history = entry.getValue();
        ProxiedPlayer player = ProxyServer.getInstance().getPlayer(uuid);
        if (player != null) {
            int ping = getPing(player);
            if (ping <= -1 || ping > TimeUnit.SECONDS.toMillis(8L)) {
                // Don't accept bad values
                continue;
            }
            history.add(new DateObj<>(time, ping));
            if (history.size() >= 30) {
                dbSystem.getDatabase().executeTransaction(new PingStoreTransaction(uuid, serverInfo.getServerUUID(), new ArrayList<>(history)));
                history.clear();
            }
        } else {
            iterator.remove();
        }
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) DateObj(com.djrapitops.plan.delivery.domain.DateObj) PingStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 2 with PingStoreTransaction

use of com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction in project Plan by plan-player-analytics.

the class SpongePingCounter method run.

@Override
public void run() {
    long time = System.currentTimeMillis();
    Iterator<Map.Entry<UUID, Long>> starts = startRecording.entrySet().iterator();
    while (starts.hasNext()) {
        Map.Entry<UUID, Long> start = starts.next();
        if (time >= start.getValue()) {
            addPlayer(start.getKey());
            starts.remove();
        }
    }
    Iterator<Map.Entry<UUID, List<DateObj<Integer>>>> iterator = playerHistory.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<UUID, List<DateObj<Integer>>> entry = iterator.next();
        UUID uuid = entry.getKey();
        List<DateObj<Integer>> history = entry.getValue();
        Optional<Player> player = Sponge.getServer().getPlayer(uuid);
        if (player.isPresent()) {
            int ping = getPing(player.get());
            if (ping <= -1 || ping > TimeUnit.SECONDS.toMillis(8L)) {
                // Don't accept bad values
                continue;
            }
            history.add(new DateObj<>(time, ping));
            if (history.size() >= 30) {
                dbSystem.getDatabase().executeTransaction(new PingStoreTransaction(uuid, serverInfo.getServerUUID(), new ArrayList<>(history)));
                history.clear();
            }
        } else {
            iterator.remove();
        }
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) DateObj(com.djrapitops.plan.delivery.domain.DateObj) PingStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 3 with PingStoreTransaction

use of com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction in project Plan by plan-player-analytics.

the class FabricPingCounter method run.

@Override
public void run() {
    if (!this.isEnabled) {
        return;
    }
    long time = System.currentTimeMillis();
    Iterator<Map.Entry<UUID, Long>> starts = startRecording.entrySet().iterator();
    while (starts.hasNext()) {
        Map.Entry<UUID, Long> start = starts.next();
        if (time >= start.getValue()) {
            addPlayer(start.getKey());
            starts.remove();
        }
    }
    Iterator<Map.Entry<UUID, List<DateObj<Integer>>>> iterator = playerHistory.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<UUID, List<DateObj<Integer>>> entry = iterator.next();
        UUID uuid = entry.getKey();
        List<DateObj<Integer>> history = entry.getValue();
        ServerPlayerEntity player = server.getPlayerManager().getPlayer(uuid);
        if (player != null) {
            int ping = getPing(player);
            if (ping <= -1 || ping > TimeUnit.SECONDS.toMillis(8L)) {
                // Don't accept bad values
                continue;
            }
            history.add(new DateObj<>(time, ping));
            if (history.size() >= 30) {
                dbSystem.getDatabase().executeTransaction(new PingStoreTransaction(uuid, serverInfo.getServerUUID(), new ArrayList<>(history)));
                history.clear();
            }
        } else {
            iterator.remove();
        }
    }
}
Also used : ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) DateObj(com.djrapitops.plan.delivery.domain.DateObj) PingStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 4 with PingStoreTransaction

use of com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction in project Plan by plan-player-analytics.

the class BukkitPingCounter method run.

@Override
public void run() {
    long time = System.currentTimeMillis();
    Iterator<Map.Entry<UUID, Long>> starts = startRecording.entrySet().iterator();
    while (starts.hasNext()) {
        Map.Entry<UUID, Long> start = starts.next();
        if (time >= start.getValue()) {
            addPlayer(start.getKey());
            starts.remove();
        }
    }
    Iterator<Map.Entry<UUID, List<DateObj<Integer>>>> iterator = playerHistory.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<UUID, List<DateObj<Integer>>> entry = iterator.next();
        UUID uuid = entry.getKey();
        List<DateObj<Integer>> history = entry.getValue();
        Player player = Bukkit.getPlayer(uuid);
        if (player != null) {
            int ping = getPing(player);
            if (ping <= -1 || ping > TimeUnit.SECONDS.toMillis(8L)) {
                // Don't accept bad values
                continue;
            }
            history.add(new DateObj<>(time, ping));
            if (history.size() >= 30) {
                dbSystem.getDatabase().executeTransaction(new PingStoreTransaction(uuid, serverInfo.getServerUUID(), new ArrayList<>(history)));
                history.clear();
            }
        } else {
            iterator.remove();
        }
    }
}
Also used : Player(org.bukkit.entity.Player) DateObj(com.djrapitops.plan.delivery.domain.DateObj) PingStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 5 with PingStoreTransaction

use of com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction in project Plan by plan-player-analytics.

the class NukkitPingCounter method run.

@Override
public void run() {
    long time = System.currentTimeMillis();
    Iterator<Map.Entry<UUID, Long>> starts = startRecording.entrySet().iterator();
    while (starts.hasNext()) {
        Map.Entry<UUID, Long> start = starts.next();
        if (time >= start.getValue()) {
            addPlayer(start.getKey());
            starts.remove();
        }
    }
    Iterator<Map.Entry<UUID, List<DateObj<Integer>>>> iterator = playerHistory.entrySet().iterator();
    while (iterator.hasNext()) {
        Map.Entry<UUID, List<DateObj<Integer>>> entry = iterator.next();
        UUID uuid = entry.getKey();
        List<DateObj<Integer>> history = entry.getValue();
        Optional<Player> player = Server.getInstance().getPlayer(uuid);
        if (player.isPresent()) {
            int ping = player.get().getPing();
            if (ping <= -1 || ping > TimeUnit.SECONDS.toMillis(8L)) {
                // Don't accept bad values
                continue;
            }
            history.add(new DateObj<>(time, ping));
            if (history.size() >= 30) {
                dbSystem.getDatabase().executeTransaction(new PingStoreTransaction(uuid, serverInfo.getServerUUID(), new ArrayList<>(history)));
                history.clear();
            }
        } else {
            iterator.remove();
        }
    }
}
Also used : Player(cn.nukkit.Player) DateObj(com.djrapitops.plan.delivery.domain.DateObj) PingStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Aggregations

PingStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction)8 DateObj (com.djrapitops.plan.delivery.domain.DateObj)7 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 Ping (com.djrapitops.plan.gathering.domain.Ping)2 Test (org.junit.jupiter.api.Test)2 Player (cn.nukkit.Player)1 Database (com.djrapitops.plan.storage.database.Database)1 Player (com.velocitypowered.api.proxy.Player)1 List (java.util.List)1 UUID (java.util.UUID)1 ProxiedPlayer (net.md_5.bungee.api.connection.ProxiedPlayer)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 Player (org.bukkit.entity.Player)1 Player (org.spongepowered.api.entity.living.player.Player)1