use of com.djrapitops.plan.identification.ServerUUID 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));
}
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class PlayerOnlineListener method actOnQuitEvent.
private void actOnQuitEvent(PlayerQuitEvent event) {
long time = System.currentTimeMillis();
Player player = event.getPlayer();
String playerName = player.getName();
UUID playerUUID = player.getUniqueId();
ServerUUID serverUUID = serverInfo.getServerUUID();
// Can be null when player is not signed in to xbox live
if (playerUUID == null)
return;
NukkitAFKListener.afkTracker.loggedOut(playerUUID, time);
nicknameCache.removeDisplayName(playerUUID);
dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, serverUUID, player::isBanned));
sessionCache.endSession(playerUUID, time).ifPresent(endedSession -> dbSystem.getDatabase().executeTransaction(new SessionEndTransaction(endedSession)));
if (config.isTrue(ExportSettings.EXPORT_ON_ONLINE_STATUS_CHANGE)) {
processing.submitNonCritical(() -> exporter.exportPlayerPage(playerUUID, playerName));
}
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class SessionQueries method fetchServerSessionsWithoutKillOrWorldData.
public static Query<List<FinishedSession>> fetchServerSessionsWithoutKillOrWorldData(long after, long before, ServerUUID serverUUID) {
String sql = SELECT + SessionsTable.ID + ',' + SessionsTable.USER_UUID + ',' + SessionsTable.SESSION_START + ',' + SessionsTable.SESSION_END + ',' + SessionsTable.DEATHS + ',' + SessionsTable.MOB_KILLS + ',' + SessionsTable.AFK_TIME + FROM + SessionsTable.TABLE_NAME + WHERE + SessionsTable.SERVER_UUID + "=?" + AND + SessionsTable.SESSION_START + ">=?" + AND + SessionsTable.SESSION_START + "<=?";
return new QueryStatement<List<FinishedSession>>(sql, 1000) {
@Override
public void prepare(PreparedStatement statement) throws SQLException {
statement.setString(1, serverUUID.toString());
statement.setLong(2, after);
statement.setLong(3, before);
}
@Override
public List<FinishedSession> processResults(ResultSet set) throws SQLException {
List<FinishedSession> sessions = new ArrayList<>();
while (set.next()) {
UUID uuid = UUID.fromString(set.getString(SessionsTable.USER_UUID));
long start = set.getLong(SessionsTable.SESSION_START);
long end = set.getLong(SessionsTable.SESSION_END);
int deaths = set.getInt(SessionsTable.DEATHS);
int mobKills = set.getInt(SessionsTable.MOB_KILLS);
int id = set.getInt(SessionsTable.ID);
long timeAFK = set.getLong(SessionsTable.AFK_TIME);
DataMap extraData = new DataMap();
extraData.put(FinishedSession.Id.class, new FinishedSession.Id(id));
extraData.put(DeathCounter.class, new DeathCounter(deaths));
extraData.put(MobKillCounter.class, new MobKillCounter(mobKills));
sessions.add(new FinishedSession(uuid, serverUUID, start, end, timeAFK, extraData));
}
return sessions;
}
};
}
use of com.djrapitops.plan.identification.ServerUUID 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());
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class PingQueries method extractUserPings.
private static Map<UUID, List<Ping>> extractUserPings(ResultSet set) throws SQLException {
Map<UUID, List<Ping>> userPings = new HashMap<>();
while (set.next()) {
UUID uuid = UUID.fromString(set.getString(PingTable.USER_UUID));
ServerUUID serverUUID = ServerUUID.fromString(set.getString(PingTable.SERVER_UUID));
long date = set.getLong(PingTable.DATE);
double avgPing = set.getDouble(PingTable.AVG_PING);
int minPing = set.getInt(PingTable.MIN_PING);
int maxPing = set.getInt(PingTable.MAX_PING);
List<Ping> pings = userPings.computeIfAbsent(uuid, Lists::create);
pings.add(new Ping(date, serverUUID, minPing, maxPing, avgPing));
}
return userPings;
}
Aggregations