Search in sources :

Example 1 with PlayerKill

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));
}
Also used : ActiveSession(com.djrapitops.plan.gathering.domain.ActiveSession) PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill)

Example 2 with PlayerKill

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;
}
Also used : PlayerContainer(com.djrapitops.plan.delivery.domain.container.PlayerContainer) PlayerContainerQuery(com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery) ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) WorldTimes(com.djrapitops.plan.gathering.domain.WorldTimes) Database(com.djrapitops.plan.storage.database.Database) DateHolderRecentComparator(com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator) WorldPie(com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie)

Example 3 with PlayerKill

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;
}
Also used : PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) FinishedSession(com.djrapitops.plan.gathering.domain.FinishedSession)

Example 4 with PlayerKill

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();
    }
}
Also used : ServerUUID(com.djrapitops.plan.identification.ServerUUID) PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) PlayerKills(com.djrapitops.plan.gathering.domain.PlayerKills) ServerUUID(com.djrapitops.plan.identification.ServerUUID) UUID(java.util.UUID)

Example 5 with PlayerKill

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());
}
Also used : GMTimes(com.djrapitops.plan.gathering.domain.GMTimes) PlayerKill(com.djrapitops.plan.gathering.domain.PlayerKill) UUID(java.util.UUID) Nickname(com.djrapitops.plan.delivery.domain.Nickname) Test(org.junit.jupiter.api.Test)

Aggregations

PlayerKill (com.djrapitops.plan.gathering.domain.PlayerKill)7 ServerUUID (com.djrapitops.plan.identification.ServerUUID)4 UUID (java.util.UUID)3 FinishedSession (com.djrapitops.plan.gathering.domain.FinishedSession)2 Test (org.junit.jupiter.api.Test)2 Nickname (com.djrapitops.plan.delivery.domain.Nickname)1 ServerIdentifier (com.djrapitops.plan.delivery.domain.ServerIdentifier)1 PlayerContainer (com.djrapitops.plan.delivery.domain.container.PlayerContainer)1 WorldPie (com.djrapitops.plan.delivery.rendering.json.graphs.pie.WorldPie)1 ActiveSession (com.djrapitops.plan.gathering.domain.ActiveSession)1 GMTimes (com.djrapitops.plan.gathering.domain.GMTimes)1 PlayerKills (com.djrapitops.plan.gathering.domain.PlayerKills)1 WorldTimes (com.djrapitops.plan.gathering.domain.WorldTimes)1 Database (com.djrapitops.plan.storage.database.Database)1 PlayerContainerQuery (com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery)1 DateHolderRecentComparator (com.djrapitops.plan.utilities.comparators.DateHolderRecentComparator)1 RepeatedTest (org.junit.jupiter.api.RepeatedTest)1