use of com.djrapitops.plan.delivery.domain.ServerIdentifier in project Plan by plan-player-analytics.
the class PlayerKillMutator method toJSONAsMap.
public List<Map<String, Object>> toJSONAsMap(Formatters formatters) {
return Lists.map(kills, kill -> {
PlayerKill.Killer killer = kill.getKiller();
PlayerKill.Victim victim = kill.getVictim();
ServerIdentifier server = kill.getServer();
Map<String, Object> killMap = new HashMap<>();
killMap.put("date", formatters.secondLong().apply(kill.getDate()));
killMap.put("killer", killer.getName());
killMap.put("victim", victim.getName());
killMap.put("killerUUID", killer.getUuid().toString());
killMap.put("victimUUID", victim.getUuid().toString());
killMap.put("killerName", killer.getName());
killMap.put("victimName", victim.getName());
killMap.put("serverUUID", server.getUuid().toString());
killMap.put("serverName", server.getName());
killMap.put("weapon", kill.getWeapon());
return killMap;
});
}
use of com.djrapitops.plan.delivery.domain.ServerIdentifier 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.delivery.domain.ServerIdentifier in project Plan by plan-player-analytics.
the class KillQueries method extractKillFromResults.
private static Optional<PlayerKill> extractKillFromResults(ResultSet set) throws SQLException {
String victimName = set.getString("victim_name");
String killerName = set.getString("killer_name");
if (victimName != null && killerName != null) {
UUID killer = UUID.fromString(set.getString(KillsTable.KILLER_UUID));
UUID victim = UUID.fromString(set.getString(KillsTable.VICTIM_UUID));
long date = set.getLong(KillsTable.DATE);
String weapon = set.getString(KillsTable.WEAPON);
return Optional.of(new PlayerKill(new PlayerKill.Killer(killer, killerName), new PlayerKill.Victim(victim, victimName), new ServerIdentifier(ServerUUID.fromString(set.getString(KillsTable.SERVER_UUID)), Server.getIdentifiableName(set.getString("server_name"), set.getInt("server_id"))), weapon, date));
}
return Optional.empty();
}
Aggregations