From 657b25ec4fc735470e87445e38029ce1125ab8cd Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Tue, 5 Jun 2018 14:15:50 +0300 Subject: [PATCH] Changed keys used for PerServerData container to use their own object. --- .../data/store/containers/PerServerData.java | 3 +- .../store/containers/PlayerContainer.java | 2 +- .../plan/data/store/keys/CommonKeys.java | 18 +++++++++++ .../plan/data/store/keys/PerServerKeys.java | 32 +++++++++++++++++++ .../plan/data/store/keys/PlayerKeys.java | 23 ++++++------- .../data/store/mutators/SessionsMutator.java | 9 ++++++ .../databases/sql/operation/SQLFetchOps.java | 26 ++++++++------- .../webserver/pages/parsing/InspectPage.java | 2 +- .../html/structure/ServerAccordion.java | 13 ++++---- 9 files changed, 97 insertions(+), 31 deletions(-) create mode 100644 Plan/src/main/java/com/djrapitops/plan/data/store/keys/PerServerKeys.java diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/PerServerData.java b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/PerServerData.java index cdff8aa11..89243e60d 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/PerServerData.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/PerServerData.java @@ -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 { } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/PlayerContainer.java b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/PlayerContainer.java index c3ed7a865..a61a98579 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/containers/PlayerContainer.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/containers/PlayerContainer.java @@ -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 { } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/CommonKeys.java b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/CommonKeys.java index f589a6ca2..74390410e 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/CommonKeys.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/CommonKeys.java @@ -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 = new Key<>(UUID.class, "uuid"); + public static final Key REGISTERED = new Key<>(Long.class, "registered"); + + public static final Key> SESSIONS = new Key<>(new Type>() {}, "sessions"); + public static final Key WORLD_TIMES = new Key<>(WorldTimes.class, "world_times"); + public static final Key LAST_SEEN = new Key<>(Long.class, "last_seen"); + + public static final Key> PLAYER_KILLS = new Key<>(new Type>() {}, "player_kills"); + public static final Key PLAYER_KILL_COUNT = new Key<>(Integer.class, "player_kill_count"); + public static final Key MOB_KILL_COUNT = new Key<>(Integer.class, "mob_kill_count"); + public static final Key DEATH_COUNT = new Key<>(Integer.class, "death_count"); + + public static final Key BANNED = new Key<>(Boolean.class, "banned"); + public static final Key OPERATOR = new Key<>(Boolean.class, "operator"); } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PerServerKeys.java b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PerServerKeys.java new file mode 100644 index 000000000..e1e2d743b --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PerServerKeys.java @@ -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 REGISTERED = CommonKeys.REGISTERED; + + public static final Key> SESSIONS = CommonKeys.SESSIONS; + public static final Key WORLD_TIMES = CommonKeys.WORLD_TIMES; + + public static final Key> PLAYER_KILLS = CommonKeys.PLAYER_KILLS; + public static final Key PLAYER_KILL_COUNT = CommonKeys.PLAYER_KILL_COUNT; + public static final Key MOB_KILL_COUNT = CommonKeys.MOB_KILL_COUNT; + public static final Key DEATH_COUNT = CommonKeys.DEATH_COUNT; + public static final Key LAST_SEEN = CommonKeys.LAST_SEEN; + + public static final Key BANNED = CommonKeys.BANNED; + public static final Key OPERATOR = CommonKeys.OPERATOR; + +} \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PlayerKeys.java b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PlayerKeys.java index 89b62f7ae..0477ef715 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PlayerKeys.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/keys/PlayerKeys.java @@ -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 NAME = new Key<>(String.class, "name"); public static final Key> NICKNAMES = new Key<>(new Type>() {}, "nicknames"); - public static final Key REGISTERED = new Key<>(Long.class, "registered"); + public static final Key REGISTERED = CommonKeys.REGISTERED; public static final Key KICK_COUNT = new Key<>(Integer.class, "kick_count"); public static final Key> GEO_INFO = new Key<>(new Type>() {}, "geo_info"); - public static final Key ACTIVE_SESSION = new Key(Session.class, "active_session"); - public static final Key> SESSIONS = new Key<>(new Type>() {}, "sessions"); - public static final Key WORLD_TIMES = new Key<>(WorldTimes.class, "world_times"); + public static final Key ACTIVE_SESSION = new Key<>(Session.class, "active_session"); + public static final Key> SESSIONS = CommonKeys.SESSIONS; + public static final Key WORLD_TIMES = CommonKeys.WORLD_TIMES; - public static final Key> PLAYER_KILLS = new Key<>(new Type>() {}, "player_kills"); - public static final Key PLAYER_KILL_COUNT = new Key<>(Integer.class, "player_kill_count"); - public static final Key MOB_KILL_COUNT = new Key<>(Integer.class, "mob_kill_count"); - public static final Key DEATH_COUNT = new Key<>(Integer.class, "death_count"); + public static final Key> PLAYER_KILLS = CommonKeys.PLAYER_KILLS; + public static final Key PLAYER_KILL_COUNT = CommonKeys.PLAYER_KILL_COUNT; + public static final Key MOB_KILL_COUNT = CommonKeys.MOB_KILL_COUNT; + public static final Key DEATH_COUNT = CommonKeys.DEATH_COUNT; public static final Key PER_SERVER = new Key<>(PerServerData.class, "per_server_data"); - public static final Key LAST_SEEN = new Key<>(Long.class, "last_seen"); + public static final Key LAST_SEEN = CommonKeys.LAST_SEEN; - public static final Key BANNED = new Key<>(Boolean.class, "banned"); - public static final Key OPERATOR = new Key<>(Boolean.class, "operator"); + public static final Key BANNED = CommonKeys.BANNED; + public static final Key OPERATOR = CommonKeys.OPERATOR; } \ No newline at end of file diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java index d7a45071b..e28bd95fc 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/SessionsMutator.java @@ -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 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 sessions) { this.sessions = sessions; } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java index 8a95df502..63a828262 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java @@ -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 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); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/InspectPage.java b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/InspectPage.java index 4f5becc7c..e80d77532 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/InspectPage.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/webserver/pages/parsing/InspectPage.java @@ -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); diff --git a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/ServerAccordion.java b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/ServerAccordion.java index 8505faa2f..b08b6c832 100644 --- a/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/ServerAccordion.java +++ b/Plan/src/main/java/com/djrapitops/plan/utilities/html/structure/ServerAccordion.java @@ -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 serverNames; private PerServerData perServer; - public ServerAccordion(PlayerContainer container, Map worldTimesPerServer, Map serverNames) { + public ServerAccordion(PlayerContainer container, Map 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 sessions = container.getValue(PlayerKeys.SESSIONS).orElse(new ArrayList<>()); + List 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());