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 7fc6257f8..bdbe87e38 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,5 +1,6 @@ package com.djrapitops.plan.data.store.keys; +import com.djrapitops.plan.data.container.Ping; import com.djrapitops.plan.data.container.PlayerDeath; import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.Session; @@ -28,6 +29,7 @@ public class CommonKeys { public static final Key SERVER_UUID = new Key<>(UUID.class, "server_uuid"); public static final Key NAME = new Key<>(String.class, "name"); public static final PlaceholderKey REGISTERED = new PlaceholderKey<>(Long.class, "registered"); + public static final Key> PING = new Key<>(new Type>() {}, "ping"); public static final Key> SESSIONS = new Key<>(new Type>() {}, "sessions"); public static final Key WORLD_TIMES = new Key<>(WorldTimes.class, "world_times"); 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 index 3327202cb..2fde29d42 100644 --- 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 @@ -1,5 +1,6 @@ package com.djrapitops.plan.data.store.keys; +import com.djrapitops.plan.data.container.Ping; import com.djrapitops.plan.data.container.PlayerDeath; import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.Session; @@ -23,6 +24,7 @@ public class PerServerKeys { } public static final Key REGISTERED = CommonKeys.REGISTERED; + public static final Key> PING = CommonKeys.PING; public static final Key> SESSIONS = CommonKeys.SESSIONS; public static final Key WORLD_TIMES = CommonKeys.WORLD_TIMES; 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 4c8879384..7807fc9f1 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 @@ -1,9 +1,6 @@ package com.djrapitops.plan.data.store.keys; -import com.djrapitops.plan.data.container.GeoInfo; -import com.djrapitops.plan.data.container.PlayerDeath; -import com.djrapitops.plan.data.container.PlayerKill; -import com.djrapitops.plan.data.container.Session; +import com.djrapitops.plan.data.container.*; import com.djrapitops.plan.data.store.Key; import com.djrapitops.plan.data.store.PlaceholderKey; import com.djrapitops.plan.data.store.Type; @@ -35,6 +32,7 @@ public class PlayerKeys { 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> PING = CommonKeys.PING; public static final Key ACTIVE_SESSION = new Key<>(Session.class, "active_session"); public static final Key> SESSIONS = CommonKeys.SESSIONS; diff --git a/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PingMutator.java b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PingMutator.java new file mode 100644 index 000000000..bbb8812ad --- /dev/null +++ b/Plan/src/main/java/com/djrapitops/plan/data/store/mutators/PingMutator.java @@ -0,0 +1,21 @@ +package com.djrapitops.plan.data.store.mutators; + +import com.djrapitops.plan.data.container.Ping; +import com.djrapitops.plan.data.store.containers.DataContainer; +import com.djrapitops.plan.data.store.keys.CommonKeys; + +import java.util.ArrayList; +import java.util.List; + +public class PingMutator { + + private final List pings; + + public PingMutator(List pings) { + this.pings = pings; + } + + public static PingMutator forContainer(DataContainer container) { + return new PingMutator(container.getValue(CommonKeys.PING).orElse(new ArrayList<>())); + } +} 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 9f4d62bf6..76c49c0ef 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 @@ -1,10 +1,7 @@ package com.djrapitops.plan.system.database.databases.sql.operation; import com.djrapitops.plan.data.WebUser; -import com.djrapitops.plan.data.container.GeoInfo; -import com.djrapitops.plan.data.container.Session; -import com.djrapitops.plan.data.container.TPS; -import com.djrapitops.plan.data.container.UserInfo; +import com.djrapitops.plan.data.container.*; import com.djrapitops.plan.data.store.containers.*; import com.djrapitops.plan.data.store.keys.*; import com.djrapitops.plan.data.store.mutators.PerServerMutator; @@ -101,6 +98,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { List serverUserInfo = userInfoTable.getServerUserInfo(serverUUID); Map timesKicked = usersTable.getAllTimesKicked(); Map> geoInfo = geoInfoTable.getAllGeoInfo(); + Map> allPings = pingTable.getAllPings(); Map> sessions = sessionsTable.getSessionInfoOfServer(serverUUID); Map>> map = new HashMap<>(); @@ -110,7 +108,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { Map> serverUserInfos = Collections.singletonMap(serverUUID, serverUserInfo); Map>> serverSessions = Collections.singletonMap(serverUUID, sessions); - Map perServerInfo = getPerServerData(serverSessions, serverUserInfos); + Map perServerInfo = getPerServerData(serverSessions, serverUserInfos, allPings); for (UserInfo userInfo : serverUserInfo) { PlayerContainer container = new PlayerContainer(); @@ -120,9 +118,10 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { container.putRawData(PlayerKeys.REGISTERED, userInfo.getRegistered()); container.putRawData(PlayerKeys.NAME, userInfo.getName()); container.putRawData(PlayerKeys.KICK_COUNT, timesKicked.get(uuid)); - container.putSupplier(PlayerKeys.GEO_INFO, () -> geoInfo.get(uuid)); + container.putRawData(PlayerKeys.GEO_INFO, geoInfo.get(uuid)); + container.putRawData(PlayerKeys.PING, allPings.get(uuid)); container.putSupplier(PlayerKeys.NICKNAMES, () -> nicknamesTable.getNicknameInformation(uuid)); - container.putSupplier(PlayerKeys.PER_SERVER, () -> perServerInfo.get(uuid)); + container.putRawData(PlayerKeys.PER_SERVER, perServerInfo.get(uuid)); container.putRawData(PlayerKeys.BANNED, userInfo.isBanned()); container.putRawData(PlayerKeys.OPERATOR, userInfo.isOperator()); @@ -163,10 +162,11 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { Map users = usersTable.getUsers(); Map timesKicked = usersTable.getAllTimesKicked(); Map> geoInfo = geoInfoTable.getAllGeoInfo(); + Map> allPings = pingTable.getAllPings(); Map>> sessions = sessionsTable.getAllSessions(false); Map> allUserInfo = userInfoTable.getAllUserInfo(); - Map perServerInfo = getPerServerData(sessions, allUserInfo); + Map perServerInfo = getPerServerData(sessions, allUserInfo, allPings); for (UserInfo userInfo : users.values()) { PlayerContainer container = new PlayerContainer(); @@ -176,9 +176,10 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { container.putRawData(PlayerKeys.REGISTERED, userInfo.getRegistered()); container.putRawData(PlayerKeys.NAME, userInfo.getName()); container.putRawData(PlayerKeys.KICK_COUNT, timesKicked.get(uuid)); - container.putSupplier(PlayerKeys.GEO_INFO, () -> geoInfo.get(uuid)); + container.putRawData(PlayerKeys.GEO_INFO, geoInfo.get(uuid)); + container.putRawData(PlayerKeys.PING, allPings.get(uuid)); container.putSupplier(PlayerKeys.NICKNAMES, () -> nicknamesTable.getNicknameInformation(uuid)); - container.putSupplier(PlayerKeys.PER_SERVER, () -> perServerInfo.get(uuid)); + container.putRawData(PlayerKeys.PER_SERVER, perServerInfo.get(uuid)); container.putSupplier(PlayerKeys.SESSIONS, () -> { List playerSessions = PerServerMutator.forContainer(container).flatMapSessions(); @@ -198,7 +199,11 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { return containers; } - private Map getPerServerData(Map>> sessions, Map> allUserInfo) { + private Map getPerServerData( + Map>> sessions, + Map> allUserInfo, + Map> allPings + ) { Map perServerContainers = new HashMap<>(); for (Map.Entry> entry : allUserInfo.entrySet()) { @@ -245,6 +250,23 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { } } + for (Map.Entry> entry : allPings.entrySet()) { + UUID uuid = entry.getKey(); + for (Ping ping : entry.getValue()) { + UUID serverUUID = ping.getServerUUID(); + PerServerContainer perServerContainer = perServerContainers.getOrDefault(uuid, new PerServerContainer()); + DataContainer container = perServerContainer.getOrDefault(serverUUID, new DataContainer()); + + if (!container.supports(PerServerKeys.PING)) { + container.putRawData(PerServerKeys.PING, new ArrayList<>()); + } + container.getUnsafe(PerServerKeys.PING).add(ping); + + perServerContainer.put(serverUUID, container); + perServerContainers.put(uuid, perServerContainer); + } + } + return perServerContainers; }