use of com.djrapitops.plan.gathering.domain.PlayerKill in project Plan by plan-player-analytics.
the class PlayerKillProcessor method run.
@Override
public void run() {
Optional<ActiveSession> cachedSession = SessionCache.getCachedSession(killer.getUuid());
if (!cachedSession.isPresent()) {
return;
}
ActiveSession session = cachedSession.get();
session.addPlayerKill(new PlayerKill(killer, victim, server, weaponName, time));
}
use of com.djrapitops.plan.gathering.domain.PlayerKill in project Plan by plan-player-analytics.
the class PlayerJSONCreator method createJSONAsMap.
public Map<String, Object> createJSONAsMap(UUID playerUUID) {
Database db = dbSystem.getDatabase();
Map<ServerUUID, String> serverNames = db.query(ServerQueries.fetchServerNames());
String[] pieColors = theme.getPieColors(ThemeVal.GRAPH_WORLD_PIE);
PlayerContainer player = db.query(new PlayerContainerQuery(playerUUID));
SessionsMutator sessionsMutator = SessionsMutator.forContainer(player);
Map<ServerUUID, WorldTimes> worldTimesPerServer = PerServerMutator.forContainer(player).worldTimesPerServer();
List<Map<String, Object>> serverAccordion = new ServerAccordion(player, serverNames, graphs, year, timeAmount, locale.getString(GenericLang.UNKNOWN)).asMaps();
List<PlayerKill> kills = player.getValue(PlayerKeys.PLAYER_KILLS).orElse(Collections.emptyList());
List<PlayerKill> deaths = player.getValue(PlayerKeys.PLAYER_DEATHS_KILLS).orElse(Collections.emptyList());
PingMutator.forContainer(player).addPingToSessions(sessionsMutator.all());
Map<String, Object> data = new HashMap<>();
data.put("info", createInfoJSONMap(player, serverNames));
data.put("online_activity", createOnlineActivityJSONMap(sessionsMutator));
data.put("kill_data", createPvPPvEMap(player));
data.put("nicknames", player.getValue(PlayerKeys.NICKNAMES).map(nicks -> Nickname.fromDataNicknames(nicks, serverNames, year)).orElse(Collections.emptyList()));
data.put("connections", player.getValue(PlayerKeys.GEO_INFO).map(geoInfo -> ConnectionInfo.fromGeoInfo(geoInfo, year)).orElse(Collections.emptyList()));
data.put("player_kills", new PlayerKillMutator(kills).filterNonSelfKills().toJSONAsMap(formatters));
data.put("player_deaths", new PlayerKillMutator(deaths).toJSONAsMap(formatters));
data.put("sessions", sessionsMutator.sort(new DateHolderRecentComparator()).toServerNameJSONMaps(graphs, config.getWorldAliasSettings(), formatters));
data.put("sessions_per_page", config.get(DisplaySettings.SESSIONS_PER_PAGE));
data.put("servers", serverAccordion);
data.put("punchcard_series", graphs.special().punchCard(sessionsMutator).getDots());
WorldPie worldPie = graphs.pie().worldPie(player.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes()));
data.put("world_pie_series", worldPie.getSlices());
data.put("gm_series", worldPie.toHighChartsDrillDownMaps());
data.put("calendar_series", graphs.calendar().playerCalendar(player).getEntries());
data.put("server_pie_series", graphs.pie().serverPreferencePie(serverNames, worldTimesPerServer).getSlices());
data.put("server_pie_colors", pieColors);
// Monday
data.put("first_day", 1);
return data;
}
use of com.djrapitops.plan.gathering.domain.PlayerKill in project Plan by plan-player-analytics.
the class PlayerCalendar method getEntries.
public List<CalendarEntry> getEntries() {
List<CalendarEntry> entries = new ArrayList<>();
entries.add(CalendarEntry.of(locale.getString(HtmlLang.LABEL_REGISTERED) + ": " + year.apply(registered), registered).withColor(theme.getValue(ThemeVal.LIGHT_GREEN)));
Map<String, List<FinishedSession>> sessionsByDay = getSessionsByDay();
for (Map.Entry<String, List<FinishedSession>> entry : sessionsByDay.entrySet()) {
String day = entry.getKey();
List<FinishedSession> sessions = entry.getValue();
int sessionCount = sessions.size();
long playtime = sessions.stream().mapToLong(FinishedSession::getLength).sum();
entries.add(CalendarEntry.of(locale.getString(HtmlLang.LABEL_PLAYTIME) + ": " + timeAmount.apply(playtime), day).withColor(theme.getValue(ThemeVal.GREEN)));
entries.add(CalendarEntry.of(locale.getString(HtmlLang.SIDE_SESSIONS) + ": " + sessionCount, day));
}
long fiveMinutes = TimeUnit.MINUTES.toMillis(5L);
for (FinishedSession session : allSessions) {
String length = timeAmount.apply(session.getLength());
long start = session.getStart();
long end = session.getEnd();
entries.add(CalendarEntry.of(locale.getString(HtmlLang.SESSION) + ": " + length, start + timeZone.getOffset(start)).withEnd(end + timeZone.getOffset(end)));
for (PlayerKill kill : session.getExtraData(PlayerKills.class).map(PlayerKills::asList).orElseGet(ArrayList::new)) {
long time = kill.getDate();
String victim = kill.getVictim().getName();
entries.add(CalendarEntry.of(locale.getString(HtmlLang.KILLED) + ": " + victim, time).withEnd(time + fiveMinutes).withColor(theme.getValue(ThemeVal.RED)));
}
}
return entries;
}
use of com.djrapitops.plan.gathering.domain.PlayerKill in project Plan by plan-player-analytics.
the class KillsTable method addSessionKillsToBatch.
public static void addSessionKillsToBatch(PreparedStatement statement, FinishedSession session) throws SQLException {
UUID playerUUID = session.getPlayerUUID();
ServerUUID serverUUID = session.getServerUUID();
Optional<PlayerKills> playerKills = session.getExtraData().get(PlayerKills.class);
if (!playerKills.isPresent())
return;
for (PlayerKill kill : playerKills.get().asList()) {
// Session ID select statement parameters
statement.setString(1, playerUUID.toString());
statement.setString(2, serverUUID.toString());
statement.setLong(3, session.getStart());
statement.setLong(4, session.getEnd());
// Kill data
statement.setString(5, playerUUID.toString());
statement.setString(6, kill.getVictim().getUuid().toString());
statement.setString(7, serverUUID.toString());
statement.setLong(8, kill.getDate());
statement.setString(9, StringUtils.truncate(kill.getWeapon(), WEAPON_COLUMN_LENGTH));
statement.addBatch();
}
}
use of com.djrapitops.plan.gathering.domain.PlayerKill in project Plan by plan-player-analytics.
the class ImportBuilderTest method userDataBuilderConstructsCorrectItem.
@Test
void userDataBuilderConstructsCorrectItem() {
UserImportData.UserImportDataBuilder builder = UserImportData.builder(TestConstants.SERVER_UUID);
UUID uuid = UUID.randomUUID();
PlayerKill playerKill = TestData.getPlayerKill(uuid, uuid, TestConstants.SERVER_UUID, randomString, 1);
GMTimes gmTimes = new GMTimes(randomString, randomInt);
UserImportData data = builder.uuid(uuid).banned().banned(false).op().ips(randomString, randomString).ips(Collections.singletonList(randomString)).kills(playerKill, playerKill, playerKill).kills(Collections.singleton(playerKill)).name(randomString).registered(randomInt).timesKicked(randomInt).mobKills(randomInt).worldTimes(randomString, randomInt, randomInt, randomInt, randomInt).worldTimes(randomString, gmTimes).deaths(randomInt).worldTimes(ImmutableMap.of(randomString, gmTimes)).nicknames(randomString, randomString).nicknames(Collections.singletonList(new Nickname(randomString, System.currentTimeMillis(), TestConstants.SERVER_UUID))).build();
assertNotNull(data);
assertFalse(data.isBanned());
assertTrue(data.isOp());
assertEquals(randomInt, data.getDeaths());
assertEquals(1, data.getWorldTimes().size());
assertEquals(3, data.getIps().size());
assertEquals(playerKill, data.getKills().get(0));
assertEquals(randomInt, data.getMobKills());
assertEquals(3, data.getNicknames().size());
assertEquals(randomInt, data.getTimesKicked());
assertEquals(uuid, data.getUuid());
assertEquals(randomString, data.getName());
}
Aggregations