diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportHandlerMessenger.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportHandlerMessenger.java index 880a8faf1..f2750e8a9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportHandlerMessenger.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportHandlerMessenger.java @@ -13,7 +13,7 @@ import mineplex.core.common.jsonchat.HoverEvent; import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.C; import mineplex.core.common.util.F; -import mineplex.core.report.packet.HandlerNotification; +import mineplex.core.report.redis.HandlerNotification; import mineplex.core.report.data.Report; import mineplex.core.report.data.ReportMessage; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 9229c363d..95103d9cf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -1,8 +1,11 @@ package mineplex.core.report; +import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; import java.util.stream.Collectors; @@ -23,13 +26,14 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilFuture; import mineplex.core.portal.Portal; -import mineplex.core.report.packet.HandlerNotification; -import mineplex.core.report.packet.ReportCommandCallback; +import mineplex.core.report.redis.HandlerNotification; +import mineplex.core.report.redis.ReportCommandCallback; import mineplex.core.report.data.Report; import mineplex.core.report.data.ReportMessage; import mineplex.core.report.data.ReportProfile; import mineplex.core.report.data.ReportProfileRepository; import mineplex.core.report.data.ReportRepository; +import mineplex.core.report.redis.ReportersNotification; import mineplex.serverdata.commands.ServerCommandManager; import static com.google.common.base.Preconditions.checkNotNull; @@ -65,6 +69,7 @@ public class ReportManager ReportCommandCallback notificationCallback = new ReportCommandCallback(this); PushSnapshotsHandler pushHandler = new PushSnapshotsHandler(snapshotManager, _plugin.getLogger()); commandManager.registerCommandType("HandlerNotification", HandlerNotification.class, notificationCallback); + commandManager.registerCommandType("ReportersNotification", ReportersNotification.class, notificationCallback); commandManager.registerCommandType("PushSnapshotsCommand", PushSnapshotsCommand.class, pushHandler); } @@ -210,11 +215,6 @@ public class ReportManager String prefix = getReportPrefix(reportId); String reason = reasonOptional.isPresent() ? reasonOptional.get() : "No reason specified."; - reportCloser.sendMessage( - F.main(prefix, - C.cGreen + "Report marked as: " + C.cGold + reportResult.getType().getName())); - reportCloser.sendMessage(F.main(prefix, C.cGold + reason)); - if (reportResult.getType() == ReportResultType.ACCEPTED) { // todo new punish gui @@ -222,6 +222,26 @@ public class ReportManager 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, C.cGreen + "Report marked as: " + + C.cGold + reportResult.getType().getName())); + reportCloser.sendMessage(F.main(prefix, C.cGold + reason)); + + getUUIDs(report.getReporterIds()).thenAccept(ids -> + { + JsonMessage jsonMessage = new JsonMessage(F.main( + prefix, + "Your report against " + F.elem(suspectName) + " has been resolved. ")) + .extra("\n") + .add(F.main(prefix, "Result: " + F.elem(reportResult.getType().getName()))) + .add("\n") + .add(F.main(prefix, "Reason: " + F.elem(reason))); + + // TODO: Target specific servers + new ReportersNotification(ids, jsonMessage).publish(); + }); }); } }).exceptionally(throwable -> { @@ -513,6 +533,21 @@ public class ReportManager sendHandlerNotification(report, new JsonMessage(message)); } + /** + * Maps a collection of account ids to Mojang UUIDs. + * + * @param accountIds the account ids + * @return the UUIDs + */ + public CompletableFuture> getUUIDs(Collection accountIds) + { + List> futures = accountIds.stream() + .map(_reportRepository::getAccountUUID) + .collect(Collectors.toList()); + + return UtilFuture.sequence(futures, Collectors.toSet()); + } + /* STATIC HELPERS */ /** diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/packet/HandlerNotification.java b/Plugins/Mineplex.Core/src/mineplex/core/report/redis/HandlerNotification.java similarity index 94% rename from Plugins/Mineplex.Core/src/mineplex/core/report/packet/HandlerNotification.java rename to Plugins/Mineplex.Core/src/mineplex/core/report/redis/HandlerNotification.java index 77bdece24..2030e6677 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/packet/HandlerNotification.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/redis/HandlerNotification.java @@ -1,4 +1,4 @@ -package mineplex.core.report.packet; +package mineplex.core.report.redis; import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.report.data.Report; @@ -39,7 +39,7 @@ public class HandlerNotification extends ServerCommand return _handlerId; } - public String getMessage() + public String getJson() { return _message; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/packet/ReportCommandCallback.java b/Plugins/Mineplex.Core/src/mineplex/core/report/redis/ReportCommandCallback.java similarity index 75% rename from Plugins/Mineplex.Core/src/mineplex/core/report/packet/ReportCommandCallback.java rename to Plugins/Mineplex.Core/src/mineplex/core/report/redis/ReportCommandCallback.java index ea25b09e8..7d44778d5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/packet/ReportCommandCallback.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/redis/ReportCommandCallback.java @@ -1,4 +1,4 @@ -package mineplex.core.report.packet; +package mineplex.core.report.redis; import org.bukkit.Bukkit; import org.bukkit.Server; @@ -42,7 +42,7 @@ public class ReportCommandCallback implements CommandCallback if (handler != null) { - sendRawMessage(handler, reportNotification.getMessage()); + sendRawMessage(handler, reportNotification.getJson()); } } }); @@ -50,6 +50,14 @@ public class ReportCommandCallback implements CommandCallback } ); } + else if (command instanceof ReportersNotification) + { + ReportersNotification reportersNotification = (ReportersNotification) command; + reportersNotification.getReporterUUIDs().stream() + .map(Bukkit::getPlayer) + .filter(player -> player != null) + .forEach(reporter -> sendRawMessage(reporter, reportersNotification.getJson())); + } } private void sendRawMessage(Player player, String rawMessage) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/redis/ReportersNotification.java b/Plugins/Mineplex.Core/src/mineplex/core/report/redis/ReportersNotification.java new file mode 100644 index 000000000..632082c73 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/redis/ReportersNotification.java @@ -0,0 +1,33 @@ +package mineplex.core.report.redis; + +import java.util.Set; +import java.util.UUID; + +import mineplex.core.common.jsonchat.JsonMessage; +import mineplex.serverdata.commands.ServerCommand; + +/** + * When this packet is received by a server, it will check to see if any of the reporters are online. + * If so, it will send the supplied notification to them. + */ +public class ReportersNotification extends ServerCommand +{ + private Set _reporters; + private String _message; // in json format + + public ReportersNotification(Set ids, JsonMessage jsonMessage) + { + _reporters = ids; + _message = jsonMessage.toString(); + } + + public Set getReporterUUIDs() + { + return _reporters; + } + + public String getJson() + { + return _message; + } +}