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 1d617384e..b66c1b26d 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 @@ -71,4 +71,21 @@ public interface CommonQueries { boolean doesDBHaveTable(String table); boolean doesDBHaveTableColumn(String table, String column); + + /** + * Calculates the activity index for the player at a specific date. + * + * @param playerUUID UUID of the player. + * @param epochMs Epoch millisecond to use for calculation + * @return a double between 0.0 and 5.0. + */ + double fetchActivityIndexOf(UUID playerUUID, long epochMs); + + /** + * Get a String that represents the Activity group for an index. + * + * @param activityIndex a double between 0.0 and 5.0. + * @return Name of the group (in English) that this activityIndex falls within. + */ + String getActivityGroupForIndex(double activityIndex); } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/placeholder/PlayerPlaceHolders.java b/Plan/common/src/main/java/com/djrapitops/plan/placeholder/PlayerPlaceHolders.java index cbffe07b1..3211208b1 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/placeholder/PlayerPlaceHolders.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/placeholder/PlayerPlaceHolders.java @@ -25,6 +25,8 @@ import com.djrapitops.plan.delivery.formatting.Formatter; import com.djrapitops.plan.delivery.formatting.Formatters; import com.djrapitops.plan.identification.Server; import com.djrapitops.plan.identification.ServerInfo; +import com.djrapitops.plan.settings.config.PlanConfig; +import com.djrapitops.plan.settings.config.paths.TimeSettings; import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.queries.objects.ServerQueries; import com.djrapitops.plan.utilities.Predicates; @@ -42,16 +44,19 @@ import static com.djrapitops.plan.utilities.MiscUtils.*; @Singleton public class PlayerPlaceHolders implements Placeholders { + private final PlanConfig config; private final DBSystem dbSystem; private final ServerInfo serverInfo; private final Formatters formatters; @Inject public PlayerPlaceHolders( + PlanConfig config, DBSystem dbSystem, ServerInfo serverInfo, Formatters formatters ) { + this.config = config; this.dbSystem = dbSystem; this.serverInfo = serverInfo; this.formatters = formatters; @@ -209,5 +214,18 @@ public class PlayerPlaceHolders implements Placeholders { .map(Server::getName) .orElse("-") ); + + placeholders.register("player_activity_index", + player -> player.getActivityIndex( + now(), + config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD) + ).getValue() + ); + placeholders.register("player_activity_group", + player -> player.getActivityIndex( + now(), + config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD) + ).getGroup() + ); } } 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 a45f71ed0..041c72089 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,10 +16,14 @@ */ package com.djrapitops.plan.query; +import com.djrapitops.plan.delivery.domain.mutators.ActivityIndex; import com.djrapitops.plan.gathering.cache.SessionCache; import com.djrapitops.plan.gathering.domain.Session; +import com.djrapitops.plan.settings.config.PlanConfig; +import com.djrapitops.plan.settings.config.paths.TimeSettings; import com.djrapitops.plan.storage.database.DBType; import com.djrapitops.plan.storage.database.Database; +import com.djrapitops.plan.storage.database.queries.containers.PlayerContainerQuery; import com.djrapitops.plan.storage.database.queries.objects.ServerQueries; import com.djrapitops.plan.storage.database.queries.objects.SessionQueries; import com.djrapitops.plan.storage.database.queries.objects.UserIdentifierQueries; @@ -34,9 +38,11 @@ import java.util.UUID; public class CommonQueriesImplementation implements CommonQueries { private final Database db; + private final PlanConfig config; - CommonQueriesImplementation(Database db) { + CommonQueriesImplementation(Database db, PlanConfig config) { this.db = db; + this.config = config; } @Override @@ -98,4 +104,14 @@ public class CommonQueriesImplementation implements CommonQueries { throw new IllegalStateException("Unsupported Database Type: " + dbType.getName()); } } + + @Override + public double fetchActivityIndexOf(UUID playerUUID, long epochMs) { + return db.query(new PlayerContainerQuery(playerUUID)).getActivityIndex(epochMs, config.get(TimeSettings.ACTIVE_PLAY_THRESHOLD)).getValue(); + } + + @Override + public String getActivityGroupForIndex(double activityIndex) { + return ActivityIndex.getGroup(activityIndex); + } } diff --git a/Plan/common/src/main/java/com/djrapitops/plan/query/QuerySvc.java b/Plan/common/src/main/java/com/djrapitops/plan/query/QuerySvc.java index 7cdf5294e..922ce6c38 100644 --- a/Plan/common/src/main/java/com/djrapitops/plan/query/QuerySvc.java +++ b/Plan/common/src/main/java/com/djrapitops/plan/query/QuerySvc.java @@ -18,6 +18,7 @@ package com.djrapitops.plan.query; import com.djrapitops.plan.exceptions.database.DBOpException; import com.djrapitops.plan.identification.ServerInfo; +import com.djrapitops.plan.settings.config.PlanConfig; import com.djrapitops.plan.storage.database.DBSystem; import com.djrapitops.plan.storage.database.Database; import com.djrapitops.plan.storage.database.queries.QueryAPIExecutable; @@ -40,6 +41,7 @@ import java.util.function.Consumer; @Singleton public class QuerySvc implements QueryService { + private final PlanConfig config; private final DBSystem dbSystem; private final ServerInfo serverInfo; private final ErrorLogger errorLogger; @@ -49,10 +51,12 @@ public class QuerySvc implements QueryService { @Inject public QuerySvc( + PlanConfig config, DBSystem dbSystem, ServerInfo serverInfo, ErrorLogger errorLogger ) { + this.config = config; this.dbSystem = dbSystem; this.serverInfo = serverInfo; this.errorLogger = errorLogger; @@ -132,6 +136,6 @@ public class QuerySvc implements QueryService { public CommonQueries getCommonQueries() { Database database = dbSystem.getDatabase(); if (database == null) throw new IllegalStateException("Database has not been initialized."); - return new CommonQueriesImplementation(database); + return new CommonQueriesImplementation(database, config); } }