Added ACTIVE_SESSION to Player placeholders

Playtime was not being updated live for the player placeholders because
the Active session was not added in the PlayerContainer before
calculations.

- Added the active session (if present) to the placeholders
- Updated session state when it is fetched from the cache (world time)

Affects issues:
- Close #1209
This commit is contained in:
Rsl1122 2019-11-07 12:55:57 +02:00
parent 97094a9e03
commit f641c44bf2
3 changed files with 12 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import com.djrapitops.plan.delivery.domain.mutators.PlayerVersusMutator;
import com.djrapitops.plan.delivery.domain.mutators.SessionsMutator;
import com.djrapitops.plan.delivery.formatting.Formatter;
import com.djrapitops.plan.delivery.formatting.Formatters;
import com.djrapitops.plan.gathering.cache.SessionCache;
import com.djrapitops.plan.identification.ServerInfo;
import com.djrapitops.plan.storage.database.DBSystem;
import com.djrapitops.plan.storage.database.queries.containers.ContainerFetchQueries;
@ -161,6 +162,8 @@ public class PlayerPlaceHolder extends AbstractPlanPlaceHolder {
// Checkstyle.ON: CyclomaticComplexity
private PlayerContainer getPlayer(UUID playerUUID) {
return dbSystem.getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(playerUUID));
PlayerContainer player = dbSystem.getDatabase().query(ContainerFetchQueries.fetchPlayerContainer(playerUUID));
SessionCache.getCachedSession(playerUUID).ifPresent(session -> player.putRawData(PlayerKeys.ACTIVE_SESSION, session));
return player;
}
}

View File

@ -49,9 +49,7 @@ public class SessionCache {
}
public static void refreshActiveSessionsState() {
for (Session session : ACTIVE_SESSIONS.values()) {
session.getValue(SessionKeys.WORLD_TIMES).ifPresent(worldTimes -> worldTimes.updateState(System.currentTimeMillis()));
}
ACTIVE_SESSIONS.values().forEach(Session::updateState);
}
/**
@ -61,7 +59,9 @@ public class SessionCache {
* @return Optional with the session inside it if found.
*/
public static Optional<Session> getCachedSession(UUID playerUUID) {
return Optional.ofNullable(ACTIVE_SESSIONS.get(playerUUID));
Optional<Session> found = Optional.ofNullable(ACTIVE_SESSIONS.get(playerUUID));
found.ifPresent(Session::updateState);
return found;
}
/**

View File

@ -254,4 +254,8 @@ public class Session extends DynamicDataContainer implements DateHolder {
", afkTime=" + afkTime +
'}';
}
public void updateState() {
worldTimes.updateState(System.currentTimeMillis());
}
}