Don't use static instances.

This commit is contained in:
Keir 2015-11-02 23:30:06 +00:00
parent 4b5ddf5385
commit 95c38b1939
5 changed files with 17 additions and 17 deletions

View File

@ -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<String, Integer> activeReports;
public ReportManager(String serverName)
public ReportManager(JavaPlugin plugin, String serverName)
{
this.serverName = serverName;
this.reportRepository = new RedisDataRepository<Report>(Region.ALL, Report.class, "reports");
this.reportProfiles = new RedisDataRepository<ReportProfile>(Region.ALL, ReportProfile.class, "reportprofiles");
this.activeReports = new HashMap<String, Integer>();
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();
}

View File

@ -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;
}

View File

@ -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

View File

@ -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);

View File

@ -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);