Store report category and only "merge" reports when the category is the same.

This commit is contained in:
Keir 2015-10-27 17:30:47 +00:00
parent 394e501682
commit bc3a119a22
3 changed files with 67 additions and 78 deletions

View File

@ -21,19 +21,17 @@ public class Report implements Data
private Set<String> _reporters;
public Set<String> getReporters() { return _reporters; }
public void addReporter(String reporter) { _reporters.add(reporter); }
/**
* Class constructor
* @param reportId
* @param playerName
* @param serverName
*/
public Report(int reportId, String playerName, String serverName)
private Category _category;
public Category getCategory() { return _category; }
public Report(int reportId, String playerName, String serverName, Category category)
{
_reportId = reportId;
_playerName = playerName;
_serverName = serverName;
_reporters = new HashSet<String>();
_category = category;
}
@Override

View File

@ -6,7 +6,6 @@ import java.util.Map.Entry;
import mineplex.core.account.CoreClient;
import mineplex.core.command.CommandCenter;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.portal.Portal;
import mineplex.core.report.command.ReportNotification;
import mineplex.serverdata.Region;
@ -14,7 +13,6 @@ import mineplex.serverdata.Utility;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.redis.RedisDataRepository;
import org.bukkit.ChatColor;
import org.bukkit.entity.Player;
import redis.clients.jedis.Jedis;
@ -28,20 +26,20 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
*
*/
public class ReportManager {
private static ReportManager instance;
// Holds active/open reports in a synchronized database.
private DataRepository<Report> reportRepository;
private DataRepository<ReportProfile> reportProfiles;
// Stores/logs closed tickets, and various reporter/staff actions.
private ReportRepository reportSqlRepository;
// 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.
*/
@ -50,23 +48,23 @@ public class ReportManager {
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");
reportSqlRepository.initialize();
}
public void retrieveReportResult(int reportId, Player reportCloser, String reason)
{
// Prompt the report closer with a menu of options to determine the result
// of the report. When confirmation is received, THEN close report.
}
public void closeReport(int reportId, Player reportCloser, String reason)
{
retrieveReportResult(reportId, reportCloser, reason);
}
public void closeReport(int reportId, Player reportCloser, String reason,
ReportResult result)
{
@ -75,13 +73,13 @@ public class ReportManager {
Report report = getReport(reportId);
reportRepository.removeElement(String.valueOf(reportId)); // Remove report from redis database
removeActiveReport(reportId);
int closerId = getPlayerAccount(reportCloser).getAccountId();
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);
// Update the reputation/profiles of all reporters on this closing report.
for (String reporterName : report.getReporters())
{
@ -90,17 +88,17 @@ public class ReportManager {
reportProfile.onReportClose(result);
reportProfiles.addElement(reportProfile);
}
if (reportCloser != null)
{
// Notify staff that the report was closed.
sendReportNotification(String.format("[Report %d] %s closed this report. (%s).", reportId,
sendReportNotification(String.format("[Report %d] %s closed this report. (%s).", reportId,
reportCloser.getName(), result.toDisplayMessage()));
}
}
}
public void handleReport(int reportId, Player reportHandler)
{
if (reportRepository.elementExists(String.valueOf(reportId)))
@ -109,82 +107,78 @@ public class ReportManager {
Portal.transferPlayer(reportHandler.getName(), report.getServerName());
String handlerName = reportHandler.getName();
sendReportNotification(String.format("[Report %d] %s is handling this report.", reportId, handlerName));
// TODO: Send display message to handler when they arrive on the server
// with info about the case/report.
int handlerId = getPlayerAccount(reportHandler).getAccountId();
reportSqlRepository.logReportHandling(reportId, handlerId); // Log handling into sql database
}
}
public void reportPlayer(Player reporter, Player reportedPlayer, String reason)
public void reportPlayer(Player reporter, Player reportedPlayer, Category category, String reason)
{
int reporterId = getPlayerAccount(reporter).getAccountId();
ReportProfile reportProfile = getReportProfile(String.valueOf(reporterId));
if (reportProfile.canReport())
{
Report report = null;
if (hasActiveReport(reportedPlayer))
int reportId = getActiveReport(reportedPlayer.getName());
Report report = getReport(reportId);
if (reportId != -1 && report.getCategory() == category)
{
int reportId = getActiveReport(reportedPlayer.getName());
report = getReport(reportId);
report.addReporter(reporter.getName());
}
else
{
String serverName = null; // TODO: Fetch name of current server
int reportId = generateReportId();
report = new Report(reportId, reportedPlayer.getName(), serverName);
reportId = generateReportId();
report = new Report(reportId, reportedPlayer.getName(), serverName, category);
report.addReporter(reporter.getName());
activeReports.put(reportedPlayer.getName().toLowerCase(), report.getReportId());
reportRepository.addElement(report);
}
if (report != null)
{
// [Report 42] [MrTwiggy +7] [Cheater102 - 5 - Speed hacking]
String message = String.format("[Report %d] [%s %d] [%s - %d - %s]", report.getReportId(),
reporter.getName(), reportProfile.getReputation(),
reportedPlayer.getName(), report.getReporters().size(), reason);
sendReportNotification(message);
reportSqlRepository.logReportSending(report.getReportId(), reporterId, reason);
}
// [Report 42] [MrTwiggy +7] [Cheater102 - 5 - Speed hacking]
String message = String.format("[Report %d] [%s %d] [%s - %d - %s]", report.getReportId(),
reporter.getName(), reportProfile.getReputation(),
reportedPlayer.getName(), report.getReporters().size(), reason);
sendReportNotification(message);
reportSqlRepository.logReportSending(report.getReportId(), reporterId, reason);
}
}
public void onPlayerQuit(Player player)
public void onPlayerQuit(Player player)
{
if (hasActiveReport(player))
{
int reportId = getActiveReport(player.getName());
this.closeReport(reportId, null, "Player Quit", ReportResult.UNDETERMINED);
// TODO: Handle 'null' report closer in closeReport metohd for NPEs.
sendReportNotification(String.format("[Report %d] %s has left the game.", reportId, player.getName()));
}
}
public ReportProfile getReportProfile(String playerName)
{
ReportProfile profile = reportProfiles.getElement(playerName);
if (profile == null)
{
profile = new ReportProfile(playerName, getAccountId(playerName));
saveReportProfile(profile);
}
return profile;
}
private void saveReportProfile(ReportProfile profile)
{
reportProfiles.addElement(profile);
}
/**
* @return a uniquely generated report id.
*/
@ -193,7 +187,7 @@ public class ReportManager {
JedisPool pool = Utility.getPool(true);
Jedis jedis = pool.getResource();
long uniqueReportId = -1;
try
{
uniqueReportId = jedis.incr("reports.unique-id");
@ -211,30 +205,30 @@ public class ReportManager {
pool.returnResource(jedis);
}
}
return (int) uniqueReportId;
}
public Report getReport(int reportId)
{
return reportRepository.getElement(String.valueOf(reportId));
}
private CoreClient getPlayerAccount(Player player)
{
return getPlayerAccount(player.getName());
}
private CoreClient getPlayerAccount(String playerName)
{
return CommandCenter.Instance.GetClientManager().Get(playerName);
}
private int getAccountId(String playerName)
{
return getPlayerAccount(playerName).getAccountId();
}
/**
* @param player - the player whose report notification settings are to be checked
* @return true, if the player should receive report notifications, false otherwise.
@ -246,7 +240,7 @@ public class ReportManager {
// Else return true.
return false;
}
/**
* Send a network-wide {@link ReportNotification} to all online staff.
* @param message - the report notification message to send.
@ -256,7 +250,7 @@ public class ReportManager {
ReportNotification reportNotification = new ReportNotification(message);
reportNotification.publish();
}
/**
* @param playerName - the name of the player whose active report id is being fetched
* @return the report id for the active report corresponding with playerName, if one
@ -268,15 +262,15 @@ public class ReportManager {
{
return activeReports.get(playerName.toLowerCase());
}
return -1;
}
public boolean hasActiveReport(Player player)
{
return getActiveReport(player.getName()) != -1;
}
public boolean isActiveReport(int reportId)
{
for (Entry<String, Integer> activeReport : activeReports.entrySet())
@ -286,10 +280,10 @@ public class ReportManager {
return true;
}
}
return false;
}
public boolean removeActiveReport(int reportId)
{
for (Entry<String, Integer> activeReport : activeReports.entrySet())
@ -300,20 +294,20 @@ public class ReportManager {
return true;
}
}
return false;
}
/**
* @return the singleton instance of {@link ReportManager}.
*/
public static ReportManager getInstance()
public static ReportManager getInstance()
{
if (instance == null)
{
instance = new ReportManager();
}
return instance;
}
}

View File

@ -18,9 +18,6 @@ import mineplex.core.report.ReportPlugin;
*/
public class ReportPage extends SimpleGui
{
// todo this and PunishPage share a lot of code, generalize?
private static final Map<Integer, Category> CATEGORY_SLOTS = Collections.unmodifiableMap(new HashMap<Integer, Category>()
{{
int rowStartSlot = 9 * 2; // 3rd row
@ -55,7 +52,7 @@ public class ReportPage extends SimpleGui
public void addReport(Category category)
{
ReportManager.getInstance().reportPlayer(_reportee, _offender, _reason); // todo add category info
ReportManager.getInstance().reportPlayer(_reportee, _offender, category, _reason);
_reportee.closeInventory();
unregisterListener();
}