From 779efe3f47c9ed51f138c21b726c67456fa62f95 Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Fri, 19 Aug 2016 16:46:25 +0100 Subject: [PATCH] Improve display of /reportstat --- .../src/mineplex/core/report/ReportRole.java | 16 ++++++++++++- .../report/command/ReportStatCommand.java | 24 +++++++++++++++---- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRole.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRole.java index 0e0b0672a..489c30212 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRole.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRole.java @@ -1,8 +1,22 @@ package mineplex.core.report; +import org.apache.commons.lang3.text.WordUtils; + public enum ReportRole { SUSPECT, REPORTER, - HANDLER + HANDLER; + + private final String _humanName; + + ReportRole() + { + _humanName = WordUtils.capitalize(name().toLowerCase().replace('_', ' ')); + } + + public String getHumanName() + { + return _humanName; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportStatCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportStatCommand.java index 07ab8804d..b847615d2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportStatCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportStatCommand.java @@ -1,6 +1,8 @@ package mineplex.core.report.command; -import java.util.function.Consumer; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -12,6 +14,9 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; import mineplex.core.report.ReportPlugin; +import mineplex.core.report.ReportRole; +import mineplex.core.report.data.Report; +import org.apache.commons.lang.StringUtils; /** * A staff command for viewing report related statistics of a player. @@ -35,13 +40,24 @@ public class ReportStatCommand extends CommandBase { int accountId = _commandCenter.GetClientManager().getAccountId(target); - // TODO Plugin.getReportManager().getStatistics(accountId).thenCompose(BukkitFuture.accept(stats -> stats.keySet().forEach(role -> { - caller.sendMessage(F.elem(role.name())); + List reportIds = stats.get(role) + .stream() + .map(Report::getId) + .filter(Optional::isPresent) + .limit(5) + .map(Optional::get) + .map(String::valueOf) + .collect(Collectors.toList()); - stats.get(role).forEach(report -> caller.sendMessage(String.valueOf(report.getId().orElse(-1L)))); + // don't show handler statistics if user has never handled a report + if (role != ReportRole.HANDLER || reportIds.size() > 0) + { + caller.sendMessage(F.main(Plugin.getName(), F.elem(role.getHumanName()))); + caller.sendMessage(F.main(Plugin.getName(), StringUtils.join(reportIds, ", "))); + } }) )); }