Skip to content

Commit c82d9b3

Browse files
committed
Add PLAYER_KILLS, MOB_KILLS and DEATHS datapoints
1 parent d5a5b3e commit c82d9b3

10 files changed

Lines changed: 452 additions & 20 deletions

File tree

Plan/common/src/main/java/com/djrapitops/plan/delivery/domain/auth/WebPermission.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,15 @@ public enum WebPermission implements Supplier<String>, Lang {
158158
DATA_NETWORK_PLAYTIME_PER_PLAYER_AVERAGE("See Average playtime per player datapoint of network"),
159159
DATA_SERVER_PLAYERS_ONLINE_PEAK("See Player online peak -datapoint of servers"),
160160
DATA_NETWORK_PLAYERS_ONLINE_PEAK("See Player online peak -datapoint of network"),
161+
DATA_PLAYER_MOB_KILLS("See Mob kills datapoint of players"),
162+
DATA_SERVER_MOB_KILLS("See Mob kills datapoint of servers"),
163+
DATA_NETWORK_MOB_KILLS("See Mob kills datapoint of network"),
164+
DATA_PLAYER_PLAYER_KILLS("See Player kills datapoint of players"),
165+
DATA_SERVER_PLAYER_KILLS("See Player kills datapoint of servers"),
166+
DATA_NETWORK_PLAYER_KILLS("See Player kills datapoint of network"),
167+
DATA_PLAYER_DEATHS("See Deaths datapoint of players"),
168+
DATA_SERVER_DEATHS("See Deaths datapoint of servers"),
169+
DATA_NETWORK_DEATHS("See Deaths datapoint of network"),
161170

162171
ACCESS("Controls access to pages"),
163172
ACCESS_PLAYER("Allows accessing any /player pages"),

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/datapoint/DatapointType.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ public enum DatapointType {
4343
SESSION_COUNT(SessionCount.class, DatapointCacheKey.SESSION),
4444
SESSION_LENGTH_AVERAGE(SessionLengthAverage.class, DatapointCacheKey.SESSION),
4545
PLAYTIME_PER_PLAYER_AVERAGE(PlaytimePerPlayerAverage.class, DatapointCacheKey.SESSION),
46-
PLAYERS_ONLINE_PEAK(PlayersOnlinePeak.class, DatapointCacheKey.TPS);
46+
PLAYERS_ONLINE_PEAK(PlayersOnlinePeak.class, DatapointCacheKey.TPS),
47+
MOB_KILLS(MobKills.class, DatapointCacheKey.SESSION),
48+
PLAYER_KILLS(PlayerKills.class, DatapointCacheKey.SESSION),
49+
DEATHS(Deaths.class, DatapointCacheKey.SESSION);
4750

4851
private final Class<? extends Datapoint<?>> datapointClass;
4952
private final DatapointCacheKey[] cacheKeys;

Plan/common/src/main/java/com/djrapitops/plan/delivery/rendering/json/datapoint/types/DatapointModule.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,23 @@ public interface DatapointModule {
8080
@IntoSet
8181
Datapoint<?> bindSessionLengthAverage(SessionLengthAverage sessionLengthAverage);
8282

83+
@Binds
84+
@IntoSet
85+
Datapoint<?> bindDeaths(Deaths deaths);
86+
8387
@Binds
8488
@IntoSet
8589
Datapoint<?> bindPlaytimePerPlayerAverage(PlaytimePerPlayerAverage playtimePerPlayerAverage);
8690

8791
@Binds
8892
@IntoSet
8993
Datapoint<?> bindPlayerOnlinePeak(PlayersOnlinePeak playersOnlinePeak);
94+
95+
@Binds
96+
@IntoSet
97+
Datapoint<?> bindMobKills(MobKills mobKills);
98+
99+
@Binds
100+
@IntoSet
101+
Datapoint<?> bindPlayerKills(PlayerKills playerKills);
90102
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* This file is part of Player Analytics (Plan).
3+
*
4+
* Plan is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License v3 as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Plan is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
package com.djrapitops.plan.delivery.rendering.json.datapoint.types;
18+
19+
import com.djrapitops.plan.delivery.domain.auth.WebPermission;
20+
import com.djrapitops.plan.delivery.domain.datatransfer.GenericFilter;
21+
import com.djrapitops.plan.delivery.rendering.json.datapoint.Datapoint;
22+
import com.djrapitops.plan.delivery.rendering.json.datapoint.DatapointType;
23+
import com.djrapitops.plan.gathering.cache.SessionCache;
24+
import com.djrapitops.plan.gathering.domain.DeathCounter;
25+
import com.djrapitops.plan.identification.ServerInfo;
26+
import com.djrapitops.plan.storage.database.DBSystem;
27+
import com.djrapitops.plan.storage.database.Database;
28+
import com.djrapitops.plan.storage.database.queries.objects.KillQueries;
29+
30+
import javax.inject.Inject;
31+
import javax.inject.Singleton;
32+
import java.util.Optional;
33+
import java.util.UUID;
34+
35+
/**
36+
* Datapoint for total death count.
37+
*/
38+
@Singleton
39+
public class Deaths implements Datapoint<Long> {
40+
41+
private final DBSystem dbSystem;
42+
private final ServerInfo serverInfo;
43+
44+
@Inject
45+
public Deaths(DBSystem dbSystem, ServerInfo serverInfo) {
46+
this.dbSystem = dbSystem;
47+
this.serverInfo = serverInfo;
48+
}
49+
50+
@Override
51+
public DatapointType getType() {
52+
return DatapointType.DEATHS;
53+
}
54+
55+
@Override
56+
public WebPermission getPermission(GenericFilter filter) {
57+
if (filter.getPlayerUUID().isPresent()) {
58+
return WebPermission.DATA_PLAYER_DEATHS;
59+
} else if (!filter.getServerUUIDs().isEmpty()) {
60+
return WebPermission.DATA_SERVER_DEATHS;
61+
} else {
62+
return WebPermission.DATA_NETWORK_DEATHS;
63+
}
64+
}
65+
66+
@Override
67+
public Optional<Long> getValue(GenericFilter filter) {
68+
Database db = dbSystem.getDatabase();
69+
Optional<UUID> playerUUID = filter.getPlayerUUID();
70+
long after = filter.getAfter();
71+
long before = filter.getBefore();
72+
73+
if (playerUUID.isPresent()) {
74+
Long value = db.query(KillQueries.deathCount(after, before, playerUUID.get(), filter.getServerUUIDs()));
75+
if (filter.contains(serverInfo.getServerUUID())) {
76+
value += SessionCache.getCachedSession(playerUUID.get())
77+
.filter(session -> session.isWithin(after, before))
78+
.flatMap(session -> session.getExtraData(DeathCounter.class))
79+
.map(DeathCounter::getCount)
80+
.orElse(0);
81+
}
82+
return Optional.of(value);
83+
}
84+
85+
Long value = db.query(KillQueries.deathCount(after, before, filter.getServerUUIDs()));
86+
if (filter.contains(serverInfo.getServerUUID())) {
87+
value += SessionCache.getActiveSessions().stream()
88+
.filter(session -> session.isWithin(after, before))
89+
.flatMap(session -> session.getExtraData(DeathCounter.class).stream())
90+
.mapToLong(DeathCounter::getCount)
91+
.sum();
92+
}
93+
return Optional.of(value);
94+
}
95+
}
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/*
2+
* This file is part of Player Analytics (Plan).
3+
*
4+
* Plan is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License v3 as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Plan is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
package com.djrapitops.plan.delivery.rendering.json.datapoint.types;
18+
19+
import com.djrapitops.plan.delivery.domain.auth.WebPermission;
20+
import com.djrapitops.plan.delivery.domain.datatransfer.GenericFilter;
21+
import com.djrapitops.plan.delivery.rendering.json.datapoint.Datapoint;
22+
import com.djrapitops.plan.delivery.rendering.json.datapoint.DatapointType;
23+
import com.djrapitops.plan.gathering.cache.SessionCache;
24+
import com.djrapitops.plan.gathering.domain.MobKillCounter;
25+
import com.djrapitops.plan.identification.ServerInfo;
26+
import com.djrapitops.plan.storage.database.DBSystem;
27+
import com.djrapitops.plan.storage.database.Database;
28+
import com.djrapitops.plan.storage.database.queries.objects.KillQueries;
29+
30+
import javax.inject.Inject;
31+
import javax.inject.Singleton;
32+
import java.util.Optional;
33+
import java.util.UUID;
34+
35+
/**
36+
* Datapoint for mob kill counts.
37+
*/
38+
@Singleton
39+
public class MobKills implements Datapoint<Long> {
40+
41+
private final DBSystem dbSystem;
42+
private final ServerInfo serverInfo;
43+
44+
@Inject
45+
public MobKills(DBSystem dbSystem, ServerInfo serverInfo) {
46+
this.dbSystem = dbSystem;
47+
this.serverInfo = serverInfo;
48+
}
49+
50+
@Override
51+
public DatapointType getType() {
52+
return DatapointType.MOB_KILLS;
53+
}
54+
55+
@Override
56+
public WebPermission getPermission(GenericFilter filter) {
57+
if (filter.getPlayerUUID().isPresent()) {
58+
return WebPermission.DATA_PLAYER_MOB_KILLS;
59+
} else if (!filter.getServerUUIDs().isEmpty()) {
60+
return WebPermission.DATA_SERVER_MOB_KILLS;
61+
} else {
62+
return WebPermission.DATA_NETWORK_MOB_KILLS;
63+
}
64+
}
65+
66+
@Override
67+
public Optional<Long> getValue(GenericFilter filter) {
68+
Database db = dbSystem.getDatabase();
69+
Optional<UUID> playerUUID = filter.getPlayerUUID();
70+
long after = filter.getAfter();
71+
long before = filter.getBefore();
72+
73+
if (playerUUID.isPresent()) {
74+
Long count = db.query(KillQueries.mobKillCount(after, before, playerUUID.get(), filter.getServerUUIDs()));
75+
if (filter.contains(serverInfo.getServerUUID())) {
76+
count += SessionCache.getCachedSession(playerUUID.get())
77+
.filter(session -> session.isWithin(after, before))
78+
.flatMap(session -> session.getExtraData(MobKillCounter.class))
79+
.map(MobKillCounter::getCount)
80+
.orElse(0);
81+
}
82+
return Optional.of(count);
83+
}
84+
85+
Long count = db.query(KillQueries.mobKillCount(after, before, filter.getServerUUIDs()));
86+
if (filter.contains(serverInfo.getServerUUID())) {
87+
count += SessionCache.getActiveSessions().stream()
88+
.filter(session -> session.isWithin(after, before))
89+
.flatMap(session -> session.getExtraData(MobKillCounter.class).stream())
90+
.mapToLong(MobKillCounter::getCount)
91+
.sum();
92+
}
93+
return Optional.of(count);
94+
}
95+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* This file is part of Player Analytics (Plan).
3+
*
4+
* Plan is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Lesser General Public License v3 as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* Plan is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License
15+
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
package com.djrapitops.plan.delivery.rendering.json.datapoint.types;
18+
19+
import com.djrapitops.plan.delivery.domain.auth.WebPermission;
20+
import com.djrapitops.plan.delivery.domain.datatransfer.GenericFilter;
21+
import com.djrapitops.plan.delivery.rendering.json.datapoint.Datapoint;
22+
import com.djrapitops.plan.delivery.rendering.json.datapoint.DatapointType;
23+
import com.djrapitops.plan.gathering.cache.SessionCache;
24+
import com.djrapitops.plan.identification.ServerInfo;
25+
import com.djrapitops.plan.storage.database.DBSystem;
26+
import com.djrapitops.plan.storage.database.Database;
27+
import com.djrapitops.plan.storage.database.queries.objects.KillQueries;
28+
29+
import javax.inject.Inject;
30+
import javax.inject.Singleton;
31+
import java.util.Optional;
32+
import java.util.UUID;
33+
34+
/**
35+
* Datapoint for player kill counts (PvP kills).
36+
*/
37+
@Singleton
38+
public class PlayerKills implements Datapoint<Long> {
39+
40+
private final DBSystem dbSystem;
41+
private final ServerInfo serverInfo;
42+
43+
@Inject
44+
public PlayerKills(DBSystem dbSystem, ServerInfo serverInfo) {
45+
this.dbSystem = dbSystem;
46+
this.serverInfo = serverInfo;
47+
}
48+
49+
@Override
50+
public DatapointType getType() {
51+
return DatapointType.PLAYER_KILLS;
52+
}
53+
54+
@Override
55+
public WebPermission getPermission(GenericFilter filter) {
56+
if (filter.getPlayerUUID().isPresent()) {
57+
return WebPermission.DATA_PLAYER_PLAYER_KILLS;
58+
} else if (!filter.getServerUUIDs().isEmpty()) {
59+
return WebPermission.DATA_SERVER_PLAYER_KILLS;
60+
} else {
61+
return WebPermission.DATA_NETWORK_PLAYER_KILLS;
62+
}
63+
}
64+
65+
@Override
66+
public Optional<Long> getValue(GenericFilter filter) {
67+
Database db = dbSystem.getDatabase();
68+
Optional<UUID> playerUUID = filter.getPlayerUUID();
69+
long after = filter.getAfter();
70+
long before = filter.getBefore();
71+
72+
if (playerUUID.isPresent()) {
73+
Long count = db.query(KillQueries.playerKillCount(after, before, playerUUID.get(), filter.getServerUUIDs()));
74+
if (filter.contains(serverInfo.getServerUUID())) {
75+
count += SessionCache.getCachedSession(playerUUID.get())
76+
.filter(session -> session.isWithin(after, before))
77+
.flatMap(session -> session.getExtraData(com.djrapitops.plan.gathering.domain.PlayerKills.class))
78+
.map(kills -> kills.asList().stream()
79+
.filter(kill -> kill.getDate() >= after && kill.getDate() < before)
80+
.count())
81+
.orElse(0L);
82+
}
83+
return Optional.of(count);
84+
}
85+
86+
Long count = db.query(KillQueries.playerKillCount(after, before, filter.getServerUUIDs()));
87+
if (filter.contains(serverInfo.getServerUUID())) {
88+
count += SessionCache.getActiveSessions().stream()
89+
.filter(session -> session.isWithin(after, before))
90+
.flatMap(session -> session.getExtraData(com.djrapitops.plan.gathering.domain.PlayerKills.class).stream())
91+
.mapToLong(kills -> kills.asList().stream()
92+
.filter(kill -> kill.getDate() >= after && kill.getDate() < before)
93+
.count())
94+
.sum();
95+
}
96+
return Optional.of(count);
97+
}
98+
}

0 commit comments

Comments
 (0)