Packet class refactorings

This commit is contained in:
Keir Nellyer 2016-07-27 16:08:23 +01:00
parent 20fc867578
commit f2435c3b43
5 changed files with 27 additions and 54 deletions

View File

@ -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.command.ReportHandlerNotification; import mineplex.core.report.packet.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;
@ -72,7 +72,7 @@ public class ReportHandlerMessenger extends BukkitRunnable
.click(ClickEvent.SUGGEST_COMMAND, "/reportclose ") .click(ClickEvent.SUGGEST_COMMAND, "/reportclose ")
.add("\n"); .add("\n");
new ReportHandlerNotification(_report, jsonMessage).publish(); new HandlerNotification(_report, jsonMessage).publish();
}); });
} }
else else

View File

@ -23,8 +23,8 @@ 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.command.ReportHandlerNotification; import mineplex.core.report.packet.HandlerNotification;
import mineplex.core.report.command.ReportNotificationCallback; import mineplex.core.report.packet.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;
@ -62,9 +62,9 @@ public class ReportManager
_reportProfileRepository = new ReportProfileRepository(plugin); _reportProfileRepository = new ReportProfileRepository(plugin);
ServerCommandManager commandManager = ServerCommandManager.getInstance(); ServerCommandManager commandManager = ServerCommandManager.getInstance();
ReportNotificationCallback notificationCallback = new ReportNotificationCallback(this); ReportCommandCallback notificationCallback = new ReportCommandCallback(this);
PushSnapshotsHandler pushHandler = new PushSnapshotsHandler(snapshotManager, _plugin.getLogger()); PushSnapshotsHandler pushHandler = new PushSnapshotsHandler(snapshotManager, _plugin.getLogger());
commandManager.registerCommandType("ReportHandlerNotification", ReportHandlerNotification.class, notificationCallback); commandManager.registerCommandType("HandlerNotification", HandlerNotification.class, notificationCallback);
commandManager.registerCommandType("PushSnapshotsCommand", PushSnapshotsCommand.class, pushHandler); commandManager.registerCommandType("PushSnapshotsCommand", PushSnapshotsCommand.class, pushHandler);
} }
@ -496,8 +496,8 @@ public class ReportManager
{ {
if (report.getHandlerId().isPresent()) if (report.getHandlerId().isPresent())
{ {
ReportHandlerNotification reportHandlerNotification = new ReportHandlerNotification(report, jsonMessage); HandlerNotification handlerNotification = new HandlerNotification(report, jsonMessage);
reportHandlerNotification.publish(); handlerNotification.publish();
} }
} }

View File

@ -1,34 +0,0 @@
package mineplex.core.report.command;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.serverdata.commands.ServerCommand;
/**
* A message regarding a report which should be sent to all moderators with report notifications enabled.
*/
public class ReportNotification extends ServerCommand
{
private final String _notification; // in json format
public ReportNotification(String notification)
{
this(new JsonMessage(notification));
}
public ReportNotification(JsonMessage notification)
{
super(); // Send to all servers
_notification = notification.toString();
}
public String getNotification()
{
return _notification;
}
@Override
public void run()
{
// Utilitizes a callback functionality to seperate dependencies
}
}

View File

@ -1,23 +1,25 @@
package mineplex.core.report.command; package mineplex.core.report.packet;
import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.jsonchat.JsonMessage;
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.serverdata.commands.ServerCommand;
/** /**
* A message regarding a report which is sent only to the player handling the report. * A message regarding a report which is sent only to the player handling the report.
*/ */
public class ReportHandlerNotification extends ReportNotification public class HandlerNotification extends ServerCommand
{ {
private long _reportId; private final long _reportId;
private int _handlerId; private final int _handlerId;
private final String _notification; // in json format
public ReportHandlerNotification(Report report, JsonMessage notification) public HandlerNotification(Report report, JsonMessage notification)
{ {
super(notification); super();
_reportId = report.getId().orElseThrow(() -> new IllegalStateException("Report has no id set.")); _reportId = report.getId().orElseThrow(() -> new IllegalStateException("Report has no id set."));
_handlerId = report.getHandlerId().orElseThrow(() -> new IllegalStateException("Report has no handler.")); _handlerId = report.getHandlerId().orElseThrow(() -> new IllegalStateException("Report has no handler."));
_notification = notification.toString();
setTargetServers(getServersInvolved(report)); setTargetServers(getServersInvolved(report));
} }
@ -36,4 +38,9 @@ public class ReportHandlerNotification extends ReportNotification
{ {
return _handlerId; return _handlerId;
} }
public String getNotification()
{
return _notification;
}
} }

View File

@ -1,4 +1,4 @@
package mineplex.core.report.command; package mineplex.core.report.packet;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Server; import org.bukkit.Server;
@ -12,11 +12,11 @@ import mineplex.serverdata.commands.ServerCommand;
/** /**
* Handles receiving of report notifications. * Handles receiving of report notifications.
*/ */
public class ReportNotificationCallback implements CommandCallback public class ReportCommandCallback implements CommandCallback
{ {
private final ReportManager _reportManager; private final ReportManager _reportManager;
public ReportNotificationCallback(ReportManager reportManager) public ReportCommandCallback(ReportManager reportManager)
{ {
_reportManager = reportManager; _reportManager = reportManager;
} }
@ -24,9 +24,9 @@ public class ReportNotificationCallback implements CommandCallback
@Override @Override
public void run(ServerCommand command) public void run(ServerCommand command)
{ {
if (command instanceof ReportHandlerNotification) if (command instanceof HandlerNotification)
{ {
ReportHandlerNotification reportNotification = (ReportHandlerNotification) command; HandlerNotification reportNotification = (HandlerNotification) command;
_reportManager.getReportRepository().getReport(reportNotification.getReportId()).thenAccept(report -> _reportManager.getReportRepository().getReport(reportNotification.getReportId()).thenAccept(report ->
{ {