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.
This commit is contained in:
Keir Nellyer 2016-04-29 23:37:40 +01:00
parent bff5751691
commit 81cebc4ce7
4 changed files with 11 additions and 23 deletions

View File

@ -11,6 +11,7 @@ import java.util.UUID;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import mineplex.core.account.CoreClient; import mineplex.core.account.CoreClient;
import mineplex.core.account.CoreClientManager;
import mineplex.core.chatsnap.Snapshot; import mineplex.core.chatsnap.Snapshot;
import mineplex.core.chatsnap.SnapshotManager; import mineplex.core.chatsnap.SnapshotManager;
import mineplex.core.chatsnap.publishing.SnapshotPublisher; import mineplex.core.chatsnap.publishing.SnapshotPublisher;
@ -59,6 +60,7 @@ public class ReportManager {
private PreferencesManager _preferencesManager; private PreferencesManager _preferencesManager;
private StatsManager _statsManager; private StatsManager _statsManager;
private SnapshotManager _snapshotManager; private SnapshotManager _snapshotManager;
private CoreClientManager _coreClientManager;
private String _serverName; private String _serverName;
// Holds active/open reports in a synchronized database. // Holds active/open reports in a synchronized database.
@ -71,12 +73,13 @@ public class ReportManager {
private Map<String, Integer> _activeReports; private Map<String, Integer> _activeReports;
public ReportManager(JavaPlugin javaPlugin, PreferencesManager preferencesManager, StatsManager statsManager, public ReportManager(JavaPlugin javaPlugin, PreferencesManager preferencesManager, StatsManager statsManager,
SnapshotManager snapshotManager, String serverName) SnapshotManager snapshotManager, CoreClientManager coreClientManager, String serverName)
{ {
_javaPlugin = javaPlugin; _javaPlugin = javaPlugin;
_preferencesManager = preferencesManager; _preferencesManager = preferencesManager;
_statsManager = statsManager; _statsManager = statsManager;
_snapshotManager = snapshotManager; _snapshotManager = snapshotManager;
_coreClientManager = coreClientManager;
_serverName = serverName; _serverName = serverName;
_reportRepository = new RedisDataRepository<>(Region.ALL, Report.class, "reports"); _reportRepository = new RedisDataRepository<>(Region.ALL, Report.class, "reports");
_activeReports = new HashMap<>(); _activeReports = new HashMap<>();
@ -97,9 +100,9 @@ public class ReportManager {
{ {
removeReport(reportId); 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(); 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); _reportSqlRepository.logReport(reportId, playerId, _serverName, closerId, result, reason);
// Update the reputation/profiles of all reporters on this closing report. // Update the reputation/profiles of all reporters on this closing report.
@ -159,7 +162,7 @@ public class ReportManager {
private void incrementTotalStat(String reporter) private void incrementTotalStat(String reporter)
{ {
int accountId = getAccountId(reporter); int accountId = _coreClientManager.Get(reporter).getAccountId();
_statsManager.incrementStat(accountId, STAT_TOTAL_COUNT, 1); _statsManager.incrementStat(accountId, STAT_TOTAL_COUNT, 1);
} }
@ -169,7 +172,7 @@ public class ReportManager {
if (statName != null) if (statName != null)
{ {
int accountId = getAccountId(reporter); int accountId = _coreClientManager.Get(reporter).getAccountId();
_statsManager.incrementStat(accountId, statName, 1); _statsManager.incrementStat(accountId, statName, 1);
} }
} }
@ -477,19 +480,4 @@ public class ReportManager {
{ {
return NAME + " #" + reportId; 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();
}
} }

View File

@ -145,7 +145,7 @@ public class Clans extends JavaPlugin
SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this)); SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this));
new SnapshotPlugin(this, snapshotManager); 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 // Enable custom-gear related managers
new CustomTagFix(this, packetHandler); new CustomTagFix(this, packetHandler);

View File

@ -158,7 +158,7 @@ public class Hub extends JavaPlugin implements IRelation
new GlobalPacketManager(this, clientManager, serverStatusManager, inventoryManager, donationManager, petManager, statsManager); new GlobalPacketManager(this, clientManager, serverStatusManager, inventoryManager, donationManager, petManager, statsManager);
SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this)); SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this));
new SnapshotPlugin(this, snapshotManager); 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); //new Replay(this, packetHandler);
AprilFoolsManager.Initialize(this, clientManager, disguiseManager); AprilFoolsManager.Initialize(this, clientManager, disguiseManager);

View File

@ -144,7 +144,7 @@ public class Arcade extends JavaPlugin
Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName()); Chat chat = new Chat(this, incognito, _clientManager, preferenceManager, achievementManager, serverStatusManager.getCurrentServerName());
new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat); new MessageManager(this, incognito, _clientManager, preferenceManager, ignoreManager, punish, friendManager, chat);
SnapshotManager snapshotManager = new SnapshotManager(new SnapshotPublisher(this)); 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 SnapshotPlugin(this, snapshotManager);
new ReportPlugin(this, reportManager); new ReportPlugin(this, reportManager);