diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/ContainerFetchQueries.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/ContainerFetchQueries.java index 408ec21ae..289ebb418 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/ContainerFetchQueries.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/ContainerFetchQueries.java @@ -17,9 +17,11 @@ package com.djrapitops.plan.db.sql.queries; import com.djrapitops.plan.data.store.containers.NetworkContainer; +import com.djrapitops.plan.data.store.containers.PlayerContainer; import com.djrapitops.plan.data.store.containers.ServerContainer; import com.djrapitops.plan.db.access.Query; import com.djrapitops.plan.db.sql.queries.containers.NetworkContainerQuery; +import com.djrapitops.plan.db.sql.queries.containers.PlayerContainerQuery; import com.djrapitops.plan.db.sql.queries.containers.ServerContainerQuery; import java.util.UUID; @@ -39,7 +41,7 @@ public class ContainerFetchQueries { * Used to get a NetworkContainer, some limitations apply to values returned by DataContainer keys. * * @return a new NetworkContainer. - * @see com.djrapitops.plan.db.sql.queries.containers.NetworkContainerQuery + * @see NetworkContainerQuery */ public static Query fetchNetworkContainer() { return new NetworkContainerQuery(); @@ -47,14 +49,26 @@ public class ContainerFetchQueries { /** * Used to get a ServerContainer, some limitations apply to values returned by DataContainer keys. - *

* * @param serverUUID UUID of the Server. * @return a new ServerContainer. - * @see com.djrapitops.plan.db.sql.queries.containers.ServerContainerQuery + * @see ServerContainerQuery */ - public static Query getServerContainer(UUID serverUUID) { + public static Query fetchServerContainer(UUID serverUUID) { return new ServerContainerQuery(serverUUID); } + /** + * Used to get a PlayerContainer of a specific player. + *

+ * Blocking methods are not called until DataContainer getter methods are called. + * + * @param playerUUID UUID of the player. + * @return a new PlayerContainer. + * @see PlayerContainerQuery + */ + public static Query fetchPlayerContainer(UUID playerUUID) { + return new PlayerContainerQuery(playerUUID); + } + } \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/containers/NetworkContainerQuery.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/containers/NetworkContainerQuery.java index 654a190b0..96655181e 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/containers/NetworkContainerQuery.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/containers/NetworkContainerQuery.java @@ -55,7 +55,7 @@ public class NetworkContainerQuery implements Query { } UUID serverUUID = proxyInformation.get().getUuid(); - ServerContainer container = db.query(ContainerFetchQueries.getServerContainer(serverUUID)); + ServerContainer container = db.query(ContainerFetchQueries.fetchServerContainer(serverUUID)); container.putCachingSupplier(ServerKeys.PLAYERS, db.fetch()::getAllPlayerContainers); container.putCachingSupplier(ServerKeys.TPS, db.getTpsTable()::getNetworkOnlineData); container.putSupplier(ServerKeys.WORLD_TIMES, null); // Additional Session information not supported diff --git a/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/containers/PlayerContainerQuery.java b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/containers/PlayerContainerQuery.java new file mode 100644 index 000000000..50c73017f --- /dev/null +++ b/Plan/common/src/main/java/com/djrapitops/plan/db/sql/queries/containers/PlayerContainerQuery.java @@ -0,0 +1,130 @@ +/* + * This file is part of Player Analytics (Plan). + * + * Plan is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License v3 as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Plan is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with Plan. If not, see . + */ +package com.djrapitops.plan.db.sql.queries.containers; + +import com.djrapitops.plan.data.container.Session; +import com.djrapitops.plan.data.container.UserInfo; +import com.djrapitops.plan.data.store.containers.DataContainer; +import com.djrapitops.plan.data.store.containers.PerServerContainer; +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.keys.SessionKeys; +import com.djrapitops.plan.data.store.mutators.PerServerMutator; +import com.djrapitops.plan.data.store.mutators.SessionsMutator; +import com.djrapitops.plan.data.time.WorldTimes; +import com.djrapitops.plan.db.SQLDB; +import com.djrapitops.plan.db.access.Query; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +/** + * Used to get a PlayerContainer of a specific player. + *

+ * Blocking methods are not called until DataContainer getter methods are called. + * + * @author Rsl1122 + */ +public class PlayerContainerQuery implements Query { + + private final UUID uuid; + + public PlayerContainerQuery(UUID uuid) { + this.uuid = uuid; + } + + @Override + public PlayerContainer executeQuery(SQLDB db) { + PlayerContainer container = new PlayerContainer(); + container.putRawData(PlayerKeys.UUID, uuid); + + container.putAll(db.getUsersTable().getUserInformation(uuid)); + container.putCachingSupplier(PlayerKeys.GEO_INFO, () -> db.getGeoInfoTable().getGeoInfo(uuid)); + container.putCachingSupplier(PlayerKeys.PING, () -> db.getPingTable().getPing(uuid)); + container.putCachingSupplier(PlayerKeys.NICKNAMES, () -> db.getNicknamesTable().getNicknameInformation(uuid)); + container.putCachingSupplier(PlayerKeys.PER_SERVER, () -> getPerServerData(db)); + + 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.putCachingSupplier(PlayerKeys.SESSIONS, () -> { + List sessions = new PerServerMutator(container.getUnsafe(PlayerKeys.PER_SERVER)).flatMapSessions(); + container.getValue(PlayerKeys.ACTIVE_SESSION).ifPresent(sessions::add); + return sessions; + } + ); + container.putCachingSupplier(PlayerKeys.WORLD_TIMES, () -> + { + 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<>()))) + ); + return worldTimes; + }); + + container.putSupplier(PlayerKeys.LAST_SEEN, () -> SessionsMutator.forContainer(container).toLastSeen()); + + 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.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount()); + container.putSupplier(PlayerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount()); + + return container; + } + + private PerServerContainer getPerServerData(SQLDB db) { + PerServerContainer perServerContainer = new PerServerContainer(); + + Map allUserInfo = db.getUserInfoTable().getAllUserInfo(uuid); + for (Map.Entry entry : allUserInfo.entrySet()) { + UUID serverUUID = entry.getKey(); + UserInfo info = entry.getValue(); + + DataContainer container = perServerContainer.getOrDefault(serverUUID, new DataContainer()); + container.putRawData(PlayerKeys.REGISTERED, info.getRegistered()); + container.putRawData(PlayerKeys.BANNED, info.isBanned()); + container.putRawData(PlayerKeys.OPERATOR, info.isOperator()); + perServerContainer.put(serverUUID, container); + } + + Map> sessions = db.getSessionsTable().getSessions(uuid); + for (Map.Entry> entry : sessions.entrySet()) { + UUID serverUUID = entry.getKey(); + List serverSessions = entry.getValue(); + + DataContainer container = perServerContainer.getOrDefault(serverUUID, new DataContainer()); + container.putRawData(PerServerKeys.SESSIONS, serverSessions); + + container.putSupplier(PerServerKeys.LAST_SEEN, () -> SessionsMutator.forContainer(container).toLastSeen()); + + container.putSupplier(PerServerKeys.WORLD_TIMES, () -> SessionsMutator.forContainer(container).toTotalWorldTimes()); + container.putSupplier(PerServerKeys.PLAYER_KILLS, () -> SessionsMutator.forContainer(container).toPlayerKillList()); + container.putSupplier(PerServerKeys.PLAYER_DEATHS, () -> SessionsMutator.forContainer(container).toPlayerDeathList()); + container.putSupplier(PerServerKeys.PLAYER_KILL_COUNT, () -> container.getUnsafe(PerServerKeys.PLAYER_KILLS).size()); + container.putSupplier(PerServerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount()); + container.putSupplier(PerServerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount()); + + perServerContainer.put(serverUUID, container); + } + + return perServerContainer; + } +} \ No newline at end of file diff --git a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java index 87d06c26b..879a69546 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/system/database/databases/sql/operation/SQLFetchOps.java @@ -50,7 +50,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { @Override public ServerContainer getServerContainer(UUID serverUUID) { - return db.query(ContainerFetchQueries.getServerContainer(serverUUID)); + return db.query(ContainerFetchQueries.fetchServerContainer(serverUUID)); } @Override @@ -235,80 +235,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations { @Override public PlayerContainer getPlayerContainer(UUID uuid) { - PlayerContainer container = new PlayerContainer(); - container.putRawData(PlayerKeys.UUID, uuid); - - container.putAll(usersTable.getUserInformation(uuid)); - container.putCachingSupplier(PlayerKeys.GEO_INFO, () -> geoInfoTable.getGeoInfo(uuid)); - container.putCachingSupplier(PlayerKeys.PING, () -> pingTable.getPing(uuid)); - container.putCachingSupplier(PlayerKeys.NICKNAMES, () -> nicknamesTable.getNicknameInformation(uuid)); - container.putCachingSupplier(PlayerKeys.PER_SERVER, () -> getPerServerData(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.putCachingSupplier(PlayerKeys.SESSIONS, () -> { - List sessions = new PerServerMutator(container.getUnsafe(PlayerKeys.PER_SERVER)).flatMapSessions(); - container.getValue(PlayerKeys.ACTIVE_SESSION).ifPresent(sessions::add); - return sessions; - } - ); - container.putCachingSupplier(PlayerKeys.WORLD_TIMES, () -> - { - 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<>()))) - ); - return worldTimes; - }); - - container.putSupplier(PlayerKeys.LAST_SEEN, () -> SessionsMutator.forContainer(container).toLastSeen()); - - 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.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount()); - container.putSupplier(PlayerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount()); - - return container; - } - - private PerServerContainer getPerServerData(UUID uuid) { - PerServerContainer perServerContainer = new PerServerContainer(); - - Map allUserInfo = userInfoTable.getAllUserInfo(uuid); - for (Map.Entry entry : allUserInfo.entrySet()) { - UUID serverUUID = entry.getKey(); - UserInfo info = entry.getValue(); - - DataContainer container = perServerContainer.getOrDefault(serverUUID, new DataContainer()); - container.putRawData(PlayerKeys.REGISTERED, info.getRegistered()); - container.putRawData(PlayerKeys.BANNED, info.isBanned()); - container.putRawData(PlayerKeys.OPERATOR, info.isOperator()); - perServerContainer.put(serverUUID, container); - } - - Map> sessions = sessionsTable.getSessions(uuid); - for (Map.Entry> entry : sessions.entrySet()) { - UUID serverUUID = entry.getKey(); - List serverSessions = entry.getValue(); - - DataContainer container = perServerContainer.getOrDefault(serverUUID, new DataContainer()); - container.putRawData(PerServerKeys.SESSIONS, serverSessions); - - container.putSupplier(PerServerKeys.LAST_SEEN, () -> SessionsMutator.forContainer(container).toLastSeen()); - - container.putSupplier(PerServerKeys.WORLD_TIMES, () -> SessionsMutator.forContainer(container).toTotalWorldTimes()); - container.putSupplier(PerServerKeys.PLAYER_KILLS, () -> SessionsMutator.forContainer(container).toPlayerKillList()); - container.putSupplier(PerServerKeys.PLAYER_DEATHS, () -> SessionsMutator.forContainer(container).toPlayerDeathList()); - container.putSupplier(PerServerKeys.PLAYER_KILL_COUNT, () -> container.getUnsafe(PerServerKeys.PLAYER_KILLS).size()); - container.putSupplier(PerServerKeys.MOB_KILL_COUNT, () -> SessionsMutator.forContainer(container).toMobKillCount()); - container.putSupplier(PerServerKeys.DEATH_COUNT, () -> SessionsMutator.forContainer(container).toDeathCount()); - - perServerContainer.put(serverUUID, container); - } - - return perServerContainer; + return db.query(ContainerFetchQueries.fetchPlayerContainer(uuid)); } @Override