mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-03-02 11:11:21 +01:00
Removed some usages of DataContainer#getUnsafe
Fixes Unsupported Key exception on player JSON export
This commit is contained in:
parent
3167cc5f6a
commit
228e2d509c
@ -21,7 +21,10 @@ import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||
import com.djrapitops.plan.data.store.objects.DateHolder;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* DataContainer for information about a player's play session.
|
||||
@ -91,7 +94,7 @@ public class Session extends DynamicDataContainer implements DateHolder {
|
||||
*/
|
||||
public Session(int id, UUID uuid, UUID serverUUID, long sessionStart, long sessionEnd, int mobKills, int deaths, long afkTime) {
|
||||
this.sessionStart = sessionStart;
|
||||
worldTimes = new WorldTimes(new HashMap<>());
|
||||
worldTimes = new WorldTimes();
|
||||
playerKills = new ArrayList<>();
|
||||
|
||||
this.mobKills = mobKills;
|
||||
|
@ -363,7 +363,7 @@ public class AnalysisContainer extends DynamicDataContainer {
|
||||
private void addGraphSuppliers() {
|
||||
Key<WorldPie> worldPie = new Key<>(WorldPie.class, "WORLD_PIE");
|
||||
putCachingSupplier(worldPie, () -> graphs.pie().worldPie(
|
||||
serverContainer.getValue(ServerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()))
|
||||
serverContainer.getValue(ServerKeys.WORLD_TIMES).orElse(new WorldTimes())
|
||||
));
|
||||
putSupplier(AnalysisKeys.WORLD_PIE_SERIES, () -> getUnsafe(worldPie).toHighChartsSeries());
|
||||
putSupplier(AnalysisKeys.GM_PIE_SERIES, () -> getUnsafe(worldPie).toHighChartsDrilldown());
|
||||
|
@ -46,13 +46,13 @@ public class PerServerMutator {
|
||||
public List<Session> flatMapSessions() {
|
||||
return data.values().stream()
|
||||
.filter(container -> container.supports(PerServerKeys.SESSIONS))
|
||||
.map(container -> container.getUnsafe(PerServerKeys.SESSIONS))
|
||||
.map(container -> container.getValue(PerServerKeys.SESSIONS).orElse(Collections.emptyList()))
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public WorldTimes flatMapWorldTimes() {
|
||||
WorldTimes total = new WorldTimes(new HashMap<>());
|
||||
WorldTimes total = new WorldTimes();
|
||||
|
||||
for (DataContainer container : data.values()) {
|
||||
if (container.supports(PerServerKeys.WORLD_TIMES)) {
|
||||
@ -68,7 +68,7 @@ public class PerServerMutator {
|
||||
Map<UUID, WorldTimes> timesMap = new HashMap<>();
|
||||
for (Map.Entry<UUID, DataContainer> entry : data.entrySet()) {
|
||||
DataContainer container = entry.getValue();
|
||||
timesMap.put(entry.getKey(), container.getValue(PerServerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>())));
|
||||
timesMap.put(entry.getKey(), container.getValue(PerServerKeys.WORLD_TIMES).orElse(new WorldTimes()));
|
||||
}
|
||||
return timesMap;
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public class SessionsMutator {
|
||||
}
|
||||
|
||||
public WorldTimes toTotalWorldTimes() {
|
||||
WorldTimes total = new WorldTimes(new HashMap<>());
|
||||
WorldTimes total = new WorldTimes();
|
||||
|
||||
for (Session session : sessions) {
|
||||
session.getValue(SessionKeys.WORLD_TIMES).ifPresent(total::add);
|
||||
|
@ -54,6 +54,10 @@ public class WorldTimes {
|
||||
this.times = times;
|
||||
}
|
||||
|
||||
public WorldTimes() {
|
||||
this(new HashMap<>());
|
||||
}
|
||||
|
||||
private void addWorld(String worldName, String gameMode, long changeTime) {
|
||||
if (worldName == null || gameMode == null) return;
|
||||
times.put(worldName, new GMTimes(gameMode, changeTime));
|
||||
|
@ -103,9 +103,9 @@ public class DataStoreQueries {
|
||||
statement.setString(1, session.getUnsafe(SessionKeys.UUID).toString());
|
||||
statement.setLong(2, session.getUnsafe(SessionKeys.START));
|
||||
statement.setLong(3, session.getUnsafe(SessionKeys.END));
|
||||
statement.setInt(4, session.getUnsafe(SessionKeys.DEATH_COUNT));
|
||||
statement.setInt(5, session.getUnsafe(SessionKeys.MOB_KILL_COUNT));
|
||||
statement.setLong(6, session.getUnsafe(SessionKeys.AFK_TIME));
|
||||
statement.setInt(4, session.getValue(SessionKeys.DEATH_COUNT).orElse(0));
|
||||
statement.setInt(5, session.getValue(SessionKeys.MOB_KILL_COUNT).orElse(0));
|
||||
statement.setLong(6, session.getValue(SessionKeys.AFK_TIME).orElse(0L));
|
||||
statement.setString(7, session.getUnsafe(SessionKeys.SERVER_UUID).toString());
|
||||
}
|
||||
};
|
||||
|
@ -341,9 +341,9 @@ public class LargeStoreQueries {
|
||||
statement.setString(1, session.getUnsafe(SessionKeys.UUID).toString());
|
||||
statement.setLong(2, session.getUnsafe(SessionKeys.START));
|
||||
statement.setLong(3, session.getUnsafe(SessionKeys.END));
|
||||
statement.setInt(4, session.getUnsafe(SessionKeys.DEATH_COUNT));
|
||||
statement.setInt(5, session.getUnsafe(SessionKeys.MOB_KILL_COUNT));
|
||||
statement.setLong(6, session.getUnsafe(SessionKeys.AFK_TIME));
|
||||
statement.setInt(4, session.getValue(SessionKeys.DEATH_COUNT).orElse(0));
|
||||
statement.setInt(5, session.getValue(SessionKeys.MOB_KILL_COUNT).orElse(0));
|
||||
statement.setLong(6, session.getValue(SessionKeys.AFK_TIME).orElse(0L));
|
||||
statement.setString(7, session.getUnsafe(SessionKeys.SERVER_UUID).toString());
|
||||
statement.addBatch();
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ public class PerServerContainerQuery implements Query<PerServerContainer> {
|
||||
// After-values that can be calculated without database.
|
||||
for (DataContainer serverContainer : perServerContainer.values()) {
|
||||
serverContainer.putSupplier(PerServerKeys.MOB_DEATH_COUNT, () ->
|
||||
serverContainer.getUnsafe(PerServerKeys.DEATH_COUNT) - serverContainer.getUnsafe(PerServerKeys.PLAYER_DEATH_COUNT)
|
||||
serverContainer.getValue(PerServerKeys.DEATH_COUNT).orElse(0) - serverContainer.getValue(PerServerKeys.PLAYER_DEATH_COUNT).orElse(0)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ package com.djrapitops.plan.db.access.queries.containers;
|
||||
import com.djrapitops.plan.data.container.BaseUser;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.Key;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.SessionKeys;
|
||||
@ -29,7 +30,7 @@ import com.djrapitops.plan.db.SQLDB;
|
||||
import com.djrapitops.plan.db.access.Query;
|
||||
import com.djrapitops.plan.db.access.queries.objects.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -64,11 +65,11 @@ public class PlayerContainerQuery implements Query<PlayerContainer> {
|
||||
container.putCachingSupplier(PlayerKeys.NICKNAMES, () -> db.query(NicknameQueries.fetchNicknameDataOfPlayer(uuid)));
|
||||
container.putCachingSupplier(PlayerKeys.PER_SERVER, () -> db.query(new PerServerContainerQuery(uuid)));
|
||||
|
||||
container.putSupplier(PlayerKeys.BANNED, () -> new PerServerMutator(container.getUnsafe(PlayerKeys.PER_SERVER)).isBanned());
|
||||
container.putSupplier(PlayerKeys.OPERATOR, () -> new PerServerMutator(container.getUnsafe(PlayerKeys.PER_SERVER)).isOperator());
|
||||
container.putSupplier(PlayerKeys.BANNED, () -> new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).isBanned());
|
||||
container.putSupplier(PlayerKeys.OPERATOR, () -> new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).isOperator());
|
||||
|
||||
container.putCachingSupplier(PlayerKeys.SESSIONS, () -> {
|
||||
List<Session> sessions = new PerServerMutator(container.getUnsafe(PlayerKeys.PER_SERVER)).flatMapSessions();
|
||||
List<Session> sessions = new PerServerMutator(container.getValue(PlayerKeys.PER_SERVER).orElse(new PerServerContainer())).flatMapSessions();
|
||||
container.getValue(PlayerKeys.ACTIVE_SESSION).ifPresent(sessions::add);
|
||||
return sessions;
|
||||
}
|
||||
@ -77,7 +78,7 @@ public class PlayerContainerQuery implements Query<PlayerContainer> {
|
||||
{
|
||||
WorldTimes worldTimes = db.query(WorldTimesQueries.fetchPlayerTotalWorldTimes(uuid));
|
||||
container.getValue(PlayerKeys.ACTIVE_SESSION).ifPresent(session -> worldTimes.add(
|
||||
session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>())))
|
||||
session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes()))
|
||||
);
|
||||
return worldTimes;
|
||||
});
|
||||
@ -86,7 +87,7 @@ public class PlayerContainerQuery implements Query<PlayerContainer> {
|
||||
|
||||
container.putSupplier(PlayerKeys.PLAYER_KILLS, () -> SessionsMutator.forContainer(container).toPlayerKillList());
|
||||
container.putSupplier(PlayerKeys.PLAYER_DEATHS, () -> SessionsMutator.forContainer(container).toPlayerDeathList());
|
||||
container.putSupplier(PlayerKeys.PLAYER_KILL_COUNT, () -> container.getUnsafe(PlayerKeys.PLAYER_KILLS).size());
|
||||
container.putSupplier(PlayerKeys.PLAYER_KILL_COUNT, () -> container.getValue(PlayerKeys.PLAYER_KILLS).map(Collection::size).orElse(0));
|
||||
container.putSupplier(PlayerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount());
|
||||
container.putSupplier(PlayerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount());
|
||||
|
||||
|
@ -103,7 +103,7 @@ public class ServerPlayerContainersQuery implements Query<List<PlayerContainer>>
|
||||
WorldTimes worldTimes = new PerServerMutator(container.getUnsafe(PlayerKeys.PER_SERVER)).flatMapWorldTimes();
|
||||
container.getValue(PlayerKeys.ACTIVE_SESSION)
|
||||
.ifPresent(session -> worldTimes.add(
|
||||
session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>())))
|
||||
session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes()))
|
||||
);
|
||||
return worldTimes;
|
||||
});
|
||||
|
@ -214,7 +214,7 @@ public class SessionQueries {
|
||||
set.getLong(SessionsTable.AFK_TIME)
|
||||
));
|
||||
|
||||
WorldTimes worldTimes = session.getUnsafe(SessionKeys.WORLD_TIMES);
|
||||
WorldTimes worldTimes = session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes());
|
||||
String worldName = set.getString(WorldTable.NAME);
|
||||
|
||||
if (!worldTimes.contains(worldName)) {
|
||||
|
@ -75,7 +75,7 @@ public class WorldTimesQueries {
|
||||
public WorldTimes processResults(ResultSet set) throws SQLException {
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
|
||||
WorldTimes worldTimes = new WorldTimes(new HashMap<>());
|
||||
WorldTimes worldTimes = new WorldTimes();
|
||||
while (set.next()) {
|
||||
String worldName = set.getString(worldColumn);
|
||||
|
||||
@ -110,7 +110,7 @@ public class WorldTimesQueries {
|
||||
public WorldTimes processResults(ResultSet set) throws SQLException {
|
||||
String[] gms = GMTimes.getGMKeyArray();
|
||||
|
||||
WorldTimes worldTimes = new WorldTimes(new HashMap<>());
|
||||
WorldTimes worldTimes = new WorldTimes();
|
||||
while (set.next()) {
|
||||
String worldName = set.getString(worldColumn);
|
||||
|
||||
@ -149,7 +149,7 @@ public class WorldTimesQueries {
|
||||
Map<UUID, WorldTimes> worldTimesMap = new HashMap<>();
|
||||
while (set.next()) {
|
||||
UUID serverUUID = UUID.fromString(set.getString(WorldTimesTable.SERVER_UUID));
|
||||
WorldTimes worldTimes = worldTimesMap.getOrDefault(serverUUID, new WorldTimes(new HashMap<>()));
|
||||
WorldTimes worldTimes = worldTimesMap.getOrDefault(serverUUID, new WorldTimes());
|
||||
String worldName = set.getString(worldColumn);
|
||||
|
||||
GMTimes gmTimes = extractGMTimes(set, gms);
|
||||
|
@ -165,7 +165,7 @@ public class WorldAliasSettings {
|
||||
if (!session.supports(SessionKeys.WORLD_TIMES)) {
|
||||
return "No World Time Data";
|
||||
}
|
||||
WorldTimes worldTimes = session.getUnsafe(SessionKeys.WORLD_TIMES);
|
||||
WorldTimes worldTimes = session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes());
|
||||
if (!session.supports(SessionKeys.END)) {
|
||||
return "Current: " + aliases.getOrDefault(worldTimes.getCurrentWorld(), "Unknown");
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ public class PlayerCalendar {
|
||||
.orElse(System.currentTimeMillis()))
|
||||
.append("}");
|
||||
|
||||
for (PlayerKill kill : session.getUnsafe(SessionKeys.PLAYER_KILLS)) {
|
||||
for (PlayerKill kill : session.getPlayerKills()) {
|
||||
long time = kill.getDate();
|
||||
|
||||
series.append(",{title: 'Killed: ").append(kill.getVictim())
|
||||
|
@ -110,7 +110,7 @@ public class PunchCard implements HighChart {
|
||||
private List<Long> getSessionStarts(Collection<Session> data) {
|
||||
return data.stream()
|
||||
.filter(Objects::nonNull)
|
||||
.map(s -> s.getUnsafe(SessionKeys.START))
|
||||
.map(session -> session.getUnsafe(SessionKeys.START))
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
@ -223,7 +223,7 @@ public class InspectPage implements Page {
|
||||
sessionsAndPlaytime(replacer, sessionsMutator, daySessionsMutator, weekSessionsMutator, monthSessionsMutator);
|
||||
|
||||
String punchCardData = graphs.special().punchCard(allSessions).toHighChartsSeries();
|
||||
WorldTimes worldTimes = player.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()));
|
||||
WorldTimes worldTimes = player.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes());
|
||||
|
||||
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
|
||||
|
||||
|
@ -25,6 +25,7 @@ import com.djrapitops.plan.utilities.comparators.SessionStartComparator;
|
||||
import com.djrapitops.plan.utilities.formatting.Formatter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@ -85,7 +86,7 @@ public class RecentLoginList {
|
||||
String name = player.getUnsafe(PlayerKeys.NAME);
|
||||
long registerDate = player.getValue(PlayerKeys.REGISTERED).orElse(0L);
|
||||
|
||||
List<Session> sessions = player.getUnsafe(PlayerKeys.SESSIONS);
|
||||
List<Session> sessions = player.getValue(PlayerKeys.SESSIONS).orElse(Collections.emptyList());
|
||||
if (sessions.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ import com.djrapitops.plan.utilities.html.icon.Icon;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||
import com.djrapitops.plugin.utilities.Format;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
@ -92,7 +91,7 @@ public class ServerAccordion extends Accordion {
|
||||
UUID serverUUID = entry.getKey();
|
||||
DataContainer container = entry.getValue();
|
||||
String serverName = serverNames.getOrDefault(serverUUID, "Unknown");
|
||||
WorldTimes worldTimes = container.getValue(PerServerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()));
|
||||
WorldTimes worldTimes = container.getValue(PerServerKeys.WORLD_TIMES).orElse(new WorldTimes());
|
||||
SessionsMutator sessionsMutator = SessionsMutator.forContainer(container);
|
||||
|
||||
boolean banned = container.getValue(PerServerKeys.BANNED).orElse(false);
|
||||
|
@ -33,7 +33,10 @@ import com.djrapitops.plan.utilities.html.graphs.pie.WorldPie;
|
||||
import com.djrapitops.plan.utilities.html.icon.Icons;
|
||||
import com.djrapitops.plan.utilities.html.tables.HtmlTables;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
@ -119,7 +122,7 @@ public class SessionAccordion extends Accordion {
|
||||
String playerName = playerNames.getOrDefault(session.getValue(SessionKeys.UUID).orElse(null), "Unknown");
|
||||
String sessionStart = yearFormatter.apply(session);
|
||||
|
||||
WorldTimes worldTimes = session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()));
|
||||
WorldTimes worldTimes = session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes());
|
||||
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
|
||||
String longestWorldPlayed = worldAliasSettings.getLongestWorldPlayed(session);
|
||||
|
||||
@ -191,7 +194,7 @@ public class SessionAccordion extends Accordion {
|
||||
String serverName = serverNames.getOrDefault(session.getValue(SessionKeys.SERVER_UUID).orElse(null), "Unknown");
|
||||
String sessionStart = yearFormatter.apply(session);
|
||||
|
||||
WorldTimes worldTimes = session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()));
|
||||
WorldTimes worldTimes = session.getValue(SessionKeys.WORLD_TIMES).orElse(new WorldTimes());
|
||||
WorldPie worldPie = graphs.pie().worldPie(worldTimes);
|
||||
String longestWorldPlayed = worldAliasSettings.getLongestWorldPlayed(session);
|
||||
|
||||
|
@ -748,7 +748,7 @@ public abstract class CommonDBTest {
|
||||
@Test
|
||||
public void emptyServerWorldTimesIsEmpty() {
|
||||
WorldTimes worldTimesOfServer = db.query(WorldTimesQueries.fetchServerTotalWorldTimes(serverUUID));
|
||||
assertEquals(new WorldTimes(new HashMap<>()), worldTimesOfServer);
|
||||
assertEquals(new WorldTimes(), worldTimesOfServer);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
Reference in New Issue
Block a user