Search in sources :

Example 1 with DateObj

use of com.djrapitops.plan.delivery.domain.DateObj 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 DateObj

use of com.djrapitops.plan.delivery.domain.DateObj in project Plan by plan-player-analytics.

the class DatabaseBackupTest method saveDataForBackup.

default void saveDataForBackup() {
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[0]));
    db().executeTransaction(new WorldNameStoreTransaction(serverUUID(), worlds[1]));
    db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    db().executeTransaction(new PlayerServerRegisterTransaction(player2UUID, RandomData::randomTime, TestConstants.PLAYER_TWO_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    execute(DataStoreQueries.storeSession(session));
    db().executeTransaction(new NicknameStoreTransaction(playerUUID, RandomData.randomNickname(serverUUID()), (uuid, name) -> false));
    db().executeTransaction(new GeoInfoStoreTransaction(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime())));
    List<TPS> expected = RandomData.randomTPS();
    for (TPS tps : expected) {
        execute(DataStoreQueries.storeTPS(serverUUID(), tps));
    }
    db().executeTransaction(new PingStoreTransaction(playerUUID, serverUUID(), Collections.singletonList(new DateObj<>(System.currentTimeMillis(), RandomData.randomInt(-1, 40)))));
    User user = new User("test", "console", null, PassEncryptUtil.createHash("testPass"), 0, Collections.emptyList());
    db().executeTransaction(new RegisterWebUserTransaction(user));
}
Also used : MoreExecutors(com.google.common.util.concurrent.MoreExecutors) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Files(java.nio.file.Files) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) File(java.io.File) Database(com.djrapitops.plan.storage.database.Database) Test(org.junit.jupiter.api.Test) List(java.util.List) SQLiteDB(com.djrapitops.plan.storage.database.SQLiteDB) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) DateObj(com.djrapitops.plan.delivery.domain.DateObj) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) BackupCopyTransaction(com.djrapitops.plan.storage.database.transactions.BackupCopyTransaction) User(com.djrapitops.plan.delivery.domain.auth.User) DatabaseTestPreparer(com.djrapitops.plan.storage.database.DatabaseTestPreparer) TPS(com.djrapitops.plan.gathering.domain.TPS) PassEncryptUtil(com.djrapitops.plan.utilities.PassEncryptUtil) RandomData(utilities.RandomData) com.djrapitops.plan.storage.database.queries.objects(com.djrapitops.plan.storage.database.queries.objects) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestConstants(utilities.TestConstants) Collections(java.util.Collections) User(com.djrapitops.plan.delivery.domain.auth.User) RegisterWebUserTransaction(com.djrapitops.plan.storage.database.transactions.commands.RegisterWebUserTransaction) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) TPS(com.djrapitops.plan.gathering.domain.TPS)

Example 3 with DateObj

use of com.djrapitops.plan.delivery.domain.DateObj 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 4 with DateObj

use of com.djrapitops.plan.delivery.domain.DateObj 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 5 with DateObj

use of com.djrapitops.plan.delivery.domain.DateObj 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)

Aggregations

DateObj (com.djrapitops.plan.delivery.domain.DateObj)12 PingStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.PingStoreTransaction)7 Database (com.djrapitops.plan.storage.database.Database)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 ServerUUID (com.djrapitops.plan.identification.ServerUUID)3 com.djrapitops.plan.storage.database.queries.objects (com.djrapitops.plan.storage.database.queries.objects)3 Formatter (com.djrapitops.plan.delivery.formatting.Formatter)2 Formatters (com.djrapitops.plan.delivery.formatting.Formatters)2 Server (com.djrapitops.plan.identification.Server)2 ServerInfo (com.djrapitops.plan.identification.ServerInfo)2 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)2 DBSystem (com.djrapitops.plan.storage.database.DBSystem)2 PlayerCountQueries (com.djrapitops.plan.storage.database.queries.analysis.PlayerCountQueries)2 HashMap (java.util.HashMap)2 TimeUnit (java.util.concurrent.TimeUnit)2 Inject (javax.inject.Inject)2 Singleton (javax.inject.Singleton)2 Player (cn.nukkit.Player)1 Arguments (com.djrapitops.plan.commands.use.Arguments)1 DateHolder (com.djrapitops.plan.delivery.domain.DateHolder)1