From 95c38b193973560f6e5153564e1d7f0290711fb5 Mon Sep 17 00:00:00 2001 From: Keir Date: Mon, 2 Nov 2015 23:30:06 +0000 Subject: [PATCH] Don't use static instances. --- .../src/mineplex/core/report/ReportManager.java | 10 ++++++---- .../src/mineplex/core/report/ReportPlugin.java | 5 ----- .../src/mineplex/core/report/ReportRepository.java | 4 ++-- .../core/report/command/ReportNotification.java | 13 ++++++++----- Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 729ce0a83..46acaad62 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -16,6 +16,7 @@ import mineplex.serverdata.data.DataRepository; import mineplex.serverdata.redis.RedisDataRepository; import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; @@ -42,18 +43,19 @@ public class ReportManager { // A mapping of PlayerName(String) to the ReportId(Integer) for all active reports on this server. private Map activeReports; - public ReportManager(String serverName) + public ReportManager(JavaPlugin plugin, String serverName) { this.serverName = serverName; this.reportRepository = new RedisDataRepository(Region.ALL, Report.class, "reports"); this.reportProfiles = new RedisDataRepository(Region.ALL, ReportProfile.class, "reportprofiles"); this.activeReports = new HashMap(); - this.reportSqlRepository = new ReportRepository(); + this.reportSqlRepository = new ReportRepository(plugin); reportSqlRepository.initialize(); } public void retrieveReportResult(int reportId, Player reportCloser, String reason) { + // TODO // Prompt the report closer with a menu of options to determine the result // of the report. When confirmation is received, THEN close report. } @@ -254,7 +256,7 @@ public class ReportManager { */ public void sendReportNotification(JsonMessage message) { - ReportNotification reportNotification = new ReportNotification(message); + ReportNotification reportNotification = new ReportNotification(this, message); reportNotification.publish(); } @@ -264,7 +266,7 @@ public class ReportManager { */ public void sendReportNotification(String message) { - ReportNotification reportNotification = new ReportNotification(message); + ReportNotification reportNotification = new ReportNotification(this, message); reportNotification.publish(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java index 1805da44f..47481b682 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java @@ -11,17 +11,12 @@ import org.bukkit.plugin.java.JavaPlugin; public class ReportPlugin extends MiniPlugin { - - private static ReportPlugin instance; - public static ReportPlugin getInstance() { return instance; } - private final ReportManager _reportManager; public ReportPlugin(JavaPlugin plugin, ReportManager reportManager) { super("Report", plugin); - instance = this; _reportManager = reportManager; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index d2bb8987a..14d78690c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -31,9 +31,9 @@ This will be used to determine if staff are handling private static String INSERT_HANDLER = "INSERT INTO reportHandlers (eventDate, reportId, handlerId) VALUES(now(), ?, ?);"; private static String INSERT_SENDER = "INSERT INTO reportSenders (eventDate, reportId, reporterId, category, reason) VALUES(now(), ?, ?, ?, ?);"; - public ReportRepository() + public ReportRepository(JavaPlugin plugin) { - super(ReportPlugin.getInstance().getPlugin(), DBPool.ACCOUNT); + super(plugin, DBPool.ACCOUNT); } @Override 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 97194b850..372c9a31c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java @@ -5,22 +5,25 @@ import org.bukkit.entity.Player; import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.UtilServer; +import mineplex.core.report.ReportManager; import mineplex.core.report.ReportPlugin; import mineplex.serverdata.commands.ServerCommand; public class ReportNotification extends ServerCommand { + private ReportManager _reportManager; private String _notification; - public ReportNotification(String notification) + public ReportNotification(ReportManager reportManager, String notification) { - this(new JsonMessage(notification)); + this(reportManager, new JsonMessage(notification)); } - public ReportNotification(JsonMessage notification) + public ReportNotification(ReportManager reportManager, JsonMessage notification) { super(); // Send to all servers - this._notification = notification.toString(); + _reportManager = reportManager; + _notification = notification.toString(); } public void run() @@ -28,7 +31,7 @@ public class ReportNotification extends ServerCommand // Message all players that can receive report notifications. for (Player player : UtilServer.getPlayers()) { - if (ReportPlugin.getInstance().getReportManager().hasReportNotifications(player)) + if (_reportManager.hasReportNotifications(player)) { Server server = UtilServer.getServer(); server.dispatchCommand(server.getConsoleSender(), "tellraw " + player.getName() + " " + _notification); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index e2fd86f86..dd1ed1cd3 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -148,7 +148,7 @@ public class Hub extends JavaPlugin implements IRelation } }); new GlobalPacketManager(this, clientManager, serverStatusManager); - new ReportPlugin(this, new ReportManager(serverStatusManager.getCurrentServerName())); + new ReportPlugin(this, new ReportManager(this, serverStatusManager.getCurrentServerName())); //new Replay(this, packetHandler); AprilFoolsManager.Initialize(this, clientManager, disguiseManager);