mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2025-02-10 17:31:36 +01:00
[Debt] Removed getServerUUID usage in Session
This commit is contained in:
parent
b80198ef51
commit
f398c2a2c2
@ -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);
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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<List<PlayerKill>> 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<WorldTimes> optional = session.getValue(SessionKeys.WORLD_TIMES);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user