Search in sources :

Example 1 with BaseUser

use of com.djrapitops.plan.gathering.domain.BaseUser in project Plan by plan-player-analytics.

the class BaseUserQueries method extractBaseUsers.

private static Collection<BaseUser> extractBaseUsers(ResultSet set) throws SQLException {
    Collection<BaseUser> users = new HashSet<>();
    while (set.next()) {
        UUID playerUUID = UUID.fromString(set.getString(UsersTable.USER_UUID));
        String name = set.getString(UsersTable.USER_NAME);
        long registered = set.getLong(UsersTable.REGISTERED);
        int kicked = set.getInt(UsersTable.TIMES_KICKED);
        users.add(new BaseUser(playerUUID, name, registered, kicked));
    }
    return users;
}
Also used : BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 2 with BaseUser

use of com.djrapitops.plan.gathering.domain.BaseUser in project Plan by plan-player-analytics.

the class BaseUserQueries method fetchBaseUserOfPlayer.

/**
 * Query database for common user information of a player.
 * <p>
 * Only one {@link BaseUser} per player exists unlike {@link UserInfo} which is available per server.
 *
 * @param playerUUID UUID of the Player.
 * @return Optional: BaseUser if found, empty if not.
 */
public static Query<Optional<BaseUser>> fetchBaseUserOfPlayer(UUID playerUUID) {
    String sql = Select.all(UsersTable.TABLE_NAME).where(UsersTable.USER_UUID + "=?").toString();
    return new QueryStatement<Optional<BaseUser>>(sql, 20000) {

        @Override
        public void prepare(PreparedStatement statement) throws SQLException {
            statement.setString(1, playerUUID.toString());
        }

        @Override
        public Optional<BaseUser> processResults(ResultSet set) throws SQLException {
            if (set.next()) {
                UUID playerUUID = UUID.fromString(set.getString(UsersTable.USER_UUID));
                String name = set.getString(UsersTable.USER_NAME);
                long registered = set.getLong(UsersTable.REGISTERED);
                int kicked = set.getInt(UsersTable.TIMES_KICKED);
                return Optional.of(new BaseUser(playerUUID, name, registered, kicked));
            }
            return Optional.empty();
        }
    };
}
Also used : BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) ServerUUID(com.djrapitops.plan.identification.ServerUUID)

Example 3 with BaseUser

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

use of com.djrapitops.plan.gathering.domain.BaseUser in project Plan by plan-player-analytics.

the class DatabaseTest method cleanDoesNotCleanActivePlayers.

@Test
default void cleanDoesNotCleanActivePlayers() {
    saveUserOne();
    saveTwoWorlds();
    long sessionStart = System.currentTimeMillis();
    ActiveSession session = new ActiveSession(playerUUID, serverUUID(), sessionStart, worlds[0], "SURVIVAL");
    execute(DataStoreQueries.storeSession(session.toFinishedSession(sessionStart + 22345L)));
    TestPluginLogger logger = new TestPluginLogger();
    new DBCleanTask(config(), new Locale(), dbSystem(), new QuerySvc(config(), dbSystem(), serverInfo(), null), serverInfo(), logger, null).cleanOldPlayers(db());
    Collection<BaseUser> found = db().query(BaseUserQueries.fetchServerBaseUsers(serverUUID()));
    assertFalse(found.isEmpty(), "All users were deleted!! D:");
}
Also used : Locale(com.djrapitops.plan.settings.locale.Locale) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) DBCleanTask(com.djrapitops.plan.storage.upkeep.DBCleanTask) QuerySvc(com.djrapitops.plan.query.QuerySvc) Test(org.junit.jupiter.api.Test)

Example 5 with BaseUser

use of com.djrapitops.plan.gathering.domain.BaseUser in project Plan by plan-player-analytics.

the class DatabaseTest method registerDateIsMinimized.

@Test
default void registerDateIsMinimized() {
    executeTransactions(new PlayerServerRegisterTransaction(playerUUID, () -> 1000, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME), new Transaction() {

        @Override
        protected void performOperations() {
            execute("UPDATE " + UserInfoTable.TABLE_NAME + " SET " + UserInfoTable.REGISTERED + "=0" + WHERE + UserInfoTable.USER_UUID + "='" + playerUUID + "'");
        }
    });
    // Check test assumptions
    Map<UUID, Long> registerDates = db().query(UserInfoQueries.fetchRegisterDates(0L, System.currentTimeMillis(), serverUUID()));
    assertEquals(0L, registerDates.get(playerUUID));
    Optional<BaseUser> baseUser = db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID));
    assertEquals(1000L, baseUser.isPresent() ? baseUser.get().getRegistered() : null);
    RegisterDateMinimizationPatch testedPatch = new RegisterDateMinimizationPatch();
    executeTransactions(testedPatch);
    // Test expected result
    Optional<BaseUser> updatedBaseUser = db().query(BaseUserQueries.fetchBaseUserOfPlayer(playerUUID));
    assertEquals(0L, updatedBaseUser.isPresent() ? updatedBaseUser.get().getRegistered() : null);
    assertTrue(testedPatch.isApplied());
}
Also used : BaseUser(com.djrapitops.plan.gathering.domain.BaseUser) RegisterDateMinimizationPatch(com.djrapitops.plan.storage.database.transactions.patches.RegisterDateMinimizationPatch) StoreConfigTransaction(com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction) Transaction(com.djrapitops.plan.storage.database.transactions.Transaction) RemovePlayerTransaction(com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction) CreateIndexTransaction(com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction) ServerUUID(com.djrapitops.plan.identification.ServerUUID) Test(org.junit.jupiter.api.Test)

Aggregations

BaseUser (com.djrapitops.plan.gathering.domain.BaseUser)5 ServerUUID (com.djrapitops.plan.identification.ServerUUID)3 Test (org.junit.jupiter.api.Test)2 PerServerContainer (com.djrapitops.plan.delivery.domain.container.PerServerContainer)1 PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)1 Key (com.djrapitops.plan.delivery.domain.keys.Key)1 PerServerMutator (com.djrapitops.plan.delivery.domain.mutators.PerServerMutator)1 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)1 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)1 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)1 QuerySvc (com.djrapitops.plan.query.QuerySvc)1 Locale (com.djrapitops.plan.settings.locale.Locale)1 QueryStatement (com.djrapitops.plan.storage.database.queries.QueryStatement)1 StoreConfigTransaction (com.djrapitops.plan.storage.database.transactions.StoreConfigTransaction)1 Transaction (com.djrapitops.plan.storage.database.transactions.Transaction)1 RemovePlayerTransaction (com.djrapitops.plan.storage.database.transactions.commands.RemovePlayerTransaction)1 CreateIndexTransaction (com.djrapitops.plan.storage.database.transactions.init.CreateIndexTransaction)1 RegisterDateMinimizationPatch (com.djrapitops.plan.storage.database.transactions.patches.RegisterDateMinimizationPatch)1 DBCleanTask (com.djrapitops.plan.storage.upkeep.DBCleanTask)1 PreparedStatement (java.sql.PreparedStatement)1