mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-26 11:08:08 +01:00
Changed keys used for PerServerData container to use their own object.
This commit is contained in:
parent
ff143af328
commit
657b25ec4f
@ -4,9 +4,10 @@ import java.util.HashMap;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Container for data
|
||||
* Container for data about a player on a single server.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @see com.djrapitops.plan.data.store.keys.PerServerKeys For Key objects.
|
||||
*/
|
||||
public class PerServerData extends HashMap<UUID, DataContainer> {
|
||||
}
|
@ -6,7 +6,7 @@ package com.djrapitops.plan.data.store.containers;
|
||||
* Use {@code getValue(PlayerKeys.REGISTERED).isPresent()} to determine if Plan has data about the player.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @see com.djrapitops.plan.data.store.keys.PlayerKeys for supported Key objects.
|
||||
* @see com.djrapitops.plan.data.store.keys.PlayerKeys For Key objects.
|
||||
*/
|
||||
public class PlayerContainer extends DataContainer {
|
||||
}
|
@ -1,7 +1,12 @@
|
||||
package com.djrapitops.plan.data.store.keys;
|
||||
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.Key;
|
||||
import com.djrapitops.plan.data.store.Type;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
@ -12,5 +17,18 @@ import java.util.UUID;
|
||||
public class CommonKeys {
|
||||
|
||||
public static final Key<UUID> UUID = new Key<>(UUID.class, "uuid");
|
||||
public static final Key<Long> REGISTERED = new Key<>(Long.class, "registered");
|
||||
|
||||
public static final Key<List<Session>> SESSIONS = new Key<>(new Type<List<Session>>() {}, "sessions");
|
||||
public static final Key<WorldTimes> WORLD_TIMES = new Key<>(WorldTimes.class, "world_times");
|
||||
public static final Key<Long> LAST_SEEN = new Key<>(Long.class, "last_seen");
|
||||
|
||||
public static final Key<List<PlayerKill>> PLAYER_KILLS = new Key<>(new Type<List<PlayerKill>>() {}, "player_kills");
|
||||
public static final Key<Integer> PLAYER_KILL_COUNT = new Key<>(Integer.class, "player_kill_count");
|
||||
public static final Key<Integer> MOB_KILL_COUNT = new Key<>(Integer.class, "mob_kill_count");
|
||||
public static final Key<Integer> DEATH_COUNT = new Key<>(Integer.class, "death_count");
|
||||
|
||||
public static final Key<Boolean> BANNED = new Key<>(Boolean.class, "banned");
|
||||
public static final Key<Boolean> OPERATOR = new Key<>(Boolean.class, "operator");
|
||||
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.djrapitops.plan.data.store.keys;
|
||||
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.Key;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Key objects for PerServerData container.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @see com.djrapitops.plan.data.store.containers.PerServerData For the DataContainer.
|
||||
*/
|
||||
public class PerServerKeys {
|
||||
|
||||
public static final Key<Long> REGISTERED = CommonKeys.REGISTERED;
|
||||
|
||||
public static final Key<List<Session>> SESSIONS = CommonKeys.SESSIONS;
|
||||
public static final Key<WorldTimes> WORLD_TIMES = CommonKeys.WORLD_TIMES;
|
||||
|
||||
public static final Key<List<PlayerKill>> PLAYER_KILLS = CommonKeys.PLAYER_KILLS;
|
||||
public static final Key<Integer> PLAYER_KILL_COUNT = CommonKeys.PLAYER_KILL_COUNT;
|
||||
public static final Key<Integer> MOB_KILL_COUNT = CommonKeys.MOB_KILL_COUNT;
|
||||
public static final Key<Integer> DEATH_COUNT = CommonKeys.DEATH_COUNT;
|
||||
public static final Key<Long> LAST_SEEN = CommonKeys.LAST_SEEN;
|
||||
|
||||
public static final Key<Boolean> BANNED = CommonKeys.BANNED;
|
||||
public static final Key<Boolean> OPERATOR = CommonKeys.OPERATOR;
|
||||
|
||||
}
|
@ -16,6 +16,7 @@ import java.util.UUID;
|
||||
* Class that holds Key objects for PlayerContainer.
|
||||
*
|
||||
* @author Rsl1122
|
||||
* @see com.djrapitops.plan.data.store.containers.PlayerContainer For DataContainer.
|
||||
*/
|
||||
public class PlayerKeys {
|
||||
|
||||
@ -23,23 +24,23 @@ public class PlayerKeys {
|
||||
public static final Key<String> NAME = new Key<>(String.class, "name");
|
||||
public static final Key<List<Nickname>> NICKNAMES = new Key<>(new Type<List<Nickname>>() {}, "nicknames");
|
||||
|
||||
public static final Key<Long> REGISTERED = new Key<>(Long.class, "registered");
|
||||
public static final Key<Long> REGISTERED = CommonKeys.REGISTERED;
|
||||
|
||||
public static final Key<Integer> KICK_COUNT = new Key<>(Integer.class, "kick_count");
|
||||
public static final Key<List<GeoInfo>> GEO_INFO = new Key<>(new Type<List<GeoInfo>>() {}, "geo_info");
|
||||
|
||||
public static final Key<Session> ACTIVE_SESSION = new Key<Session>(Session.class, "active_session");
|
||||
public static final Key<List<Session>> SESSIONS = new Key<>(new Type<List<Session>>() {}, "sessions");
|
||||
public static final Key<WorldTimes> WORLD_TIMES = new Key<>(WorldTimes.class, "world_times");
|
||||
public static final Key<Session> ACTIVE_SESSION = new Key<>(Session.class, "active_session");
|
||||
public static final Key<List<Session>> SESSIONS = CommonKeys.SESSIONS;
|
||||
public static final Key<WorldTimes> WORLD_TIMES = CommonKeys.WORLD_TIMES;
|
||||
|
||||
public static final Key<List<PlayerKill>> PLAYER_KILLS = new Key<>(new Type<List<PlayerKill>>() {}, "player_kills");
|
||||
public static final Key<Integer> PLAYER_KILL_COUNT = new Key<>(Integer.class, "player_kill_count");
|
||||
public static final Key<Integer> MOB_KILL_COUNT = new Key<>(Integer.class, "mob_kill_count");
|
||||
public static final Key<Integer> DEATH_COUNT = new Key<>(Integer.class, "death_count");
|
||||
public static final Key<List<PlayerKill>> PLAYER_KILLS = CommonKeys.PLAYER_KILLS;
|
||||
public static final Key<Integer> PLAYER_KILL_COUNT = CommonKeys.PLAYER_KILL_COUNT;
|
||||
public static final Key<Integer> MOB_KILL_COUNT = CommonKeys.MOB_KILL_COUNT;
|
||||
public static final Key<Integer> DEATH_COUNT = CommonKeys.DEATH_COUNT;
|
||||
public static final Key<PerServerData> PER_SERVER = new Key<>(PerServerData.class, "per_server_data");
|
||||
public static final Key<Long> LAST_SEEN = new Key<>(Long.class, "last_seen");
|
||||
public static final Key<Long> LAST_SEEN = CommonKeys.LAST_SEEN;
|
||||
|
||||
public static final Key<Boolean> BANNED = new Key<>(Boolean.class, "banned");
|
||||
public static final Key<Boolean> OPERATOR = new Key<>(Boolean.class, "operator");
|
||||
public static final Key<Boolean> BANNED = CommonKeys.BANNED;
|
||||
public static final Key<Boolean> OPERATOR = CommonKeys.OPERATOR;
|
||||
|
||||
}
|
@ -2,7 +2,10 @@ package com.djrapitops.plan.data.store.mutators;
|
||||
|
||||
import com.djrapitops.plan.data.container.PlayerKill;
|
||||
import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -18,6 +21,12 @@ public class SessionsMutator {
|
||||
|
||||
private List<Session> sessions;
|
||||
|
||||
public static SessionsMutator forContainer(DataContainer dataContainer) {
|
||||
Verify.isTrue(dataContainer.supports(PlayerKeys.SESSIONS),
|
||||
() -> new IllegalArgumentException("Given DataContainer does not support SESSIONS"));
|
||||
return new SessionsMutator(dataContainer.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>()));
|
||||
}
|
||||
|
||||
public SessionsMutator(List<Session> sessions) {
|
||||
this.sessions = sessions;
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.djrapitops.plan.data.container.*;
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerData;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PerServerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.store.mutators.PerServerDataMutator;
|
||||
import com.djrapitops.plan.data.store.mutators.SessionsMutator;
|
||||
@ -191,18 +192,21 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
|
||||
List<Session> serverSessions = entry.getValue();
|
||||
|
||||
DataContainer perServer = perServerData.getOrDefault(serverUUID, new DataContainer());
|
||||
perServer.putRawData(PlayerKeys.SESSIONS, serverSessions);
|
||||
perServer.putRawData(PerServerKeys.SESSIONS, serverSessions);
|
||||
|
||||
perServer.putSupplier(PlayerKeys.WORLD_TIMES, () ->
|
||||
new SessionsMutator(perServer.getUnsafe(PlayerKeys.SESSIONS)).toTotalWorldTimes());
|
||||
perServer.putSupplier(PlayerKeys.PLAYER_KILLS, () ->
|
||||
new SessionsMutator(perServer.getUnsafe(PlayerKeys.SESSIONS)).toPlayerKillList());
|
||||
perServer.putSupplier(PlayerKeys.PLAYER_KILL_COUNT, () ->
|
||||
perServer.getUnsafe(PlayerKeys.PLAYER_KILLS).size());
|
||||
perServer.putSupplier(PlayerKeys.MOB_KILL_COUNT, () ->
|
||||
new SessionsMutator(perServer.getUnsafe(PlayerKeys.SESSIONS)).toMobKillCount());
|
||||
perServer.putSupplier(PlayerKeys.DEATH_COUNT, () ->
|
||||
new SessionsMutator(perServer.getUnsafe(PlayerKeys.SESSIONS)).toDeathCount());
|
||||
perServer.putSupplier(PerServerKeys.LAST_SEEN, () ->
|
||||
new SessionsMutator(perServer.getUnsafe(PerServerKeys.SESSIONS)).toLastSeen());
|
||||
|
||||
perServer.putSupplier(PerServerKeys.WORLD_TIMES, () ->
|
||||
new SessionsMutator(perServer.getUnsafe(PerServerKeys.SESSIONS)).toTotalWorldTimes());
|
||||
perServer.putSupplier(PerServerKeys.PLAYER_KILLS, () ->
|
||||
new SessionsMutator(perServer.getUnsafe(PerServerKeys.SESSIONS)).toPlayerKillList());
|
||||
perServer.putSupplier(PerServerKeys.PLAYER_KILL_COUNT, () ->
|
||||
perServer.getUnsafe(PerServerKeys.PLAYER_KILLS).size());
|
||||
perServer.putSupplier(PerServerKeys.MOB_KILL_COUNT, () ->
|
||||
new SessionsMutator(perServer.getUnsafe(PerServerKeys.SESSIONS)).toMobKillCount());
|
||||
perServer.putSupplier(PerServerKeys.DEATH_COUNT, () ->
|
||||
new SessionsMutator(perServer.getUnsafe(PerServerKeys.SESSIONS)).toDeathCount());
|
||||
|
||||
perServerData.put(serverUUID, perServer);
|
||||
}
|
||||
|
@ -134,7 +134,7 @@ public class InspectPage extends Page {
|
||||
|
||||
String[] sessionsAccordion = HtmlStructure.createSessionsTabContentInspectPage(sessionsByServerName, allSessions, uuid);
|
||||
|
||||
ServerAccordion serverAccordion = new ServerAccordion(container, worldTimesPerServer, serverNames);
|
||||
ServerAccordion serverAccordion = new ServerAccordion(container, serverNames);
|
||||
|
||||
PlayerCalendar playerCalendar = new PlayerCalendar(allSessions, registered);
|
||||
|
||||
|
@ -9,6 +9,7 @@ import com.djrapitops.plan.data.container.Session;
|
||||
import com.djrapitops.plan.data.store.containers.DataContainer;
|
||||
import com.djrapitops.plan.data.store.containers.PerServerData;
|
||||
import com.djrapitops.plan.data.store.containers.PlayerContainer;
|
||||
import com.djrapitops.plan.data.store.keys.PerServerKeys;
|
||||
import com.djrapitops.plan.data.store.keys.PlayerKeys;
|
||||
import com.djrapitops.plan.data.time.WorldTimes;
|
||||
import com.djrapitops.plan.system.settings.theme.Theme;
|
||||
@ -32,7 +33,7 @@ public class ServerAccordion extends AbstractAccordion {
|
||||
private final Map<UUID, String> serverNames;
|
||||
private PerServerData perServer;
|
||||
|
||||
public ServerAccordion(PlayerContainer container, Map<UUID, WorldTimes> worldTimesPerServer, Map<UUID, String> serverNames) {
|
||||
public ServerAccordion(PlayerContainer container, Map<UUID, String> serverNames) {
|
||||
super("server_accordion");
|
||||
|
||||
viewScript = new StringBuilder();
|
||||
@ -58,13 +59,13 @@ public class ServerAccordion extends AbstractAccordion {
|
||||
UUID serverUUID = entry.getKey();
|
||||
DataContainer container = entry.getValue();
|
||||
String serverName = serverNames.getOrDefault(serverUUID, "Unknown");
|
||||
WorldTimes worldTimes = container.getValue(PlayerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()));
|
||||
WorldTimes worldTimes = container.getValue(PerServerKeys.WORLD_TIMES).orElse(new WorldTimes(new HashMap<>()));
|
||||
|
||||
List<Session> sessions = container.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>());
|
||||
List<Session> sessions = container.getValue(PerServerKeys.SESSIONS).orElse(new ArrayList<>());
|
||||
|
||||
boolean banned = container.getValue(PlayerKeys.BANNED).orElse(false);
|
||||
boolean opeator = container.getValue(PlayerKeys.OPERATOR).orElse(false);
|
||||
long registered = container.getValue(PlayerKeys.REGISTERED).orElse(0L);
|
||||
boolean banned = container.getValue(PerServerKeys.BANNED).orElse(false);
|
||||
boolean opeator = container.getValue(PerServerKeys.OPERATOR).orElse(false);
|
||||
long registered = container.getValue(PerServerKeys.REGISTERED).orElse(0L);
|
||||
|
||||
long playtime = PlayerProfile.getPlaytime(sessions.stream());
|
||||
long afkTime = PlayerProfile.getAFKTime(sessions.stream());
|
||||
|
Loading…
Reference in New Issue
Block a user