From 81cebc4ce72d34795a873077f589a50f7aef29fc Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Fri, 29 Apr 2016 23:37:40 +0100 Subject: [PATCH] Swap static helpers for a much better solution This allows for easier refactoring in the future when we move away from retrieving the CoreClientManager from a static instance. Mineplex coding standards are also against the use of static helpers in scenarios such as this, therefore this commit brings this branch to be in-line with the coding standards. --- .../mineplex/core/report/ReportManager.java | 28 ++++++------------- .../src/mineplex/game/clans/Clans.java | 2 +- .../Mineplex.Hub/src/mineplex/hub/Hub.java | 2 +- .../src/nautilus/game/arcade/Arcade.java | 2 +- 4 files changed, 11 insertions(+), 23 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 7a2fc317e..fb67f7b98 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -11,6 +11,7 @@ import java.util.UUID; import com.google.gson.Gson; import com.google.gson.JsonObject; import mineplex.core.account.CoreClient; +import mineplex.core.account.CoreClientManager; import mineplex.core.chatsnap.Snapshot; import mineplex.core.chatsnap.SnapshotManager; import mineplex.core.chatsnap.publishing.SnapshotPublisher; @@ -59,6 +60,7 @@ public class ReportManager { private PreferencesManager _preferencesManager; private StatsManager _statsManager; private SnapshotManager _snapshotManager; + private CoreClientManager _coreClientManager; private String _serverName; // Holds active/open reports in a synchronized database. @@ -71,12 +73,13 @@ public class ReportManager { private Map _activeReports; public ReportManager(JavaPlugin javaPlugin, PreferencesManager preferencesManager, StatsManager statsManager, - SnapshotManager snapshotManager, String serverName) + SnapshotManager snapshotManager, CoreClientManager coreClientManager, String serverName) { _javaPlugin = javaPlugin; _preferencesManager = preferencesManager; _statsManager = statsManager; _snapshotManager = snapshotManager; + _coreClientManager = coreClientManager; _serverName = serverName; _reportRepository = new RedisDataRepository<>(Region.ALL, Report.class, "reports"); _activeReports = new HashMap<>(); @@ -97,9 +100,9 @@ public class ReportManager { { removeReport(reportId); - int closerId = reportCloser != null ? getPlayerAccount(reportCloser).getAccountId() : -1; + int closerId = reportCloser != null ? _coreClientManager.Get(reportCloser).getAccountId() : -1; String suspectName = Bukkit.getOfflinePlayer(report.getSuspect()).getName(); - int playerId = getPlayerAccount(suspectName).getAccountId(); + int playerId = _coreClientManager.Get(suspectName).getAccountId(); _reportSqlRepository.logReport(reportId, playerId, _serverName, closerId, result, reason); // Update the reputation/profiles of all reporters on this closing report. @@ -159,7 +162,7 @@ public class ReportManager { private void incrementTotalStat(String reporter) { - int accountId = getAccountId(reporter); + int accountId = _coreClientManager.Get(reporter).getAccountId(); _statsManager.incrementStat(accountId, STAT_TOTAL_COUNT, 1); } @@ -169,7 +172,7 @@ public class ReportManager { if (statName != null) { - int accountId = getAccountId(reporter); + int accountId = _coreClientManager.Get(reporter).getAccountId(); _statsManager.incrementStat(accountId, statName, 1); } } @@ -477,19 +480,4 @@ public class ReportManager { { return NAME + " #" + reportId; } - - private static CoreClient getPlayerAccount(Player player) - { - return getPlayerAccount(player.getName()); - } - - private static CoreClient getPlayerAccount(String playerName) - { - return CommandCenter.Instance.GetClientManager().Get(playerName); - } - - private static int getAccountId(String playerName) - { - return getPlayerAccount(playerName).getAccountId(); - } } diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java index 347cb6c3d..d95bb34cb 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/Clans.java @@ -145,7 +145,7 @@ public class Clans extends JavaPlugin SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this)); new SnapshotPlugin(this, snapshotManager); - new ReportPlugin(this, new ReportManager(this, preferenceManager, statsManager, snapshotManager, serverStatusManager.getCurrentServerName())); + new ReportPlugin(this, new ReportManager(this, preferenceManager, statsManager, snapshotManager, CommandCenter.Instance.GetClientManager(), serverStatusManager.getCurrentServerName())); // Enable custom-gear related managers new CustomTagFix(this, packetHandler); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 079157720..76ab8e913 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -158,7 +158,7 @@ public class Hub extends JavaPlugin implements IRelation new GlobalPacketManager(this, clientManager, serverStatusManager, inventoryManager, donationManager, petManager, statsManager); SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this)); new SnapshotPlugin(this, snapshotManager); - new ReportPlugin(this, new ReportManager(this, preferenceManager, statsManager, snapshotManager, serverStatusManager.getCurrentServerName())); + new ReportPlugin(this, new ReportManager(this, preferenceManager, statsManager, snapshotManager, CommandCenter.Instance.GetClientManager(), serverStatusManager.getCurrentServerName())); //new Replay(this, packetHandler); AprilFoolsManager.Initialize(this, clientManager, disguiseManager); diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java index f75578856..745a1828b 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/Arcade.java @@ -144,7 +144,7 @@ public class Arcade extends JavaPlugin Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this)); - ReportManager reportManager = new ReportManager(this, preferenceManager, statsManager, snapshotManager, serverStatusManager.getCurrentServerName()); + ReportManager reportManager = new ReportManager(this, preferenceManager, statsManager, snapshotManager, CommandCenter.Instance.GetClientManager(), serverStatusManager.getCurrentServerName()); new SnapshotPlugin(this, snapshotManager); new ReportPlugin(this, reportManager);