From afee339e161f4e169e96ae9b328faf20ee1a1510 Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Tue, 4 Oct 2016 16:20:11 +0100 Subject: [PATCH 1/3] Any report with a handler and no conclusion is an active report, therefore we don't need to check if the report is active --- .../mineplex/core/report/ReportManager.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 902de4282..0710cbba2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -553,22 +553,22 @@ public class ReportManager reportIds.stream().map(_reportRepository::getReport).collect(Collectors.toList()) ).thenCompose(UtilFuture::sequence) .thenApply(UtilCollections::unboxPresent) - .thenCompose(reports -> UtilFuture.filter(reports, this::isActiveReport)).thenApply(reports -> - { - Report report = null; - int size = reports.size(); + .thenApply(reports -> + { + Report report = null; + int size = reports.size(); - if (size == 1) - { - report = reports.get(0); - } - else if (size > 1) - { - throw new IllegalStateException("Account is handling multiple reports."); - } + if (size == 1) + { + report = reports.get(0); + } + else if (size > 1) + { + throw new IllegalStateException("Account is handling multiple reports."); + } - return Optional.ofNullable(report); - }); + return Optional.ofNullable(report); + }); future.exceptionally(throwable -> Optional.empty()); From 6709001c8906dbd5a46992dd2c259b0fd07ab886 Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Tue, 4 Oct 2016 16:25:51 +0100 Subject: [PATCH 2/3] Remove double handle check, pointless and can potentially cause issues --- .../src/mineplex/core/report/ReportManager.java | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 0710cbba2..34b92a4f7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -512,19 +512,9 @@ public class ReportManager */ public CompletableFuture isHandlingReport(int accountId) { - CompletableFuture> future = _reportRepository.getReportsHandling(accountId); - - return future.thenApply(reportIds -> { - for (long reportId : reportIds) - { - if (isActiveReport(reportId).join()) - { - return true; - } - } - - return false; - }).exceptionally(throwable -> true); + return _reportRepository.getReportsHandling(accountId) + .thenApply(reportIds -> reportIds.size() > 0) + .exceptionally(throwable -> true); // ^ if for some reason we cannot fetch the report a user is handling // assume the worst and return true // this means we do not end up allowing a user to handle multiple reports simultaneously From 22707d6d2e0ab7b7a2be85239baa35c7b9f6ca64 Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Tue, 4 Oct 2016 16:34:19 +0100 Subject: [PATCH 3/3] Only execute if throwable is null --- .../src/mineplex/core/report/command/ReportAbortCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportAbortCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportAbortCommand.java index f210d5b01..67450ea61 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportAbortCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportAbortCommand.java @@ -34,7 +34,7 @@ public class ReportAbortCommand extends CommandBase reportManager.getReportHandling(player).whenComplete(BukkitFuture.complete((reportOptional, throwable) -> { - if (throwable != null) + if (throwable == null) { if (reportOptional.isPresent()) {