Simplify and shorten createReport method
This commit is contained in:
parent
209ca20959
commit
1885854bc4
@ -88,35 +88,20 @@ public class ReportManager
|
||||
*/
|
||||
public CompletableFuture<Report> createReport(Player reporter, Player suspect, ReportCategory category, String reason)
|
||||
{
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
int reporterId = _clientManager.Get(reporter).getAccountId();
|
||||
int suspectId = _clientManager.Get(suspect).getAccountId();
|
||||
int reporterId = _clientManager.Get(reporter).getAccountId();
|
||||
int suspectId = _clientManager.Get(suspect).getAccountId();
|
||||
|
||||
Report report = _reportRepository.getOngoingReport(suspectId, category)
|
||||
.exceptionally(throwable -> {
|
||||
_plugin.getLogger().log(Level.SEVERE, "Error fetching ongoing report.", throwable);
|
||||
return Optional.empty();
|
||||
}).thenCompose(reportIdOptional -> reportIdOptional.isPresent() ? _reportRepository.getReport(reportIdOptional.get()) : CompletableFuture.completedFuture(null))
|
||||
.join();
|
||||
|
||||
if (report == null)
|
||||
{
|
||||
report = new Report(suspectId, category);
|
||||
}
|
||||
|
||||
report.addReportReason(new ReportMessage(reporterId, reason, _serverName, _serverWeight));
|
||||
|
||||
saveReport(report)
|
||||
.exceptionally(throwable -> {
|
||||
_plugin.getLogger().log(Level.SEVERE, "Error updating report to database.", throwable);
|
||||
return null;
|
||||
}).join(); // join (block) so that report is assigned an id
|
||||
|
||||
return report;
|
||||
}).exceptionally(throwable -> {
|
||||
_plugin.getLogger().log(Level.SEVERE, "Error whilst reporting player.", throwable);
|
||||
return null;
|
||||
});
|
||||
return _reportRepository.getOngoingReport(suspectId, category)
|
||||
.thenCompose(reportIdOptional ->
|
||||
reportIdOptional.isPresent() ? _reportRepository.getReport(reportIdOptional.get()) : CompletableFuture.completedFuture(new Report(suspectId, category))
|
||||
).whenComplete((report, throwable) ->
|
||||
{
|
||||
if (report != null)
|
||||
{
|
||||
report.addReportReason(new ReportMessage(reporterId, reason, _serverName, _serverWeight));
|
||||
saveReport(report).join();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user