From 7b6f0ae22124c3d5f46497b8780a3108bf8d6694 Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Wed, 7 Sep 2016 16:40:05 +0100 Subject: [PATCH] PC-953 Make report ids in /reportstats command clickable --- .../report/command/ReportStatsCommand.java | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportStatsCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportStatsCommand.java index 670226e28..2ca932b4d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportStatsCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportStatsCommand.java @@ -9,6 +9,9 @@ import org.bukkit.entity.Player; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; +import mineplex.core.common.jsonchat.ChildJsonMessage; +import mineplex.core.common.jsonchat.ClickEvent; +import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.BukkitFuture; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -16,7 +19,6 @@ 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. @@ -43,20 +45,36 @@ public class ReportStatsCommand extends CommandBase Plugin.getReportManager().getStatistics(accountId, 5).thenCompose(BukkitFuture.accept(stats -> stats.keySet().forEach(role -> { - List reportIds = stats.get(role) + List reportIds = stats.get(role) .stream() .map(Report::getId) .filter(Optional::isPresent) .map(Optional::get) - .map(String::valueOf) .sorted() .collect(Collectors.toList()); // don't show handler statistics if user has never handled a report if (role != ReportRole.HANDLER || reportIds.size() > 0) { + // create clickable report ids + ChildJsonMessage jsonMessage = new JsonMessage(F.main(Plugin.getName(), "")) + .extra(C.mElem); + + long lastId = reportIds.get(reportIds.size() - 1); + + for (long reportId : reportIds) + { + jsonMessage = jsonMessage.add(String.valueOf(reportId)) + .click(ClickEvent.RUN_COMMAND, "/reportinfo " + reportId); + + if (reportId != lastId) + { + jsonMessage = jsonMessage.add(", "); + } + } + UtilPlayer.message(player, F.main(Plugin.getName(), F.elem(role.getHumanName()))); - UtilPlayer.message(player, F.main(Plugin.getName(), StringUtils.join(reportIds, ", "))); + jsonMessage.sendToPlayer(player); } }) ));