Implemented session playtime to Query API.

CommonQueries#fetchCurrentSessionPlaytime,
requires Capability#QUERY_API_ACTIVE_SESSION_PLAYTIME

API version increased to v5.1-R0.3

Affects issues:
- #1384
This commit is contained in:
Risto Lahtela 2020-05-03 18:32:55 +03:00
parent 4cca2251a8
commit dff96b1728
4 changed files with 23 additions and 1 deletions

View File

@ -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')

View File

@ -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}
*/

View File

@ -43,6 +43,16 @@ public interface CommonQueries {
*/
long fetchPlaytime(UUID playerUUID, UUID serverUUID, long after, long before);
/**
* Get playtime of current online session.
* <p>
* 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.
*

View File

@ -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));