Made handler messages slightly more prettier

This commit is contained in:
Keir Nellyer 2016-07-14 19:19:16 +01:00
parent e1adf7d4e2
commit 7f48151c8c

View File

@ -1,27 +1,30 @@
package mineplex.core.report.task;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
import org.bukkit.ChatColor;
import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.chatsnap.SnapshotRepository;
import mineplex.core.common.jsonchat.ChildJsonMessage;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.HoverEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.report.Report;
import mineplex.core.report.ReportCategory;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportMessage;
import mineplex.core.report.command.ReportHandlerNotification;
import org.apache.commons.lang3.StringUtils;
/**
* Displays a message containing up-to-date details of a report to it's handler.
*/
public class ReportHandlerMessageTask extends BukkitRunnable
{
private static final String DECORATION = C.cAqua + "------------------------------------";
private final ReportManager _reportManager;
private final Report _report;
@ -43,22 +46,34 @@ public class ReportHandlerMessageTask extends BukkitRunnable
_reportManager.getReportRepository().getAccountName(_report.getSuspectId())
.thenAccept(suspectName ->
{
// TODO: Make this message look prettier
JsonMessage jsonMessage = new JsonMessage(DECORATION)
.extra("\n")
.add(C.cAqua + "Reviewing Ticket " + C.cGold + "#" + reportId)
.add("\n\n")
.add(C.cPurple + StringUtils.join(getReportReasons(), "\n" + C.cPurple))
.add("\n\n")
.add(C.cAqua + "Suspect: " + C.cGold + suspectName)
String prefix = F.main("Report", "");
ChildJsonMessage jsonMessage = new JsonMessage("\n")
.extra(prefix + C.cAqua + "Handling" + C.cGold + " #" + reportId)
.add("\n")
.add((_report.getCategory() == ReportCategory.CHAT_ABUSE ? C.cAqua + "Chat Log: " + C.cGold + "Click Here" + "\n" : ""))
.click(ClickEvent.OPEN_URL, SnapshotRepository.getURL(reportId))
.add(prefix + C.cAqua + "Suspect - " + C.cGold + suspectName)
.add("\n")
.add(C.cAqua + "Type " + C.cGold + "/reportclose " + reportId + " <reason>" + C.cAqua + " to close this report.")
.click(ClickEvent.SUGGEST_COMMAND, "/reportclose " + reportId)
.add(prefix + C.cAqua + "Type - " + C.cGold + _report.getCategory().getHumanName())
.add("\n" + prefix + "\n")
.add(prefix + C.cGold + _report.getMessages().size() + C.cAqua + " total reports")
.add("\n")
.add(DECORATION);
.add(Arrays.stream(getReportReasons()).map(s -> prefix + s).collect(Collectors.joining("\n")))
.add("\n" + prefix + "\n");
if (_report.getCategory() == ReportCategory.CHAT_ABUSE)
{
jsonMessage = jsonMessage
.add(prefix + C.cAqua + "View chat log")
.hover(HoverEvent.SHOW_TEXT, C.cGray + "Opens the chat log in your default browser")
.click(ClickEvent.OPEN_URL, SnapshotRepository.getURL(reportId))
.add("\n");
}
jsonMessage = jsonMessage
.add(prefix + C.cAqua + "Close this report")
.hover(HoverEvent.SHOW_TEXT, C.cGray + "Usage: /reportclose <report-id> <reason>")
.click(ClickEvent.SUGGEST_COMMAND, "/reportclose " + reportId + " ")
.add("\n");
new ReportHandlerNotification(_report, jsonMessage).publish();
});
@ -83,7 +98,7 @@ public class ReportHandlerMessageTask extends BukkitRunnable
String reporterName = _reportManager.getReportRepository().getAccountName(reportMessage.getReporterId()).join();
// triple backslashes so this translates to valid JSON
output[count++] = "\\\"" + reportMessage.getMessage() + "\\\" - " + reporterName;
output[count++] = String.format("%4$s(%d%4$s) %s%s%s - \\\"%s%s%4$s\\\"", count, C.cGold, reporterName, C.cGray, C.cPurple, reportMessage.getMessage());
}
return output;