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;
}
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();
}
};
}
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;
}
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:");
}
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());
}
Aggregations