Cancel messaging task if handler is no longer present
This commit is contained in:
parent
10a6cbfe3b
commit
ee78cf2bb9
@ -36,51 +36,59 @@ public class ReportHandlerMessenger extends BukkitRunnable
|
||||
{
|
||||
long reportId = _report.getId().orElse((long) -1);
|
||||
|
||||
_reportManager.isActiveReport(_report).thenAccept(isActive ->
|
||||
if (_report.getHandlerId().isPresent())
|
||||
{
|
||||
if (isActive)
|
||||
_reportManager.isActiveReport(_report).thenAccept(isActive ->
|
||||
{
|
||||
_reportManager.getReportRepository().getAccountName(_report.getSuspectId())
|
||||
.thenAccept(suspectName ->
|
||||
{
|
||||
String prefix = F.main(ReportManager.getReportPrefix(reportId), "");
|
||||
if (isActive)
|
||||
{
|
||||
_reportManager.getReportRepository().getAccountName(_report.getSuspectId())
|
||||
.thenAccept(suspectName ->
|
||||
{
|
||||
String prefix = F.main(ReportManager.getReportPrefix(reportId), "");
|
||||
|
||||
ChildJsonMessage jsonMessage = new JsonMessage("\n")
|
||||
.extra(prefix + C.cAqua + "Report Overview")
|
||||
.add("\n")
|
||||
.add(prefix + C.cAqua + "Suspect - " + C.cGold + suspectName)
|
||||
.add("\n")
|
||||
.add(prefix + C.cAqua + "Type - " + C.cGold + _report.getCategory().getName())
|
||||
.add("\n" + prefix + "\n")
|
||||
.add(prefix + C.cGold + _report.getMessages().size() + C.cAqua + " total reports")
|
||||
.add("\n")
|
||||
.add(Arrays.stream(getReportReasons()).map(s -> prefix + s).collect(Collectors.joining("\n")))
|
||||
.add("\n" + prefix + "\n");
|
||||
ChildJsonMessage jsonMessage = new JsonMessage("\n")
|
||||
.extra(prefix + C.cAqua + "Report Overview")
|
||||
.add("\n")
|
||||
.add(prefix + C.cAqua + "Suspect - " + C.cGold + suspectName)
|
||||
.add("\n")
|
||||
.add(prefix + C.cAqua + "Type - " + C.cGold + _report.getCategory().getName())
|
||||
.add("\n" + prefix + "\n")
|
||||
.add(prefix + C.cGold + _report.getMessages().size() + C.cAqua + " total reports")
|
||||
.add("\n")
|
||||
.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");
|
||||
}
|
||||
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 <reason>")
|
||||
.click(ClickEvent.SUGGEST_COMMAND, "/reportclose ")
|
||||
.add("\n");
|
||||
jsonMessage = jsonMessage
|
||||
.add(prefix + C.cAqua + "Close this report")
|
||||
.hover(HoverEvent.SHOW_TEXT, C.cGray + "Usage: /reportclose <reason>")
|
||||
.click(ClickEvent.SUGGEST_COMMAND, "/reportclose ")
|
||||
.add("\n");
|
||||
|
||||
new HandlerNotification(_report, jsonMessage).publish();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// report has been closed, so this task should be cancelled
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
new HandlerNotification(_report, jsonMessage).publish();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// report has been closed, so this task should be cancelled
|
||||
cancel();
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
// no handler (report perhaps aborted), so cancel task
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private String[] getReportReasons()
|
||||
|
Loading…
Reference in New Issue
Block a user