diff --git a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java index c9675e1af..857578059 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/container/Session.java @@ -4,7 +4,6 @@ import com.djrapitops.plan.data.store.containers.DataContainer; import com.djrapitops.plan.data.store.keys.SessionKeys; import com.djrapitops.plan.data.store.objects.DateHolder; import com.djrapitops.plan.data.time.WorldTimes; -import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.settings.WorldAliasSettings; import com.djrapitops.plan.utilities.formatting.Formatter; @@ -30,11 +29,12 @@ public class Session extends DataContainer implements DateHolder { * Creates a new session. * * @param uuid UUID of the Player. + * @param serverUUID UUID of the server. * @param sessionStart Epoch ms the session started. * @param world Starting world. * @param gm Starting GameMode. */ - public Session(UUID uuid, long sessionStart, String world, String gm) { + public Session(UUID uuid, UUID serverUUID, long sessionStart, String world, String gm) { this.sessionStart = sessionStart; worldTimes = new WorldTimes(world, gm, sessionStart); playerKills = new ArrayList<>(); @@ -44,6 +44,7 @@ public class Session extends DataContainer implements DateHolder { afkTime = 0; putRawData(SessionKeys.UUID, uuid); + putRawData(SessionKeys.SERVER_UUID, serverUUID); putSupplier(SessionKeys.START, this::getSessionStart); putSupplier(SessionKeys.WORLD_TIMES, this::getWorldTimes); putSupplier(SessionKeys.PLAYER_KILLS, this::getPlayerKills); @@ -56,7 +57,6 @@ public class Session extends DataContainer implements DateHolder { putSupplier(SessionKeys.LENGTH, () -> getValue(SessionKeys.END).orElse(System.currentTimeMillis()) - getUnsafe(SessionKeys.START)); putSupplier(SessionKeys.ACTIVE_TIME, () -> getUnsafe(SessionKeys.LENGTH) - getUnsafe(SessionKeys.AFK_TIME)); - putSupplier(SessionKeys.SERVER_UUID, ServerInfo::getServerUUID_Old); putSupplier(SessionKeys.LONGEST_WORLD_PLAYED, this::getLongestWorldPlayed); } diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java index c0a96a425..d71687d1f 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bukkit/PlayerOnlineListener.java @@ -2,6 +2,7 @@ package com.djrapitops.plan.system.listeners.bukkit; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.system.cache.SessionCache; +import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.Processors; import com.djrapitops.plan.system.settings.Settings; @@ -35,6 +36,7 @@ public class PlayerOnlineListener implements Listener { private final PlanConfig config; private final Processors processors; private final Processing processing; + private final ServerInfo serverInfo; private final SessionCache sessionCache; private final ErrorHandler errorHandler; private final RunnableFactory runnableFactory; @@ -48,6 +50,7 @@ public class PlayerOnlineListener implements Listener { PlanConfig config, Processors processors, Processing processing, + ServerInfo serverInfo, SessionCache sessionCache, RunnableFactory runnableFactory, ErrorHandler errorHandler @@ -55,6 +58,7 @@ public class PlayerOnlineListener implements Listener { this.config = config; this.processors = processors; this.processing = processing; + this.serverInfo = serverInfo; this.sessionCache = sessionCache; this.runnableFactory = runnableFactory; this.errorHandler = errorHandler; @@ -120,7 +124,7 @@ public class PlayerOnlineListener implements Listener { String playerName = player.getName(); String displayName = player.getDisplayName(); - sessionCache.cacheSession(uuid, new Session(uuid, time, world, gm)); + sessionCache.cacheSession(uuid, new Session(uuid, serverInfo.getServerUUID(), time, world, gm)); boolean gatheringGeolocations = config.isTrue(Settings.DATA_GEOLOCATIONS); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java index 35dce0c44..17e8b0bb1 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/bungee/PlayerOnlineListener.java @@ -66,7 +66,7 @@ public class PlayerOnlineListener implements Listener { InetAddress address = player.getAddress().getAddress(); long time = System.currentTimeMillis(); - sessionCache.cacheSession(uuid, new Session(uuid, time, "", "")); + sessionCache.cacheSession(uuid, new Session(uuid, serverInfo.getServerUUID(), time, "", "")); boolean gatheringGeolocations = config.isTrue(Settings.DATA_GEOLOCATIONS); @@ -102,7 +102,7 @@ public class PlayerOnlineListener implements Listener { long time = System.currentTimeMillis(); // Replaces the current session in the cache. - sessionCache.cacheSession(uuid, new Session(uuid, time, "", "")); + sessionCache.cacheSession(uuid, new Session(uuid, serverInfo.getServerUUID(), time, "", "")); processing.submit(processors.info().playerPageUpdateProcessor(uuid)); } catch (Exception e) { errorHandler.log(L.WARN, this.getClass(), e); diff --git a/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java b/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java index b999e9f46..c6da90701 100644 --- a/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java +++ b/Plan/src/main/java/com/djrapitops/plan/system/listeners/sponge/SpongePlayerListener.java @@ -2,6 +2,7 @@ package com.djrapitops.plan.system.listeners.sponge; import com.djrapitops.plan.data.container.Session; import com.djrapitops.plan.system.cache.SessionCache; +import com.djrapitops.plan.system.info.server.ServerInfo; import com.djrapitops.plan.system.processing.Processing; import com.djrapitops.plan.system.processing.processors.Processors; import com.djrapitops.plan.system.settings.Settings; @@ -36,6 +37,7 @@ public class SpongePlayerListener { private final PlanConfig config; private final Processors processors; private final Processing processing; + private final ServerInfo serverInfo; private SessionCache sessionCache; private RunnableFactory runnableFactory; private ErrorHandler errorHandler; @@ -45,6 +47,7 @@ public class SpongePlayerListener { PlanConfig config, Processors processors, Processing processing, + ServerInfo serverInfo, SessionCache sessionCache, RunnableFactory runnableFactory, ErrorHandler errorHandler @@ -52,6 +55,7 @@ public class SpongePlayerListener { this.config = config; this.processors = processors; this.processing = processing; + this.serverInfo = serverInfo; this.sessionCache = sessionCache; this.runnableFactory = runnableFactory; this.errorHandler = errorHandler; @@ -121,7 +125,7 @@ public class SpongePlayerListener { String playerName = player.getName(); String displayName = player.getDisplayNameData().displayName().get().toPlain(); - sessionCache.cacheSession(uuid, new Session(uuid, time, world, gm)); + sessionCache.cacheSession(uuid, new Session(uuid, serverInfo.getServerUUID(), time, world, gm)); boolean gatheringGeolocations = config.isTrue(Settings.DATA_GEOLOCATIONS); diff --git a/Plan/src/test/java/com/djrapitops/plan/data/container/SessionTest.java b/Plan/src/test/java/com/djrapitops/plan/data/container/SessionTest.java index d58898680..37870eed7 100644 --- a/Plan/src/test/java/com/djrapitops/plan/data/container/SessionTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/data/container/SessionTest.java @@ -7,6 +7,7 @@ import utilities.TestConstants; import java.util.List; import java.util.Optional; +import java.util.UUID; import static org.junit.Assert.*; @@ -17,10 +18,12 @@ import static org.junit.Assert.*; */ public class SessionTest { + private final UUID serverUUID = TestConstants.SERVER_UUID; + @Test public void safeStartKeyConstructor() { for (int i = 0; i < 10000; i++) { - Session session = new Session(null, System.currentTimeMillis(), null, null); + Session session = new Session(null, serverUUID, System.currentTimeMillis(), null, null); // Should not throw session.getUnsafe(SessionKeys.START); @@ -40,7 +43,7 @@ public class SessionTest { @Test public void killsAreAdded() { - Session session = new Session(null, System.currentTimeMillis(), "", ""); + Session session = new Session(null, serverUUID, System.currentTimeMillis(), "", ""); Optional> beforeOptional = session.getValue(SessionKeys.PLAYER_KILLS); assertTrue(beforeOptional.isPresent()); @@ -59,7 +62,7 @@ public class SessionTest { @Test public void killsAreAdded2() { - Session session = new Session(null, System.currentTimeMillis(), "", ""); + Session session = new Session(null, serverUUID, System.currentTimeMillis(), "", ""); session.playerKilled(new PlayerKill(TestConstants.PLAYER_TWO_UUID, "Weapon", System.currentTimeMillis())); @@ -73,7 +76,7 @@ public class SessionTest { @Test public void worldTimesWorks() { long time = System.currentTimeMillis(); - Session session = new Session(null, time, "One", "Survival"); + Session session = new Session(null, serverUUID, time, "One", "Survival"); session.changeState("Two", "Three", time + 5L); Optional optional = session.getValue(SessionKeys.WORLD_TIMES); diff --git a/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java b/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java index 54a6ce57a..1a27c5f90 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/system/cache/SessionCacheTest.java @@ -23,6 +23,7 @@ public class SessionCacheTest { private SessionCache sessionCache; private Session session; private final UUID uuid = TestConstants.PLAYER_ONE_UUID; + private final UUID serverUUID = TestConstants.SERVER_UUID; private Database database; // TODO @@ -35,7 +36,7 @@ public class SessionCacheTest { @Before public void setUp() { sessionCache = new SessionCache(database); - session = new Session(uuid, 12345L, "World1", "SURVIVAL"); + session = new Session(uuid, serverUUID, 12345L, "World1", "SURVIVAL"); sessionCache.cacheSession(uuid, session); } diff --git a/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java b/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java index 1b7ce2b33..6303fdf94 100644 --- a/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java +++ b/Plan/src/test/java/com/djrapitops/plan/system/database/databases/SQLiteTest.java @@ -60,6 +60,8 @@ public class SQLiteTest { @Rule public Timeout globalTimeout = Timeout.seconds(5); + private final UUID serverUUID = TestConstants.SERVER_UUID; + @BeforeClass public static void setUpClass() throws Exception { System.out.println("--- Test Class Setup ---"); @@ -340,7 +342,7 @@ public class SQLiteTest { saveTwoWorlds(); saveUserOne(); saveUserTwo(); - Session session = new Session(TestConstants.PLAYER_ONE_UUID, 12345L, "", ""); + Session session = new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, 12345L, "", ""); session.endSession(22345L); session.setWorldTimes(createWorldTimes()); session.setPlayerKills(createKills()); @@ -371,7 +373,7 @@ public class SQLiteTest { saveUserOne(); saveUserTwo(); - Session session = new Session(TestConstants.PLAYER_ONE_UUID, 12345L, "", ""); + Session session = new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, 12345L, "", ""); session.endSession(22345L); session.setWorldTimes(createWorldTimes()); session.setPlayerKills(createKills()); @@ -535,7 +537,7 @@ public class SQLiteTest { userInfoTable.registerUserInfo(playerUUID, 223456789L); saveTwoWorlds(); - Session session = new Session(TestConstants.PLAYER_ONE_UUID, 12345L, "", ""); + Session session = new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, 12345L, "", ""); session.endSession(22345L); session.setWorldTimes(createWorldTimes()); session.setPlayerKills(createKills()); @@ -601,7 +603,7 @@ public class SQLiteTest { userInfoTable.registerUserInfo(playerUUID, 223456789L); saveTwoWorlds(database); - Session session = new Session(TestConstants.PLAYER_ONE_UUID, 12345L, "", ""); + Session session = new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, 12345L, "", ""); session.endSession(22345L); session.setWorldTimes(createWorldTimes()); session.setPlayerKills(createKills()); @@ -695,7 +697,7 @@ public class SQLiteTest { saveUserOne(); saveUserTwo(); - Session session = new Session(TestConstants.PLAYER_ONE_UUID, 12345L, "", ""); + Session session = new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, 12345L, "", ""); session.endSession(22345L); session.setWorldTimes(createWorldTimes()); session.setPlayerKills(createKills()); @@ -934,7 +936,7 @@ public class SQLiteTest { assertTrue(container.supports(PlayerKeys.PLAYER_KILL_COUNT)); assertFalse(container.supports(PlayerKeys.ACTIVE_SESSION)); - container.putRawData(PlayerKeys.ACTIVE_SESSION, new Session(TestConstants.PLAYER_ONE_UUID, System.currentTimeMillis(), "TestWorld", "SURVIVAL")); + container.putRawData(PlayerKeys.ACTIVE_SESSION, new Session(TestConstants.PLAYER_ONE_UUID, serverUUID, System.currentTimeMillis(), "TestWorld", "SURVIVAL")); assertTrue(container.supports(PlayerKeys.ACTIVE_SESSION)); long end = System.nanoTime();