Prevent double exception printing when an error occurs whilst saving

a report
This commit is contained in:
Keir Nellyer 2016-09-30 01:05:50 +01:00
parent 26d6540b2f
commit 45eeac8cee

View File

@ -266,64 +266,68 @@ public class ReportManager
saveCompletableFuture.thenAccept(reportId -> saveCompletableFuture.thenAccept(reportId ->
{ {
if (reportResult.getType() == ReportResultType.ABUSIVE) try
{ {
// if report was marked abusive, check if each of the reporters if (reportResult.getType() == ReportResultType.ABUSIVE)
// should be banned from using the report system
report.getReporterIds().forEach(reporterId ->
_reportRepository.getAccountUUID(reporterId).thenAccept(reporterUUID ->
{
CoreClient reporterClient = _clientManager.Get(reporterUUID);
checkAbuseBan(reporterClient, reportCloser, reportId);
}));
}
Bukkit.getScheduler().runTask(_plugin, () ->
{
String prefix = getReportPrefix(reportId);
String reason = reportResult.getReason().orElse("No reason specified.");
if (reportCloser != null)
{ {
if (reportResult.getType() == ReportResultType.ACCEPTED) // if report was marked abusive, check if each of the reporters
{ // should be banned from using the report system
// TODO: force moderator to choose a punishment (requires new punish gui) report.getReporterIds().forEach(reporterId ->
CommandCenter.Instance.onPlayerCommandPreprocess( _reportRepository.getAccountUUID(reporterId).thenAccept(reporterUUID ->
new PlayerCommandPreprocessEvent(reportCloser, {
String.format("/punish %s Report #%s - %s", suspectName, reportId, reason))); CoreClient reporterClient = _clientManager.Get(reporterUUID);
} checkAbuseBan(reporterClient, reportCloser, reportId);
}));
// TODO: send these after punishment has been decided (requires new punish gui)
reportCloser.sendMessage(
F.main(prefix, "Report marked as: "
+ C.cGold + reportResult.getType().getName()));
reportCloser.sendMessage(F.main(prefix, "Reason: " + F.elem(reason)));
} }
getUUIDs(report.getReporterIds()).thenAccept(ids -> Bukkit.getScheduler().runTask(_plugin, () ->
{ {
ReportResultType resultType = reportResult.getType(); String prefix = getReportPrefix(reportId);
ChildJsonMessage jsonMessage = new JsonMessage(F.main( String reason = reportResult.getReason().orElse("No reason specified.");
prefix,
"Your report against " + F.elem(suspectName) + " was marked as " + F.elem(resultType.getName()) + "."))
.extra("\n");
if (resultType == ReportResultType.ABUSIVE) if (reportCloser != null)
{ {
jsonMessage = jsonMessage.add(F.main(prefix, C.cRed + "Submitting false reports may result in punishment.")) if (reportResult.getType() == ReportResultType.ACCEPTED)
.add("\n"); {
// TODO: force moderator to choose a punishment (requires new punish gui)
CommandCenter.Instance.onPlayerCommandPreprocess(
new PlayerCommandPreprocessEvent(reportCloser,
String.format("/punish %s Report #%s - %s", suspectName, reportId, reason)));
}
// TODO: send these after punishment has been decided (requires new punish gui)
reportCloser.sendMessage(
F.main(prefix, "Report marked as: "
+ C.cGold + reportResult.getType().getName()));
reportCloser.sendMessage(F.main(prefix, "Reason: " + F.elem(reason)));
} }
jsonMessage = jsonMessage.add(F.main(prefix, "Reason: " + F.elem(reason))); getUUIDs(report.getReporterIds()).thenAccept(ids ->
{
ReportResultType resultType = reportResult.getType();
ChildJsonMessage jsonMessage = new JsonMessage(F.main(
prefix,
"Your report against " + F.elem(suspectName) + " was marked as " + F.elem(resultType.getName()) + "."))
.extra("\n");
new ReportersNotification(ids, jsonMessage).publish(); if (resultType == ReportResultType.ABUSIVE)
{
jsonMessage = jsonMessage.add(F.main(prefix, C.cRed + "Submitting false reports may result in punishment."))
.add("\n");
}
jsonMessage = jsonMessage.add(F.main(prefix, "Reason: " + F.elem(reason)));
new ReportersNotification(ids, jsonMessage).publish();
});
}); });
});
_reportRepository.clearCache(reportId); _reportRepository.clearCache(reportId);
}).exceptionally(throwable -> { }
_plugin.getLogger().log(Level.SEVERE, "Post-report save failed.", throwable); catch (Throwable throwable)
return null; {
_plugin.getLogger().log(Level.SEVERE, "Post-report save failed.", throwable);
}
}); });
}); });
} }