diff --git a/Plan/api/build.gradle b/Plan/api/build.gradle index cd70e6ed6..0dad51d1a 100644 --- a/Plan/api/build.gradle +++ b/Plan/api/build.gradle @@ -7,7 +7,7 @@ dependencies { compileOnly "com.google.code.gson:gson:$gsonVersion" } -ext.apiVersion = '5.1-R0.2' +ext.apiVersion = '5.1-R0.3' bintray { user = System.getenv('BINTRAY_USER') diff --git a/Plan/api/src/main/java/com/djrapitops/plan/capability/Capability.java b/Plan/api/src/main/java/com/djrapitops/plan/capability/Capability.java index b1ac9bf8c..b3e4ede2e 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/capability/Capability.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/capability/Capability.java @@ -17,6 +17,7 @@ package com.djrapitops.plan.capability; import java.util.Optional; +import java.util.UUID; /** * List of different capabilities current version provides. @@ -59,6 +60,10 @@ enum Capability { * {@link com.djrapitops.plan.query.QueryService} and {@link com.djrapitops.plan.query.CommonQueries} */ QUERY_API, + /** + * {@link com.djrapitops.plan.query.CommonQueries#fetchCurrentSessionPlaytime(UUID)} + */ + QUERY_API_ACTIVE_SESSION_PLAYTIME, /** * {@link com.djrapitops.plan.settings.SettingsService} */ diff --git a/Plan/api/src/main/java/com/djrapitops/plan/query/CommonQueries.java b/Plan/api/src/main/java/com/djrapitops/plan/query/CommonQueries.java index ceb2740b4..1d617384e 100644 --- a/Plan/api/src/main/java/com/djrapitops/plan/query/CommonQueries.java +++ b/Plan/api/src/main/java/com/djrapitops/plan/query/CommonQueries.java @@ -43,6 +43,16 @@ public interface CommonQueries { */ long fetchPlaytime(UUID playerUUID, UUID serverUUID, long after, long before); + /** + * Get playtime of current online session. + *
+ * Requires Capability QUERY_API_ACTIVE_SESSION_PLAYTIME + * + * @param playerUUID UUID of the player. + * @return Milliseconds the player has played during current online session. 0 if player is offline. + */ + long fetchCurrentSessionPlaytime(UUID playerUUID); + /** * Fetch last seen Epoch ms for a player on a server. * diff --git a/Plan/common/src/main/java/com/djrapitops/plan/query/CommonQueriesImplementation.java b/Plan/common/src/main/java/com/djrapitops/plan/query/CommonQueriesImplementation.java index bba7113ce..a45f71ed0 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/query/CommonQueriesImplementation.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/query/CommonQueriesImplementation.java @@ -16,6 +16,8 @@ */ package com.djrapitops.plan.query; +import com.djrapitops.plan.gathering.cache.SessionCache; +import com.djrapitops.plan.gathering.domain.Session; import com.djrapitops.plan.storage.database.DBType; import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.queries.objects.ServerQueries; @@ -42,6 +44,11 @@ public class CommonQueriesImplementation implements CommonQueries { return db.query(SessionQueries.playtimeOfPlayer(after, before, playerUUID)).getOrDefault(serverUUID, 0L); } + @Override + public long fetchCurrentSessionPlaytime(UUID playerUUID) { + return SessionCache.getCachedSession(playerUUID).map(Session::getLength).orElse(0L); + } + @Override public long fetchLastSeen(UUID playerUUID, UUID serverUUID) { return db.query(SessionQueries.lastSeen(playerUUID, serverUUID));