Ensure suspect messages actually involved the reporter

This commit is contained in:
Keir Nellyer 2016-09-14 14:53:39 +01:00
parent efe532e8a6
commit 9af606ae20
2 changed files with 10 additions and 2 deletions

View File

@ -126,7 +126,6 @@ public class ReportManager
*/ */
public CompletableFuture<Report> createReport(int reporterId, int suspectId, ReportCategory category, String message) public CompletableFuture<Report> createReport(int reporterId, int suspectId, ReportCategory category, String message)
{ {
// TODO only allow report if suspect actually did something
return fetchOrCreateReport(suspectId, category).whenComplete((report, throwable) -> return fetchOrCreateReport(suspectId, category).whenComplete((report, throwable) ->
{ {
if (report != null) if (report != null)

View File

@ -1,11 +1,15 @@
package mineplex.core.report.ui; package mineplex.core.report.ui;
import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.chatsnap.SnapshotManager;
import mineplex.core.chatsnap.SnapshotMessage;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -69,7 +73,12 @@ public class ReportCategoryPage extends SimpleGui
private boolean hasSentMessage(int accountId) private boolean hasSentMessage(int accountId)
{ {
return _plugin.getReportManager().getSnapshotManager().getMessagesFrom(accountId).size() > 0; SnapshotManager snapshotManager = _plugin.getReportManager().getSnapshotManager();
List<SnapshotMessage> suspectMessages = snapshotManager.getMessagesFrom(accountId).stream()
.filter(message -> message.getRecipientIds().contains(_suspect.getAccountId()))
.collect(Collectors.toList());
return suspectMessages.size() > 0;
} }
private void createReport(ReportCategory category) private void createReport(ReportCategory category)