PC-953 Make report ids in /reportstats command clickable

This commit is contained in:
Keir Nellyer 2016-09-07 16:40:05 +01:00
parent e2840f36b5
commit 7b6f0ae221

View File

@ -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<ReportPlugin>
Plugin.getReportManager().getStatistics(accountId, 5).thenCompose(BukkitFuture.accept(stats ->
stats.keySet().forEach(role ->
{
List<String> reportIds = stats.get(role)
List<Long> 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);
}
})
));