use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class BukkitEventPipelineModule method mapToPlayerLeave.
private PlayerLeave mapToPlayerLeave(DataService service, PlayerQuitEvent event) {
UUID playerUUID = event.getPlayer().getUniqueId();
Optional<PlayerMetadata> metadata = service.map(playerUUID, event.getPlayer(), PlayerMetadata.class);
return PlayerLeave.builder().playerUUID(playerUUID).serverUUID(service.pullWithoutId(ServerUUID.class).orElseThrow(MissingPipelineException::new)).playerMetadata(metadata.orElseThrow(MissingPipelineException::new)).time(System.currentTimeMillis()).build();
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class BukkitEventPipelineModule method mapToPlayerJoin.
private PlayerJoin mapToPlayerJoin(DataService service, PlayerJoinEvent event) {
UUID playerUUID = event.getPlayer().getUniqueId();
Optional<PlayerMetadata> metadata = service.map(playerUUID, event.getPlayer(), PlayerMetadata.class);
return PlayerJoin.builder().playerUUID(playerUUID).serverUUID(service.pullWithoutId(ServerUUID.class).orElseThrow(MissingPipelineException::new)).playerMetadata(metadata.orElseThrow(MissingPipelineException::new)).time(System.currentTimeMillis()).build();
}
use of com.djrapitops.plan.identification.ServerUUID in project Plan by plan-player-analytics.
the class PlayerOnlineListener method onPlayerLogin.
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerLogin(PlayerLoginEvent event) {
try {
PlayerLoginEvent.Result result = event.getResult();
UUID playerUUID = event.getPlayer().getUniqueId();
ServerUUID serverUUID = serverInfo.getServerUUID();
boolean banned = result == PlayerLoginEvent.Result.KICK_BANNED;
String joinAddress = event.getHostname();
if (!joinAddress.isEmpty()) {
joinAddresses.put(playerUUID, joinAddress.substring(0, joinAddress.lastIndexOf(':')));
}
dbSystem.getDatabase().executeTransaction(new BanStatusTransaction(playerUUID, serverUUID, () -> banned));
} catch (Exception e) {
errorLogger.error(e, ErrorContext.builder().related(event, event.getResult()).build());
}
}
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();
BukkitAFKListener.afkTracker.loggedOut(playerUUID, time);
joinAddresses.remove(playerUUID);
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 JSONFactory method serversAsJSONMaps.
public Map<String, Object> serversAsJSONMaps() {
Database db = dbSystem.getDatabase();
long now = System.currentTimeMillis();
long weekAgo = now - TimeUnit.DAYS.toMillis(7L);
Formatter<Long> year = formatters.yearLong();
Formatter<Double> decimals = formatters.decimals();
Formatter<Long> timeAmount = formatters.timeAmount();
Map<ServerUUID, Server> serverInformation = db.query(ServerQueries.fetchPlanServerInformation());
ServerUUID proxyUUID = serverInformation.values().stream().filter(Server::isProxy).findFirst().map(Server::getUuid).orElse(null);
Map<ServerUUID, List<TPS>> tpsData = db.query(TPSQueries.fetchTPSDataOfAllServersBut(weekAgo, now, proxyUUID));
Map<ServerUUID, Integer> totalPlayerCounts = db.query(PlayerCountQueries.newPlayerCounts(0, now));
Map<ServerUUID, Integer> newPlayerCounts = db.query(PlayerCountQueries.newPlayerCounts(weekAgo, now));
Map<ServerUUID, Integer> uniquePlayerCounts = db.query(PlayerCountQueries.uniquePlayerCounts(weekAgo, now));
List<Map<String, Object>> servers = new ArrayList<>();
serverInformation.entrySet().stream().sorted(Comparator.comparing(entry -> entry.getValue().getIdentifiableName().toLowerCase())).filter(entry -> entry.getValue().isNotProxy()).forEach(entry -> {
ServerUUID serverUUID = entry.getKey();
Map<String, Object> server = new HashMap<>();
server.put("name", entry.getValue().getIdentifiableName());
Optional<DateObj<Integer>> recentPeak = db.query(TPSQueries.fetchPeakPlayerCount(serverUUID, now - TimeUnit.DAYS.toMillis(2L)));
Optional<DateObj<Integer>> allTimePeak = db.query(TPSQueries.fetchAllTimePeakPlayerCount(serverUUID));
server.put("last_peak_date", recentPeak.map(DateObj::getDate).map(year).orElse("-"));
server.put("best_peak_date", allTimePeak.map(DateObj::getDate).map(year).orElse("-"));
server.put("last_peak_players", recentPeak.map(DateObj::getValue).orElse(0));
server.put("best_peak_players", allTimePeak.map(DateObj::getValue).orElse(0));
TPSMutator tpsMonth = new TPSMutator(tpsData.getOrDefault(serverUUID, Collections.emptyList()));
server.put("playersOnline", tpsMonth.all().stream().map(tps -> new double[] { tps.getDate(), tps.getPlayers() }).toArray(double[][]::new));
server.put("players", totalPlayerCounts.getOrDefault(serverUUID, 0));
server.put("new_players", newPlayerCounts.getOrDefault(serverUUID, 0));
server.put("unique_players", uniquePlayerCounts.getOrDefault(serverUUID, 0));
TPSMutator tpsWeek = tpsMonth.filterDataBetween(weekAgo, now);
double averageTPS = tpsWeek.averageTPS();
server.put("avg_tps", averageTPS != -1 ? decimals.apply(averageTPS) : locale.get(HtmlLang.UNIT_NO_DATA).toString());
server.put("low_tps_spikes", tpsWeek.lowTpsSpikeCount(config.get(DisplaySettings.GRAPH_TPS_THRESHOLD_MED)));
server.put("downtime", timeAmount.apply(tpsWeek.serverDownTime()));
server.put("current_uptime", serverUptimeCalculator.getServerUptimeMillis(serverUUID).map(timeAmount).orElse(locale.getString(GenericLang.UNAVAILABLE)));
Optional<TPS> online = tpsWeek.getLast();
server.put("online", online.map(point -> point.getDate() >= now - TimeUnit.MINUTES.toMillis(3L) ? point.getPlayers() : "Possibly offline").orElse(locale.get(HtmlLang.UNIT_NO_DATA).toString()));
servers.add(server);
});
return Collections.singletonMap("servers", servers);
}
Aggregations