diff --git a/Plan/common/src/main/java/com/djrapitops/plan/gathering/cache/SessionCache.java b/Plan/common/src/main/java/com/djrapitops/plan/gathering/cache/SessionCache.java index d9afef3a2..1e82a59f1 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/gathering/cache/SessionCache.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/gathering/cache/SessionCache.java @@ -90,10 +90,13 @@ public class SessionCache { * @return Optional: ended session. Recipients of this object should decide if it needs to be saved. */ public Optional endSession(UUID playerUUID, long time, ActiveSession activeSession) { - if (activeSession == null || activeSession.getStart() > time) { + if (activeSession == null) { return Optional.empty(); } ACTIVE_SESSIONS.remove(playerUUID); + if (activeSession.getStart() > time) { + return Optional.empty(); + } return Optional.of(activeSession.toFinishedSession(time)); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerJoinEventConsumer.java b/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerJoinEventConsumer.java index f9c2ed48b..3120b01aa 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerJoinEventConsumer.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerJoinEventConsumer.java @@ -80,12 +80,13 @@ public class PlayerJoinEventConsumer { } public void onJoinGameServer(PlayerJoin join) { + Optional interruptedSession = cacheActiveSession(join); processing.submitCritical(() -> { storeWorldInformation(join); storeGamePlayer(join) .thenRunAsync(() -> { storeJoinAddress(join); - cacheActiveSession(join).ifPresent(this::storeInterruptedSession); + interruptedSession.ifPresent(this::storeInterruptedSession); storeGeolocation(join); storeOperatorStatus(join); storeNickname(join); @@ -96,9 +97,9 @@ public class PlayerJoinEventConsumer { } public void onJoinProxyServer(PlayerJoin join) { + cacheActiveSession(join); processing.submitCritical(() -> storeProxyPlayer(join) .thenRunAsync(() -> { - cacheActiveSession(join); storeGeolocation(join); updatePlayerDataExtensionValues(join); updateExport(join); diff --git a/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerLeaveEventConsumer.java b/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerLeaveEventConsumer.java index fb75536b7..994cce117 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerLeaveEventConsumer.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/gathering/events/PlayerLeaveEventConsumer.java @@ -22,6 +22,7 @@ import com.djrapitops.plan.extension.ExtensionSvc; import com.djrapitops.plan.gathering.cache.JoinAddressCache; import com.djrapitops.plan.gathering.cache.NicknameCache; import com.djrapitops.plan.gathering.cache.SessionCache; +import com.djrapitops.plan.gathering.domain.ActiveSession; import com.djrapitops.plan.gathering.domain.FinishedSession; import com.djrapitops.plan.gathering.domain.event.PlayerLeave; import com.djrapitops.plan.processing.Processing; @@ -67,6 +68,13 @@ public class PlayerLeaveEventConsumer { } public void onLeaveGameServer(PlayerLeave leave) { + Optional activeSession = SessionCache.getCachedSession(leave.getPlayerUUID()); + if (activeSession.isEmpty()) { + // Quit event processed before Join event, delay processing + processing.submitCritical(() -> onLeaveGameServer(leave)); + return; + } + endSession(leave).ifPresent(this::storeFinishedSession); storeBanStatus(leave); updateExport(leave);