Notify the handler of a report (if any) when the report they are handling is purged.

This commit is contained in:
Keir 2015-11-20 21:10:03 +00:00
parent 80c87fa1fc
commit fc6e1fe003
2 changed files with 36 additions and 7 deletions

View File

@ -401,14 +401,14 @@ public class ReportManager {
return _activeReports.values(); return _activeReports.values();
} }
/* PRIVATE STATIC HELPERS */ /* STATIC HELPERS */
private static String getReportPrefix(Report report) public static String getReportPrefix(Report report)
{ {
return getReportPrefix(report.getReportId()); return getReportPrefix(report.getReportId());
} }
private static String getReportPrefix(int reportId) public static String getReportPrefix(int reportId)
{ {
return NAME + " #" + reportId; return NAME + " #" + reportId;
} }

View File

@ -2,6 +2,7 @@ package mineplex.core.report.task;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import mineplex.core.common.util.C;
import mineplex.core.report.Report; import mineplex.core.report.Report;
import mineplex.core.report.ReportManager; import mineplex.core.report.ReportManager;
@ -27,7 +28,10 @@ public class ReportPurgeTask extends BukkitRunnable
if (report != null) if (report != null)
{ {
checkReportActive(report); if (checkForPurge(report))
{
notifyHandler(report);
}
} }
else else
{ {
@ -37,21 +41,46 @@ public class ReportPurgeTask extends BukkitRunnable
} }
} }
public boolean checkReportActive(Report report) /**
* Checks if a report should be purged and carries it out if so.
*
* @param report the report to check for purging (and act accordingly)
* @return true if the report was purged, false otherwise
*/
public boolean checkForPurge(Report report)
{ {
if (!report.isActive()) if (!report.isActive())
{ {
int reportId = report.getReportId(); int reportId = report.getReportId();
purgeReport(reportId); purgeReport(reportId);
return false; return true;
} }
return true; return false;
} }
/**
* Purges a report.
*
* @param reportId the report id to purge
*/
public void purgeReport(int reportId) public void purgeReport(int reportId)
{ {
_reportManager.removeReport(reportId); _reportManager.removeReport(reportId);
_reportManager.removeActiveReport(reportId); _reportManager.removeActiveReport(reportId);
} }
/**
* Notifies the handler of a report (if any) that the report was purged.
*
* @param report the report which was purged
*/
public void notifyHandler(Report report)
{
// would result in spam if many reports with no handlers are purged (causing each member of staff to receive a message for every purged report)
if (report.getHandler() != null)
{
_reportManager.sendHandlerNotification(report, ReportManager.getReportPrefix(report) + C.cRed + "Purging report due to inactivity.");
}
}
} }