Closing a report will now display a GUI in which the closer can decide on the result of the report. Some of these options will yield additional options, such as punishment options if a report is indeed valid.

Store count of a players accepted, denied and abusive reports.
The previous partially implemented reputation system has been removed, at least for now.
This commit is contained in:
Keir 2015-11-12 00:02:38 +00:00
parent 9573751a87
commit 6295a8ce08
9 changed files with 220 additions and 66 deletions

View File

@ -21,6 +21,7 @@ import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.redis.RedisDataRepository;
import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.plugin.java.JavaPlugin;
import redis.clients.jedis.Jedis;
@ -62,18 +63,6 @@ public class ReportManager {
ServerCommandManager.getInstance().registerCommandType("ReportNotification", ReportNotification.class, new ReportNotificationCallback(this));
}
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.
}
public void closeReport(int reportId, Player reportCloser, String reason)
{
retrieveReportResult(reportId, reportCloser, reason);
}
public void closeReport(int reportId, Player reportCloser, String reason,
ReportResult result)
{
@ -84,7 +73,7 @@ public class ReportManager {
removeActiveReport(reportId);
int closerId = reportCloser != null ? getPlayerAccount(reportCloser).getAccountId() : -1;
String playerName = getReport(reportId).getPlayerName();
String playerName = report.getPlayerName();
int playerId = getPlayerAccount(playerName).getAccountId();
_reportSqlRepository.logReport(reportId, playerId, _serverName, closerId, result, reason);
@ -100,8 +89,11 @@ public class ReportManager {
if (reportCloser != null)
{
// Notify staff that the report was closed.
sendReportNotification(String.format("[Report %d] %s closed this report. (%s).", reportId,
reportCloser.getName(), result.toDisplayMessage()));
sendReportNotification(String.format("[Report %d] %s closed this report for: %s (%s).", reportId,
reportCloser.getName(), reason, result.toDisplayMessage()));
CommandCenter.Instance.OnPlayerCommandPreprocess(
new PlayerCommandPreprocessEvent(reportCloser, "/punish " + playerName + " " + reason));
}
}
}
@ -156,10 +148,10 @@ public class ReportManager {
// only start notifying staff when
if (report.getReporters().size() >= 1)
{
// [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);
// [Report #42] [MrTwiggy] [Cheater102 - 5 - Speed hacking]
String message = String.format("[Report #%d] [%s] [%s - %d - %s]", report.getReportId(),
reporter.getName(), reportedPlayer.getName(),
report.getReporters().size(), reason);
JsonMessage clickableMessage = new JsonMessage("Click ")
.extra("here")
@ -264,7 +256,6 @@ public class ReportManager {
{
boolean isStaff = CommandCenter.Instance.GetClientManager().Get(player).GetRank().has(Rank.MODERATOR);
boolean hasReportNotifications = _preferencesManager.Get(player).ShowUserReports;
System.out.println("player " + player.getName() + " isstaff " + isStaff + " hasnotif " + hasReportNotifications);
return isStaff && hasReportNotifications;
}

View File

@ -6,16 +6,20 @@ public class ReportProfile implements Data
{
private String _playerName;
private int _playerId;
private int _totalReports;
private int _successfulReports;
private int _reputation;
public int getReputation() { return _reputation; }
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)
@ -23,8 +27,9 @@ public class ReportProfile implements Data
_playerName = playerName;
_playerId = playerId;
_totalReports = 0;
_successfulReports = 0;
_reputation = 0;
_acceptedReports = 0;
_deniedReports = 0;
_abuseReports = 0;
_banned = false;
}
@ -46,16 +51,19 @@ public class ReportProfile implements Data
public void onReportClose(ReportResult result)
{
_totalReports++;
if (result == ReportResult.MUTED || result == ReportResult.BANNED)
switch (result)
{
_successfulReports++;
_reputation++;
}
else if (result == ReportResult.ABUSE)
{
_reputation = -1;
_banned = true;
default: break;
case ACCEPTED:
_acceptedReports++;
break;
case DENIED:
_deniedReports++;
break;
case ABUSIVE:
_abuseReports++;
break;
}
}
}

View File

@ -4,22 +4,46 @@ import org.bukkit.ChatColor;
public enum ReportResult
{
UNDETERMINED(ChatColor.WHITE, "Could not determine"),
MUTED(ChatColor.YELLOW, "Muted"),
BANNED(ChatColor.RED, "Banned"),
ABUSE(ChatColor.DARK_RED, "Abuse of report system");
private ChatColor color;
private String displayMessage;
private ReportResult(ChatColor color, String displayMessage)
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"),
UNDETERMINED(ChatColor.LIGHT_PURPLE, null, "Undetermined");
private ChatColor _color;
private String _actionMessage;
private String _resultMessage;
private String[] _lore;
ReportResult(ChatColor color, String actionMessage, String resultMessage, String... lore)
{
this.color = color;
this.displayMessage = displayMessage;
_color = color;
_actionMessage = actionMessage;
_resultMessage = resultMessage;
_lore = lore;
}
public ChatColor getColor()
{
return _color;
}
public String getActionMessage()
{
return _actionMessage;
}
public String getResultMessage()
{
return _resultMessage;
}
public String[] getLore()
{
return _lore;
}
public String toDisplayMessage()
{
return color + displayMessage;
return _color + _resultMessage;
}
}

View File

@ -7,6 +7,7 @@ import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.report.ui.ReportResultPage;
import org.bukkit.entity.Player;
@ -30,8 +31,16 @@ public class ReportCloseCommand extends CommandBase<ReportPlugin>
{
int reportId = Integer.parseInt(args[0]);
String reason = F.combine(args, 1, null, false);
Plugin.getReportManager().closeReport(reportId, player, reason);
if (Plugin.getReportManager().isActiveReport(reportId))
{
ReportResultPage reportResultPage = new ReportResultPage(Plugin, reportId, player, reason);
reportResultPage.openInventory(); // report is closed when player selects the result
}
else
{
UtilPlayer.message(player, F.main(Plugin.getName(), C.cRed + "That report either does not exist or has been closed."));
}
}
}
}

View File

@ -6,7 +6,7 @@ import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.report.ReportPlugin;
import mineplex.core.report.ui.ReportPage;
import mineplex.core.report.ui.ReportCategoryPage;
import org.bukkit.entity.Player;
@ -34,7 +34,7 @@ public class ReportCommand extends CommandBase<ReportPlugin>
if (reportedPlayer != null)
{
new ReportPage(Plugin, player, reportedPlayer, reason).openInventory();
new ReportCategoryPage(Plugin, player, reportedPlayer, reason).openInventory();
}
else
{

View File

@ -7,15 +7,15 @@ import mineplex.core.gui.SimpleGuiItem;
import mineplex.core.report.Category;
/**
* Represents a clickable button in a {@link ReportPage} which determines the type of infraction a player has committed.
* Represents a clickable button in a {@link ReportCategoryPage} which determines the type of infraction a player has committed.
* @author iKeirNez
*/
public class ReportButton extends SimpleGuiItem
public class ReportCategoryButton extends SimpleGuiItem
{
private ReportPage _reportPage;
private ReportCategoryPage _reportCategoryPage;
private Category _category;
public ReportButton(ReportPage reportPage, Category category) {
public ReportCategoryButton(ReportCategoryPage reportCategoryPage, Category category) {
super(category.getItemMaterial(), 1, (short) 0);
ItemMeta itemMeta = getItemMeta();
@ -23,13 +23,13 @@ public class ReportButton extends SimpleGuiItem
itemMeta.setLore(category.getItemLore());
setItemMeta(itemMeta);
this._reportPage = reportPage;
this._reportCategoryPage = reportCategoryPage;
this._category = category;
}
@Override
public void click(ClickType clickType)
{
_reportPage.addReport(_category);
_reportCategoryPage.addReport(_category);
}
}

View File

@ -11,18 +11,17 @@ import mineplex.core.common.util.C;
import mineplex.core.gui.SimpleGui;
import mineplex.core.report.Category;
import mineplex.core.report.Report;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
/**
* User interface shown to a player when reporting another player.
* @author iKeirNez
*/
public class ReportPage extends SimpleGui
public class ReportCategoryPage extends SimpleGui
{
private static final Map<Integer, Category> CATEGORY_SLOTS = Collections.unmodifiableMap(new HashMap<Integer, Category>()
{{
int rowStartSlot = 9 * 2; // 3rd row
int rowStartSlot = 9 * 2; // end of row 2
put(rowStartSlot + 3, Category.HACKING);
put(rowStartSlot + 5, Category.CHAT_ABUSE);
}});
@ -32,7 +31,7 @@ public class ReportPage extends SimpleGui
private Player _offender;
private String _reason;
public ReportPage(ReportPlugin reportPlugin, Player reportee, Player offender, String reason)
public ReportCategoryPage(ReportPlugin reportPlugin, Player reportee, Player offender, String reason)
{
super(reportPlugin.getPlugin(), reportee, "Report " + offender.getName(), 9 * 5);
@ -49,7 +48,7 @@ public class ReportPage extends SimpleGui
for (Map.Entry<Integer, Category> entry : CATEGORY_SLOTS.entrySet())
{
Category category = entry.getValue();
setItem(entry.getKey(), new ReportButton(this, category));
setItem(entry.getKey(), new ReportCategoryButton(this, category));
}
}

View File

@ -0,0 +1,48 @@
package mineplex.core.report.ui;
import java.util.List;
import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import mineplex.core.gui.SimpleGuiItem;
import mineplex.core.report.ReportResult;
/**
* Represents a button which can be clicked to determine the result of a report.
* @author iKeirNez
*/
public class ReportResultButton extends SimpleGuiItem
{
private ReportResultPage _reportResultPage;
private ReportResult _result;
public ReportResultButton(ReportResultPage reportResultPage, ReportResult result, ItemStack displayItem)
{
super(displayItem);
_reportResultPage = reportResultPage;
_result = result;
}
@Override
public void setup()
{
// replace all occurances of "%suspect%" in the lore with the actual name
ItemMeta itemMeta = getItemMeta();
List<String> lore = itemMeta.getLore();
for (int i = 0; i < lore.size(); i++)
{
lore.set(i, lore.get(i).replace("%suspect%", _reportResultPage.getPlayer().getName()));
}
setItemMeta(itemMeta);
}
@Override
public void click(ClickType clickType)
{
_reportResultPage.setResult(_result);
}
}

View File

@ -0,0 +1,75 @@
package mineplex.core.report.ui;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.gui.SimpleGui;
import mineplex.core.itemstack.ItemBuilder;
import mineplex.core.report.ReportManager;
import mineplex.core.report.ReportPlugin;
import mineplex.core.report.ReportResult;
/**
* User interface shown to a moderator when closing a report to determine the result of the report.
* @author iKeirNez
*/
public class ReportResultPage extends SimpleGui
{
private static final ItemStack ITEM_ACCEPT = new ItemBuilder(Material.WOOL)
.setColor(Color.GREEN)
.setTitle(C.cGreen + "Accept Report")
.addLore("%suspect% is cheating without a doubt.")
.build();
private static final ItemStack ITEM_DENY = new ItemBuilder(Material.WOOL)
.setColor(Color.YELLOW)
.setTitle(C.cYellow + "Deny Report")
.addLore("There is not enough evidence against %suspect%.")
.build();
private static final ItemStack ITEM_ABUSE = new ItemBuilder(Material.WOOL)
.setColor(Color.RED)
.setTitle(C.cGreen + "Accept Report")
.addLore("%suspect% is cheating without a doubt.")
.build();
private ReportManager _reportManager;
private int _reportId;
private Player _reportCloser;
private String _reason;
public ReportResultPage(ReportPlugin reportPlugin, int reportId, Player reportCloser, String reason)
{
super(reportPlugin.getPlugin(), reportCloser, "Report Result", 9 * 3);
_reportManager = reportPlugin.getReportManager();
_reportId = reportId;
_reportCloser = reportCloser;
_reason = reason;
buildPage();
}
private void buildPage()
{
setItem(11, new ReportResultButton(this, ReportResult.ACCEPTED, ITEM_ACCEPT));
setItem(13, new ReportResultButton(this, ReportResult.DENIED, ITEM_DENY));
setItem(15, new ReportResultButton(this, ReportResult.ABUSIVE, ITEM_ABUSE));
}
public void setResult(ReportResult result)
{
_reportCloser.closeInventory();
unregisterListener();
_reportManager.closeReport(_reportId, _reportCloser, _reason, result);
}
public void unregisterListener()
{
HandlerList.unregisterAll(this);
}
}