From 0a2bb0d203d8432a548e944236eca790d59c917f Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Fri, 25 Oct 2019 13:25:27 +0300 Subject: [PATCH] Player time placeholder changes - Fixed time amount formatting - Added player_server_ placeholders for all _time placeholders --- .../placeholders/PlayerPlaceHolder.java | 46 ++++++++++++++++--- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/Plan/bukkit/src/main/java/com/djrapitops/plan/addons/placeholderapi/placeholders/PlayerPlaceHolder.java b/Plan/bukkit/src/main/java/com/djrapitops/plan/addons/placeholderapi/placeholders/PlayerPlaceHolder.java index 6fa52aefd..51d05b1a8 100644 --- a/Plan/bukkit/src/main/java/com/djrapitops/plan/addons/placeholderapi/placeholders/PlayerPlaceHolder.java +++ b/Plan/bukkit/src/main/java/com/djrapitops/plan/addons/placeholderapi/placeholders/PlayerPlaceHolder.java @@ -42,6 +42,7 @@ public class PlayerPlaceHolder extends AbstractPlanPlaceHolder { private final DBSystem dbSystem; private Formatter year; + private Formatter time; public PlayerPlaceHolder( DBSystem dbSystem, @@ -50,6 +51,7 @@ public class PlayerPlaceHolder extends AbstractPlanPlaceHolder { ) { super(serverInfo); this.dbSystem = dbSystem; + time = formatters.timeAmount(); year = formatters.yearLong(); } @@ -100,30 +102,60 @@ public class PlayerPlaceHolder extends AbstractPlanPlaceHolder { return year.apply(player.getValue(PlayerKeys.REGISTERED).orElse((long) 0)); case "player_time_active": - return year.apply(SessionsMutator.forContainer(player) + return time.apply(SessionsMutator.forContainer(player) .toActivePlaytime()); case "player_time_afk": - return year.apply(SessionsMutator.forContainer(player) + return time.apply(SessionsMutator.forContainer(player) .toAfkTime()); case "player_time_total": - return year.apply(SessionsMutator.forContainer(player) + return time.apply(SessionsMutator.forContainer(player) .toPlaytime()); case "player_time_day": - return year.apply(SessionsMutator.forContainer(player) + return time.apply(SessionsMutator.forContainer(player) .filterSessionsBetween(dayAgo(), now()) .toPlaytime()); case "player_time_week": - return year.apply(SessionsMutator.forContainer(player) + return time.apply(SessionsMutator.forContainer(player) .filterSessionsBetween(weekAgo(), now()) .toPlaytime()); case "player_time_month": - return year.apply(SessionsMutator.forContainer(player) + return time.apply(SessionsMutator.forContainer(player) .filterSessionsBetween(monthAgo(), now()) .toPlaytime()); + case "player_server_time_active": + return time.apply(SessionsMutator.forContainer(player) + .filterPlayedOnServer(serverUUID()) + .toActivePlaytime()); + case "player_server_time_afk": + return time.apply(SessionsMutator.forContainer(player) + .filterPlayedOnServer(serverUUID()) + .toAfkTime()); + + case "player_server_time_total": + return time.apply(SessionsMutator.forContainer(player) + .filterPlayedOnServer(serverUUID()) + .toPlaytime()); + case "player_server_time_day": + return time.apply(SessionsMutator.forContainer(player) + .filterSessionsBetween(dayAgo(), now()) + .filterPlayedOnServer(serverUUID()) + .toPlaytime()); + case "player_server_time_week": + return time.apply(SessionsMutator.forContainer(player) + .filterSessionsBetween(weekAgo(), now()) + .filterPlayedOnServer(serverUUID()) + .toPlaytime()); + case "player_server_time_month": + return time.apply(SessionsMutator.forContainer(player) + .filterSessionsBetween(monthAgo(), now()) + .filterPlayedOnServer(serverUUID()) + .toPlaytime()); + + default: + return null; } - return null; } // Checkstyle.ON: CyclomaticComplexity