Search in sources :

Example 11 with ActiveSession

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

the class PlayerKillProcessor method run.

@Override
public void run() {
    Optional<ActiveSession> cachedSession = SessionCache.getCachedSession(killer.getUuid());
    if (!cachedSession.isPresent()) {
        return;
    }
    ActiveSession session = cachedSession.get();
    session.addPlayerKill(new PlayerKill(killer, victim, server, weaponName, time));
}
Also used : ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill)

Example 12 with ActiveSession

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

the class SpongeGMChangeListener method actOnGMChangeEvent.

private void actOnGMChangeEvent(ChangeGameModeEvent.TargetPlayer event) {
    Player player = event.getTargetEntity();
    UUID uuid = player.getUniqueId();
    long time = System.currentTimeMillis();
    String gameMode = event.getGameMode().getName().toUpperCase();
    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.spongepowered.api.entity.living.player.Player) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) WorldNameStoreTransaction(com.djrapitops.plan.storage.database.transactions.events.WorldNameStoreTransaction) UUID(java.util.UUID)

Example 13 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(ServerPlayerEntity player) {
    UUID playerUUID = player.getUuid();
    ServerUUID serverUUID = serverInfo.getServerUUID();
    long time = System.currentTimeMillis();
    FabricAFKListener.afkTracker.performedAction(playerUUID, time);
    String world = player.getServerWorld().getRegistryKey().getValue().toString();
    String gm = player.interactionManager.getGameMode().name();
    Database database = dbSystem.getDatabase();
    database.executeTransaction(new WorldNameStoreTransaction(serverUUID, world));
    InetSocketAddress socketAddress = (InetSocketAddress) player.networkHandler.connection.getAddress();
    InetAddress address = InetAddresses.forString(socketAddress.getAddress().toString().replace("/", ""));
    Supplier<String> getHostName = () -> getHostname(player);
    String playerName = player.getEntityName();
    String displayName = player.getDisplayName().asString();
    boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
    if (gatheringGeolocations) {
        database.executeTransaction(new GeoInfoStoreTransaction(playerUUID, address, time, geolocationCache::getCountry));
    }
    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, System::currentTimeMillis, playerName, serverUUID, getHostName));
    database.executeTransaction(new OperatorStatusTransaction(playerUUID, serverUUID, server.getPlayerManager().getOpList().isOp(player.getGameProfile())));
    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) SocketAddress(java.net.SocketAddress) Exporter(com.djrapitops.plan.delivery.export.Exporter) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerUUID(com.djrapitops.plan.identification.ServerUUID) GameProfile(com.mojang.authlib.GameProfile) FabricListener(net.playeranalytics.plan.gathering.listeners.FabricListener) DataGatheringSettings(com.djrapitops.plan.settings.config.paths.DataGatheringSettings) HashMap(java.util.HashMap) MinecraftDedicatedServer(net.minecraft.server.dedicated.MinecraftDedicatedServer) Supplier(java.util.function.Supplier) Database(com.djrapitops.plan.storage.database.Database) DBSystem(com.djrapitops.plan.storage.database.DBSystem) Inject(javax.inject.Inject) InetAddress(java.net.InetAddress) ServerPlayConnectionEvents(net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents) 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) ServerName(com.djrapitops.plan.delivery.domain.ServerName) ServerInfo(com.djrapitops.plan.identification.ServerInfo) ExportSettings(com.djrapitops.plan.settings.config.paths.ExportSettings) UUID(java.util.UUID) PlanFabricEvents(net.playeranalytics.plan.gathering.listeners.events.PlanFabricEvents) InetSocketAddress(java.net.InetSocketAddress) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ErrorLogger(com.djrapitops.plan.utilities.logging.ErrorLogger) com.djrapitops.plan.storage.database.transactions.events(com.djrapitops.plan.storage.database.transactions.events) CallEvents(com.djrapitops.plan.extension.CallEvents) Processing(com.djrapitops.plan.processing.Processing) InetAddresses(com.google.common.net.InetAddresses) GeolocationCache(com.djrapitops.plan.gathering.geolocation.GeolocationCache) Nickname(com.djrapitops.plan.delivery.domain.Nickname) ServerUUID(com.djrapitops.plan.identification.ServerUUID) InetSocketAddress(java.net.InetSocketAddress) 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)

Example 14 with ActiveSession

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

the class SpongeDeathListener method onEntityDeath.

@Listener
public void onEntityDeath(DestructEntityEvent.Death event) {
    long time = System.currentTimeMillis();
    Living dead = event.getTargetEntity();
    if (dead instanceof Player) {
        // Process Death
        SessionCache.getCachedSession(dead.getUniqueId()).ifPresent(ActiveSession::addDeath);
    }
    try {
        List<EntityDamageSource> causes = event.getCause().allOf(EntityDamageSource.class);
        Optional<Player> foundKiller = findKiller(causes, 0);
        if (!foundKiller.isPresent()) {
            return;
        }
        Player killer = foundKiller.get();
        Runnable processor = dead instanceof Player ? new PlayerKillProcessor(getKiller(killer), getVictim((Player) dead), serverInfo.getServerIdentifier(), findWeapon(event), time) : new MobKillProcessor(killer.getUniqueId());
        processing.submitCritical(processor);
    } catch (Exception e) {
        errorLogger.error(e, ErrorContext.builder().related(event, dead).build());
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) Living(org.spongepowered.api.entity.living.Living) PlayerKillProcessor(com.djrapitops.plan.processing.processors.player.PlayerKillProcessor) MobKillProcessor(com.djrapitops.plan.processing.processors.player.MobKillProcessor) EntityDamageSource(org.spongepowered.api.event.cause.entity.damage.source.EntityDamageSource) Listener(org.spongepowered.api.event.Listener)

Example 15 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 = GMTimes.magicNumberToGMName(event.getNewGamemode());
    String worldName = player.getLevel().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(cn.nukkit.Player) 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