Search in sources :

Example 1 with ActiveSession

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

the class WorldAliasSettings method getLongestWorldPlayed.

public String getLongestWorldPlayed(ActiveSession session) {
    Optional<WorldTimes> foundWorldTimes = session.getExtraData(WorldTimes.class);
    if (!foundWorldTimes.isPresent()) {
        return locale.get().getString(HtmlLang.UNIT_NO_DATA);
    }
    WorldTimes worldTimes = foundWorldTimes.orElseGet(WorldTimes::new);
    return worldTimes.getCurrentWorld().map(currentWorld -> "Current: " + getAlias(currentWorld).orElse(currentWorld)).orElse("Current: " + locale.get().getString(GenericLang.UNAVAILABLE));
}
Also used : HtmlLang(com.djrapitops.plan.settings.locale.lang.HtmlLang) java.util(java.util) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) GenericLang(com.djrapitops.plan.settings.locale.lang.GenericLang) Formatters(com.djrapitops.plan.delivery.formatting.Formatters) IOException(java.io.IOException) Singleton(javax.inject.Singleton) Lazy(dagger.Lazy) StringUtils(org.apache.commons.lang3.StringUtils) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) Inject(javax.inject.Inject) GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) Locale(com.djrapitops.plan.settings.locale.Locale) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ErrorContext(com.djrapitops.plan.utilities.logging.ErrorContext) Processing(com.djrapitops.plan.processing.Processing) DisplaySettings(com.djrapitops.plan.settings.config.paths.DisplaySettings) Formatter(com.djrapitops.plan.delivery.formatting.Formatter) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes)

Example 2 with ActiveSession

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

the class PlayerOnlineListener method actOnServerSwitch.

public void actOnServerSwitch(ServerConnectedEvent event) {
    Player player = event.getPlayer();
    String playerName = player.getUsername();
    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 : Player(com.velocitypowered.api.proxy.Player) 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)

Example 3 with ActiveSession

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

the class PlayerOnlineListener method actOnLogin.

public void actOnLogin(PostLoginEvent event) {
    Player player = event.getPlayer();
    UUID playerUUID = player.getUniqueId();
    String playerName = player.getUsername();
    InetAddress address = player.getRemoteAddress().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 : Player(com.velocitypowered.api.proxy.Player) 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 4 with ActiveSession

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

the class DeathEventListener method onDeath.

@EventHandler(priority = EventPriority.MONITOR)
public void onDeath(EntityDeathEvent event) {
    long time = System.currentTimeMillis();
    LivingEntity dead = event.getEntity();
    if (dead instanceof Player) {
        // Process Death
        SessionCache.getCachedSession(dead.getUniqueId()).ifPresent(ActiveSession::addDeath);
    }
    try {
        Optional<Player> foundKiller = findKiller(dead);
        if (!foundKiller.isPresent()) {
            return;
        }
        Player killer = foundKiller.get();
        Runnable processor = dead instanceof Player ? new PlayerKillProcessor(getKiller(killer), getVictim((Player) dead), serverInfo.getServerIdentifier(), findWeapon(dead), time) : new MobKillProcessor(killer.getUniqueId());
        processing.submitCritical(processor);
    } catch (Exception e) {
        errorLogger.error(e, ErrorContext.builder().related(event, dead).build());
    }
}
Also used : ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) PlayerKillProcessor(com.djrapitops.plan.processing.processors.player.PlayerKillProcessor) MobKillProcessor(com.djrapitops.plan.processing.processors.player.MobKillProcessor) EventHandler(org.bukkit.event.EventHandler)

Example 5 with ActiveSession

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

the class PlayerOnlineListener method actOnJoinEvent.

private void actOnJoinEvent(PlayerJoinEvent event) {
    Player player = event.getPlayer();
    UUID playerUUID = player.getUniqueId();
    ServerUUID serverUUID = serverInfo.getServerUUID();
    long time = System.currentTimeMillis();
    BukkitAFKListener.afkTracker.performedAction(playerUUID, time);
    String world = player.getWorld().getName();
    String gm = Optional.ofNullable(player.getGameMode()).map(gameMode -> gameMode.name()).orElse("Unknown");
    Database database = dbSystem.getDatabase();
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
    InetAddress address = player.getAddress().getAddress();
    Supplier<String> getHostName = () -> getHostname(player);
    String playerName = player.getName();
    String displayName = player.getDisplayName();
    boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
    if (gatheringGeolocations) {
        database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
    }
    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, player::getFirstPlayed, playerName, serverUUID, getHostName));
    database.executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, player.isOp()));
    ActiveSession session = new ActiveSession(playerUUID, serverUUID, time, world, gm);
    session.getExtraData().put(PlayerName.class, new PlayerName(playerName));
    session.getExtraData().put(ServerName.class, new ServerName(serverInfo.getServer().getIdentifiableName()));
    sessionCache.cacheSession(playerUUID, session).ifPresent(previousSession -> database.executeTransaction(new SessionEndTransaction(previousSession)));
    database.executeTransaction(new NicknameStoreTransaction(playerUUID, new Nickname(displayName, time, serverUUID), (uuid, name) -> nicknameCache.getDisplayName(playerUUID).map(name::equals).orElse(false)));
    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 : PlanConfig(com.djrapitops.plan.settings.config.PlanConfig) NicknameCache(com.djrapitops.plan.gathering.cache.NicknameCache) Exporter(com.djrapitops.plan.delivery.export.Exporter) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerUUID(com.djrapitops.plan.identification.ServerUUID) DataGatheringSettings(com.djrapitops.plan.settings.config.paths.DataGatheringSettings) HashMap(java.util.HashMap) Player(org.bukkit.entity.Player) Supplier(java.util.function.Supplier) Database(com.djrapitops.plan.storage.database.Database) DBSystem(com.djrapitops.plan.storage.database.DBSystem) EventHandler(org.bukkit.event.EventHandler) Inject(javax.inject.Inject) InetAddress(java.net.InetAddress) ExtensionSvc(com.djrapitops.plan.extension.ExtensionSvc) SessionCache(com.djrapitops.plan.gathering.cache.SessionCache) Map(java.util.Map) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) ErrorContext(com.djrapitops.plan.utilities.logging.ErrorContext) Listener(org.bukkit.event.Listener) PlayerJoinEvent(org.bukkit.event.player.PlayerJoinEvent) ServerName(com.djrapitops.plan.delivery.domain.ServerName) PlayerLoginEvent(org.bukkit.event.player.PlayerLoginEvent) ServerInfo(com.djrapitops.plan.identification.ServerInfo) ExportSettings(com.djrapitops.plan.settings.config.paths.ExportSettings) UUID(java.util.UUID) Status(com.djrapitops.plan.gathering.listeners.Status) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) EventPriority(org.bukkit.event.EventPriority) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) PlayerKickEvent(org.bukkit.event.player.PlayerKickEvent) PlayerQuitEvent(org.bukkit.event.player.PlayerQuitEvent) CallEvents(com.djrapitops.plan.extension.CallEvents) Optional(java.util.Optional) Processing(com.djrapitops.plan.processing.Processing) GeolocationCache(com.djrapitops.plan.gathering.geolocation.GeolocationCache) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Player(org.bukkit.entity.Player) ServerUUID(com.djrapitops.plan.identification.ServerUUID) 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) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID) InetAddress(java.net.InetAddress) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

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