Display message to reporters of a report when it is closed
This commit is contained in:
parent
4dbbe6c32a
commit
8ee6ab6a1b
@ -13,7 +13,7 @@ import mineplex.core.common.jsonchat.HoverEvent;
|
|||||||
import mineplex.core.common.jsonchat.JsonMessage;
|
import mineplex.core.common.jsonchat.JsonMessage;
|
||||||
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.report.packet.HandlerNotification;
|
import mineplex.core.report.redis.HandlerNotification;
|
||||||
import mineplex.core.report.data.Report;
|
import mineplex.core.report.data.Report;
|
||||||
import mineplex.core.report.data.ReportMessage;
|
import mineplex.core.report.data.ReportMessage;
|
||||||
|
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
package mineplex.core.report;
|
package mineplex.core.report;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.stream.Collectors;
|
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.F;
|
||||||
import mineplex.core.common.util.UtilFuture;
|
import mineplex.core.common.util.UtilFuture;
|
||||||
import mineplex.core.portal.Portal;
|
import mineplex.core.portal.Portal;
|
||||||
import mineplex.core.report.packet.HandlerNotification;
|
import mineplex.core.report.redis.HandlerNotification;
|
||||||
import mineplex.core.report.packet.ReportCommandCallback;
|
import mineplex.core.report.redis.ReportCommandCallback;
|
||||||
import mineplex.core.report.data.Report;
|
import mineplex.core.report.data.Report;
|
||||||
import mineplex.core.report.data.ReportMessage;
|
import mineplex.core.report.data.ReportMessage;
|
||||||
import mineplex.core.report.data.ReportProfile;
|
import mineplex.core.report.data.ReportProfile;
|
||||||
import mineplex.core.report.data.ReportProfileRepository;
|
import mineplex.core.report.data.ReportProfileRepository;
|
||||||
import mineplex.core.report.data.ReportRepository;
|
import mineplex.core.report.data.ReportRepository;
|
||||||
|
import mineplex.core.report.redis.ReportersNotification;
|
||||||
import mineplex.serverdata.commands.ServerCommandManager;
|
import mineplex.serverdata.commands.ServerCommandManager;
|
||||||
import static com.google.common.base.Preconditions.checkNotNull;
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
@ -65,6 +69,7 @@ public class ReportManager
|
|||||||
ReportCommandCallback notificationCallback = new ReportCommandCallback(this);
|
ReportCommandCallback notificationCallback = new ReportCommandCallback(this);
|
||||||
PushSnapshotsHandler pushHandler = new PushSnapshotsHandler(snapshotManager, _plugin.getLogger());
|
PushSnapshotsHandler pushHandler = new PushSnapshotsHandler(snapshotManager, _plugin.getLogger());
|
||||||
commandManager.registerCommandType("HandlerNotification", HandlerNotification.class, notificationCallback);
|
commandManager.registerCommandType("HandlerNotification", HandlerNotification.class, notificationCallback);
|
||||||
|
commandManager.registerCommandType("ReportersNotification", ReportersNotification.class, notificationCallback);
|
||||||
commandManager.registerCommandType("PushSnapshotsCommand", PushSnapshotsCommand.class, pushHandler);
|
commandManager.registerCommandType("PushSnapshotsCommand", PushSnapshotsCommand.class, pushHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,11 +215,6 @@ public class ReportManager
|
|||||||
String prefix = getReportPrefix(reportId);
|
String prefix = getReportPrefix(reportId);
|
||||||
String reason = reasonOptional.isPresent() ? reasonOptional.get() : "No reason specified.";
|
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)
|
if (reportResult.getType() == ReportResultType.ACCEPTED)
|
||||||
{
|
{
|
||||||
// todo new punish gui
|
// todo new punish gui
|
||||||
@ -222,6 +222,26 @@ public class ReportManager
|
|||||||
new PlayerCommandPreprocessEvent(reportCloser,
|
new PlayerCommandPreprocessEvent(reportCloser,
|
||||||
String.format("/punish %s Report #%s - %s", suspectName, reportId, reason)));
|
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 -> {
|
}).exceptionally(throwable -> {
|
||||||
@ -513,6 +533,21 @@ public class ReportManager
|
|||||||
sendHandlerNotification(report, new JsonMessage(message));
|
sendHandlerNotification(report, new JsonMessage(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps a collection of account ids to Mojang UUIDs.
|
||||||
|
*
|
||||||
|
* @param accountIds the account ids
|
||||||
|
* @return the UUIDs
|
||||||
|
*/
|
||||||
|
public CompletableFuture<Set<UUID>> getUUIDs(Collection<Integer> accountIds)
|
||||||
|
{
|
||||||
|
List<CompletableFuture<UUID>> futures = accountIds.stream()
|
||||||
|
.map(_reportRepository::getAccountUUID)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
return UtilFuture.sequence(futures, Collectors.toSet());
|
||||||
|
}
|
||||||
|
|
||||||
/* STATIC HELPERS */
|
/* STATIC HELPERS */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
package mineplex.core.report.packet;
|
package mineplex.core.report.redis;
|
||||||
|
|
||||||
import mineplex.core.common.jsonchat.JsonMessage;
|
import mineplex.core.common.jsonchat.JsonMessage;
|
||||||
import mineplex.core.report.data.Report;
|
import mineplex.core.report.data.Report;
|
||||||
@ -39,7 +39,7 @@ public class HandlerNotification extends ServerCommand
|
|||||||
return _handlerId;
|
return _handlerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMessage()
|
public String getJson()
|
||||||
{
|
{
|
||||||
return _message;
|
return _message;
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package mineplex.core.report.packet;
|
package mineplex.core.report.redis;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
@ -42,7 +42,7 @@ public class ReportCommandCallback implements CommandCallback
|
|||||||
|
|
||||||
if (handler != null)
|
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)
|
private void sendRawMessage(Player player, String rawMessage)
|
@ -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<UUID> _reporters;
|
||||||
|
private String _message; // in json format
|
||||||
|
|
||||||
|
public ReportersNotification(Set<UUID> ids, JsonMessage jsonMessage)
|
||||||
|
{
|
||||||
|
_reporters = ids;
|
||||||
|
_message = jsonMessage.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<UUID> getReporterUUIDs()
|
||||||
|
{
|
||||||
|
return _reporters;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getJson()
|
||||||
|
{
|
||||||
|
return _message;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user