Search in sources :

Example 1 with PlayerName

use of com.djrapitops.plan.delivery.domain.PlayerName 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 2 with PlayerName

use of com.djrapitops.plan.delivery.domain.PlayerName 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 3 with PlayerName

use of com.djrapitops.plan.delivery.domain.PlayerName 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)

Example 4 with PlayerName

use of com.djrapitops.plan.delivery.domain.PlayerName 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 5 with PlayerName

use of com.djrapitops.plan.delivery.domain.PlayerName in project Plan by plan-player-analytics.

the class SessionQueries method extractDataFromSessionSelectStatement.

private static List<FinishedSession> extractDataFromSessionSelectStatement(ResultSet set) throws SQLException {
    // Server UUID - Player UUID - Session Start - Session
    Map<ServerUUID, Map<UUID, SortedMap<Long, FinishedSession>>> byServer = new HashMap<>();
    // Utilities
    String[] gms = GMTimes.getGMKeyArray();
    Comparator<DateHolder> mostRecentFirst = new DateHolderRecentComparator();
    // Descending order, most recent first.
    Comparator<Long> longRecentComparator = (one, two) -> Long.compare(two, one);
    while (set.next()) {
        ServerUUID serverUUID = ServerUUID.fromString(set.getString(SessionsTable.SERVER_UUID));
        Map<UUID, SortedMap<Long, FinishedSession>> serverSessions = byServer.computeIfAbsent(serverUUID, Maps::create);
        UUID playerUUID = UUID.fromString(set.getString(SessionsTable.USER_UUID));
        SortedMap<Long, FinishedSession> playerSessions = serverSessions.computeIfAbsent(playerUUID, key -> new TreeMap<>(longRecentComparator));
        long sessionStart = set.getLong(SessionsTable.SESSION_START);
        // id, uuid, serverUUID, sessionStart, sessionEnd, mobKills, deaths, afkTime
        FinishedSession session = playerSessions.getOrDefault(sessionStart, new FinishedSession(playerUUID, serverUUID, sessionStart, set.getLong(SessionsTable.SESSION_END), set.getLong(SessionsTable.AFK_TIME), new DataMap()));
        DataMap extraData = session.getExtraData();
        extraData.put(FinishedSession.Id.class, new FinishedSession.Id(set.getInt(SessionsTable.ID)));
        extraData.put(MobKillCounter.class, new MobKillCounter(set.getInt(SessionsTable.MOB_KILLS)));
        extraData.put(DeathCounter.class, new DeathCounter(set.getInt(SessionsTable.DEATHS)));
        Optional<WorldTimes> existingWorldTimes = extraData.get(WorldTimes.class);
        Optional<PlayerKills> existingPlayerKills = extraData.get(PlayerKills.class);
        WorldTimes worldTimes = existingWorldTimes.orElseGet(WorldTimes::new);
        String worldName = set.getString(WorldTable.NAME);
        if (!worldTimes.contains(worldName)) {
            Map<String, Long> gmMap = new HashMap<>();
            gmMap.put(gms[0], set.getLong(WorldTimesTable.SURVIVAL));
            gmMap.put(gms[1], set.getLong(WorldTimesTable.CREATIVE));
            gmMap.put(gms[2], set.getLong(WorldTimesTable.ADVENTURE));
            gmMap.put(gms[3], set.getLong(WorldTimesTable.SPECTATOR));
            GMTimes gmTimes = new GMTimes(gmMap);
            worldTimes.setGMTimesForWorld(worldName, gmTimes);
        }
        if (!existingWorldTimes.isPresent())
            extraData.put(WorldTimes.class, worldTimes);
        ServerName serverName = new ServerName(Server.getIdentifiableName(set.getString("server_name"), set.getInt("server_id")));
        extraData.put(ServerName.class, serverName);
        PlayerKills playerKills = existingPlayerKills.orElseGet(PlayerKills::new);
        String victimName = set.getString("victim_name");
        if (victimName != null) {
            PlayerKill.Killer killer = new PlayerKill.Killer(UUID.fromString(set.getString(KillsTable.KILLER_UUID)), set.getString("killer_name"));
            PlayerKill.Victim victim = new PlayerKill.Victim(UUID.fromString(set.getString(KillsTable.VICTIM_UUID)), victimName);
            ServerIdentifier serverIdentifier = new ServerIdentifier(serverUUID, serverName);
            String weapon = set.getString(KillsTable.WEAPON);
            long date = set.getLong(KillsTable.DATE);
            PlayerKill newKill = new PlayerKill(killer, victim, serverIdentifier, weapon, date);
            if (!playerKills.contains(newKill)) {
                playerKills.add(newKill);
            }
        }
        if (!existingPlayerKills.isPresent())
            extraData.put(PlayerKills.class, playerKills);
        extraData.put(PlayerName.class, new PlayerName(set.getString("name")));
        session.setAsFirstSessionIfMatches(set.getLong("registered"));
        playerSessions.put(sessionStart, session);
    }
    return byServer.values().stream().map(Map::values).flatMap(Collection::stream).map(SortedMap::values).flatMap(Collection::stream).sorted(// Disorder arises
    mostRecentFirst).collect(Collectors.toList());
}
Also used : SessionsMutator(com.djrapitops.plan.delivery.domain.mutators.SessionsMutator) java.util(java.util) ServerName(com.djrapitops.plan.delivery.domain.ServerName) com.djrapitops.plan.gathering.domain(com.djrapitops.plan.gathering.domain) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerUUID(com.djrapitops.plan.identification.ServerUUID) TextStringBuilder(org.apache.commons.text.TextStringBuilder) Query(com.djrapitops.plan.storage.database.queries.Query) QueryAllStatement(com.djrapitops.plan.storage.database.queries.QueryAllStatement) com.djrapitops.plan.storage.database.sql.tables(com.djrapitops.plan.storage.database.sql.tables) PreparedStatement(java.sql.PreparedStatement) Sql(com.djrapitops.plan.storage.database.sql.building.Sql) Collectors(java.util.stream.Collectors) SQLException(java.sql.SQLException) DateHolder(com.djrapitops.plan.delivery.domain.DateHolder) Server(com.djrapitops.plan.identification.Server) ResultSet(java.sql.ResultSet) ServerIdentifier(com.djrapitops.plan.delivery.domain.ServerIdentifier) DateHolderRecentComparator(com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator) Maps(com.djrapitops.plan.utilities.java.Maps) QueryStatement(com.djrapitops.plan.storage.database.queries.QueryStatement) Maps(com.djrapitops.plan.utilities.java.Maps) PlayerName(com.djrapitops.plan.delivery.domain.PlayerName) ServerUUID(com.djrapitops.plan.identification.ServerUUID) ServerIdentifier(com.djrapitops.plan.delivery.domain.ServerIdentifier) ServerUUID(com.djrapitops.plan.identification.ServerUUID) DateHolder(com.djrapitops.plan.delivery.domain.DateHolder) ServerName(com.djrapitops.plan.delivery.domain.ServerName) DateHolderRecentComparator(com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator)

Aggregations

PlayerName (com.djrapitops.plan.delivery.domain.PlayerName)9 ServerName (com.djrapitops.plan.delivery.domain.ServerName)9 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)8 UUID (java.util.UUID)8 Database (com.djrapitops.plan.storage.database.Database)6 InetAddress (java.net.InetAddress)6 ServerUUID (com.djrapitops.plan.identification.ServerUUID)5 Nickname (com.djrapitops.plan.delivery.domain.Nickname)4 Exporter (com.djrapitops.plan.delivery.export.Exporter)4 CallEvents (com.djrapitops.plan.extension.CallEvents)4 ExtensionSvc (com.djrapitops.plan.extension.ExtensionSvc)4 NicknameCache (com.djrapitops.plan.gathering.cache.NicknameCache)4 SessionCache (com.djrapitops.plan.gathering.cache.SessionCache)4 GeolocationCache (com.djrapitops.plan.gathering.geolocation.GeolocationCache)4 ServerInfo (com.djrapitops.plan.identification.ServerInfo)4 Processing (com.djrapitops.plan.processing.Processing)4 PlanConfig (com.djrapitops.plan.settings.config.PlanConfig)4 DataGatheringSettings (com.djrapitops.plan.settings.config.paths.DataGatheringSettings)4 ExportSettings (com.djrapitops.plan.settings.config.paths.ExportSettings)4 DBSystem (com.djrapitops.plan.storage.database.DBSystem)4