diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 0fc047cd9..3ed7541a3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -1,6 +1,7 @@ package mineplex.core.report; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Optional; @@ -126,37 +127,42 @@ public class ReportManager public CompletableFuture createReport(int reporterId, int suspectId, ReportCategory category, String message) { // TODO only allow report if suspect actually did something - return _reportRepository.getOngoingReport(suspectId, category) - .thenCompose(reportIdOptional -> - reportIdOptional.isPresent() ? _reportRepository - .getReport(reportIdOptional.get()) : CompletableFuture - .completedFuture(new Report(suspectId, category)) - ).whenComplete((report, throwable) -> + return _reportRepository.getOngoingReports(suspectId, category).thenCompose(reportIds -> + { + if (reportIds.size() > 0) + { + return _reportRepository.getReport(Collections.max(reportIds)); + } + else + { + return CompletableFuture.completedFuture(new Report(suspectId, category)); + } + }).whenComplete((report, throwable) -> + { + if (report != null) + { + ReportMessage reportMessage = report.getReportMessage(reporterId); + + if (reportMessage != null) { - if (report != null) - { - ReportMessage reportMessage = report.getReportMessage(reporterId); + reportMessage.setMessage(message); + } + else + { + reportMessage = new ReportMessage(reporterId, message, _serverName, _serverWeight); + report.addReportReason(reportMessage); + } - if (reportMessage != null) - { - reportMessage.setMessage(message); - } - else - { - reportMessage = new ReportMessage(reporterId, message, _serverName, _serverWeight); - report.addReportReason(reportMessage); - } + // create snapshot id ahead of time + if (category == ReportCategory.CHAT_ABUSE) + { + int snapshotId = _snapshotManager.getSnapshotRepository().createSnapshot(null).join(); + report.setSnapshotId(snapshotId); + } - // create snapshot id ahead of time - if (category == ReportCategory.CHAT_ABUSE) - { - int snapshotId = _snapshotManager.getSnapshotRepository().createSnapshot(null).join(); - report.setSnapshotId(snapshotId); - } - - saveReport(report).join(); - } - }); + saveReport(report).join(); + } + }); } /** diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportRepository.java index 63b93c250..09b1d1d0c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/data/ReportRepository.java @@ -445,9 +445,9 @@ public class ReportRepository return future; } - public CompletableFuture> getOngoingReport(int accountId, ReportCategory category) + public CompletableFuture> getOngoingReports(int accountId, ReportCategory category) { - CompletableFuture> future = CompletableFuture.supplyAsync(() -> + CompletableFuture> future = CompletableFuture.supplyAsync(() -> { try (Connection connection = DBPool.getAccount().getConnection()) { @@ -456,23 +456,24 @@ public class ReportRepository preparedStatement.setInt(2, category.getId()); ResultSet resultSet = preparedStatement.executeQuery(); - if (resultSet.next()) + List reports = new ArrayList<>(); + while (resultSet.next()) { - return Optional.of(resultSet.getInt("id")); + reports.add(resultSet.getInt("id")); } + + return reports; } catch (SQLException e) { throw new RuntimeException(e); } - - return Optional.empty(); }); future.exceptionally(throwable -> { _logger.log(Level.SEVERE, "Error fetching ongoing report for account: " + accountId + ", category: " + category + ".", throwable); - return Optional.empty(); + return new ArrayList<>(); }); return future;