Pass server name to ReportManager.

This commit is contained in:
Keir 2015-11-01 16:44:02 +00:00
parent ec5cbbe684
commit 93a5ebf0eb
6 changed files with 22 additions and 37 deletions

View File

@ -29,7 +29,7 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
*/
public class ReportManager {
private static ReportManager instance;
private String serverName;
// Holds active/open reports in a synchronized database.
private DataRepository<Report> reportRepository;
@ -42,17 +42,15 @@ public class ReportManager {
// A mapping of PlayerName(String) to the ReportId(Integer) for all active reports on this server.
private Map<String, Integer> activeReports;
/**
* Private constructor to prevent non-singleton instances.
*/
private ReportManager()
public ReportManager(String serverName, String logsConnectionString)
{
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>();
// TODO: Get JavaPlugin instance and locate ConnectionString from config?
this.reportSqlRepository = new ReportRepository(ReportPlugin.getPluginInstance(), "CONNECTION STRING HERE");
this.reportSqlRepository = new ReportRepository(ReportPlugin.getInstance().getPlugin(), logsConnectionString);
reportSqlRepository.initialize();
}
@ -79,8 +77,7 @@ public class ReportManager {
int closerId = reportCloser != null ? getPlayerAccount(reportCloser).getAccountId() : -1;
String playerName = getReport(reportId).getPlayerName();
int playerId = getPlayerAccount(playerName).getAccountId();
String server = null; // TODO: Get current server name
reportSqlRepository.logReport(reportId, playerId, server, closerId, result, reason);
reportSqlRepository.logReport(reportId, playerId, serverName, closerId, result, reason);
// Update the reputation/profiles of all reporters on this closing report.
for (String reporterName : report.getReporters())
@ -134,7 +131,6 @@ public class ReportManager {
}
else
{
String serverName = null; // TODO: Fetch name of current server
reportId = generateReportId();
report = new Report(reportId, reportedPlayer.getName(), serverName, category);
report.addReporter(reporter.getName());
@ -320,17 +316,4 @@ public class ReportManager {
return false;
}
/**
* @return the singleton instance of {@link ReportManager}.
*/
public static ReportManager getInstance()
{
if (instance == null)
{
instance = new ReportManager();
}
return instance;
}
}

View File

@ -12,22 +12,22 @@ import org.bukkit.plugin.java.JavaPlugin;
public class ReportPlugin extends MiniPlugin
{
private static JavaPlugin instance;
public static JavaPlugin getPluginInstance() { return instance; }
private static ReportPlugin instance;
public static ReportPlugin getInstance() { return instance; }
private final String _serverName;
private final ReportManager _reportManager;
public ReportPlugin(JavaPlugin plugin, String serverName)
public ReportPlugin(JavaPlugin plugin, ReportManager reportManager)
{
super("Report", plugin);
instance = plugin;
_serverName = serverName;
instance = this;
_reportManager = reportManager;
}
public String getServerName()
public ReportManager getReportManager()
{
return _serverName;
return _reportManager;
}
@Override
@ -42,6 +42,6 @@ public class ReportPlugin extends MiniPlugin
@EventHandler
public void onPlayerQuit(PlayerQuitEvent e)
{
ReportManager.getInstance().onPlayerQuit(e.getPlayer());
_reportManager.onPlayerQuit(e.getPlayer());
}
}

View File

@ -31,7 +31,7 @@ public class ReportCloseCommand extends CommandBase<ReportPlugin>
int reportId = Integer.parseInt(args[0]);
String reason = F.combine(args, 1, null, false);
ReportManager.getInstance().closeReport(reportId, player, reason);
Plugin.getReportManager().closeReport(reportId, player, reason);
}
}
}

View File

@ -30,7 +30,7 @@ public class ReportHandleCommand extends CommandBase<ReportPlugin>
{
int reportId = Integer.parseInt(args[0]);
ReportManager.getInstance().handleReport(reportId, player);
Plugin.getReportManager().handleReport(reportId, player);
}
}
}

View File

@ -5,7 +5,7 @@ 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
@ -28,7 +28,7 @@ public class ReportNotification extends ServerCommand
// Message all players that can receive report notifications.
for (Player player : UtilServer.getPlayers())
{
if (ReportManager.getInstance().hasReportNotifications(player))
if (ReportPlugin.getInstance().getReportManager().hasReportNotifications(player))
{
Server server = UtilServer.getServer();
server.dispatchCommand(server.getConsoleSender(), "tellraw " + player.getName() + " " + _notification);

View File

@ -25,6 +25,7 @@ public class ReportPage extends SimpleGui
put(rowStartSlot + 5, Category.CHAT_ABUSE);
}});
private ReportPlugin _reportPlugin;
private Player _reportee;
private Player _offender;
private String _reason;
@ -33,6 +34,7 @@ public class ReportPage extends SimpleGui
{
super(reportPlugin.getPlugin(), reportee, "Report " + offender.getName(), 9 * 5);
this._reportPlugin = reportPlugin;
this._reportee = reportee;
this._offender = offender;
this._reason = reason;
@ -52,7 +54,7 @@ public class ReportPage extends SimpleGui
public void addReport(Category category)
{
ReportManager.getInstance().reportPlayer(_reportee, _offender, category, _reason);
_reportPlugin.getReportManager().reportPlayer(_reportee, _offender, category, _reason);
_reportee.closeInventory();
unregisterListener();
}