Search in sources :

Example 16 with ActiveSession

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

the class NukkitAFKListenerTest 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 NukkitAFKListener(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) NukkitAFKListener(com.djrapitops.plan.gathering.listeners.nukkit.NukkitAFKListener) 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 17 with ActiveSession

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

the class GameModeChangeListener method actOnEvent.

private void actOnEvent(PlayerGameModeChangeEvent event) {
    Player player = event.getPlayer();
    UUID uuid = player.getUniqueId();
    long time = System.currentTimeMillis();
    String gameMode = event.getNewGameMode().name();
    String worldName = player.getWorld().getName();
    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 : Player(org.bukkit.entity.Player) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) UUID(java.util.UUID)

Example 18 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(PlayerChangedWorldEvent event) {
    long time = System.currentTimeMillis();
    Player player = event.getPlayer();
    UUID uuid = player.getUniqueId();
    String worldName = player.getWorld().getName();
    String gameMode = player.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 : Player(org.bukkit.entity.Player) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) UUID(java.util.UUID)

Example 19 with ActiveSession

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

the class PlayerOnlineListener method actOnLogin.

private void actOnLogin(PostLoginEvent event) {
    ProxiedPlayer player = event.getPlayer();
    UUID playerUUID = player.getUniqueId();
    String playerName = player.getName();
    InetAddress address = player.getAddress().getAddress();
    long time = System.currentTimeMillis();
    ActiveSession session = new ActiveSession(playerUUID, serverInfo.getServerUUID(), time, null, null);
    session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
    session.getExtraData().put(ServerName.class, new ServerName("Proxy Server"));
    sessionCache.cacheSession(playerUUID, session);
    Database database = dbSystem.getDatabase();
    boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
    if (gatheringGeolocations) {
        database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
    }
    database.executeTransaction(new PlayerRegisterTransaction(playerUUID, () -> time, playerName));
    processing.submitNonCritical(() -> extensionService.updatePlayerValues(playerUUID, playerName, CallEvents.PLAYER_JOIN));
    if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
        processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerName(com.djrapitops.plan.delivery.domain.ServerName) Database(com.djrapitops.plan.storage.database.Database) GeoInfoStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.GeoInfoStoreTransaction) PlayerRegisterTransaction(com.djrapitops.plan.storage.database.transactions.events.PlayerRegisterTransaction) UUID(java.util.UUID) InetAddress(java.net.InetAddress)

Example 20 with ActiveSession

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

the class PlayerOnlineListener method actOnServerSwitch.

private void actOnServerSwitch(ServerSwitchEvent event) {
    ProxiedPlayer player = event.getPlayer();
    String playerName = player.getName();
    UUID playerUUID = player.getUniqueId();
    long time = System.currentTimeMillis();
    // Replaces the current session in the cache.
    ActiveSession session = new ActiveSession(playerUUID, serverInfo.getServerUUID(), time, null, null);
    session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
    session.getExtraData().put(ServerName.class, new ServerName("Proxy Server"));
    sessionCache.cacheSession(playerUUID, session);
    if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
        processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
    }
}
Also used : ProxiedPlayer(net.md_5.bungee.api.connection.ProxiedPlayer) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerName(com.djrapitops.plan.delivery.domain.ServerName) 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