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);
}
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));
}
});
}
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());
}
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;
});
}
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));
}
});
}
Aggregations