Added Ping to PlayerContainer and PerServerContainers

This commit is contained in:
Rsl1122 2018-07-16 10:44:57 +03:00
parent 1fbd1fb943
commit c9b4cae8e6
5 changed files with 60 additions and 15 deletions

View File

@ -1,5 +1,6 @@
package com.djrapitops.plan.data.store.keys; 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.PlayerDeath;
import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.PlayerKill;
import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.container.Session;
@ -28,6 +29,7 @@ public class CommonKeys {
public static final Key<UUID> SERVER_UUID = new Key<>(UUID.class, "server_uuid"); public static final Key<UUID> SERVER_UUID = new Key<>(UUID.class, "server_uuid");
public static final Key<String> NAME = new Key<>(String.class, "name"); public static final Key<String> NAME = new Key<>(String.class, "name");
public static final PlaceholderKey<Long> REGISTERED = new PlaceholderKey<>(Long.class, "registered"); public static final PlaceholderKey<Long> REGISTERED = new PlaceholderKey<>(Long.class, "registered");
public static final Key<List<Ping>> PING = new Key<>(new Type<List<Ping>>() {}, "ping");
public static final Key<List<Session>> SESSIONS = new Key<>(new Type<List<Session>>() {}, "sessions"); 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<WorldTimes> WORLD_TIMES = new Key<>(WorldTimes.class, "world_times");

View File

@ -1,5 +1,6 @@
package com.djrapitops.plan.data.store.keys; 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.PlayerDeath;
import com.djrapitops.plan.data.container.PlayerKill; import com.djrapitops.plan.data.container.PlayerKill;
import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.data.container.Session;
@ -23,6 +24,7 @@ public class PerServerKeys {
} }
public static final Key<Long> REGISTERED = CommonKeys.REGISTERED; public static final Key<Long> REGISTERED = CommonKeys.REGISTERED;
public static final Key<List<Ping>> PING = CommonKeys.PING;
public static final Key<List<Session>> SESSIONS = CommonKeys.SESSIONS; public static final Key<List<Session>> SESSIONS = CommonKeys.SESSIONS;
public static final Key<WorldTimes> WORLD_TIMES = CommonKeys.WORLD_TIMES; public static final Key<WorldTimes> WORLD_TIMES = CommonKeys.WORLD_TIMES;

View File

@ -1,9 +1,6 @@
package com.djrapitops.plan.data.store.keys; package com.djrapitops.plan.data.store.keys;
import com.djrapitops.plan.data.container.GeoInfo; import com.djrapitops.plan.data.container.*;
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.store.Key; import com.djrapitops.plan.data.store.Key;
import com.djrapitops.plan.data.store.PlaceholderKey; import com.djrapitops.plan.data.store.PlaceholderKey;
import com.djrapitops.plan.data.store.Type; import com.djrapitops.plan.data.store.Type;
@ -35,6 +32,7 @@ public class PlayerKeys {
public static final Key<Integer> KICK_COUNT = new Key<>(Integer.class, "kick_count"); 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<List<GeoInfo>> GEO_INFO = new Key<>(new Type<List<GeoInfo>>() {}, "geo_info");
public static final Key<List<Ping>> PING = CommonKeys.PING;
public static final Key<Session> ACTIVE_SESSION = new Key<>(Session.class, "active_session"); 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<List<Session>> SESSIONS = CommonKeys.SESSIONS;

View File

@ -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<Ping> pings;
public PingMutator(List<Ping> pings) {
this.pings = pings;
}
public static PingMutator forContainer(DataContainer container) {
return new PingMutator(container.getValue(CommonKeys.PING).orElse(new ArrayList<>()));
}
}

View File

@ -1,10 +1,7 @@
package com.djrapitops.plan.system.database.databases.sql.operation; package com.djrapitops.plan.system.database.databases.sql.operation;
import com.djrapitops.plan.data.WebUser; import com.djrapitops.plan.data.WebUser;
import com.djrapitops.plan.data.container.GeoInfo; import com.djrapitops.plan.data.container.*;
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.store.containers.*; import com.djrapitops.plan.data.store.containers.*;
import com.djrapitops.plan.data.store.keys.*; import com.djrapitops.plan.data.store.keys.*;
import com.djrapitops.plan.data.store.mutators.PerServerMutator; import com.djrapitops.plan.data.store.mutators.PerServerMutator;
@ -101,6 +98,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
List<UserInfo> serverUserInfo = userInfoTable.getServerUserInfo(serverUUID); List<UserInfo> serverUserInfo = userInfoTable.getServerUserInfo(serverUUID);
Map<UUID, Integer> timesKicked = usersTable.getAllTimesKicked(); Map<UUID, Integer> timesKicked = usersTable.getAllTimesKicked();
Map<UUID, List<GeoInfo>> geoInfo = geoInfoTable.getAllGeoInfo(); Map<UUID, List<GeoInfo>> geoInfo = geoInfoTable.getAllGeoInfo();
Map<UUID, List<Ping>> allPings = pingTable.getAllPings();
Map<UUID, List<Session>> sessions = sessionsTable.getSessionInfoOfServer(serverUUID); Map<UUID, List<Session>> sessions = sessionsTable.getSessionInfoOfServer(serverUUID);
Map<UUID, Map<UUID, List<Session>>> map = new HashMap<>(); Map<UUID, Map<UUID, List<Session>>> map = new HashMap<>();
@ -110,7 +108,7 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
Map<UUID, List<UserInfo>> serverUserInfos = Collections.singletonMap(serverUUID, serverUserInfo); Map<UUID, List<UserInfo>> serverUserInfos = Collections.singletonMap(serverUUID, serverUserInfo);
Map<UUID, Map<UUID, List<Session>>> serverSessions = Collections.singletonMap(serverUUID, sessions); Map<UUID, Map<UUID, List<Session>>> serverSessions = Collections.singletonMap(serverUUID, sessions);
Map<UUID, PerServerContainer> perServerInfo = getPerServerData(serverSessions, serverUserInfos); Map<UUID, PerServerContainer> perServerInfo = getPerServerData(serverSessions, serverUserInfos, allPings);
for (UserInfo userInfo : serverUserInfo) { for (UserInfo userInfo : serverUserInfo) {
PlayerContainer container = new PlayerContainer(); PlayerContainer container = new PlayerContainer();
@ -120,9 +118,10 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
container.putRawData(PlayerKeys.REGISTERED, userInfo.getRegistered()); container.putRawData(PlayerKeys.REGISTERED, userInfo.getRegistered());
container.putRawData(PlayerKeys.NAME, userInfo.getName()); container.putRawData(PlayerKeys.NAME, userInfo.getName());
container.putRawData(PlayerKeys.KICK_COUNT, timesKicked.get(uuid)); 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.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.BANNED, userInfo.isBanned());
container.putRawData(PlayerKeys.OPERATOR, userInfo.isOperator()); container.putRawData(PlayerKeys.OPERATOR, userInfo.isOperator());
@ -163,10 +162,11 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
Map<UUID, UserInfo> users = usersTable.getUsers(); Map<UUID, UserInfo> users = usersTable.getUsers();
Map<UUID, Integer> timesKicked = usersTable.getAllTimesKicked(); Map<UUID, Integer> timesKicked = usersTable.getAllTimesKicked();
Map<UUID, List<GeoInfo>> geoInfo = geoInfoTable.getAllGeoInfo(); Map<UUID, List<GeoInfo>> geoInfo = geoInfoTable.getAllGeoInfo();
Map<UUID, List<Ping>> allPings = pingTable.getAllPings();
Map<UUID, Map<UUID, List<Session>>> sessions = sessionsTable.getAllSessions(false); Map<UUID, Map<UUID, List<Session>>> sessions = sessionsTable.getAllSessions(false);
Map<UUID, List<UserInfo>> allUserInfo = userInfoTable.getAllUserInfo(); Map<UUID, List<UserInfo>> allUserInfo = userInfoTable.getAllUserInfo();
Map<UUID, PerServerContainer> perServerInfo = getPerServerData(sessions, allUserInfo); Map<UUID, PerServerContainer> perServerInfo = getPerServerData(sessions, allUserInfo, allPings);
for (UserInfo userInfo : users.values()) { for (UserInfo userInfo : users.values()) {
PlayerContainer container = new PlayerContainer(); PlayerContainer container = new PlayerContainer();
@ -176,9 +176,10 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
container.putRawData(PlayerKeys.REGISTERED, userInfo.getRegistered()); container.putRawData(PlayerKeys.REGISTERED, userInfo.getRegistered());
container.putRawData(PlayerKeys.NAME, userInfo.getName()); container.putRawData(PlayerKeys.NAME, userInfo.getName());
container.putRawData(PlayerKeys.KICK_COUNT, timesKicked.get(uuid)); 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.NICKNAMES, () -> nicknamesTable.getNicknameInformation(uuid));
container.putSupplier(PlayerKeys.PER_SERVER, () -> perServerInfo.get(uuid)); container.putRawData(PlayerKeys.PER_SERVER, perServerInfo.get(uuid));
container.putSupplier(PlayerKeys.SESSIONS, () -> { container.putSupplier(PlayerKeys.SESSIONS, () -> {
List<Session> playerSessions = PerServerMutator.forContainer(container).flatMapSessions(); List<Session> playerSessions = PerServerMutator.forContainer(container).flatMapSessions();
@ -198,7 +199,11 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
return containers; return containers;
} }
private Map<UUID, PerServerContainer> getPerServerData(Map<UUID, Map<UUID, List<Session>>> sessions, Map<UUID, List<UserInfo>> allUserInfo) { private Map<UUID, PerServerContainer> getPerServerData(
Map<UUID, Map<UUID, List<Session>>> sessions,
Map<UUID, List<UserInfo>> allUserInfo,
Map<UUID, List<Ping>> allPings
) {
Map<UUID, PerServerContainer> perServerContainers = new HashMap<>(); Map<UUID, PerServerContainer> perServerContainers = new HashMap<>();
for (Map.Entry<UUID, List<UserInfo>> entry : allUserInfo.entrySet()) { for (Map.Entry<UUID, List<UserInfo>> entry : allUserInfo.entrySet()) {
@ -245,6 +250,23 @@ public class SQLFetchOps extends SQLOps implements FetchOperations {
} }
} }
for (Map.Entry<UUID, List<Ping>> 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; return perServerContainers;
} }