Search in sources :

Example 1 with Key

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

the class PlayerContainerQuery method executeQuery.

@Override
public PlayerContainer executeQuery(SQLDB db) {
    PlayerContainer container = new PlayerContainer();
    container.putRawData(PlayerKeys.UUID, uuid);
    Key<BaseUser> baseUserKey = new Key<>(BaseUser.class, "BASE_USER");
    container.putSupplier(baseUserKey, () -> db.query(BaseUserQueries.fetchBaseUserOfPlayer(uuid)).orElse(null));
    container.putSupplier(PlayerKeys.REGISTERED, () -> container.getValue(baseUserKey).map(BaseUser::getRegistered).orElse(null));
    container.putSupplier(PlayerKeys.NAME, () -> container.getValue(baseUserKey).map(BaseUser::getName).orElse(null));
    container.putSupplier(PlayerKeys.KICK_COUNT, () -> container.getValue(baseUserKey).map(BaseUser::getTimesKicked).orElse(null));
    container.putCachingSupplier(PlayerKeys.GEO_INFO, () -> db.query(GeoInfoQueries.fetchPlayerGeoInformation(uuid)));
    container.putCachingSupplier(PlayerKeys.PING, () -> db.query(PingQueries.fetchPingDataOfPlayer(uuid)));
    container.putCachingSupplier(PlayerKeys.NICKNAMES, () -> db.query(NicknameQueries.fetchNicknameDataOfPlayer(uuid)));
    container.putCachingSupplier(PlayerKeys.PER_SERVER, () -> db.query(new PerServerContainerQuery(uuid)));
    container.putSupplier(PlayerKeys.BANNED, () -> new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).isBanned());
    container.putSupplier(PlayerKeys.OPERATOR, () -> new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).isOperator());
    container.putCachingSupplier(PlayerKeys.SESSIONS, () -> {
        List<FinishedSession> sessions = new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).flatMapSessions();
        container.getValue(PlayerKeys.ACTIVE_SESSION).map(ActiveSession::toFinishedSessionFromStillActive).ifPresent(sessions::add);
        return sessions;
    });
    container.putCachingSupplier(PlayerKeys.WORLD_TIMES, () -> {
        WorldTimes worldTimes = db.query(WorldTimesQueries.fetchPlayerTotalWorldTimes(uuid));
        container.getValue(PlayerKeys.ACTIVE_SESSION).ifPresent(session -> worldTimes.add(session.getExtraData(WorldTimes.class).orElseGet(WorldTimes::new)));
        return worldTimes;
    });
    container.putSupplier(PlayerKeys.LAST_SEEN, () -> SessionsMutator.forContainer(container).toLastSeen());
    container.putSupplier(PlayerKeys.PLAYER_KILLS, () -> db.query(KillQueries.fetchPlayerKillsOfPlayer(uuid)));
    container.putSupplier(PlayerKeys.PLAYER_DEATHS_KILLS, () -> db.query(KillQueries.fetchPlayerDeathsOfPlayer(uuid)));
    container.putSupplier(PlayerKeys.PLAYER_KILL_COUNT, () -> container.getValue(PlayerKeys.PLAYER_KILLS).map(Collection::size).orElse(0));
    container.putSupplier(PlayerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount());
    container.putSupplier(PlayerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount());
    SessionCache.getCachedSession(uuid).ifPresent(session -> container.putRawData(PlayerKeys.ACTIVE_SESSION, session));
    return container;
}
Also used : PerServerContainer(com.djrapitops.plan.delivery.domain.container.PerServerContainer) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) PerServerMutator(com.djrapitops.plan.delivery.domain.mutators.PerServerMutator) Collection(java.util.Collection) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) Key(com.djrapitops.plan.delivery.domain.keys.Key)

Example 2 with Key

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

the class DatabaseTest method playerContainerSupportsAllPlayerKeys.

@Test
default void playerContainerSupportsAllPlayerKeys() throws IllegalAccessException {
    saveUserOne();
    saveUserTwo();
    saveTwoWorlds();
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
    execute(DataStoreQueries.storeSession(session));
    db().executeTransaction(new NicknameStoreTransaction(playerUUID, RandomData.randomNickname(serverUUID()), (uuid, name) -> false));
    saveGeoInfo(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime()));
    assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
    db().executeTransaction(new PingStoreTransaction(playerUUID, serverUUID(), RandomData.randomIntDateObjects()));
    PlayerContainer playerContainer = db().query(ContainerFetchQueries.fetchPlayerContainer(playerUUID));
    // Active sessions are added after fetching
    playerContainer.putRawData(PlayerKeys.ACTIVE_SESSION, RandomData.randomUnfinishedSession(serverUUID(), worlds, playerUUID));
    List<String> unsupported = new ArrayList<>();
    List<Key> keys = FieldFetcher.getPublicStaticFields(PlayerKeys.class, Key.class);
    for (Key<?> key : keys) {
        if (!playerContainer.supports(key)) {
            unsupported.add(key.getKeyName());
        }
    }
    assertTrue(unsupported.isEmpty(), () -> "Some keys are not supported by PlayerContainer: PlayerKeys." + unsupported.toString());
}
Also used : SELECT(com.djrapitops.plan.storage.database.sql.building.Sql.SELECT) java.util(java.util) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) ServerTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.ServerTablePlayersQuery) UserInfoTable(com.djrapitops.plan.storage.database.sql.tables.UserInfoTable) ServerUUID(com.djrapitops.plan.identification.ServerUUID) TablePlayer(com.djrapitops.plan.delivery.domain.TablePlayer) Disabled(org.junit.jupiter.api.Disabled) utilities(utilities) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) com.djrapitops.plan.storage.database.queries(com.djrapitops.plan.storage.database.queries) SQLException(java.sql.SQLException) NetworkTablePlayersQuery(com.djrapitops.plan.storage.database.queries.objects.playertable.NetworkTablePlayersQuery) ResultSet(java.sql.ResultSet) BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) PlayerKeys(com.djrapitops.plan.delivery.domain.keys.PlayerKeys) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) ContainerFetchQueries(com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WHERE(com.djrapitops.plan.storage.database.sql.building.Sql.WHERE) ServerPlayerContainersQuery(com.djrapitops.plan.storage.database.queries.containers.ServerPlayerContainersQuery) QuerySvc(com.djrapitops.plan.query.QuerySvc) Sql(com.djrapitops.plan.storage.database.sql.building.Sql) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) Key(com.djrapitops.plan.delivery.domain.keys.Key) DBCleanTask(com.djrapitops.plan.storage.upkeep.DBCleanTask) Locale(com.djrapitops.plan.settings.locale.Locale) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) Assertions(org.junit.jupiter.api.Assertions) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) com.djrapitops.plan.storage.database.queries.objects(com.djrapitops.plan.storage.database.queries.objects) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) CreateIndexTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction) RegisterDateMinimizationPatch(com.djrapitops.plan.storage.database.transactions.patches.RegisterDateMinimizationPatch) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Config(com.djrapitops.plan.settings.config.Config) PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) GeoInfo(com.djrapitops.plan.gathering.domain.GeoInfo) Key(com.djrapitops.plan.delivery.domain.keys.Key) Test(org.junit.jupiter.api.Test)

Aggregations

PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)2 Key (com.djrapitops.plan.delivery.domain.keys.Key)2 BaseUser (com.djrapitops.plan.gathering.domain.BaseUser)2 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)2 Nickname (com.djrapitops.plan.delivery.domain.Nickname)1 TablePlayer (com.djrapitops.plan.delivery.domain.TablePlayer)1 PerServerContainer (com.djrapitops.plan.delivery.domain.container.PerServerContainer)1 PlayerKeys (com.djrapitops.plan.delivery.domain.keys.PlayerKeys)1 PerServerMutator (com.djrapitops.plan.delivery.domain.mutators.PerServerMutator)1 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)1 GeoInfo (com.djrapitops.plan.gathering.domain.GeoInfo)1 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)1 ServerUUID (com.djrapitops.plan.identification.ServerUUID)1 QuerySvc (com.djrapitops.plan.query.QuerySvc)1 Config (com.djrapitops.plan.settings.config.Config)1 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)1 Locale (com.djrapitops.plan.settings.locale.Locale)1 com.djrapitops.plan.storage.database.queries (com.djrapitops.plan.storage.database.queries)1 ContainerFetchQueries (com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries)1 ServerPlayerContainersQuery (com.djrapitops.plan.storage.database.queries.containers.ServerPlayerContainersQuery)1