diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/command/PushSnapshotsCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/command/PushSnapshotsCommand.java new file mode 100644 index 000000000..c39b26700 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/command/PushSnapshotsCommand.java @@ -0,0 +1,35 @@ +package mineplex.core.chatsnap.command; + +import mineplex.serverdata.commands.ServerCommand; + +/** + * This command when executed will get all snapshots involving a particular account and push them to the database. + */ +public class PushSnapshotsCommand extends ServerCommand +{ + private final int _accountId; + private final long _reportId; + + public PushSnapshotsCommand(int accountId, long reportId) + { + super(); + _accountId = accountId; + _reportId = reportId; + } + + public int getAccountId() + { + return _accountId; + } + + public long getReportId() + { + return _reportId; + } + + @Override + public void run() + { + // Utilitizes a callback functionality to seperate dependencies + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/command/PushSnapshotsHandler.java b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/command/PushSnapshotsHandler.java new file mode 100644 index 000000000..3333e8730 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/chatsnap/command/PushSnapshotsHandler.java @@ -0,0 +1,46 @@ +package mineplex.core.chatsnap.command; + +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; + +import mineplex.core.chatsnap.Snapshot; +import mineplex.core.chatsnap.SnapshotManager; +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; + +/** + * Handles receiving of {@link PushSnapshotsCommand} instances. + */ +public class PushSnapshotsHandler implements CommandCallback +{ + private final SnapshotManager _snapshotManager; + private final Logger _logger; + + public PushSnapshotsHandler(SnapshotManager snapshotManager, Logger logger) + { + _snapshotManager = snapshotManager; + _logger = logger; + } + + @Override + public void run(ServerCommand command) + { + if (command instanceof PushSnapshotsCommand) + { + PushSnapshotsCommand pushCommand = (PushSnapshotsCommand) command; + int accountId = pushCommand.getAccountId(); + long reportId = pushCommand.getReportId(); + Set snapshots = _snapshotManager.getSnapshots(accountId); + + if (snapshots.size() > 0) + { + _snapshotManager.getSnapshotRepository().insertSnapshots(reportId, snapshots) + .exceptionally(throwable -> { + _logger.log(Level.SEVERE, "Error whilst inserting snapshots into database (" + reportId + ").", throwable); + return null; + }); + } + } + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 25a818efd..b9c650266 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -2,13 +2,13 @@ package mineplex.core.report; import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.logging.Level; import mineplex.core.account.CoreClientManager; -import mineplex.core.chatsnap.Snapshot; import mineplex.core.chatsnap.SnapshotManager; +import mineplex.core.chatsnap.command.PushSnapshotsCommand; +import mineplex.core.chatsnap.command.PushSnapshotsHandler; import mineplex.core.command.CommandCenter; import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.F; @@ -58,8 +58,11 @@ public class ReportManager _reportProfileRepository = new ReportProfileRepository(javaPlugin); - ReportNotificationCallback callback = new ReportNotificationCallback(this); - ServerCommandManager.getInstance().registerCommandType("ReportHandlerNotification", ReportHandlerNotification.class, callback); + ServerCommandManager commandManager = ServerCommandManager.getInstance(); + ReportNotificationCallback notificationCallback = new ReportNotificationCallback(this); + PushSnapshotsHandler pushHandler = new PushSnapshotsHandler(_snapshotManager, _javaPlugin.getLogger()); + commandManager.registerCommandType("ReportHandlerNotification", ReportHandlerNotification.class, notificationCallback); + commandManager.registerCommandType("PushSnapshotsCommand", PushSnapshotsCommand.class, pushHandler); } /** @@ -149,12 +152,8 @@ public class ReportManager if (report.getCategory() == ReportCategory.CHAT_ABUSE) { - Set relatedSnapshots = _snapshotManager.getSnapshots(report.getSuspectId()); - _snapshotManager.getSnapshotRepository().insertSnapshots(reportId, relatedSnapshots) - .exceptionally(throwable -> { - _javaPlugin.getLogger().log(Level.SEVERE, "Error whilst inserting snapshots into database.", throwable); - return null; - }); + PushSnapshotsCommand pushCommand = new PushSnapshotsCommand(report.getSuspectId(), reportId); + pushCommand.publish(); } _reportRepository.updateReport(report); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java index ba13fa670..d8b7ef460 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java @@ -26,6 +26,7 @@ public class ReportNotification extends ServerCommand return _notification; } + @Override public void run() { // Utilitizes a callback functionality to seperate dependencies