Search in sources :

Example 16 with PlayerContainer

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

the class ServerPlayerContainersQuery method executeQuery.

@Override
public List<PlayerContainer> executeQuery(SQLDB db) {
    List<PlayerContainer> containers = new ArrayList<>();
    Collection<BaseUser> baseUsers = db.query(BaseUserQueries.fetchServerBaseUsers(serverUUID));
    Map<UUID, List<GeoInfo>> geoInformation = db.query(GeoInfoQueries.fetchServerGeoInformation(serverUUID));
    Map<UUID, List<Nickname>> nicknames = db.query(NicknameQueries.fetchNicknameDataOfServer(serverUUID));
    Map<UUID, List<Ping>> pingData = db.query(PingQueries.fetchPingDataOfServer(serverUUID));
    Map<UUID, List<FinishedSession>> sessions = db.query(SessionQueries.fetchSessionsOfServer(serverUUID));
    Map<UUID, UserInfo> userInformation = db.query(UserInfoQueries.fetchUserInformationOfServer(serverUUID));
    Map<UUID, PerServerContainer> perServerInfo = getPerServerData(userInformation, sessions, pingData);
    for (BaseUser user : baseUsers) {
        PlayerContainer container = new PlayerContainer();
        // BaseUser
        UUID uuid = user.getUuid();
        container.putRawData(PlayerKeys.UUID, uuid);
        container.putRawData(PlayerKeys.NAME, user.getName());
        container.putRawData(PlayerKeys.REGISTERED, user.getRegistered());
        container.putRawData(PlayerKeys.KICK_COUNT, user.getTimesKicked());
        // GeoInfo
        container.putRawData(PlayerKeys.GEO_INFO, geoInformation.getOrDefault(uuid, Collections.emptyList()));
        // Ping
        container.putRawData(PlayerKeys.PING, pingData.get(uuid));
        // Nickname, only used for the raw server JSON.
        container.putRawData(PlayerKeys.NICKNAMES, nicknames.get(uuid));
        // PerServerContainer
        container.putRawData(PlayerKeys.PER_SERVER, perServerInfo.get(uuid));
        container.putCachingSupplier(PlayerKeys.SESSIONS, () -> {
            List<FinishedSession> playerSessions = sessions.getOrDefault(uuid, new ArrayList<>());
            container.getValue(PlayerKeys.ACTIVE_SESSION).map(ActiveSession::toFinishedSessionFromStillActive).ifPresent(playerSessions::add);
            return playerSessions;
        });
        // Calculating getters
        container.putCachingSupplier(PlayerKeys.WORLD_TIMES, () -> {
            WorldTimes worldTimes = new PerServerMutator(container.getUnsafe(PlayerKeys.PER_SERVER)).flatMapWorldTimes();
            container.getValue(PlayerKeys.ACTIVE_SESSION).ifPresent(session -> worldTimes.add(session.getExtraData(WorldTimes.class).orElseGet(WorldTimes::new)));
            return worldTimes;
        });
        container.putSupplier(PlayerKeys.BANNED, () -> PerServerMutator.forContainer(container).isBanned());
        container.putSupplier(PlayerKeys.OPERATOR, () -> PerServerMutator.forContainer(container).isOperator());
        container.putSupplier(PlayerKeys.LAST_SEEN, () -> SessionsMutator.forContainer(container).toLastSeen());
        container.putSupplier(PlayerKeys.PLAYER_KILLS, () -> SessionsMutator.forContainer(container).toPlayerKillList());
        container.putSupplier(PlayerKeys.PLAYER_KILL_COUNT, () -> container.getUnsafe(PlayerKeys.PLAYER_KILLS).size());
        container.putSupplier(PlayerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount());
        container.putSupplier(PlayerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount());
        containers.add(container);
    }
    return containers;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) PerServerMutator(com.djrapitops.plan.delivery.domain.mutators.PerServerMutator) PerServerContainer(com.djrapitops.plan.delivery.domain.container.PerServerContainer) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Aggregations

PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)16 ServerUUID (com.djrapitops.plan.identification.ServerUUID)5 GeoInfo (com.djrapitops.plan.gathering.domain.GeoInfo)4 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)3 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)3 PlayerContainerQuery (com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery)3 ServerTablePlayersQuery (com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery)3 PerServerContainer (com.djrapitops.plan.delivery.domain.container.PerServerContainer)2 Key (com.djrapitops.plan.delivery.domain.keys.Key)2 PlayerKeys (com.djrapitops.plan.delivery.domain.keys.PlayerKeys)2 PerServerMutator (com.djrapitops.plan.delivery.domain.mutators.PerServerMutator)2 BaseUser (com.djrapitops.plan.gathering.domain.BaseUser)2 Ping (com.djrapitops.plan.gathering.domain.Ping)2 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)2 Database (com.djrapitops.plan.storage.database.Database)2 RemoveEverythingTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemoveEverythingTransaction)2 Patch (com.djrapitops.plan.storage.database.transactions.patches.Patch)2 java.util (java.util)2 Test (org.junit.jupiter.api.Test)2 Arguments (com.djrapitops.plan.commands.use.Arguments)1