Search in sources :

Example 1 with JoinAddress

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

the class JoinAddressQueriesTest method joinAddressQueryHasDistinctPlayers.

@Test
default void joinAddressQueryHasDistinctPlayers() {
    joinAddressCanBeUnknown();
    db().executeTransaction(TestData.storeServers());
    FinishedSession session = RandomData.randomSession(serverUUID(), worlds, player2UUID, playerUUID);
    String expectedAddress = TestConstants.GET_PLAYER_HOSTNAME.get();
    session.getExtraData().put(JoinAddress.class, new JoinAddress(expectedAddress));
    db().executeTransaction(new StoreSessionTransaction(session));
    Map<String, Integer> expected = Map.of(JoinAddressTable.DEFAULT_VALUE_FOR_LOOKUP, 1, expectedAddress, 1);
    Map<String, Integer> result = db().query(JoinAddressQueries.latestJoinAddresses());
    assertEquals(expected, result);
}
Also used : StoreSessionTransaction(com.djrapitops.plan.storage.database.transactions.events.StoreSessionTransaction) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) Test(org.junit.jupiter.api.Test)

Example 2 with JoinAddress

use of com.djrapitops.plan.gathering.domain.event.JoinAddress 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));
    Supplier<String> getHostName = () -> getHostname(player);
    String playerName = player.getEntityName();
    String displayName = player.getDisplayName().asString();
    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, System::currentTimeMillis, playerName, serverUUID, getHostName)).thenRunAsync(() -> {
        boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
        if (gatheringGeolocations) {
            gatherGeolocation(player, playerUUID, time, database);
        }
        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()));
        session.getExtraData().put(JoinAddress.class, new JoinAddress(getHostName));
        sessionCache.cacheSession(playerUUID, session).ifPresent(previousSession -> database.executeTransaction(new StoreSessionTransaction(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) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) 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) FabricPlayerPositionTracker(net.playeranalytics.plan.gathering.FabricPlayerPositionTracker) 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) DBSystem(com.djrapitops.plan.storage.database.DBSystem) 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) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Example 3 with JoinAddress

use of com.djrapitops.plan.gathering.domain.event.JoinAddress 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("server_uuid"));
        Map<UUID, SortedMap<Long, FinishedSession>> serverSessions = byServer.computeIfAbsent(serverUUID, Maps::create);
        UUID playerUUID = UUID.fromString(set.getString(UsersTable.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)));
        extraData.put(JoinAddress.class, new JoinAddress(set.getString("join_address")));
        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) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) 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) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) 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)

Example 4 with JoinAddress

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

the class SessionsMutator method toJSONMaps.

private List<Map<String, Object>> toJSONMaps(Graphs graphs, WorldAliasSettings worldAliasSettings, Formatters formatters, Function<Map<String, Object>, Object> nameFunction) {
    return Lists.map(sessions, session -> {
        Map<String, Object> sessionMap = new HashMap<>();
        String playerUUID = session.getPlayerUUID().toString();
        String serverUUID = session.getServerUUID().toString();
        String playerName = session.getExtraData(PlayerName.class).map(PlayerName::get).orElse(playerUUID);
        String serverName = session.getExtraData(ServerName.class).map(ServerName::get).orElse(serverUUID);
        sessionMap.put("player_name", playerName);
        sessionMap.put("player_url_name", Html.encodeToURL(playerName));
        sessionMap.put("player_uuid", playerUUID);
        sessionMap.put("server_name", serverName);
        sessionMap.put("server_url_name", Html.encodeToURL(serverName));
        sessionMap.put("server_uuid", serverUUID);
        sessionMap.put("name", nameFunction.apply(sessionMap));
        sessionMap.put("start", formatters.yearLong().apply(session.getStart()) + (session.getExtraData(ActiveSession.class).isPresent() ? " (Online)" : ""));
        sessionMap.put("end", formatters.yearLong().apply(session.getEnd()));
        sessionMap.put("most_used_world", worldAliasSettings.getLongestWorldPlayed(session));
        sessionMap.put("length", formatters.timeAmount().apply(session.getLength()));
        sessionMap.put("afk_time", formatters.timeAmount().apply(session.getAfkTime()));
        sessionMap.put("mob_kills", session.getMobKillCount());
        sessionMap.put("deaths", session.getDeathCount());
        sessionMap.put("player_kills", session.getExtraData(PlayerKills.class).map(PlayerKills::asMutator).map(killsMutator -> killsMutator.toJSONAsMap(formatters)).orElseGet(ArrayList::new));
        sessionMap.put("first_session", session.isFirstSession());
        WorldPie worldPie = graphs.pie().worldPie(session.getExtraData(WorldTimes.class).orElseGet(WorldTimes::new));
        sessionMap.put("world_series", worldPie.getSlices());
        sessionMap.put("gm_series", worldPie.toHighChartsDrillDownMaps());
        sessionMap.put("join_address", session.getExtraData(JoinAddress.class).map(JoinAddress::getAddress).orElse("-"));
        session.getExtraData(AveragePing.class).ifPresent(averagePing -> sessionMap.put("avg_ping", formatters.decimals().apply(averagePing.getValue()) + " ms"));
        return sessionMap;
    });
}
Also used : WorldPie(com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie) AveragePing(com.djrapitops.plan.delivery.domain.AveragePing) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress)

Example 5 with JoinAddress

use of com.djrapitops.plan.gathering.domain.event.JoinAddress 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(Enum::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();
    database.executeTransaction(new PlayerServerRegisterTransaction(playerUUID, player::getFirstPlayed, playerName, serverUUID, getHostName)).thenRunAsync(() -> {
        boolean gatheringGeolocations = config.isTrue(DataGatheringSettings.GEOLOCATIONS);
        if (gatheringGeolocations) {
            database.executeTransaction(new StoreGeoInfoTransaction(playerUUID, address, time, geolocationCache::getCountry));
        }
        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()));
        session.getExtraData().put(JoinAddress.class, new JoinAddress(getHostName));
        sessionCache.cacheSession(playerUUID, session).map(StoreSessionTransaction::new).ifPresent(database::executeTransaction);
        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) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) 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) JoinAddress(com.djrapitops.plan.gathering.domain.event.JoinAddress) InetAddress(java.net.InetAddress) Nickname(com.djrapitops.plan.delivery.domain.Nickname)

Aggregations

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