From fc7106033af111a3cf72079f1140aacb70ead4dc Mon Sep 17 00:00:00 2001 From: Heliosares Date: Mon, 6 Mar 2023 16:47:11 -0500 Subject: [PATCH] Allow time ranges in /ap playtime --- .../auxprotect/core/commands/LookupCommand.java | 6 +++++- .../heliosares/auxprotect/utils/PlayTimeSolver.java | 13 ++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/dev/heliosares/auxprotect/core/commands/LookupCommand.java b/src/dev/heliosares/auxprotect/core/commands/LookupCommand.java index 9f787a6..1f433a9 100644 --- a/src/dev/heliosares/auxprotect/core/commands/LookupCommand.java +++ b/src/dev/heliosares/auxprotect/core/commands/LookupCommand.java @@ -361,7 +361,11 @@ public class LookupCommand extends Command { return; } String name = users.get(0); - sender.sendMessage(PlayTimeSolver.solvePlaytime(rs, params.getAfter(), (int) Math.round((double) (params.time_created - params.getAfter()) / (1000 * 3600)), name, plugin.getSenderAdapter(name) != null)); + sender.sendMessage(PlayTimeSolver.solvePlaytime(rs, + params.getAfter(), + params.getBefore() == Long.MAX_VALUE ? System.currentTimeMillis() : params.getBefore(), + name, + plugin.getSenderAdapter(name) != null)); return; } else if (params.getFlags().contains(Flag.ACTIVITY)) { String uuid = sender.getUniqueId().toString(); diff --git a/src/dev/heliosares/auxprotect/utils/PlayTimeSolver.java b/src/dev/heliosares/auxprotect/utils/PlayTimeSolver.java index 9932f0a..d2e045c 100644 --- a/src/dev/heliosares/auxprotect/utils/PlayTimeSolver.java +++ b/src/dev/heliosares/auxprotect/utils/PlayTimeSolver.java @@ -18,10 +18,11 @@ import java.time.format.DateTimeFormatter; import java.util.List; public class PlayTimeSolver { - public static BaseComponent[] solvePlaytime(List entries, long startTimeMillis, int hours, String player, final boolean currentlyOnline) { + public static BaseComponent[] solvePlaytime(List entries, long startTimeMillis, long stopTimeMillis, String player, final boolean currentlyOnline) { ComponentBuilder message = new ComponentBuilder().append("", FormatRetention.NONE); final int limitDays = 60; - if (hours > limitDays * 24) { + final int hours = (int) Math.ceil((stopTimeMillis - startTimeMillis) / 3600000D); + if (hours - 1 > limitDays * 24) { message.append(Language.L.COMMAND__LOOKUP__PLAYTIME__TOOLONG.translate(limitDays)); return message.create(); } @@ -37,7 +38,7 @@ public class PlayTimeSolver { long logout = 0; boolean newLogin = false; boolean newLogout = false; - double[] counter = new double[hours + 1]; + double[] counter = new double[hours]; int hour = 0; for (int i = entries.size() - 1; i >= 0; i--) { DbEntry entry = entries.get(i); @@ -134,12 +135,10 @@ public class PlayTimeSolver { } for (int i = counter.length; ; i++) { LocalDateTime time = startTime.plusHours(i); - if (time.getHour() == 0) { - break; - } + if (time.getHour() == 0) break; message.append(AuxProtectSpigot.BLOCK + "").color(ChatColor.BLACK).event((HoverEvent) null); } - message.append(" " + LocalDateTime.now().format(formatterDate)).color(ChatColor.BLUE); + message.append(" " + startTime.plusHours(hours).format(formatterDate)).color(ChatColor.BLUE); message.append(" (" + (Math.round(hourCount * 10.0) / 10.0) + "h)").color(ChatColor.GRAY) .event((HoverEvent) null); return message.create();