Replace ReportProfile by using statistics to track total reports and accepted, denied & abusive reports. 1 or more abusive reports results in being banned from the report system.

This commit is contained in:
Keir 2015-11-20 22:03:57 +00:00
parent fc6e1fe003
commit 470ff67f86
3 changed files with 63 additions and 109 deletions

View File

@ -1,5 +1,6 @@
package mineplex.core.report;
import java.sql.SQLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
@ -17,6 +18,8 @@ import mineplex.core.report.command.ReportHandlerNotification;
import mineplex.core.report.command.ReportNotificationCallback;
import mineplex.core.report.command.ReportNotification;
import mineplex.core.report.task.ReportHandlerMessageTask;
import mineplex.core.stats.PlayerStats;
import mineplex.core.stats.StatsManager;
import mineplex.serverdata.Region;
import mineplex.serverdata.Utility;
import mineplex.serverdata.commands.ServerCommandManager;
@ -41,28 +44,31 @@ public class ReportManager {
private static final String NAME = "Report";
// statistic constants
private static final String STAT_TOTAL_COUNT = "Global.TotalReportsCount";
private static final int ABUSE_BAN_THRESHOLD = 1;
private JavaPlugin _javaPlugin;
private PreferencesManager _preferencesManager;
private StatsManager _statsManager;
private String _serverName;
// 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;
public ReportManager(JavaPlugin javaPlugin, PreferencesManager preferencesManager, String serverName)
public ReportManager(JavaPlugin javaPlugin, PreferencesManager preferencesManager, StatsManager statsManager, String serverName)
{
_javaPlugin = javaPlugin;
_preferencesManager = preferencesManager;
_statsManager = statsManager;
_serverName = serverName;
_reportRepository = new RedisDataRepository<Report>(Region.ALL, Report.class, "reports");
_reportProfiles = new RedisDataRepository<ReportProfile>(Region.ALL, ReportProfile.class, "reportprofiles");
_activeReports = new HashMap<String, Integer>();
_reportSqlRepository = new ReportRepository(javaPlugin);
_reportSqlRepository.initialize();
@ -89,10 +95,7 @@ public class ReportManager {
// Update the reputation/profiles of all reporters on this closing report.
for (String reporterName : report.getReporters())
{
CoreClient reporterAccount = getPlayerAccount(reporterName);
ReportProfile reportProfile = getReportProfile(String.valueOf(reporterAccount.getAccountId()));
reportProfile.onReportClose(result);
saveReportProfile(reportProfile);
incrementStat(reporterName, result);
}
if (reportCloser != null)
@ -133,13 +136,43 @@ public class ReportManager {
}
}
public boolean canReport(Player player)
{
try {
PlayerStats playerStats = _statsManager.getOfflinePlayerStats(player.getName());
long abusiveReportsCount = playerStats.getStat(ReportResult.ABUSIVE.getStatName());
return abusiveReportsCount < ABUSE_BAN_THRESHOLD;
}
catch (SQLException e)
{
player.sendMessage(C.cRed + "Internal error.");
e.printStackTrace();
return false;
}
}
private void incrementTotalStat(String reporter)
{
int accountId = getAccountId(reporter);
_statsManager.incrementStat(accountId, STAT_TOTAL_COUNT, 1);
}
private void incrementStat(String reporter, ReportResult reportResult)
{
String statName = reportResult.getStatName();
if (statName != null)
{
int accountId = getAccountId(reporter);
_statsManager.incrementStat(accountId, statName, 1);
}
}
public Report reportPlayer(Player reporter, Player reportedPlayer, ReportCategory category, String reason)
{
int reporterId = getPlayerAccount(reporter).getAccountId();
ReportProfile reportProfile = getReportProfile(String.valueOf(reporterId));
if (reportProfile.canReport())
if (canReport(reportedPlayer))
{
int reporterId = getPlayerAccount(reporter).getAccountId();
Report report = getActiveReport(reportedPlayer.getName());
if (report != null && report.getCategory() == category)
@ -153,12 +186,13 @@ public class ReportManager {
_activeReports.put(reportedPlayer.getName().toLowerCase(), report.getReportId());
}
int reportId = report.getReportId();
incrementTotalStat(reporter.getName());
saveReport(report);
// only start notifying staff when
if (report.getReporters().size() >= category.getNotifyThreshold())
{
int reportId = report.getReportId();
String prefix = getReportPrefix(reportId);
// Report #2 > iKeirNez - Flying around in arcade game (Hacking)
@ -175,7 +209,7 @@ public class ReportManager {
if (report.getHandler() == null)
{
// this needs to be 'equals' otherwise we get errors when attempting to send this (due to incomplete JSON)
message = message.extra("\n" + F.main(getReportPrefix(reportId), "Click to handle this ticket."))
message = message.extra("\n" + F.main(prefix, "Click to handle this ticket."))
.click(ClickEvent.RUN_COMMAND, "/reporthandle " + reportId);
sendStaffNotification(message);
@ -211,24 +245,6 @@ public class ReportManager {
}
}
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.
*/

View File

@ -1,69 +0,0 @@
package mineplex.core.report;
import mineplex.serverdata.data.Data;
public class ReportProfile implements Data
{
private String _playerName;
private int _playerId;
private int _totalReports;
public int getTotalReports() { return _totalReports; }
private int _acceptedReports;
public int getAcceptedReports() { return _acceptedReports; }
private int _deniedReports;
public int getDeniedReports() { return _deniedReports; }
private int _abuseReports;
public int getAbuseReports() { return _abuseReports; }
private boolean _banned;
public ReportProfile(String playerName, int playerId)
{
_playerName = playerName;
_playerId = playerId;
_totalReports = 0;
_acceptedReports = 0;
_deniedReports = 0;
_abuseReports = 0;
_banned = false;
}
@Override
public String getDataId()
{
return String.valueOf(_playerId);
}
public boolean canReport()
{
return !_banned;
}
/**
* Called when a report made by this player is closed.
* @param result - the result of the closed report.
*/
public void onReportClose(ReportResult result)
{
_totalReports++;
switch (result)
{
default: break;
case ACCEPTED:
_acceptedReports++;
break;
case DENIED:
_deniedReports++;
break;
case ABUSIVE:
_abuseReports++;
break;
}
}
}

View File

@ -4,23 +4,30 @@ import org.bukkit.ChatColor;
public enum ReportResult
{
ACCEPTED(ChatColor.GREEN, "Accept Report (Punish Player)", "Accepted (Player Received Punishment)"),
DENIED(ChatColor.YELLOW, "Deny Report", "Denied"),
ABUSIVE(ChatColor.RED, "Mark Abusive Report", "Abusive Report");
ACCEPTED("Global.AcceptedReportsCount", ChatColor.GREEN, "Accept Report (Punish Player)", "Accepted (Player Received Punishment)"),
DENIED("Global.DeniedReportsCount", ChatColor.YELLOW, "Deny Report", "Denied"),
ABUSIVE("Global.AbusiveReportsCount", ChatColor.RED, "Mark Abusive Report", "Abusive Report");
private ChatColor _color;
private String _actionMessage;
private String _resultMessage;
private String[] _lore;
private final String _statName;
private final ChatColor _color;
private final String _actionMessage;
private final String _resultMessage;
private final String[] _lore;
ReportResult(ChatColor color, String actionMessage, String resultMessage, String... lore)
ReportResult(String statName, ChatColor color, String actionMessage, String resultMessage, String... lore)
{
_statName = statName;
_color = color;
_actionMessage = actionMessage;
_resultMessage = resultMessage;
_lore = lore;
}
public String getStatName()
{
return _statName;
}
public ChatColor getColor()
{
return _color;