Search in sources :

Example 6 with ActiveSession

use of com.djrapitops.plan.gathering.domain.ActiveSession 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());
}
Also used : ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Future(java.util.concurrent.Future) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 7 with ActiveSession

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

the class SessionCacheTest method setUp.

@BeforeEach
void setUp() {
    session = new ActiveSession(uuid, serverUUID, 12345L, "World1", "SURVIVAL");
    sessionCache = new SessionCache();
    sessionCache.cacheSession(uuid, session);
}
Also used : ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with ActiveSession

use of com.djrapitops.plan.gathering.domain.ActiveSession 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);
        }
    }
}
Also used : ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) Test(org.junit.jupiter.api.Test)

Example 9 with ActiveSession

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

the class BukkitAFKListenerTest method setUp.

@BeforeAll
static void setUp() {
    PlanConfig config = Mockito.mock(PlanConfig.class);
    when(config.get(TimeSettings.AFK_THRESHOLD)).thenReturn(TimeUnit.MINUTES.toMillis(3));
    errorLogger = Mockito.mock(ErrorLogger.class);
    underTest = new BukkitAFKListener(config, errorLogger);
    new SessionCache().cacheSession(TestConstants.PLAYER_ONE_UUID, new ActiveSession(null, null, 0, null, null));
    new SessionCache().cacheSession(TestConstants.PLAYER_TWO_UUID, new ActiveSession(null, null, 0, null, null));
}
Also used : ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) BukkitAFKListener(com.djrapitops.plan.gathering.listeners.bukkit.BukkitAFKListener) SessionCache(com.djrapitops.plan.gathering.cache.SessionCache) PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 10 with ActiveSession

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

the class WorldChangeListener method actOnEvent.

private void actOnEvent(ServerPlayerEntity player) {
    long time = System.currentTimeMillis();
    UUID uuid = player.getUuid();
    String worldName = player.getServerWorld().getRegistryKey().getValue().toString();
    String gameMode = player.interactionManager.getGameMode().name();
    dbSystem.getDatabase().executeTransaction(new WorldNameStoreTransaction(serverInfo.getServerUUID(), worldName));
    worldAliasSettings.addWorld(worldName);
    Optional<ActiveSession> cachedSession = SessionCache.getCachedSession(uuid);
    cachedSession.ifPresent(session -> session.changeState(worldName, gameMode, time));
}
Also used : ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) UUID(java.util.UUID)

Aggregations

ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)34 UUID (java.util.UUID)20 WorldNameStoreTransaction (com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction)9 PlayerName (com.djrapitops.plan.delivery.domain.PlayerName)8 ServerName (com.djrapitops.plan.delivery.domain.ServerName)8 ServerUUID (com.djrapitops.plan.identification.ServerUUID)8 SessionCache (com.djrapitops.plan.gathering.cache.SessionCache)7 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)7 ErrorLogger (com.djrapitops.plan.utilities.logging.ErrorLogger)7 Database (com.djrapitops.plan.storage.database.Database)6 InetAddress (java.net.InetAddress)6 Test (org.junit.jupiter.api.Test)6 CallEvents (com.djrapitops.plan.extension.CallEvents)5 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)5 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)5 Processing (com.djrapitops.plan.processing.Processing)5 ErrorContext (com.djrapitops.plan.utilities.logging.ErrorContext)5 Supplier (java.util.function.Supplier)5 Inject (javax.inject.Inject)5 Player (cn.nukkit.Player)4