use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class ShutdownDataPreservationTransaction method ensureAllPlayersAreRegistered.
private void ensureAllPlayersAreRegistered() {
Set<UUID> playerUUIDs = new HashSet<>();
Map<UUID, String> playerNames = new HashMap<>();
Map<UUID, Long> earliestDates = new HashMap<>();
for (FinishedSession finishedSession : finishedSessions) {
UUID playerUUID = finishedSession.getPlayerUUID();
playerUUIDs.add(playerUUID);
finishedSession.getExtraData(PlayerKills.class).map(PlayerKills::asList).ifPresent(kills -> {
for (PlayerKill kill : kills) {
playerUUIDs.add(kill.getKiller().getUuid());
playerUUIDs.add(kill.getVictim().getUuid());
}
});
finishedSession.getExtraData(PlayerName.class).map(PlayerName::get).ifPresent(playerName -> playerNames.put(playerUUID, playerName));
long start = finishedSession.getStart();
Long previous = earliestDates.get(playerUUID);
if (previous == null || start < previous) {
earliestDates.put(playerUUID, start);
}
}
Set<UUID> existingUUIDs = query(BaseUserQueries.fetchExistingUUIDs(playerUUIDs));
for (UUID playerUUID : playerUUIDs) {
if (!existingUUIDs.contains(playerUUID)) {
LongSupplier registerDate = () -> Optional.ofNullable(earliestDates.get(playerUUID)).orElseGet(System::currentTimeMillis);
String playerName = Optional.ofNullable(playerNames.get(playerUUID)).orElseGet(playerUUID::toString);
executeOther(new PlayerRegisterTransaction(playerUUID, registerDate, playerName));
}
}
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class DatabaseTest method testRemovalSingleUser.
@Test
default void testRemovalSingleUser() {
saveUserTwo();
db().executeTransaction(new PlayerServerRegisterTransaction(playerUUID, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME, serverUUID(), TestConstants.GET_PLAYER_HOSTNAME));
saveTwoWorlds();
FinishedSession session = RandomData.randomSession(serverUUID(), worlds, playerUUID, player2UUID);
db().executeTransaction(new StoreSessionTransaction(session));
db().executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname("TestNick", RandomData.randomTime(), serverUUID()), (uuid, name) -> false));
db().executeTransaction(new StoreGeoInfoTransaction(playerUUID, new GeoInfo("TestLoc", RandomData.randomTime())));
assertTrue(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
db().executeTransaction(new RemovePlayerTransaction(playerUUID));
assertFalse(db().query(PlayerFetchQueries.isPlayerRegistered(playerUUID)));
assertFalse(db().query(PlayerFetchQueries.isPlayerRegisteredOnServer(playerUUID, serverUUID())));
assertTrue(db().query(NicknameQueries.fetchNicknameDataOfPlayer(playerUUID)).isEmpty());
assertTrue(db().query(GeoInfoQueries.fetchPlayerGeoInformation(playerUUID)).isEmpty());
assertQueryIsEmpty(db(), SessionQueries.fetchSessionsOfPlayer(playerUUID));
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class ShutdownSaveTest method sessionsAreNotSavedWhenNotShuttingDown.
@Test
void sessionsAreNotSavedWhenNotShuttingDown() {
for (int i = 0; i < 100; i++) {
UUID playerUUID = UUID.randomUUID();
ActiveSession session = RandomData.randomUnfinishedSession(TestConstants.SERVER_UUID, new String[] { "w1", "w2" }, playerUUID);
sessionCache.cacheSession(playerUUID, session);
}
Optional<Future<?>> save = underTest.performSave();
assertFalse(save.isPresent());
List<FinishedSession> sessions = database.query(SessionQueries.fetchAllSessions());
assertEquals(0, sessions.size());
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class SessionCacheTest method sessionsAreRemovedFromCacheOnStart.
@Test
void sessionsAreRemovedFromCacheOnStart() {
Optional<FinishedSession> ended = new SessionCache().cacheSession(uuid, new ActiveSession(uuid, serverUUID, 52345L, "World1", "SURVIVAL"));
assertTrue(ended.isPresent());
for (ActiveSession session : SessionCache.getActiveSessions()) {
if (session.getStart() == 12345L) {
fail("Session was still in cache: " + session);
}
}
}
use of com.djrapitops.plan.gathering.domain.FinishedSession in project Plan by plan-player-analytics.
the class ExportJSErrorRegressionTest method savePlayerData.
private static void savePlayerData() {
DBSystem dbSystem = planSystem.getDatabaseSystem();
Database database = dbSystem.getDatabase();
UUID uuid = TestConstants.PLAYER_ONE_UUID;
database.executeTransaction(new PlayerRegisterTransaction(uuid, RandomData::randomTime, TestConstants.PLAYER_ONE_NAME));
FinishedSession session = new FinishedSession(uuid, serverUUID, 1000L, 11000L, 500L, new DataMap());
database.executeTransaction(new WorldNameStoreTransaction(serverUUID, "world"));
database.executeTransaction(new StoreSessionTransaction(session));
}
Aggregations