From 29587b93f7eeac34c3127d41a09347cae1ef7c25 Mon Sep 17 00:00:00 2001 From: Keir Date: Sat, 24 Oct 2015 03:41:03 +0100 Subject: [PATCH 01/39] Implement initial report interface. Added getPlugin() method to CommandBase. Changed mini-plugin name from "ReportPlugin" to "Report" to match the other mini-plugins. This is very WIP, still a lot to be done. --- .../mineplex/core/command/CommandBase.java | 7 +- .../src/mineplex/core/report/Category.java | 12 ++ .../mineplex/core/report/ReportPlugin.java | 2 +- .../core/report/command/ReportCommand.java | 3 +- .../mineplex/core/report/ui/ReportButton.java | 28 +++++ .../mineplex/core/report/ui/ReportPage.java | 103 ++++++++++++++++++ .../Mineplex.Hub/src/mineplex/hub/Hub.java | 2 + 7 files changed, 154 insertions(+), 3 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/Category.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java index dd274ce22..fff7be318 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java @@ -39,7 +39,12 @@ public abstract class CommandBase implements ICom _aliases = Arrays.asList(aliases); } - + + public PluginType getPlugin() + { + return Plugin; + } + public Collection Aliases() { return _aliases; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java b/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java new file mode 100644 index 000000000..4cc9048b6 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java @@ -0,0 +1,12 @@ +package mineplex.core.report; + +/** + * Contains all the reasons a player can be reported for. + */ +public enum Category +{ + + HACKING, + CHAT_ABUSE + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java index b03857fc8..8ed58381d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java @@ -15,7 +15,7 @@ public class ReportPlugin extends MiniPlugin public ReportPlugin(JavaPlugin plugin, String serverName) { - super("ReportPlugin", plugin); + super("Report", plugin); instance = plugin; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java index 9faf41139..87aa8ea9d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java @@ -9,6 +9,7 @@ import mineplex.core.common.util.UtilPlayer; import mineplex.core.portal.Portal; import mineplex.core.report.ReportManager; import mineplex.core.report.ReportPlugin; +import mineplex.core.report.ui.ReportPage; import org.bukkit.entity.Player; @@ -36,7 +37,7 @@ public class ReportCommand extends CommandBase if (reportedPlayer != null) { - ReportManager.getInstance().reportPlayer(player, reportedPlayer, reason); + new ReportPage(getPlugin(), player, reportedPlayer, reason); } else { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportButton.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportButton.java new file mode 100644 index 000000000..add7caf72 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportButton.java @@ -0,0 +1,28 @@ +package mineplex.core.report.ui; + +import org.bukkit.entity.Player; +import org.bukkit.event.inventory.ClickType; + +import mineplex.core.report.Category; +import mineplex.core.shop.item.IButton; + +/** + * Represents a clickable button in a {@link ReportPage} which determines the type of infraction a player has committed. + * @author iKeirNez + */ +public class ReportButton implements IButton +{ + private ReportPage _reportPage; + private Category _category; + + public ReportButton(ReportPage reportPage, Category category) { + this._reportPage = reportPage; + this._category = category; + } + + @Override + public void onClick(Player player, ClickType clickType) + { + _reportPage.addReport(_category); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java new file mode 100644 index 000000000..2a6b16482 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java @@ -0,0 +1,103 @@ +package mineplex.core.report.ui; + +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Material; +import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventoryCustom; +import org.bukkit.entity.HumanEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.HandlerList; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryCloseEvent; + +import mineplex.core.common.util.NautHashMap; +import mineplex.core.report.Category; +import mineplex.core.report.ReportManager; +import mineplex.core.report.ReportPlugin; +import mineplex.core.shop.item.IButton; +import mineplex.core.shop.item.ShopItem; + +/** + * User interface shown to a player when reporting another player. + * @author iKeirNez + */ +public class ReportPage extends CraftInventoryCustom implements Listener +{ + + // todo this and PunishPage share a lot of code, generalize? + + private static final Map CATEGORY_SLOTS = Collections.unmodifiableMap(new HashMap(){{ + int rowStartSlot = 9 * 3; // 3rd row + put(rowStartSlot + 3, Category.HACKING); + put(rowStartSlot + 5, Category.CHAT_ABUSE); + }}); + + private ReportPlugin _plugin; + private Player _reportee; + private Player _offender; + private String _reason; + + private NautHashMap _buttonMap = new NautHashMap<>(); + + public ReportPage(ReportPlugin plugin, Player reportee, Player offender, String reason) + { + super(null, 9 * 5, "Report " + offender.getName() + " for: \"" + reason + "\""); // todo title needs tweaking + + this._plugin = plugin; + this._reportee = reportee; + this._offender = offender; + this._reason = reason; + + buildPage(); + + reportee.openInventory(this); + plugin.registerEvents(this); + } + + private void buildPage() { + for (Map.Entry entry : CATEGORY_SLOTS.entrySet()) { + Category category = entry.getValue(); + addButton(entry.getKey(), new ShopItem(Material.BEDROCK, category.name(), new String[0], 1, false, true), new ReportButton(this, category)); // todo relevant material, user friendly name, descriptive lore + } + } + + private void addButton(int slot, ShopItem shopItem, IButton button) { + setItem(slot, shopItem); + _buttonMap.put(slot, button); + } + + public void addReport(Category category) { + ReportManager.getInstance().reportPlayer(_reportee, _offender, _reason); // todo add category info + _reportee.closeInventory(); + unregisterListener(); + } + + public void unregisterListener() { + HandlerList.unregisterAll(this); + } + + @EventHandler + public void onInventoryClick(InventoryClickEvent e) { + HumanEntity humanEntity = e.getWhoClicked(); + + if (humanEntity instanceof Player) { + Player player = (Player) humanEntity; + int slot = e.getSlot(); + + if (_buttonMap.containsKey(slot)) { + _buttonMap.get(slot).onClick(player, e.getClick()); + } + } + } + + @EventHandler + public void onInventoryClose(InventoryCloseEvent e) { + if (e.getInventory().getName().equals(getName()) && e.getPlayer().equals(_reportee)) { + unregisterListener(); + } + } +} diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index b0074e49b..c5e13b6c7 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -38,6 +38,7 @@ import mineplex.core.preferences.PreferencesManager; import mineplex.core.projectile.ProjectileManager; import mineplex.core.punish.Punish; import mineplex.core.recharge.Recharge; +import mineplex.core.report.ReportPlugin; import mineplex.core.resourcepack.ResUnloadCheck; import mineplex.core.resourcepack.ResPackManager; import mineplex.core.serverConfig.ServerConfiguration; @@ -144,6 +145,7 @@ public class Hub extends JavaPlugin implements IRelation return true; } }); + new ReportPlugin(this, serverStatusManager.getCurrentServerName()); //new Replay(this, packetHandler); AprilFoolsManager.Initialize(this, clientManager, disguiseManager); From a9fedecc7015c82e14f878e004b4d356bbc607ed Mon Sep 17 00:00:00 2001 From: Keir Date: Sat, 24 Oct 2015 17:10:50 +0100 Subject: [PATCH 02/39] Make the ui more appealing and use existing gui system to handle it. --- .../src/mineplex/core/report/Category.java | 43 +++++++++++- .../mineplex/core/report/ui/ReportButton.java | 15 ++-- .../mineplex/core/report/ui/ReportPage.java | 69 +++++-------------- 3 files changed, 69 insertions(+), 58 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java b/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java index 4cc9048b6..1a6065bf0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java @@ -1,12 +1,51 @@ package mineplex.core.report; +import java.util.ArrayList; +import java.util.List; + +import org.bukkit.Material; + +import mineplex.core.common.util.C; + /** * Contains all the reasons a player can be reported for. + * @author iKeirNez */ public enum Category { - HACKING, - CHAT_ABUSE + // descriptions borrowed from PunishPage + HACKING(Material.IRON_SWORD, C.cRedB + "Hacking", "X-ray, Forcefield, Speed, Fly etc"), + CHAT_ABUSE(Material.BOOK_AND_QUILL, C.cDBlueB + "Chat Abuse", "Verbal Abuse, Spam, Harassment, Trolling, etc"); + private Material _displayMaterial; + private String _title; + private List _lore; + + Category(Material displayMaterial, String title, String... lore) + { + this._displayMaterial = displayMaterial; + this._title = title; + this._lore = new ArrayList<>(); + + // prefix are lore lines + for (String loreLine : lore) { + _lore.add(C.cGray + loreLine); + } + } + + public Material getItemMaterial() + { + return _displayMaterial; + } + + public String getItemDisplayName() + { + return _title; + } + + public List getItemLore() + { + return _lore; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportButton.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportButton.java index add7caf72..c3f7d2e0e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportButton.java @@ -1,27 +1,34 @@ package mineplex.core.report.ui; -import org.bukkit.entity.Player; import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.meta.ItemMeta; +import mineplex.core.gui.SimpleGuiItem; import mineplex.core.report.Category; -import mineplex.core.shop.item.IButton; /** * Represents a clickable button in a {@link ReportPage} which determines the type of infraction a player has committed. * @author iKeirNez */ -public class ReportButton implements IButton +public class ReportButton extends SimpleGuiItem { private ReportPage _reportPage; private Category _category; public ReportButton(ReportPage reportPage, Category category) { + super(category.getItemMaterial(), 1, (short) 0); + + ItemMeta itemMeta = getItemMeta(); + itemMeta.setDisplayName(category.getItemDisplayName()); + itemMeta.setLore(category.getItemLore()); + setItemMeta(itemMeta); + this._reportPage = reportPage; this._category = category; } @Override - public void onClick(Player player, ClickType clickType) + public void click(ClickType clickType) { _reportPage.addReport(_category); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java index 2a6b16482..56c450d5f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java @@ -4,100 +4,65 @@ import java.util.Collections; import java.util.HashMap; import java.util.Map; -import org.bukkit.Material; -import org.bukkit.craftbukkit.v1_7_R4.inventory.CraftInventoryCustom; -import org.bukkit.entity.HumanEntity; import org.bukkit.entity.Player; -import org.bukkit.event.EventHandler; import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; -import org.bukkit.event.inventory.InventoryClickEvent; -import org.bukkit.event.inventory.InventoryCloseEvent; -import mineplex.core.common.util.NautHashMap; +import mineplex.core.gui.SimpleGui; import mineplex.core.report.Category; import mineplex.core.report.ReportManager; import mineplex.core.report.ReportPlugin; -import mineplex.core.shop.item.IButton; -import mineplex.core.shop.item.ShopItem; /** * User interface shown to a player when reporting another player. * @author iKeirNez */ -public class ReportPage extends CraftInventoryCustom implements Listener +public class ReportPage extends SimpleGui { // todo this and PunishPage share a lot of code, generalize? - private static final Map CATEGORY_SLOTS = Collections.unmodifiableMap(new HashMap(){{ - int rowStartSlot = 9 * 3; // 3rd row + private static final Map CATEGORY_SLOTS = Collections.unmodifiableMap(new HashMap() + {{ + int rowStartSlot = 9 * 2; // 3rd row put(rowStartSlot + 3, Category.HACKING); put(rowStartSlot + 5, Category.CHAT_ABUSE); }}); - private ReportPlugin _plugin; private Player _reportee; private Player _offender; private String _reason; - private NautHashMap _buttonMap = new NautHashMap<>(); - - public ReportPage(ReportPlugin plugin, Player reportee, Player offender, String reason) + public ReportPage(ReportPlugin reportPlugin, Player reportee, Player offender, String reason) { - super(null, 9 * 5, "Report " + offender.getName() + " for: \"" + reason + "\""); // todo title needs tweaking + super(reportPlugin.getPlugin(), reportee, "Report " + offender.getName(), 9 * 5); - this._plugin = plugin; this._reportee = reportee; this._offender = offender; this._reason = reason; buildPage(); - - reportee.openInventory(this); - plugin.registerEvents(this); + openInventory(); } - private void buildPage() { - for (Map.Entry entry : CATEGORY_SLOTS.entrySet()) { + private void buildPage() + { + for (Map.Entry entry : CATEGORY_SLOTS.entrySet()) + { Category category = entry.getValue(); - addButton(entry.getKey(), new ShopItem(Material.BEDROCK, category.name(), new String[0], 1, false, true), new ReportButton(this, category)); // todo relevant material, user friendly name, descriptive lore + setItem(entry.getKey(), new ReportButton(this, category)); } } - private void addButton(int slot, ShopItem shopItem, IButton button) { - setItem(slot, shopItem); - _buttonMap.put(slot, button); - } - - public void addReport(Category category) { + public void addReport(Category category) + { ReportManager.getInstance().reportPlayer(_reportee, _offender, _reason); // todo add category info _reportee.closeInventory(); unregisterListener(); } - public void unregisterListener() { + public void unregisterListener() + { HandlerList.unregisterAll(this); } - @EventHandler - public void onInventoryClick(InventoryClickEvent e) { - HumanEntity humanEntity = e.getWhoClicked(); - - if (humanEntity instanceof Player) { - Player player = (Player) humanEntity; - int slot = e.getSlot(); - - if (_buttonMap.containsKey(slot)) { - _buttonMap.get(slot).onClick(player, e.getClick()); - } - } - } - - @EventHandler - public void onInventoryClose(InventoryCloseEvent e) { - if (e.getInventory().getName().equals(getName()) && e.getPlayer().equals(_reportee)) { - unregisterListener(); - } - } } From bc3a119a22c27f2e9ecb8892062d2da8f3e3ec5f Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 27 Oct 2015 17:30:47 +0000 Subject: [PATCH 03/39] Store report category and only "merge" reports when the category is the same. --- .../src/mineplex/core/report/Report.java | 14 +- .../mineplex/core/report/ReportManager.java | 126 +++++++++--------- .../mineplex/core/report/ui/ReportPage.java | 5 +- 3 files changed, 67 insertions(+), 78 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java b/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java index 3367b15ab..dd20593ff 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java @@ -21,19 +21,17 @@ public class Report implements Data private Set _reporters; public Set 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(); + _category = category; } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index a6f7fd59b..bd4fc6819 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -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 reportRepository; - + private DataRepository 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 activeReports; - + /** * Private constructor to prevent non-singleton instances. */ @@ -50,23 +48,23 @@ public class ReportManager { this.reportRepository = new RedisDataRepository(Region.ALL, Report.class, "reports"); this.reportProfiles = new RedisDataRepository(Region.ALL, ReportProfile.class, "reportprofiles"); this.activeReports = new HashMap(); - + // 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 activeReport : activeReports.entrySet()) @@ -286,10 +280,10 @@ public class ReportManager { return true; } } - + return false; } - + public boolean removeActiveReport(int reportId) { for (Entry 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; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java index 56c450d5f..21e043302 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java @@ -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 CATEGORY_SLOTS = Collections.unmodifiableMap(new HashMap() {{ 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(); } From 53f2356cba20f5ff0ca06ad83ff2a085472225c2 Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 27 Oct 2015 22:08:42 +0000 Subject: [PATCH 04/39] Handle null report closers. --- .../Mineplex.Core/src/mineplex/core/report/ReportManager.java | 4 +--- .../src/mineplex/core/report/ReportRepository.java | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index bd4fc6819..22feed2e8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -74,7 +74,7 @@ public class ReportManager { reportRepository.removeElement(String.valueOf(reportId)); // Remove report from redis database removeActiveReport(reportId); - int closerId = getPlayerAccount(reportCloser).getAccountId(); + 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 @@ -155,8 +155,6 @@ public class ReportManager { { 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())); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index cbae2678c..50fc6da63 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -30,7 +30,8 @@ id, date, reportId, accountId of Staff This will be used to determine if staff are handling */ - + + // todo include category private static String CREATE_TICKET_TABLE = "CREATE TABLE IF NOT EXISTS reportTickets (reportId INT NOT NULL, date LONG, eventDate LONG, playerId INT NOT NULL, server VARCHAR(50), closerId INT NOT NULL, result VARCHAR(25), reason VARCHAR(100), PRIMARY KEY (reportId), INDEX playerIdIndex (playerId), INDEX closerIdIndex (closerId));"; private static String CREATE_HANDLER_TABLE = "CREATE TABLE IF NOT EXISTS reportHandlers (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, handlerId INT NOT NULL, PRIMARY KEY (id), INDEX handlerIdIndex (handlerId) );"; private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, reason VARCHAR(100), PRIMARY KEY (id), INDEX reporterIdIndex (reporterId));"; From d9fb0adabbd3eba53684f8d3e82563cf742ebcdf Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 27 Oct 2015 22:14:33 +0000 Subject: [PATCH 05/39] Only notify staff if 3 or more players report a player. --- .../src/mineplex/core/report/ReportManager.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 22feed2e8..619a8505d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -140,11 +140,16 @@ public class ReportManager { reportRepository.addElement(report); } - // [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); + // only start notifying staff when + if (report.getReporters().size() >= 3) + { + // [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); } } From cb1c779f372782979d337785f26e40d63968bc62 Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 27 Oct 2015 22:15:06 +0000 Subject: [PATCH 06/39] Close player report if the reported player leaves the game mid-report. --- .../src/mineplex/core/report/ReportPlugin.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java index 8ed58381d..c8914b8a4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java @@ -5,6 +5,8 @@ import mineplex.core.report.command.ReportCloseCommand; import mineplex.core.report.command.ReportCommand; import mineplex.core.report.command.ReportHandleCommand; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; public class ReportPlugin extends MiniPlugin @@ -28,4 +30,10 @@ public class ReportPlugin extends MiniPlugin addCommand(new ReportCloseCommand(this)); //AddCommand(new ReportDebugCommand(this)); } + + @EventHandler + public void onPlayerQuit(PlayerQuitEvent e) + { + ReportManager.getInstance().onPlayerQuit(e.getPlayer()); + } } From 4ceb8f20aa0c411f9c69130e401b0c30a66ac159 Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 27 Oct 2015 22:26:02 +0000 Subject: [PATCH 07/39] Make ReportNotification capable of sending json messages. --- .../core/report/command/ReportNotification.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java index 7d9d0153a..a66873bbf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java @@ -1,20 +1,26 @@ package mineplex.core.report.command; +import org.bukkit.Server; import org.bukkit.entity.Player; +import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.UtilServer; import mineplex.core.report.ReportManager; import mineplex.serverdata.commands.ServerCommand; public class ReportNotification extends ServerCommand { - - // TODO: Encode in JSON-interactive chat message - private String notification; - + private String _notification; + public ReportNotification(String notification) + { + this(new JsonMessage(notification)); + } + + public ReportNotification(JsonMessage notification) { super(); // Send to all servers + this._notification = notification.toString(); } public void run() @@ -24,7 +30,8 @@ public class ReportNotification extends ServerCommand { if (ReportManager.getInstance().hasReportNotifications(player)) { - player.sendMessage(notification); + Server server = UtilServer.getServer(); + server.dispatchCommand(server.getConsoleSender(), "tellraw " + player.getName() + " " + _notification); } } } From 38425f25feb6da5372f636ccc106ac735b167dde Mon Sep 17 00:00:00 2001 From: Keir Date: Wed, 28 Oct 2015 16:03:02 +0000 Subject: [PATCH 08/39] Add missing child overridden methods for chaining. --- .../common/jsonchat/ChildJsonMessage.java | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/ChildJsonMessage.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/ChildJsonMessage.java index e6fdb1914..3cab17227 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/ChildJsonMessage.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/jsonchat/ChildJsonMessage.java @@ -20,7 +20,7 @@ public class ChildJsonMessage extends JsonMessage _parent = parent; } - + public ChildJsonMessage add(String text) { Builder.append("}, "); @@ -42,6 +42,38 @@ public class ChildJsonMessage extends JsonMessage return this; } + + @Override + public ChildJsonMessage italic() + { + super.italic(); + + return this; + } + + @Override + public ChildJsonMessage underlined() + { + super.underlined(); + + return this; + } + + @Override + public ChildJsonMessage strikethrough() + { + super.strikethrough(); + + return this; + } + + @Override + public ChildJsonMessage obfuscated() + { + super.obfuscated(); + + return this; + } @Override public ChildJsonMessage click(String action, String value) @@ -50,6 +82,14 @@ public class ChildJsonMessage extends JsonMessage return this; } + + @Override + public ChildJsonMessage click(ClickEvent event, String value) + { + super.click(event, value); + + return this; + } @Override public ChildJsonMessage hover(String action, String value) @@ -58,7 +98,15 @@ public class ChildJsonMessage extends JsonMessage return this; } - + + @Override + public ChildJsonMessage hover(HoverEvent event, String value) + { + super.hover(event, value); + + return this; + } + @Override public String toString() { From 1857afa8266a431b918b0f3079ff14f83d261800 Mon Sep 17 00:00:00 2001 From: Keir Date: Thu, 29 Oct 2015 17:51:17 +0000 Subject: [PATCH 09/39] Log report category to database. Allow report to easily be handled by clicking text to fire the reporthandle command. --- .../mineplex/core/report/ReportManager.java | 22 ++++++++++++++++++- .../mineplex/core/report/ReportPlugin.java | 12 ++++++++-- .../core/report/ReportRepository.java | 14 +++++------- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 619a8505d..554d36074 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -6,6 +6,8 @@ import java.util.Map.Entry; import mineplex.core.account.CoreClient; import mineplex.core.command.CommandCenter; +import mineplex.core.common.jsonchat.ClickEvent; +import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.portal.Portal; import mineplex.core.report.command.ReportNotification; import mineplex.serverdata.Region; @@ -147,10 +149,18 @@ public class ReportManager { String message = String.format("[Report %d] [%s %d] [%s - %d - %s]", report.getReportId(), reporter.getName(), reportProfile.getReputation(), reportedPlayer.getName(), report.getReporters().size(), reason); + + JsonMessage clickableMessage = new JsonMessage("Click ") + .extra("here") + .bold() + .click(ClickEvent.RUN_COMMAND, "/reporthandle " + reportId) + .add(" to respond to ticket."); + sendReportNotification(message); + sendReportNotification(clickableMessage); } - reportSqlRepository.logReportSending(report.getReportId(), reporterId, reason); + reportSqlRepository.logReportSending(report.getReportId(), reporterId, category, reason); } } @@ -244,6 +254,16 @@ public class ReportManager { return false; } + /** + * Send a network-wide {@link ReportNotification} to all online staff. + * @param message - the report notification message to send. + */ + public void sendReportNotification(JsonMessage message) + { + ReportNotification reportNotification = new ReportNotification(message); + reportNotification.publish(); + } + /** * Send a network-wide {@link ReportNotification} to all online staff. * @param message - the report notification message to send. diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java index c8914b8a4..5e8a89ef0 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java @@ -14,14 +14,22 @@ public class ReportPlugin extends MiniPlugin private static JavaPlugin instance; public static JavaPlugin getPluginInstance() { return instance; } - + + private final String _serverName; + public ReportPlugin(JavaPlugin plugin, String serverName) { super("Report", plugin); instance = plugin; + _serverName = serverName; } - + + public String getServerName() + { + return _serverName; + } + @Override public void addCommands() { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index 50fc6da63..bdf480d26 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -10,6 +10,7 @@ import mineplex.core.common.util.NautHashMap; import mineplex.core.database.DBPool; import mineplex.core.database.RepositoryBase; import mineplex.core.database.ResultSetCallable; +import mineplex.core.database.column.Column; import mineplex.core.database.column.ColumnInt; import mineplex.core.database.column.ColumnVarChar; import mineplex.core.preferences.UserPreferences; @@ -31,14 +32,13 @@ id, date, reportId, accountId of Staff This will be used to determine if staff are handling */ - // todo include category private static String CREATE_TICKET_TABLE = "CREATE TABLE IF NOT EXISTS reportTickets (reportId INT NOT NULL, date LONG, eventDate LONG, playerId INT NOT NULL, server VARCHAR(50), closerId INT NOT NULL, result VARCHAR(25), reason VARCHAR(100), PRIMARY KEY (reportId), INDEX playerIdIndex (playerId), INDEX closerIdIndex (closerId));"; private static String CREATE_HANDLER_TABLE = "CREATE TABLE IF NOT EXISTS reportHandlers (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, handlerId INT NOT NULL, PRIMARY KEY (id), INDEX handlerIdIndex (handlerId) );"; - private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, reason VARCHAR(100), PRIMARY KEY (id), INDEX reporterIdIndex (reporterId));"; + private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, category VARCHAR(20), reason VARCHAR(100), PRIMARY KEY (id), INDEX reporterIdIndex (reporterId));"; private static String INSERT_TICKET = "INSERT INTO reportTickets (reportId, eventDate, playerId, server, closerId, result, reason) VALUES (?, now(), ?, ?, ?, ?, ?);"; private static String INSERT_HANDLER = "INSERT INTO reportHandlers (eventDate, reportId, handlerId) VALUES(now(), ?, ?);"; - private static String INSERT_SENDER = "INSERT INTO reportSenders (eventDate, reportId, reporterId, reason) VALUES(now(), ?, ?, ?);"; + private static String INSERT_SENDER = "INSERT INTO reportSenders (eventDate, reportId, reporterId, category, reason) VALUES(now(), ?, ?, ?, ?);"; public ReportRepository(JavaPlugin plugin, String connectionString) { @@ -48,11 +48,9 @@ This will be used to determine if staff are handling @Override protected void initialize() { - /* executeUpdate(CREATE_TICKET_TABLE); executeUpdate(CREATE_HANDLER_TABLE); executeUpdate(CREATE_REPORTERS_TABLE); - */ } @Override @@ -66,10 +64,10 @@ This will be used to determine if staff are handling executeUpdate(INSERT_HANDLER, new ColumnInt("reportId", reportId), new ColumnInt("handlerId", handlerId)); } - public void logReportSending(int reportId, int reporterId, String reason) + public void logReportSending(int reportId, int reporterId, Category category, String reason) { - executeUpdate(INSERT_SENDER, new ColumnInt("reportId", reportId), new ColumnInt("reporterId", reporterId), - new ColumnVarChar("reason", 100, reason)); + executeUpdate(INSERT_SENDER, new ColumnInt("reportId", reportId), new ColumnInt("reporterId", reporterId), + new ColumnVarChar("type", 20, category.name()), new ColumnVarChar("reason", 100, reason)); } public void logReport(int reportId, int playerId, String server, int closerId, ReportResult result, String reason) From e8c01a173352a968cbf2765c0ae257792f0e0dfd Mon Sep 17 00:00:00 2001 From: Keir Date: Thu, 29 Oct 2015 23:29:38 +0000 Subject: [PATCH 10/39] Cleanup imports. --- .../src/mineplex/core/report/ReportRepository.java | 10 ---------- .../core/report/command/ReportCloseCommand.java | 2 -- .../mineplex/core/report/command/ReportCommand.java | 3 --- .../core/report/command/ReportHandleCommand.java | 2 -- 4 files changed, 17 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index bdf480d26..1f84d7c9b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -1,19 +1,9 @@ package mineplex.core.report; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.util.UUID; -import java.util.Map.Entry; - -import mineplex.core.common.util.NautHashMap; import mineplex.core.database.DBPool; import mineplex.core.database.RepositoryBase; -import mineplex.core.database.ResultSetCallable; -import mineplex.core.database.column.Column; import mineplex.core.database.column.ColumnInt; import mineplex.core.database.column.ColumnVarChar; -import mineplex.core.preferences.UserPreferences; import org.bukkit.plugin.java.JavaPlugin; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java index 03ce14e9a..d4feec075 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java @@ -3,10 +3,8 @@ package mineplex.core.report.command; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.portal.Portal; import mineplex.core.report.ReportManager; import mineplex.core.report.ReportPlugin; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java index 87aa8ea9d..f69bec64e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java @@ -3,11 +3,8 @@ package mineplex.core.report.command; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.portal.Portal; -import mineplex.core.report.ReportManager; import mineplex.core.report.ReportPlugin; import mineplex.core.report.ui.ReportPage; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java index 3b037a0a2..103991b6f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java @@ -3,10 +3,8 @@ package mineplex.core.report.command; import mineplex.core.command.CommandBase; import mineplex.core.common.Rank; import mineplex.core.common.util.C; -import mineplex.core.common.util.Callback; import mineplex.core.common.util.F; import mineplex.core.common.util.UtilPlayer; -import mineplex.core.portal.Portal; import mineplex.core.report.ReportManager; import mineplex.core.report.ReportPlugin; From e266acaf442357d6dbeafcb3f182cb57552260b0 Mon Sep 17 00:00:00 2001 From: Keir Date: Thu, 29 Oct 2015 23:33:23 +0000 Subject: [PATCH 11/39] Store report categories with a TINYINT to save space and increase lookup performance. --- .../src/mineplex/core/report/Category.java | 26 ++++++++++++++++--- .../core/report/ReportRepository.java | 5 ++-- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java b/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java index 1a6065bf0..734d7de81 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java @@ -15,15 +15,17 @@ public enum Category { // descriptions borrowed from PunishPage - HACKING(Material.IRON_SWORD, C.cRedB + "Hacking", "X-ray, Forcefield, Speed, Fly etc"), - CHAT_ABUSE(Material.BOOK_AND_QUILL, C.cDBlueB + "Chat Abuse", "Verbal Abuse, Spam, Harassment, Trolling, etc"); + HACKING(0, Material.IRON_SWORD, C.cRedB + "Hacking", "X-ray, Forcefield, Speed, Fly etc"), + CHAT_ABUSE(1, Material.BOOK_AND_QUILL, C.cDBlueB + "Chat Abuse", "Verbal Abuse, Spam, Harassment, Trolling, etc"); + private int _id; private Material _displayMaterial; private String _title; private List _lore; - Category(Material displayMaterial, String title, String... lore) + Category(int id, Material displayMaterial, String title, String... lore) { + this._id = id; this._displayMaterial = displayMaterial; this._title = title; this._lore = new ArrayList<>(); @@ -34,6 +36,11 @@ public enum Category } } + public int getId() + { + return _id; + } + public Material getItemMaterial() { return _displayMaterial; @@ -48,4 +55,17 @@ public enum Category { return _lore; } + + public static Category fromId(int id) + { + for (Category category : values()) + { + if (category.getId() == id) + { + return category; + } + } + + return null; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index 1f84d7c9b..9877edf58 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -2,6 +2,7 @@ package mineplex.core.report; import mineplex.core.database.DBPool; import mineplex.core.database.RepositoryBase; +import mineplex.core.database.column.ColumnByte; import mineplex.core.database.column.ColumnInt; import mineplex.core.database.column.ColumnVarChar; @@ -24,7 +25,7 @@ This will be used to determine if staff are handling private static String CREATE_TICKET_TABLE = "CREATE TABLE IF NOT EXISTS reportTickets (reportId INT NOT NULL, date LONG, eventDate LONG, playerId INT NOT NULL, server VARCHAR(50), closerId INT NOT NULL, result VARCHAR(25), reason VARCHAR(100), PRIMARY KEY (reportId), INDEX playerIdIndex (playerId), INDEX closerIdIndex (closerId));"; private static String CREATE_HANDLER_TABLE = "CREATE TABLE IF NOT EXISTS reportHandlers (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, handlerId INT NOT NULL, PRIMARY KEY (id), INDEX handlerIdIndex (handlerId) );"; - private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, category VARCHAR(20), reason VARCHAR(100), PRIMARY KEY (id), INDEX reporterIdIndex (reporterId));"; + private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, category TINYINT, reason VARCHAR(100), PRIMARY KEY (id), INDEX reporterIdIndex (reporterId));"; private static String INSERT_TICKET = "INSERT INTO reportTickets (reportId, eventDate, playerId, server, closerId, result, reason) VALUES (?, now(), ?, ?, ?, ?, ?);"; private static String INSERT_HANDLER = "INSERT INTO reportHandlers (eventDate, reportId, handlerId) VALUES(now(), ?, ?);"; @@ -57,7 +58,7 @@ This will be used to determine if staff are handling public void logReportSending(int reportId, int reporterId, Category category, String reason) { executeUpdate(INSERT_SENDER, new ColumnInt("reportId", reportId), new ColumnInt("reporterId", reporterId), - new ColumnVarChar("type", 20, category.name()), new ColumnVarChar("reason", 100, reason)); + new ColumnByte("type", (byte) category.getId()), new ColumnVarChar("reason", 100, reason)); } public void logReport(int reportId, int playerId, String server, int closerId, ReportResult result, String reason) From ec5cbbe684d94dbba0ee77e5802d516a93b16a7d Mon Sep 17 00:00:00 2001 From: Keir Date: Fri, 30 Oct 2015 01:05:45 +0000 Subject: [PATCH 12/39] This method is not required, "Plugin" is protected, not private as I previously assumed. --- .../Mineplex.Core/src/mineplex/core/command/CommandBase.java | 5 ----- .../src/mineplex/core/report/command/ReportCommand.java | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java index fff7be318..b395667da 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/command/CommandBase.java @@ -40,11 +40,6 @@ public abstract class CommandBase implements ICom _aliases = Arrays.asList(aliases); } - public PluginType getPlugin() - { - return Plugin; - } - public Collection Aliases() { return _aliases; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java index f69bec64e..a47f5f6ca 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java @@ -34,7 +34,7 @@ public class ReportCommand extends CommandBase if (reportedPlayer != null) { - new ReportPage(getPlugin(), player, reportedPlayer, reason); + new ReportPage(Plugin, player, reportedPlayer, reason); } else { From 93a5ebf0ebaae655279861e53993daa482a806b5 Mon Sep 17 00:00:00 2001 From: Keir Date: Sun, 1 Nov 2015 16:44:02 +0000 Subject: [PATCH 13/39] Pass server name to ReportManager. --- .../mineplex/core/report/ReportManager.java | 27 ++++--------------- .../mineplex/core/report/ReportPlugin.java | 20 +++++++------- .../report/command/ReportCloseCommand.java | 2 +- .../report/command/ReportHandleCommand.java | 2 +- .../report/command/ReportNotification.java | 4 +-- .../mineplex/core/report/ui/ReportPage.java | 4 ++- 6 files changed, 22 insertions(+), 37 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 554d36074..0ef706b78 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -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 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 activeReports; - /** - * Private constructor to prevent non-singleton instances. - */ - private ReportManager() + public ReportManager(String serverName, String logsConnectionString) { + this.serverName = serverName; this.reportRepository = new RedisDataRepository(Region.ALL, Report.class, "reports"); this.reportProfiles = new RedisDataRepository(Region.ALL, ReportProfile.class, "reportprofiles"); this.activeReports = new HashMap(); // 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; - } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java index 5e8a89ef0..1805da44f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java @@ -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()); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java index d4feec075..f6da4439a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java @@ -31,7 +31,7 @@ public class ReportCloseCommand extends CommandBase 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); } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java index 103991b6f..04048de6f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java @@ -30,7 +30,7 @@ public class ReportHandleCommand extends CommandBase { int reportId = Integer.parseInt(args[0]); - ReportManager.getInstance().handleReport(reportId, player); + Plugin.getReportManager().handleReport(reportId, player); } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java index a66873bbf..97194b850 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java @@ -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); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java index 21e043302..5c5c1b9a2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java @@ -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(); } From d09ed2a823808134f0d7cc2c6e2a0e3600a1bc62 Mon Sep 17 00:00:00 2001 From: Keir Date: Sun, 1 Nov 2015 16:47:54 +0000 Subject: [PATCH 14/39] Small changes and missed changes from last commit. --- .../Mineplex.Core/src/mineplex/core/report/ReportManager.java | 4 ++-- .../src/mineplex/core/report/ReportRepository.java | 4 ++-- Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java | 3 ++- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 0ef706b78..7a9a11819 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -42,7 +42,7 @@ public class ReportManager { // A mapping of PlayerName(String) to the ReportId(Integer) for all active reports on this server. private Map activeReports; - public ReportManager(String serverName, String logsConnectionString) + public ReportManager(String serverName) { this.serverName = serverName; this.reportRepository = new RedisDataRepository(Region.ALL, Report.class, "reports"); @@ -50,7 +50,7 @@ public class ReportManager { this.activeReports = new HashMap(); // TODO: Get JavaPlugin instance and locate ConnectionString from config? - this.reportSqlRepository = new ReportRepository(ReportPlugin.getInstance().getPlugin(), logsConnectionString); + this.reportSqlRepository = new ReportRepository(); reportSqlRepository.initialize(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index 9877edf58..54ad8fb63 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -31,9 +31,9 @@ This will be used to determine if staff are handling private static String INSERT_HANDLER = "INSERT INTO reportHandlers (eventDate, reportId, handlerId) VALUES(now(), ?, ?);"; private static String INSERT_SENDER = "INSERT INTO reportSenders (eventDate, reportId, reporterId, category, reason) VALUES(now(), ?, ?, ?, ?);"; - public ReportRepository(JavaPlugin plugin, String connectionString) + public ReportRepository() { - super(plugin, DBPool.ACCOUNT); + super(ReportPlugin.getInstance().getPlugin(), DBPool.ACCOUNT); } @Override diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index 0a43ea697..e2fd86f86 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -39,6 +39,7 @@ import mineplex.core.preferences.PreferencesManager; import mineplex.core.projectile.ProjectileManager; import mineplex.core.punish.Punish; import mineplex.core.recharge.Recharge; +import mineplex.core.report.ReportManager; import mineplex.core.report.ReportPlugin; import mineplex.core.resourcepack.ResUnloadCheck; import mineplex.core.resourcepack.ResPackManager; @@ -147,7 +148,7 @@ public class Hub extends JavaPlugin implements IRelation } }); new GlobalPacketManager(this, clientManager, serverStatusManager); - new ReportPlugin(this, serverStatusManager.getCurrentServerName()); + new ReportPlugin(this, new ReportManager(serverStatusManager.getCurrentServerName())); //new Replay(this, packetHandler); AprilFoolsManager.Initialize(this, clientManager, disguiseManager); From 4b5ddf5385818e08277cdb06fc92668f98217e14 Mon Sep 17 00:00:00 2001 From: Keir Date: Sun, 1 Nov 2015 19:14:29 +0000 Subject: [PATCH 15/39] Disable SQL create table queries until they are approved. --- .../src/mineplex/core/report/ReportManager.java | 2 -- .../src/mineplex/core/report/ReportRepository.java | 7 ++++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 7a9a11819..729ce0a83 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -48,8 +48,6 @@ public class ReportManager { this.reportRepository = new RedisDataRepository(Region.ALL, Report.class, "reports"); this.reportProfiles = new RedisDataRepository(Region.ALL, ReportProfile.class, "reportprofiles"); this.activeReports = new HashMap(); - - // TODO: Get JavaPlugin instance and locate ConnectionString from config? this.reportSqlRepository = new ReportRepository(); reportSqlRepository.initialize(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index 54ad8fb63..d2bb8987a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -39,9 +39,10 @@ This will be used to determine if staff are handling @Override protected void initialize() { - executeUpdate(CREATE_TICKET_TABLE); - executeUpdate(CREATE_HANDLER_TABLE); - executeUpdate(CREATE_REPORTERS_TABLE); + // disabled until approved + // executeUpdate(CREATE_TICKET_TABLE); + // executeUpdate(CREATE_HANDLER_TABLE); + // executeUpdate(CREATE_REPORTERS_TABLE); } @Override From 95c38b193973560f6e5153564e1d7f0290711fb5 Mon Sep 17 00:00:00 2001 From: Keir Date: Mon, 2 Nov 2015 23:30:06 +0000 Subject: [PATCH 16/39] Don't use static instances. --- .../src/mineplex/core/report/ReportManager.java | 10 ++++++---- .../src/mineplex/core/report/ReportPlugin.java | 5 ----- .../src/mineplex/core/report/ReportRepository.java | 4 ++-- .../core/report/command/ReportNotification.java | 13 ++++++++----- Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 729ce0a83..46acaad62 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -16,6 +16,7 @@ import mineplex.serverdata.data.DataRepository; import mineplex.serverdata.redis.RedisDataRepository; import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; @@ -42,18 +43,19 @@ public class ReportManager { // A mapping of PlayerName(String) to the ReportId(Integer) for all active reports on this server. private Map activeReports; - public ReportManager(String serverName) + public ReportManager(JavaPlugin plugin, String serverName) { this.serverName = serverName; this.reportRepository = new RedisDataRepository(Region.ALL, Report.class, "reports"); this.reportProfiles = new RedisDataRepository(Region.ALL, ReportProfile.class, "reportprofiles"); this.activeReports = new HashMap(); - this.reportSqlRepository = new ReportRepository(); + this.reportSqlRepository = new ReportRepository(plugin); reportSqlRepository.initialize(); } 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. } @@ -254,7 +256,7 @@ public class ReportManager { */ public void sendReportNotification(JsonMessage message) { - ReportNotification reportNotification = new ReportNotification(message); + ReportNotification reportNotification = new ReportNotification(this, message); reportNotification.publish(); } @@ -264,7 +266,7 @@ public class ReportManager { */ public void sendReportNotification(String message) { - ReportNotification reportNotification = new ReportNotification(message); + ReportNotification reportNotification = new ReportNotification(this, message); reportNotification.publish(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java index 1805da44f..47481b682 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java @@ -11,17 +11,12 @@ import org.bukkit.plugin.java.JavaPlugin; public class ReportPlugin extends MiniPlugin { - - private static ReportPlugin instance; - public static ReportPlugin getInstance() { return instance; } - private final ReportManager _reportManager; public ReportPlugin(JavaPlugin plugin, ReportManager reportManager) { super("Report", plugin); - instance = this; _reportManager = reportManager; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index d2bb8987a..14d78690c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -31,9 +31,9 @@ This will be used to determine if staff are handling private static String INSERT_HANDLER = "INSERT INTO reportHandlers (eventDate, reportId, handlerId) VALUES(now(), ?, ?);"; private static String INSERT_SENDER = "INSERT INTO reportSenders (eventDate, reportId, reporterId, category, reason) VALUES(now(), ?, ?, ?, ?);"; - public ReportRepository() + public ReportRepository(JavaPlugin plugin) { - super(ReportPlugin.getInstance().getPlugin(), DBPool.ACCOUNT); + super(plugin, DBPool.ACCOUNT); } @Override diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java index 97194b850..372c9a31c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java @@ -5,22 +5,25 @@ 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 { + private ReportManager _reportManager; private String _notification; - public ReportNotification(String notification) + public ReportNotification(ReportManager reportManager, String notification) { - this(new JsonMessage(notification)); + this(reportManager, new JsonMessage(notification)); } - public ReportNotification(JsonMessage notification) + public ReportNotification(ReportManager reportManager, JsonMessage notification) { super(); // Send to all servers - this._notification = notification.toString(); + _reportManager = reportManager; + _notification = notification.toString(); } public void run() @@ -28,7 +31,7 @@ public class ReportNotification extends ServerCommand // Message all players that can receive report notifications. for (Player player : UtilServer.getPlayers()) { - if (ReportPlugin.getInstance().getReportManager().hasReportNotifications(player)) + if (_reportManager.hasReportNotifications(player)) { Server server = UtilServer.getServer(); server.dispatchCommand(server.getConsoleSender(), "tellraw " + player.getName() + " " + _notification); diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index e2fd86f86..dd1ed1cd3 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -148,7 +148,7 @@ public class Hub extends JavaPlugin implements IRelation } }); new GlobalPacketManager(this, clientManager, serverStatusManager); - new ReportPlugin(this, new ReportManager(serverStatusManager.getCurrentServerName())); + new ReportPlugin(this, new ReportManager(this, serverStatusManager.getCurrentServerName())); //new Replay(this, packetHandler); AprilFoolsManager.Initialize(this, clientManager, disguiseManager); From 9030b4f264981df9d7e5d272778877c9594ba5f1 Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 3 Nov 2015 15:27:32 +0000 Subject: [PATCH 17/39] Remove unused column 'date'. --- .../src/mineplex/core/report/ReportRepository.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index 14d78690c..a8de2e45f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -23,7 +23,7 @@ id, date, reportId, accountId of Staff This will be used to determine if staff are handling */ - private static String CREATE_TICKET_TABLE = "CREATE TABLE IF NOT EXISTS reportTickets (reportId INT NOT NULL, date LONG, eventDate LONG, playerId INT NOT NULL, server VARCHAR(50), closerId INT NOT NULL, result VARCHAR(25), reason VARCHAR(100), PRIMARY KEY (reportId), INDEX playerIdIndex (playerId), INDEX closerIdIndex (closerId));"; + private static String CREATE_TICKET_TABLE = "CREATE TABLE IF NOT EXISTS reportTickets (reportId INT NOT NULL, eventDate LONG, playerId INT NOT NULL, server VARCHAR(50), closerId INT NOT NULL, result VARCHAR(25), reason VARCHAR(100), PRIMARY KEY (reportId), INDEX playerIdIndex (playerId), INDEX closerIdIndex (closerId));"; private static String CREATE_HANDLER_TABLE = "CREATE TABLE IF NOT EXISTS reportHandlers (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, handlerId INT NOT NULL, PRIMARY KEY (id), INDEX handlerIdIndex (handlerId) );"; private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, category TINYINT, reason VARCHAR(100), PRIMARY KEY (id), INDEX reporterIdIndex (reporterId));"; From 6054bfaac4e6faa2a3fc2744b9a0edc58a7850a2 Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 3 Nov 2015 15:37:39 +0000 Subject: [PATCH 18/39] Do all database operations asynchronously. --- .../core/report/ReportRepository.java | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index a8de2e45f..f7d5c4738 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -1,6 +1,7 @@ package mineplex.core.report; import mineplex.core.database.DBPool; +import mineplex.core.database.DatabaseRunnable; import mineplex.core.database.RepositoryBase; import mineplex.core.database.column.ColumnByte; import mineplex.core.database.column.ColumnInt; @@ -51,22 +52,42 @@ This will be used to determine if staff are handling } - public void logReportHandling(int reportId, int handlerId) + public void logReportHandling(final int reportId, final int handlerId) { - executeUpdate(INSERT_HANDLER, new ColumnInt("reportId", reportId), new ColumnInt("handlerId", handlerId)); + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + @Override + public void run() + { + executeUpdate(INSERT_HANDLER, new ColumnInt("reportId", reportId), new ColumnInt("handlerId", handlerId)); + } + }), "Error logging report " + reportId + " as being handled by user " + handlerId + "."); } - public void logReportSending(int reportId, int reporterId, Category category, String reason) + public void logReportSending(final int reportId, final int reporterId, final Category category, final String reason) { - executeUpdate(INSERT_SENDER, new ColumnInt("reportId", reportId), new ColumnInt("reporterId", reporterId), - new ColumnByte("type", (byte) category.getId()), new ColumnVarChar("reason", 100, reason)); + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + @Override + public void run() + { + executeUpdate(INSERT_SENDER, new ColumnInt("reportId", reportId), new ColumnInt("reporterId", reporterId), + new ColumnByte("type", (byte) category.getId()), new ColumnVarChar("reason", 100, reason)); + } + }), "Error logging report " + reportId + " by user " + reporterId + "."); } - public void logReport(int reportId, int playerId, String server, int closerId, ReportResult result, String reason) + public void logReport(final int reportId, final int playerId, final String server, final int closerId, final ReportResult result, final String reason) { - executeUpdate(INSERT_TICKET, new ColumnInt("reportId", reportId), new ColumnInt("playerId", playerId), - new ColumnVarChar("server", 50, server), new ColumnInt("closerId", closerId), - new ColumnVarChar("result", 25, result.toString()), new ColumnVarChar("reason", 100, reason)); + handleDatabaseCall(new DatabaseRunnable(new Runnable() + { + @Override + public void run() + { + executeUpdate(INSERT_TICKET, new ColumnInt("reportId", reportId), new ColumnInt("playerId", playerId), + new ColumnVarChar("server", 50, server), new ColumnInt("closerId", closerId), + new ColumnVarChar("result", 25, result.toString()), new ColumnVarChar("reason", 100, reason)); + } + }), "Error logging result for report " + reportId + "."); } - } \ No newline at end of file From bd6ce21cf731822c44e6bf1bc04cbd3b7221e44d Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 3 Nov 2015 16:40:31 +0000 Subject: [PATCH 19/39] Make use of foreign keys in table creation and drop "INDEX" statements (foreign keys are auto-indexed). --- .../src/mineplex/core/report/ReportRepository.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index f7d5c4738..709a911ce 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -24,9 +24,9 @@ id, date, reportId, accountId of Staff This will be used to determine if staff are handling */ - private static String CREATE_TICKET_TABLE = "CREATE TABLE IF NOT EXISTS reportTickets (reportId INT NOT NULL, eventDate LONG, playerId INT NOT NULL, server VARCHAR(50), closerId INT NOT NULL, result VARCHAR(25), reason VARCHAR(100), PRIMARY KEY (reportId), INDEX playerIdIndex (playerId), INDEX closerIdIndex (closerId));"; - private static String CREATE_HANDLER_TABLE = "CREATE TABLE IF NOT EXISTS reportHandlers (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, handlerId INT NOT NULL, PRIMARY KEY (id), INDEX handlerIdIndex (handlerId) );"; - private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, category TINYINT, reason VARCHAR(100), PRIMARY KEY (id), INDEX reporterIdIndex (reporterId));"; + private static String CREATE_TICKET_TABLE = "CREATE TABLE IF NOT EXISTS reportTickets (reportId INT NOT NULL, eventDate LONG, playerId INT NOT NULL, server VARCHAR(50), closerId INT NOT NULL, result VARCHAR(25), reason VARCHAR(100), PRIMARY KEY (reportId), FOREIGN KEY (playerId) REFERENCES accounts(id), FOREIGN KEY (closerId) REFERENCES accounts(id));"; + private static String CREATE_HANDLER_TABLE = "CREATE TABLE IF NOT EXISTS reportHandlers (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, handlerId INT NOT NULL, PRIMARY KEY (id), FOREIGN KEY (reportId) REFERENCES reportTickets(reportId), FOREIGN KEY (handlerId) REFERENCES accounts(id) );"; + private static String CREATE_REPORTERS_TABLE = "CREATE TABLE IF NOT EXISTS reportSenders (id INT NOT NULL AUTO_INCREMENT, reportId INT NOT NULL, eventDate LONG, reporterId INT NOT NULL, category TINYINT, reason VARCHAR(100), PRIMARY KEY (id), FOREIGN KEY (reportId) REFERENCES reportTickets(reportId), FOREIGN KEY (reporterId) REFERENCES accounts(id));"; private static String INSERT_TICKET = "INSERT INTO reportTickets (reportId, eventDate, playerId, server, closerId, result, reason) VALUES (?, now(), ?, ?, ?, ?, ?);"; private static String INSERT_HANDLER = "INSERT INTO reportHandlers (eventDate, reportId, handlerId) VALUES(now(), ?, ?);"; From 72b650086d5f24feeffa10d5f1058c8e40fc71e3 Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 3 Nov 2015 17:03:09 +0000 Subject: [PATCH 20/39] Instantiating a page shouldn't cause it to automatically open. --- .../src/mineplex/core/report/command/ReportCommand.java | 2 +- .../Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java index a47f5f6ca..0b8faef59 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java @@ -34,7 +34,7 @@ public class ReportCommand extends CommandBase if (reportedPlayer != null) { - new ReportPage(Plugin, player, reportedPlayer, reason); + new ReportPage(Plugin, player, reportedPlayer, reason).openInventory(); } else { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java index 5c5c1b9a2..aac7ab7e4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java @@ -40,7 +40,6 @@ public class ReportPage extends SimpleGui this._reason = reason; buildPage(); - openInventory(); } private void buildPage() From e449e47b9a910ad227b54ef89e1a796963cb1ad9 Mon Sep 17 00:00:00 2001 From: Keir Date: Fri, 6 Nov 2015 01:33:46 +0000 Subject: [PATCH 21/39] Document ReportNotification. --- .../mineplex/core/report/command/ReportNotification.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java index 372c9a31c..f5b1b2dcf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java @@ -6,13 +6,15 @@ 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; +/** + * A message regarding a report which should be sent to all moderators with report notifications enabled. + */ public class ReportNotification extends ServerCommand { private ReportManager _reportManager; - private String _notification; + private String _notification; // in json format public ReportNotification(ReportManager reportManager, String notification) { From fd2a54341892f44cca1152ccca81b19c504f1479 Mon Sep 17 00:00:00 2001 From: Keir Date: Fri, 6 Nov 2015 16:46:10 +0000 Subject: [PATCH 22/39] Add "ShowUserReports" preference (however currently not visible to players nor does it get saved to the DB currently). Fix variable names in ReportManager. --- .../core/preferences/UserPreferences.java | 1 + .../core/preferences/ui/PreferencesPage.java | 21 +++++- .../mineplex/core/report/ReportManager.java | 70 ++++++++++--------- .../Mineplex.Hub/src/mineplex/hub/Hub.java | 2 +- 4 files changed, 58 insertions(+), 36 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/UserPreferences.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/UserPreferences.java index e52e7d249..6b9c5a8eb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/UserPreferences.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/UserPreferences.java @@ -12,6 +12,7 @@ public class UserPreferences public boolean Invisibility = false; public boolean HubForcefield = false; public boolean ShowMacReports = false; + public boolean ShowUserReports = false; public boolean IgnoreVelocity = false; public boolean PendingFriendRequests = true; public boolean friendDisplayInventoryUI = true; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java index 2d4b29462..4d28be7cf 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java @@ -26,6 +26,7 @@ public class PreferencesPage extends ShopPageBase reportRepository; + private DataRepository _reportRepository; - private DataRepository reportProfiles; + private DataRepository _reportProfiles; // Stores/logs closed tickets, and various reporter/staff actions. - private ReportRepository reportSqlRepository; + private ReportRepository _reportSqlRepository; // A mapping of PlayerName(String) to the ReportId(Integer) for all active reports on this server. - private Map activeReports; + private Map _activeReports; - public ReportManager(JavaPlugin plugin, String serverName) + public ReportManager(JavaPlugin plugin, PreferencesManager preferencesManager, String serverName) { - this.serverName = serverName; - this.reportRepository = new RedisDataRepository(Region.ALL, Report.class, "reports"); - this.reportProfiles = new RedisDataRepository(Region.ALL, ReportProfile.class, "reportprofiles"); - this.activeReports = new HashMap(); - this.reportSqlRepository = new ReportRepository(plugin); - reportSqlRepository.initialize(); + _preferencesManager = preferencesManager; + _serverName = serverName; + _reportRepository = new RedisDataRepository(Region.ALL, Report.class, "reports"); + _reportProfiles = new RedisDataRepository(Region.ALL, ReportProfile.class, "reportprofiles"); + _activeReports = new HashMap(); + _reportSqlRepository = new ReportRepository(plugin); + _reportSqlRepository.initialize(); } public void retrieveReportResult(int reportId, Player reportCloser, String reason) @@ -71,13 +75,13 @@ public class ReportManager { if (isActiveReport(reportId)) { Report report = getReport(reportId); - reportRepository.removeElement(String.valueOf(reportId)); // Remove report from redis database + _reportRepository.removeElement(String.valueOf(reportId)); // Remove report from redis database removeActiveReport(reportId); int closerId = reportCloser != null ? getPlayerAccount(reportCloser).getAccountId() : -1; String playerName = getReport(reportId).getPlayerName(); int playerId = getPlayerAccount(playerName).getAccountId(); - reportSqlRepository.logReport(reportId, playerId, serverName, 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()) @@ -85,7 +89,7 @@ public class ReportManager { CoreClient reporterAccount = getPlayerAccount(reporterName); ReportProfile reportProfile = getReportProfile(String.valueOf(reporterAccount.getAccountId())); reportProfile.onReportClose(result); - reportProfiles.addElement(reportProfile); + _reportProfiles.addElement(reportProfile); } if (reportCloser != null) @@ -95,12 +99,11 @@ public class ReportManager { reportCloser.getName(), result.toDisplayMessage())); } } - } public void handleReport(int reportId, Player reportHandler) { - if (reportRepository.elementExists(String.valueOf(reportId))) + if (_reportRepository.elementExists(String.valueOf(reportId))) { Report report = getReport(reportId); Portal.transferPlayer(reportHandler.getName(), report.getServerName()); @@ -111,7 +114,7 @@ public class ReportManager { // with info about the case/report. int handlerId = getPlayerAccount(reportHandler).getAccountId(); - reportSqlRepository.logReportHandling(reportId, handlerId); // Log handling into sql database + _reportSqlRepository.logReportHandling(reportId, handlerId); // Log handling into sql database } } @@ -132,10 +135,10 @@ public class ReportManager { else { reportId = generateReportId(); - report = new Report(reportId, reportedPlayer.getName(), serverName, category); + report = new Report(reportId, reportedPlayer.getName(), _serverName, category); report.addReporter(reporter.getName()); - activeReports.put(reportedPlayer.getName().toLowerCase(), report.getReportId()); - reportRepository.addElement(report); + _activeReports.put(reportedPlayer.getName().toLowerCase(), report.getReportId()); + _reportRepository.addElement(report); } // only start notifying staff when @@ -156,7 +159,7 @@ public class ReportManager { sendReportNotification(clickableMessage); } - reportSqlRepository.logReportSending(report.getReportId(), reporterId, category, reason); + _reportSqlRepository.logReportSending(report.getReportId(), reporterId, category, reason); } } @@ -172,7 +175,7 @@ public class ReportManager { public ReportProfile getReportProfile(String playerName) { - ReportProfile profile = reportProfiles.getElement(playerName); + ReportProfile profile = _reportProfiles.getElement(playerName); if (profile == null) { @@ -185,7 +188,7 @@ public class ReportManager { private void saveReportProfile(ReportProfile profile) { - reportProfiles.addElement(profile); + _reportProfiles.addElement(profile); } /** @@ -220,7 +223,7 @@ public class ReportManager { public Report getReport(int reportId) { - return reportRepository.getElement(String.valueOf(reportId)); + return _reportRepository.getElement(String.valueOf(reportId)); } private CoreClient getPlayerAccount(Player player) @@ -244,10 +247,9 @@ public class ReportManager { */ public boolean hasReportNotifications(Player player) { - // If player is not staff, return false. - // If player is staff but has report notifications pref disabled, return false; - // Else return true. - return false; + boolean isStaff = CommandCenter.Instance.GetClientManager().Get(player).GetRank().has(Rank.HELPER); + boolean hasReportNotifications = _preferencesManager.Get(player).ShowUserReports; + return isStaff && hasReportNotifications; } /** @@ -277,9 +279,9 @@ public class ReportManager { */ public int getActiveReport(String playerName) { - if (activeReports.containsKey(playerName.toLowerCase())) + if (_activeReports.containsKey(playerName.toLowerCase())) { - return activeReports.get(playerName.toLowerCase()); + return _activeReports.get(playerName.toLowerCase()); } return -1; @@ -292,7 +294,7 @@ public class ReportManager { public boolean isActiveReport(int reportId) { - for (Entry activeReport : activeReports.entrySet()) + for (Entry activeReport : _activeReports.entrySet()) { if (activeReport.getValue() == reportId) { @@ -305,11 +307,11 @@ public class ReportManager { public boolean removeActiveReport(int reportId) { - for (Entry activeReport : activeReports.entrySet()) + for (Entry activeReport : _activeReports.entrySet()) { if (activeReport.getValue() == reportId) { - activeReports.remove(activeReport.getKey()); + _activeReports.remove(activeReport.getKey()); return true; } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java index dd1ed1cd3..8e3e5cf76 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/Hub.java @@ -148,7 +148,7 @@ public class Hub extends JavaPlugin implements IRelation } }); new GlobalPacketManager(this, clientManager, serverStatusManager); - new ReportPlugin(this, new ReportManager(this, serverStatusManager.getCurrentServerName())); + new ReportPlugin(this, new ReportManager(this, preferenceManager, serverStatusManager.getCurrentServerName())); //new Replay(this, packetHandler); AprilFoolsManager.Initialize(this, clientManager, disguiseManager); From 03a59542248308d26ca50a8ad0781209c076fd41 Mon Sep 17 00:00:00 2001 From: Keir Date: Mon, 9 Nov 2015 18:35:03 +0000 Subject: [PATCH 23/39] Handle saving and loading of the ShowUserReports setting. --- .../core/preferences/PreferencesRepository.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java index 44852c23e..b17baf48b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java @@ -15,9 +15,9 @@ import mineplex.core.database.column.ColumnVarChar; public class PreferencesRepository extends RepositoryBase { - //private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), games BOOL NOT NULL DEFAULT 1, visibility BOOL NOT NULL DEFAULT 1, showChat BOOL NOT NULL DEFAULT 1, friendChat BOOL NOT NULL DEFAULT 1, privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));"; + //private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), games BOOL NOT NULL DEFAULT 1, visibility BOOL NOT NULL DEFAULT 1, showChat BOOL NOT NULL DEFAULT 1, friendChat BOOL NOT NULL DEFAULT 1, privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL NOT NULL DEFAULT 0, showUserReports BOOL NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));"; private static String INSERT_ACCOUNT = "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;"; - private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ?, friendDisplayInventoryUI = ? WHERE uuid=?;"; + private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ?, friendDisplayInventoryUI = ?, showUserReports = ? WHERE uuid=?;"; public PreferencesRepository(JavaPlugin plugin) { @@ -57,7 +57,8 @@ public class PreferencesRepository extends RepositoryBase preparedStatement.setBoolean(10, entry.getValue().IgnoreVelocity); preparedStatement.setBoolean(11, entry.getValue().PendingFriendRequests); preparedStatement.setBoolean(12, entry.getValue().friendDisplayInventoryUI); - preparedStatement.setString(13, entry.getKey()); + preparedStatement.setBoolean(13, entry.getValue().ShowUserReports); + preparedStatement.setString(14, entry.getKey()); preparedStatement.addBatch(); } @@ -83,7 +84,8 @@ public class PreferencesRepository extends RepositoryBase preparedStatement.setBoolean(10, entry.getValue().IgnoreVelocity); preparedStatement.setBoolean(11, entry.getValue().PendingFriendRequests); preparedStatement.setBoolean(12, entry.getValue().friendDisplayInventoryUI); - preparedStatement.setString(13, entry.getKey()); + preparedStatement.setBoolean(13, entry.getValue().ShowUserReports); + preparedStatement.setString(14, entry.getKey()); preparedStatement.execute(); } From 217ac78d4910f82891dd538441a98192231da1bf Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 10 Nov 2015 11:38:13 +0000 Subject: [PATCH 24/39] Alter "accountPreferences" table to include a new column "showUserReports". --- .../src/mineplex/core/preferences/PreferencesRepository.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java index b17baf48b..039f11338 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java @@ -18,6 +18,7 @@ public class PreferencesRepository extends RepositoryBase //private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), games BOOL NOT NULL DEFAULT 1, visibility BOOL NOT NULL DEFAULT 1, showChat BOOL NOT NULL DEFAULT 1, friendChat BOOL NOT NULL DEFAULT 1, privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL NOT NULL DEFAULT 0, showUserReports BOOL NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));"; private static String INSERT_ACCOUNT = "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;"; private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ?, friendDisplayInventoryUI = ?, showUserReports = ? WHERE uuid=?;"; + private static String ADD_USER_REPORTS_COLUMN = "ALTER TABLE accountPreferences ADD showUserReports BOOL DEFAULT 0 NOT NULL;"; public PreferencesRepository(JavaPlugin plugin) { @@ -28,6 +29,7 @@ public class PreferencesRepository extends RepositoryBase protected void initialize() { //executeUpdate(CREATE_ACCOUNT_TABLE); + executeUpdate(ADD_USER_REPORTS_COLUMN); } @Override From e59b5c254919118a0bda9cf5d39f2ad539f89acc Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 10 Nov 2015 16:07:32 +0000 Subject: [PATCH 25/39] Actually show the report toggle action. --- .../src/mineplex/core/preferences/ui/PreferencesPage.java | 3 ++- .../Mineplex.Core/src/mineplex/core/report/ReportManager.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java index 0acce3755..c1dcd3d75 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java @@ -294,13 +294,14 @@ public class PreferencesPage extends ShopPageBase Date: Tue, 10 Nov 2015 16:08:16 +0000 Subject: [PATCH 26/39] Load show user reports value from database. --- .../src/mineplex/core/preferences/PreferencesRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java index 039f11338..13f09f8b6 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java @@ -118,6 +118,7 @@ public class PreferencesRepository extends RepositoryBase preferences.IgnoreVelocity = resultSet.getBoolean(10); preferences.PendingFriendRequests = resultSet.getBoolean(11); preferences.friendDisplayInventoryUI = resultSet.getBoolean(12); + preferences.ShowUserReports = resultSet.getBoolean(13); } return preferences; From 7d63a95ec920ebee0ae3ff4b0749fd60db696035 Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 10 Nov 2015 21:22:21 +0000 Subject: [PATCH 27/39] Remove ALTER statement, modifications have been done. --- .../src/mineplex/core/preferences/PreferencesRepository.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java index 13f09f8b6..69c811dc9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java @@ -18,7 +18,6 @@ public class PreferencesRepository extends RepositoryBase //private static String CREATE_ACCOUNT_TABLE = "CREATE TABLE IF NOT EXISTS accountPreferences (id INT NOT NULL AUTO_INCREMENT, uuid VARCHAR(256), games BOOL NOT NULL DEFAULT 1, visibility BOOL NOT NULL DEFAULT 1, showChat BOOL NOT NULL DEFAULT 1, friendChat BOOL NOT NULL DEFAULT 1, privateMessaging BOOL NOT NULL DEFAULT 1, partyRequests BOOL NOT NULL DEFAULT 0, invisibility BOOL NOT NULL DEFAULT 0, forcefield BOOL NOT NULL DEFAULT 0, showMacReports BOOL NOT NULL DEFAULT 0, ignoreVelocity BOOL NOT NULL DEFAULT 0, showUserReports BOOL NOT NULL DEFAULT 0, PRIMARY KEY (id), UNIQUE INDEX uuid_index (uuid));"; private static String INSERT_ACCOUNT = "INSERT INTO accountPreferences (uuid) VALUES (?) ON DUPLICATE KEY UPDATE uuid=uuid;"; private static String UPDATE_ACCOUNT_PREFERENCES = "UPDATE accountPreferences SET games = ?, visibility = ?, showChat = ?, friendChat = ?, privateMessaging = ?, partyRequests = ?, invisibility = ?, forcefield = ?, showMacReports = ?, ignoreVelocity = ?, pendingFriendRequests = ?, friendDisplayInventoryUI = ?, showUserReports = ? WHERE uuid=?;"; - private static String ADD_USER_REPORTS_COLUMN = "ALTER TABLE accountPreferences ADD showUserReports BOOL DEFAULT 0 NOT NULL;"; public PreferencesRepository(JavaPlugin plugin) { @@ -29,7 +28,6 @@ public class PreferencesRepository extends RepositoryBase protected void initialize() { //executeUpdate(CREATE_ACCOUNT_TABLE); - executeUpdate(ADD_USER_REPORTS_COLUMN); } @Override From f1c85642634acee8b1e58b2030d13d25718cdeec Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 10 Nov 2015 21:40:35 +0000 Subject: [PATCH 28/39] Fix preference inventory. --- .../src/mineplex/core/preferences/ui/PreferencesPage.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java index c1dcd3d75..89b6dabf8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/ui/PreferencesPage.java @@ -294,14 +294,14 @@ public class PreferencesPage extends ShopPageBase Date: Wed, 11 Nov 2015 14:53:22 +0000 Subject: [PATCH 29/39] Actually fetch the showUserReports value from the database. --- .../src/mineplex/core/preferences/PreferencesManager.java | 2 +- .../src/mineplex/core/preferences/PreferencesRepository.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java index c69ab7bed..42a32410c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesManager.java @@ -131,6 +131,6 @@ public class PreferencesManager extends MiniDbClientPlugin @Override public String getQuery(int accountId, String uuid, String name) { - return "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests, friendDisplayInventoryUI FROM accountPreferences WHERE accountPreferences.uuid = '" + uuid + "' LIMIT 1;"; + return "SELECT games, visibility, showChat, friendChat, privateMessaging, partyRequests, invisibility, forcefield, showMacReports, ignoreVelocity, pendingFriendRequests, friendDisplayInventoryUI, showUserReports FROM accountPreferences WHERE accountPreferences.uuid = '" + uuid + "' LIMIT 1;"; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java index 69c811dc9..9f3997bff 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/preferences/PreferencesRepository.java @@ -101,7 +101,7 @@ public class PreferencesRepository extends RepositoryBase public UserPreferences loadClientInformation(final ResultSet resultSet) throws SQLException { final UserPreferences preferences = new UserPreferences(); - + if (resultSet.next()) { preferences.HubGames = resultSet.getBoolean(1); From 9c45a48a2603714591a782da26d975cadc75087c Mon Sep 17 00:00:00 2001 From: Keir Date: Wed, 11 Nov 2015 15:05:36 +0000 Subject: [PATCH 30/39] Add confirmation message when a report is successful. --- .../src/mineplex/core/report/ReportManager.java | 5 ++++- .../src/mineplex/core/report/ui/ReportPage.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index e2069843b..5a97a979c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -118,7 +118,7 @@ public class ReportManager { } } - public void reportPlayer(Player reporter, Player reportedPlayer, Category category, String reason) + public Report reportPlayer(Player reporter, Player reportedPlayer, Category category, String reason) { int reporterId = getPlayerAccount(reporter).getAccountId(); ReportProfile reportProfile = getReportProfile(String.valueOf(reporterId)); @@ -160,7 +160,10 @@ public class ReportManager { } _reportSqlRepository.logReportSending(report.getReportId(), reporterId, category, reason); + return report; } + + return null; } public void onPlayerQuit(Player player) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java index aac7ab7e4..e72f481a8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java @@ -7,8 +7,10 @@ import java.util.Map; import org.bukkit.entity.Player; import org.bukkit.event.HandlerList; +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; @@ -53,9 +55,10 @@ public class ReportPage extends SimpleGui public void addReport(Category category) { - _reportPlugin.getReportManager().reportPlayer(_reportee, _offender, category, _reason); + Report report = _reportPlugin.getReportManager().reportPlayer(_reportee, _offender, category, _reason); _reportee.closeInventory(); unregisterListener(); + _reportee.sendMessage(C.cGreen + "Report sent successfully (" + C.cGold + "#" + report.getReportId() + C.cGreen + ")."); } public void unregisterListener() From d7ba2e473114693603aefce3f985c30a54bcd93d Mon Sep 17 00:00:00 2001 From: Keir Date: Wed, 11 Nov 2015 16:12:28 +0000 Subject: [PATCH 31/39] Fix infinite gson loop by separating dependencies. --- .../mineplex/core/report/ReportManager.java | 11 +++-- .../report/command/ReportNotification.java | 30 +++++-------- .../command/ReportNotificationCallback.java | 42 +++++++++++++++++++ 3 files changed, 60 insertions(+), 23 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotificationCallback.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 5a97a979c..c40793da5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -11,9 +11,11 @@ import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; +import mineplex.core.report.command.ReportNotificationCallback; import mineplex.core.report.command.ReportNotification; import mineplex.serverdata.Region; import mineplex.serverdata.Utility; +import mineplex.serverdata.commands.ServerCommandManager; import mineplex.serverdata.data.DataRepository; import mineplex.serverdata.redis.RedisDataRepository; @@ -55,6 +57,8 @@ public class ReportManager { _activeReports = new HashMap(); _reportSqlRepository = new ReportRepository(plugin); _reportSqlRepository.initialize(); + + ServerCommandManager.getInstance().registerCommandType("ReportNotification", ReportNotification.class, new ReportNotificationCallback(this)); } public void retrieveReportResult(int reportId, Player reportCloser, String reason) @@ -142,7 +146,7 @@ public class ReportManager { } // only start notifying staff when - if (report.getReporters().size() >= 3) + 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(), @@ -252,6 +256,7 @@ 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; } @@ -261,7 +266,7 @@ public class ReportManager { */ public void sendReportNotification(JsonMessage message) { - ReportNotification reportNotification = new ReportNotification(this, message); + ReportNotification reportNotification = new ReportNotification(message); reportNotification.publish(); } @@ -271,7 +276,7 @@ public class ReportManager { */ public void sendReportNotification(String message) { - ReportNotification reportNotification = new ReportNotification(this, message); + ReportNotification reportNotification = new ReportNotification(message); reportNotification.publish(); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java index f5b1b2dcf..ca2d7814a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotification.java @@ -1,11 +1,6 @@ package mineplex.core.report.command; -import org.bukkit.Server; -import org.bukkit.entity.Player; - import mineplex.core.common.jsonchat.JsonMessage; -import mineplex.core.common.util.UtilServer; -import mineplex.core.report.ReportManager; import mineplex.serverdata.commands.ServerCommand; /** @@ -13,31 +8,26 @@ import mineplex.serverdata.commands.ServerCommand; */ public class ReportNotification extends ServerCommand { - private ReportManager _reportManager; private String _notification; // in json format - public ReportNotification(ReportManager reportManager, String notification) + public ReportNotification(String notification) { - this(reportManager, new JsonMessage(notification)); + this(new JsonMessage(notification)); } - public ReportNotification(ReportManager reportManager, JsonMessage notification) + public ReportNotification(JsonMessage notification) { super(); // Send to all servers - _reportManager = reportManager; _notification = notification.toString(); } - + + public String getNotification() + { + return _notification; + } + public void run() { - // Message all players that can receive report notifications. - for (Player player : UtilServer.getPlayers()) - { - if (_reportManager.hasReportNotifications(player)) - { - Server server = UtilServer.getServer(); - server.dispatchCommand(server.getConsoleSender(), "tellraw " + player.getName() + " " + _notification); - } - } + // Utilitizes a callback functionality to seperate dependencies } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotificationCallback.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotificationCallback.java new file mode 100644 index 000000000..10cdf0e33 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotificationCallback.java @@ -0,0 +1,42 @@ +package mineplex.core.report.command; + +import org.bukkit.Server; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.UtilServer; +import mineplex.core.report.ReportManager; +import mineplex.serverdata.commands.CommandCallback; +import mineplex.serverdata.commands.ServerCommand; + +/** + * Handles receiving of report notifications. + * @author iKeirNez + */ +public class ReportNotificationCallback implements CommandCallback +{ + private ReportManager _reportManager; + + public ReportNotificationCallback(ReportManager reportManager) + { + _reportManager = reportManager; + } + + @Override + public void run(ServerCommand command) + { + if (command instanceof ReportNotification) + { + ReportNotification reportNotification = (ReportNotification) command; + + // Message all players that can receive report notifications. + for (Player player : UtilServer.getPlayers()) + { + if (_reportManager.hasReportNotifications(player)) + { + Server server = UtilServer.getServer(); + server.dispatchCommand(server.getConsoleSender(), "tellraw " + player.getName() + " " + reportNotification.getNotification()); + } + } + } + } +} From f2e88c1c54504c5d3368d5b7abaf4896ec493f5f Mon Sep 17 00:00:00 2001 From: Keir Date: Wed, 11 Nov 2015 19:05:29 +0000 Subject: [PATCH 32/39] Only allow 1 player at a time to handle a report. --- .../src/mineplex/core/report/Report.java | 5 +++++ .../mineplex/core/report/ReportManager.java | 22 +++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java b/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java index dd20593ff..bfc4b3606 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java @@ -2,6 +2,7 @@ package mineplex.core.report; import java.util.HashSet; import java.util.Set; +import java.util.UUID; import mineplex.serverdata.data.Data; @@ -22,6 +23,10 @@ public class Report implements Data public Set getReporters() { return _reporters; } public void addReporter(String reporter) { _reporters.add(reporter); } + private String _handler = null; + public void setHandler(String handler) { _handler = handler; } + public String getHandler() { return _handler; } + private Category _category; public Category getCategory() { return _category; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index c40793da5..1103fd05f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -9,6 +9,7 @@ import mineplex.core.command.CommandCenter; import mineplex.core.common.Rank; import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.JsonMessage; +import mineplex.core.common.util.C; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; import mineplex.core.report.command.ReportNotificationCallback; @@ -110,15 +111,22 @@ public class ReportManager { if (_reportRepository.elementExists(String.valueOf(reportId))) { Report report = getReport(reportId); - 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. + if (report.getPlayerName() != null) { + reportHandler.sendMessage(C.cRed + "Someone is already handling this report."); + } else { + String handlerName = reportHandler.getName(); + report.setHandler(handlerName); - int handlerId = getPlayerAccount(reportHandler).getAccountId(); - _reportSqlRepository.logReportHandling(reportId, handlerId); // Log handling into sql database + sendReportNotification(String.format("[Report %d] %s is handling this report.", reportId, handlerName)); + Portal.transferPlayer(reportHandler.getName(), report.getServerName()); + + // 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 + } } } From 727da2c6b596703125812b56d29c47cfacf4a2ba Mon Sep 17 00:00:00 2001 From: Keir Date: Wed, 11 Nov 2015 19:23:10 +0000 Subject: [PATCH 33/39] Embarrassing typo. --- .../Mineplex.Core/src/mineplex/core/report/ReportManager.java | 2 +- .../src/mineplex/core/report/command/ReportHandleCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 1103fd05f..121f23f3c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -112,7 +112,7 @@ public class ReportManager { { Report report = getReport(reportId); - if (report.getPlayerName() != null) { + if (report.getHandler() != null) { reportHandler.sendMessage(C.cRed + "Someone is already handling this report."); } else { String handlerName = reportHandler.getName(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java index 04048de6f..a7d6ab95a 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandleCommand.java @@ -29,7 +29,7 @@ public class ReportHandleCommand extends CommandBase else { int reportId = Integer.parseInt(args[0]); - + Plugin.getReportManager().handleReport(reportId, player); } } From 6295a8ce087934289f17d33e3b8f3ccbff361683 Mon Sep 17 00:00:00 2001 From: Keir Date: Thu, 12 Nov 2015 00:02:38 +0000 Subject: [PATCH 34/39] 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. --- .../mineplex/core/report/ReportManager.java | 31 +++----- .../mineplex/core/report/ReportProfile.java | 44 ++++++----- .../mineplex/core/report/ReportResult.java | 50 +++++++++---- .../report/command/ReportCloseCommand.java | 13 +++- .../core/report/command/ReportCommand.java | 4 +- ...tButton.java => ReportCategoryButton.java} | 12 +-- ...eportPage.java => ReportCategoryPage.java} | 9 +-- .../core/report/ui/ReportResultButton.java | 48 ++++++++++++ .../core/report/ui/ReportResultPage.java | 75 +++++++++++++++++++ 9 files changed, 220 insertions(+), 66 deletions(-) rename Plugins/Mineplex.Core/src/mineplex/core/report/ui/{ReportButton.java => ReportCategoryButton.java} (57%) rename Plugins/Mineplex.Core/src/mineplex/core/report/ui/{ReportPage.java => ReportCategoryPage.java} (85%) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultButton.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultPage.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 121f23f3c..6858e4140 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -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; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportProfile.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportProfile.java index 1f70102ce..c3056dec8 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportProfile.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportProfile.java @@ -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; } } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java index fc2f3abcf..34af4972f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java @@ -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; } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java index f6da4439a..4bd99a4e9 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCloseCommand.java @@ -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 { 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.")); + } } } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java index 0b8faef59..b4a0f22f3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportCommand.java @@ -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 if (reportedPlayer != null) { - new ReportPage(Plugin, player, reportedPlayer, reason).openInventory(); + new ReportCategoryPage(Plugin, player, reportedPlayer, reason).openInventory(); } else { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportButton.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryButton.java similarity index 57% rename from Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportButton.java rename to Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryButton.java index c3f7d2e0e..e3d8bc9a7 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryButton.java @@ -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); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryPage.java similarity index 85% rename from Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java rename to Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryPage.java index e72f481a8..705dc2d38 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryPage.java @@ -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 CATEGORY_SLOTS = Collections.unmodifiableMap(new HashMap() {{ - 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 entry : CATEGORY_SLOTS.entrySet()) { Category category = entry.getValue(); - setItem(entry.getKey(), new ReportButton(this, category)); + setItem(entry.getKey(), new ReportCategoryButton(this, category)); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultButton.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultButton.java new file mode 100644 index 000000000..6d9917d91 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultButton.java @@ -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 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); + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultPage.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultPage.java new file mode 100644 index 000000000..2f0c264cf --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultPage.java @@ -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); + } +} From 3c419b32177806bcdcffad73bdbb9b84eaadf4e6 Mon Sep 17 00:00:00 2001 From: Keir Date: Thu, 12 Nov 2015 00:24:31 +0000 Subject: [PATCH 35/39] Small fixes from last commit. --- .../mineplex/core/report/ui/ReportResultButton.java | 3 ++- .../src/mineplex/core/report/ui/ReportResultPage.java | 10 +++++----- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultButton.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultButton.java index 6d9917d91..4a28efe14 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultButton.java @@ -28,7 +28,7 @@ public class ReportResultButton extends SimpleGuiItem @Override public void setup() { - // replace all occurances of "%suspect%" in the lore with the actual name + // replace all occurrences of "%suspect%" in the lore with the actual name ItemMeta itemMeta = getItemMeta(); List lore = itemMeta.getLore(); @@ -37,6 +37,7 @@ public class ReportResultButton extends SimpleGuiItem lore.set(i, lore.get(i).replace("%suspect%", _reportResultPage.getPlayer().getName())); } + itemMeta.setLore(lore); setItemMeta(itemMeta); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultPage.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultPage.java index 2f0c264cf..176445f96 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportResultPage.java @@ -21,21 +21,21 @@ import mineplex.core.report.ReportResult; public class ReportResultPage extends SimpleGui { private static final ItemStack ITEM_ACCEPT = new ItemBuilder(Material.WOOL) - .setColor(Color.GREEN) + .setData(DyeColor.GREEN.getData()) .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) + .setData(DyeColor.YELLOW.getData()) .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.") + .setData(DyeColor.RED.getData()) + .setTitle(C.cRed + "Flag Abuse") + .addLore("The reporter(s) were abusing the report system.") .build(); private ReportManager _reportManager; From a6d3ba10c20cd880330fc5beecbd850a2b37222d Mon Sep 17 00:00:00 2001 From: Keir Date: Fri, 13 Nov 2015 01:23:33 +0000 Subject: [PATCH 36/39] Show the handler of the report a message every 10 seconds whilst they are handling a report. Any part of the message is clickable and when clicked shows the close report GUI. Jazz-up messages sent to players. Rename Category to ReportCategory. --- .../src/mineplex/core/report/Report.java | 21 ++--- .../{Category.java => ReportCategory.java} | 12 +-- .../core/report/ReportHandlerMessageTask.java | 71 ++++++++++++++++ .../mineplex/core/report/ReportManager.java | 80 +++++++++++++------ .../core/report/ReportRepository.java | 2 +- .../command/ReportHandlerNotification.java | 43 ++++++++++ .../command/ReportNotificationCallback.java | 33 +++++++- .../core/report/ui/ReportCategoryButton.java | 10 +-- .../core/report/ui/ReportCategoryPage.java | 14 ++-- 9 files changed, 228 insertions(+), 58 deletions(-) rename Plugins/Mineplex.Core/src/mineplex/core/report/{Category.java => ReportCategory.java} (80%) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/ReportHandlerMessageTask.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandlerNotification.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java b/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java index bfc4b3606..f96d7f0d5 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/Report.java @@ -1,8 +1,8 @@ package mineplex.core.report; -import java.util.HashSet; +import java.util.HashMap; +import java.util.Map; import java.util.Set; -import java.util.UUID; import mineplex.serverdata.data.Data; @@ -18,24 +18,25 @@ public class Report implements Data private String _playerName; public String getPlayerName() { return _playerName; } - // Set of account ids of players who contributed to reporting this player - private Set _reporters; - public Set getReporters() { return _reporters; } - public void addReporter(String reporter) { _reporters.add(reporter); } + // Set of player names and the reason they reported this player + private Map _reportReasons; + public Map getReportReasons() { return _reportReasons; } + public Set getReporters() { return _reportReasons.keySet(); } + public void addReporter(String reporter, String reason) { _reportReasons.put(reporter, reason); } private String _handler = null; public void setHandler(String handler) { _handler = handler; } public String getHandler() { return _handler; } - private Category _category; - public Category getCategory() { return _category; } + private ReportCategory _category; + public ReportCategory getCategory() { return _category; } - public Report(int reportId, String playerName, String serverName, Category category) + public Report(int reportId, String playerName, String serverName, ReportCategory category) { _reportId = reportId; _playerName = playerName; _serverName = serverName; - _reporters = new HashSet(); + _reportReasons = new HashMap<>(); _category = category; } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportCategory.java similarity index 80% rename from Plugins/Mineplex.Core/src/mineplex/core/report/Category.java rename to Plugins/Mineplex.Core/src/mineplex/core/report/ReportCategory.java index 734d7de81..ca9970e41 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/Category.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportCategory.java @@ -11,7 +11,7 @@ import mineplex.core.common.util.C; * Contains all the reasons a player can be reported for. * @author iKeirNez */ -public enum Category +public enum ReportCategory { // descriptions borrowed from PunishPage @@ -23,7 +23,7 @@ public enum Category private String _title; private List _lore; - Category(int id, Material displayMaterial, String title, String... lore) + ReportCategory(int id, Material displayMaterial, String title, String... lore) { this._id = id; this._displayMaterial = displayMaterial; @@ -46,19 +46,19 @@ public enum Category return _displayMaterial; } - public String getItemDisplayName() + public String getTitle() { return _title; } - public List getItemLore() + public List getDescription() { return _lore; } - public static Category fromId(int id) + public static ReportCategory fromId(int id) { - for (Category category : values()) + for (ReportCategory category : values()) { if (category.getId() == id) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportHandlerMessageTask.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportHandlerMessageTask.java new file mode 100644 index 000000000..60e8aecad --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportHandlerMessageTask.java @@ -0,0 +1,71 @@ +package mineplex.core.report; + +import java.util.Map; + +import org.bukkit.scheduler.BukkitRunnable; + +import mineplex.core.common.jsonchat.JsonMessage; +import mineplex.core.common.util.C; +import mineplex.core.report.command.ReportHandlerNotification; +import org.apache.commons.lang3.StringUtils; + +/** + * Displays a message containing up-to-date details of a report to it's handler. + * @author iKeirNez + */ +public class ReportHandlerMessageTask extends BukkitRunnable +{ + private static final String BORDER = C.cAqua + "------------------------------------"; + + private ReportManager _reportManager; + private Report _report; + + public ReportHandlerMessageTask(ReportManager reportManager, Report report) + { + _reportManager = reportManager; + _report = report; + } + + @Override + public void run() + { + int reportId = _report.getReportId(); + + if (_reportManager.isActiveReport(reportId)) + { + Report report = _reportManager.getReport(reportId); + JsonMessage jsonMessage = new JsonMessage(BORDER + + "\n" + + C.cAqua + "Reviewing Ticket " + C.cGold + "#" + reportId + + "\n\n" + + StringUtils.join(getReportReasons(), "\n") + + "\n\n" + + "Suspect: " + _report.getPlayerName() + + "\n" + + BORDER); + // TODO make clickable + + new ReportHandlerNotification(report, jsonMessage).publish(); + } + else + { + // report has been closed, so this task should be cancelled + cancel(); + } + } + + public String[] getReportReasons() + { + Map reportReasons = _report.getReportReasons(); + String[] output = new String[reportReasons.size()]; + int count = 0; + + for (Map.Entry entry : reportReasons.entrySet()) + { + // triple backslashes so this translates to valid JSON + output[count++] = "\\\"" + entry.getValue() + "\\\" - " + entry.getKey(); + } + + return output; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 6858e4140..fcd3bbae2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -10,8 +10,10 @@ import mineplex.core.common.Rank; import mineplex.core.common.jsonchat.ClickEvent; import mineplex.core.common.jsonchat.JsonMessage; import mineplex.core.common.util.C; +import mineplex.core.common.util.F; import mineplex.core.portal.Portal; import mineplex.core.preferences.PreferencesManager; +import mineplex.core.report.command.ReportHandlerNotification; import mineplex.core.report.command.ReportNotificationCallback; import mineplex.core.report.command.ReportNotification; import mineplex.serverdata.Region; @@ -36,6 +38,9 @@ import redis.clients.jedis.exceptions.JedisConnectionException; */ public class ReportManager { + private static final String NAME = "Report"; + + private JavaPlugin _javaPlugin; private PreferencesManager _preferencesManager; private String _serverName; @@ -50,21 +55,24 @@ public class ReportManager { // A mapping of PlayerName(String) to the ReportId(Integer) for all active reports on this server. private Map _activeReports; - public ReportManager(JavaPlugin plugin, PreferencesManager preferencesManager, String serverName) + public ReportManager(JavaPlugin javaPlugin, PreferencesManager preferencesManager, String serverName) { + _javaPlugin = javaPlugin; _preferencesManager = preferencesManager; _serverName = serverName; _reportRepository = new RedisDataRepository(Region.ALL, Report.class, "reports"); _reportProfiles = new RedisDataRepository(Region.ALL, ReportProfile.class, "reportprofiles"); _activeReports = new HashMap(); - _reportSqlRepository = new ReportRepository(plugin); + _reportSqlRepository = new ReportRepository(javaPlugin); _reportSqlRepository.initialize(); - ServerCommandManager.getInstance().registerCommandType("ReportNotification", ReportNotification.class, new ReportNotificationCallback(this)); + ReportNotificationCallback callback = new ReportNotificationCallback(this); + ServerCommandManager.getInstance().registerCommandType("ReportNotification", ReportNotification.class, callback); + ServerCommandManager.getInstance().registerCommandType("ReportHandlerNotification", ReportHandlerNotification.class, callback); } public void closeReport(int reportId, Player reportCloser, String reason, - ReportResult result) + ReportResult result) { if (isActiveReport(reportId)) { @@ -89,8 +97,9 @@ public class ReportManager { if (reportCloser != null) { // Notify staff that the report was closed. - sendReportNotification(String.format("[Report %d] %s closed this report for: %s (%s).", reportId, - reportCloser.getName(), reason, result.toDisplayMessage())); + sendReportNotification( + F.main(getReportPrefix(reportId), String.format("%s closed the report for: %s (%s).", + reportCloser.getName(), reason, result.toDisplayMessage() + C.mBody))); CommandCenter.Instance.OnPlayerCommandPreprocess( new PlayerCommandPreprocessEvent(reportCloser, "/punish " + playerName + " " + reason)); @@ -105,16 +114,17 @@ public class ReportManager { Report report = getReport(reportId); if (report.getHandler() != null) { - reportHandler.sendMessage(C.cRed + "Someone is already handling this report."); + reportHandler.sendMessage(F.main(getReportPrefix(reportId), String.format("%s is already handling this report.", report.getHandler()))); } else { String handlerName = reportHandler.getName(); report.setHandler(handlerName); + _reportRepository.addElement(report); // update existing value in Redis - sendReportNotification(String.format("[Report %d] %s is handling this report.", reportId, handlerName)); + sendReportNotification(F.main(getReportPrefix(reportId), String.format("%s is handling this report.", handlerName))); Portal.transferPlayer(reportHandler.getName(), report.getServerName()); - // TODO: Send display message to handler when they arrive on the server - // with info about the case/report. + // Show user details of the report every x seconds + new ReportHandlerMessageTask(this, report).runTaskTimer(_javaPlugin, 20L * 10, 20L * 10); int handlerId = getPlayerAccount(reportHandler).getAccountId(); _reportSqlRepository.logReportHandling(reportId, handlerId); // Log handling into sql database @@ -122,7 +132,7 @@ public class ReportManager { } } - public Report reportPlayer(Player reporter, Player reportedPlayer, Category category, String reason) + public Report reportPlayer(Player reporter, Player reportedPlayer, ReportCategory category, String reason) { int reporterId = getPlayerAccount(reporter).getAccountId(); ReportProfile reportProfile = getReportProfile(String.valueOf(reporterId)); @@ -134,33 +144,46 @@ public class ReportManager { if (reportId != -1 && report.getCategory() == category) { - report.addReporter(reporter.getName()); + report.addReporter(reporter.getName(), reason); } else { reportId = generateReportId(); report = new Report(reportId, reportedPlayer.getName(), _serverName, category); - report.addReporter(reporter.getName()); + report.addReporter(reporter.getName(), reason); _activeReports.put(reportedPlayer.getName().toLowerCase(), report.getReportId()); - _reportRepository.addElement(report); } + _reportRepository.addElement(report); // add (or update) the report to Redis + // only start notifying staff when if (report.getReporters().size() >= 1) { - // [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); + String prefix = getReportPrefix(reportId); - JsonMessage clickableMessage = new JsonMessage("Click ") - .extra("here") - .bold() - .click(ClickEvent.RUN_COMMAND, "/reporthandle " + reportId) - .add(" to respond to ticket."); + // Report #2 > iKeirNez - Flying around in arcade game (Hacking) + // Report #2 > Reported by Chiss. + // Report #2 > 5 total reporter(s). + JsonMessage message = new JsonMessage(F.main(prefix, String.format("%s - %s (%s)", + C.cGoldB + report.getPlayerName() + C.mBody, + reason, C.cGoldB + report.getCategory().getTitle() + C.mBody)) + + "\n" + + F.main(prefix, String.format("Reported by %s.", reporter.getName())) + + "\n" + + F.main(prefix, String.format("%d total reporter(s).", report.getReporters().size()))); - sendReportNotification(message); - sendReportNotification(clickableMessage); + 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.")) + .click(ClickEvent.RUN_COMMAND, "/reporthandle " + reportId); + + sendReportNotification(message); + } + else + { + // TODO send to handler? + } } _reportSqlRepository.logReportSending(report.getReportId(), reporterId, category, reason); @@ -176,7 +199,7 @@ public class ReportManager { { int reportId = getActiveReport(player.getName()); this.closeReport(reportId, null, "Player Quit", ReportResult.UNDETERMINED); - sendReportNotification(String.format("[Report %d] %s has left the game.", reportId, player.getName())); + sendReportNotification(F.main(getReportPrefix(reportId), String.format("%s has left the game.", player.getName()))); } } @@ -325,4 +348,9 @@ public class ReportManager { return false; } + + private static String getReportPrefix(int reportId) + { + return NAME + " #" + reportId; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java index 709a911ce..889c1f2ac 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportRepository.java @@ -64,7 +64,7 @@ This will be used to determine if staff are handling }), "Error logging report " + reportId + " as being handled by user " + handlerId + "."); } - public void logReportSending(final int reportId, final int reporterId, final Category category, final String reason) + public void logReportSending(final int reportId, final int reporterId, final ReportCategory category, final String reason) { handleDatabaseCall(new DatabaseRunnable(new Runnable() { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandlerNotification.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandlerNotification.java new file mode 100644 index 000000000..585d85341 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportHandlerNotification.java @@ -0,0 +1,43 @@ +package mineplex.core.report.command; + +import mineplex.core.common.jsonchat.JsonMessage; +import mineplex.core.report.Report; + +/** + * A message regarding a report which is sent only to the player handling the report. + * @author iKeirNez + */ +public class ReportHandlerNotification extends ReportNotification +{ + private int _reportId; + private String _server; // the server the incident took place on + + public ReportHandlerNotification(Report report, String notification) + { + this(report, new JsonMessage(notification)); + } + + public ReportHandlerNotification(Report report, JsonMessage notification) + { + super(notification); + + if (report.getHandler() == null) + { + throw new IllegalStateException("Report has no handler."); + } + + _reportId = report.getReportId(); + _server = report.getServerName(); + setTargetServers(_server); + } + + public int getReportId() + { + return _reportId; + } + + public String getServer() + { + return _server; + } +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotificationCallback.java b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotificationCallback.java index 10cdf0e33..ca4e25bbb 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotificationCallback.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/command/ReportNotificationCallback.java @@ -1,9 +1,11 @@ package mineplex.core.report.command; +import org.bukkit.Bukkit; import org.bukkit.Server; import org.bukkit.entity.Player; import mineplex.core.common.util.UtilServer; +import mineplex.core.report.Report; import mineplex.core.report.ReportManager; import mineplex.serverdata.commands.CommandCallback; import mineplex.serverdata.commands.ServerCommand; @@ -24,7 +26,27 @@ public class ReportNotificationCallback implements CommandCallback @Override public void run(ServerCommand command) { - if (command instanceof ReportNotification) + if (command instanceof ReportHandlerNotification) + { + ReportHandlerNotification reportNotification = (ReportHandlerNotification) command; + Report report = _reportManager.getReport(reportNotification.getReportId()); + + if (report != null) + { + String handlerName = report.getHandler(); + + if (handlerName != null) + { + Player handler = Bukkit.getPlayerExact(handlerName); + + if (handler != null) + { + sendRawMessage(handler, reportNotification.getNotification()); + } + } + } + } + else if (command instanceof ReportNotification) { ReportNotification reportNotification = (ReportNotification) command; @@ -33,10 +55,15 @@ public class ReportNotificationCallback implements CommandCallback { if (_reportManager.hasReportNotifications(player)) { - Server server = UtilServer.getServer(); - server.dispatchCommand(server.getConsoleSender(), "tellraw " + player.getName() + " " + reportNotification.getNotification()); + sendRawMessage(player, reportNotification.getNotification()); } } } } + + private void sendRawMessage(Player player, String rawMessage) + { + Server server = UtilServer.getServer(); + server.dispatchCommand(server.getConsoleSender(), "tellraw " + player.getName() + " " + rawMessage); + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryButton.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryButton.java index e3d8bc9a7..1067fc08f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryButton.java @@ -4,7 +4,7 @@ import org.bukkit.event.inventory.ClickType; import org.bukkit.inventory.meta.ItemMeta; import mineplex.core.gui.SimpleGuiItem; -import mineplex.core.report.Category; +import mineplex.core.report.ReportCategory; /** * Represents a clickable button in a {@link ReportCategoryPage} which determines the type of infraction a player has committed. @@ -13,14 +13,14 @@ import mineplex.core.report.Category; public class ReportCategoryButton extends SimpleGuiItem { private ReportCategoryPage _reportCategoryPage; - private Category _category; + private ReportCategory _category; - public ReportCategoryButton(ReportCategoryPage reportCategoryPage, Category category) { + public ReportCategoryButton(ReportCategoryPage reportCategoryPage, ReportCategory category) { super(category.getItemMaterial(), 1, (short) 0); ItemMeta itemMeta = getItemMeta(); - itemMeta.setDisplayName(category.getItemDisplayName()); - itemMeta.setLore(category.getItemLore()); + itemMeta.setDisplayName(category.getTitle()); + itemMeta.setLore(category.getDescription()); setItemMeta(itemMeta); this._reportCategoryPage = reportCategoryPage; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryPage.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryPage.java index 705dc2d38..fe3bdf26d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryPage.java @@ -9,7 +9,7 @@ import org.bukkit.event.HandlerList; import mineplex.core.common.util.C; import mineplex.core.gui.SimpleGui; -import mineplex.core.report.Category; +import mineplex.core.report.ReportCategory; import mineplex.core.report.Report; import mineplex.core.report.ReportPlugin; @@ -19,11 +19,11 @@ import mineplex.core.report.ReportPlugin; */ public class ReportCategoryPage extends SimpleGui { - private static final Map CATEGORY_SLOTS = Collections.unmodifiableMap(new HashMap() + private static final Map CATEGORY_SLOTS = Collections.unmodifiableMap(new HashMap() {{ int rowStartSlot = 9 * 2; // end of row 2 - put(rowStartSlot + 3, Category.HACKING); - put(rowStartSlot + 5, Category.CHAT_ABUSE); + put(rowStartSlot + 3, ReportCategory.HACKING); + put(rowStartSlot + 5, ReportCategory.CHAT_ABUSE); }}); private ReportPlugin _reportPlugin; @@ -45,14 +45,14 @@ public class ReportCategoryPage extends SimpleGui private void buildPage() { - for (Map.Entry entry : CATEGORY_SLOTS.entrySet()) + for (Map.Entry entry : CATEGORY_SLOTS.entrySet()) { - Category category = entry.getValue(); + ReportCategory category = entry.getValue(); setItem(entry.getKey(), new ReportCategoryButton(this, category)); } } - public void addReport(Category category) + public void addReport(ReportCategory category) { Report report = _reportPlugin.getReportManager().reportPlayer(_reportee, _offender, category, _reason); _reportee.closeInventory(); From bf81c26874770d35130a6515c5b4f172d2399a94 Mon Sep 17 00:00:00 2001 From: Keir Date: Fri, 13 Nov 2015 01:27:34 +0000 Subject: [PATCH 37/39] Only notify staff when a report count reaches a certain amount (3 for hacking, 1 for chat abuse). --- .../mineplex/core/report/ReportCategory.java | 21 ++++++++++++------- .../mineplex/core/report/ReportManager.java | 2 +- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportCategory.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportCategory.java index ca9970e41..1aad207a1 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportCategory.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportCategory.java @@ -15,20 +15,22 @@ public enum ReportCategory { // descriptions borrowed from PunishPage - HACKING(0, Material.IRON_SWORD, C.cRedB + "Hacking", "X-ray, Forcefield, Speed, Fly etc"), - CHAT_ABUSE(1, Material.BOOK_AND_QUILL, C.cDBlueB + "Chat Abuse", "Verbal Abuse, Spam, Harassment, Trolling, etc"); + HACKING(0, 3, Material.IRON_SWORD, C.cRedB + "Hacking", "X-ray, Forcefield, Speed, Fly etc"), + CHAT_ABUSE(1, 1, Material.BOOK_AND_QUILL, C.cDBlueB + "Chat Abuse", "Verbal Abuse, Spam, Harassment, Trolling, etc"); private int _id; + private int _notifyThreshold; private Material _displayMaterial; private String _title; private List _lore; - ReportCategory(int id, Material displayMaterial, String title, String... lore) + ReportCategory(int id, int notifyThreshold, Material displayMaterial, String title, String... lore) { - this._id = id; - this._displayMaterial = displayMaterial; - this._title = title; - this._lore = new ArrayList<>(); + _id = id; + _notifyThreshold = notifyThreshold; + _displayMaterial = displayMaterial; + _title = title; + _lore = new ArrayList<>(); // prefix are lore lines for (String loreLine : lore) { @@ -41,6 +43,11 @@ public enum ReportCategory return _id; } + public int getNotifyThreshold() + { + return _notifyThreshold; + } + public Material getItemMaterial() { return _displayMaterial; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index fcd3bbae2..6f0438d89 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -157,7 +157,7 @@ public class ReportManager { _reportRepository.addElement(report); // add (or update) the report to Redis // only start notifying staff when - if (report.getReporters().size() >= 1) + if (report.getReporters().size() >= category.getNotifyThreshold()) { String prefix = getReportPrefix(reportId); From a1713ca8662209169862c5f127f8adf6a5971329 Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 17 Nov 2015 14:21:05 +0000 Subject: [PATCH 38/39] If someone is currently handling a report, re-direct all messages relating to that report to them. --- .../mineplex/core/report/ReportManager.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 6f0438d89..321ffdbbd 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -182,7 +182,7 @@ public class ReportManager { } else { - // TODO send to handler? + sendReportHandlerNotification(report, message); } } @@ -284,6 +284,7 @@ public class ReportManager { /** * Send a network-wide {@link ReportNotification} to all online staff. + * * @param message - the report notification message to send. */ public void sendReportNotification(JsonMessage message) @@ -294,6 +295,7 @@ public class ReportManager { /** * Send a network-wide {@link ReportNotification} to all online staff. + * * @param message - the report notification message to send. */ public void sendReportNotification(String message) @@ -302,6 +304,30 @@ public class ReportManager { reportNotification.publish(); } + /** + * Send to the handler of a {@link Report}, regardless of whether or not the handler is currently on this server instance. + * + * @param report the report of which a message should be sent ot it's handler + * @param jsonMessage the report notification message to send + */ + public void sendReportHandlerNotification(Report report, JsonMessage jsonMessage) + { + ReportHandlerNotification reportNotification = new ReportHandlerNotification(report, jsonMessage); + reportNotification.publish(); + } + + /** + * Send to the handler of a {@link Report}, regardless of whether or not the handler is currently on this server instance. + * + * @param report the report of which a message should be sent ot it's handler + * @param message the report notification message to send + */ + public void sendReportHandlerNotification(Report report, String message) + { + ReportHandlerNotification reportNotification = new ReportHandlerNotification(report, 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 From 6ee40aa1ce21306fa210ef27665b159461bb1fc8 Mon Sep 17 00:00:00 2001 From: Keir Date: Tue, 17 Nov 2015 15:08:35 +0000 Subject: [PATCH 39/39] No longer close reports when the player quits, instead alert the handler and alert again when (and if) the player re-joins if the report is still active. --- .../mineplex/core/report/ReportManager.java | 48 +++++++++++++------ .../mineplex/core/report/ReportPlugin.java | 7 +++ .../mineplex/core/report/ReportResult.java | 3 +- 3 files changed, 42 insertions(+), 16 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index 321ffdbbd..bbb32b7f2 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -97,7 +97,7 @@ public class ReportManager { if (reportCloser != null) { // Notify staff that the report was closed. - sendReportNotification( + sendStaffNotification( F.main(getReportPrefix(reportId), String.format("%s closed the report for: %s (%s).", reportCloser.getName(), reason, result.toDisplayMessage() + C.mBody))); @@ -120,7 +120,7 @@ public class ReportManager { report.setHandler(handlerName); _reportRepository.addElement(report); // update existing value in Redis - sendReportNotification(F.main(getReportPrefix(reportId), String.format("%s is handling this report.", handlerName))); + sendStaffNotification(F.main(getReportPrefix(reportId), String.format("%s is handling this report.", handlerName))); Portal.transferPlayer(reportHandler.getName(), report.getServerName()); // Show user details of the report every x seconds @@ -178,11 +178,11 @@ public class ReportManager { message = message.extra("\n" + F.main(getReportPrefix(reportId), "Click to handle this ticket.")) .click(ClickEvent.RUN_COMMAND, "/reporthandle " + reportId); - sendReportNotification(message); + sendStaffNotification(message); } else { - sendReportHandlerNotification(report, message); + sendHandlerNotification(report, message); } } @@ -193,13 +193,23 @@ public class ReportManager { return null; } + public void onPlayerJoin(Player player) + { + if (hasActiveReport(player)) + { + int reportId = getActiveReport(player.getName()); + Report report = getReport(reportId); + sendHandlerNotification(report, F.main(getReportPrefix(reportId), String.format("%s has re-joined the game.", player.getName()))); + } + } + public void onPlayerQuit(Player player) { if (hasActiveReport(player)) { int reportId = getActiveReport(player.getName()); - this.closeReport(reportId, null, "Player Quit", ReportResult.UNDETERMINED); - sendReportNotification(F.main(getReportPrefix(reportId), String.format("%s has left the game.", player.getName()))); + Report report = getReport(reportId); + sendHandlerNotification(report, F.main(getReportPrefix(reportId), String.format("%s has left the game.", player.getName()))); } } @@ -287,7 +297,7 @@ public class ReportManager { * * @param message - the report notification message to send. */ - public void sendReportNotification(JsonMessage message) + public void sendStaffNotification(JsonMessage message) { ReportNotification reportNotification = new ReportNotification(message); reportNotification.publish(); @@ -298,7 +308,7 @@ public class ReportManager { * * @param message - the report notification message to send. */ - public void sendReportNotification(String message) + public void sendStaffNotification(String message) { ReportNotification reportNotification = new ReportNotification(message); reportNotification.publish(); @@ -306,26 +316,35 @@ public class ReportManager { /** * Send to the handler of a {@link Report}, regardless of whether or not the handler is currently on this server instance. + * If there is no handler for a report, it will be sent to all staff instead. * * @param report the report of which a message should be sent ot it's handler * @param jsonMessage the report notification message to send */ - public void sendReportHandlerNotification(Report report, JsonMessage jsonMessage) + public void sendHandlerNotification(Report report, JsonMessage jsonMessage) { - ReportHandlerNotification reportNotification = new ReportHandlerNotification(report, jsonMessage); - reportNotification.publish(); + if (report.getHandler() != null) + { + ReportHandlerNotification reportHandlerNotification = new ReportHandlerNotification(report, jsonMessage); + reportHandlerNotification.publish(); + } + else + { + // If there is no report handler, send it to all staff + sendStaffNotification(jsonMessage); + } } /** * Send to the handler of a {@link Report}, regardless of whether or not the handler is currently on this server instance. + * If there is no handler for a report, it will be sent to all staff instead. * * @param report the report of which a message should be sent ot it's handler * @param message the report notification message to send */ - public void sendReportHandlerNotification(Report report, String message) + public void sendHandlerNotification(Report report, String message) { - ReportHandlerNotification reportNotification = new ReportHandlerNotification(report, message); - reportNotification.publish(); + sendHandlerNotification(report, new JsonMessage(message)); } /** @@ -343,6 +362,7 @@ public class ReportManager { return -1; } + // TODO this and related methods only function on the server where the report was created public boolean hasActiveReport(Player player) { return getActiveReport(player.getName()) != -1; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java index 47481b682..ea0d0d54f 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportPlugin.java @@ -6,6 +6,7 @@ import mineplex.core.report.command.ReportCommand; import mineplex.core.report.command.ReportHandleCommand; import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; @@ -34,6 +35,12 @@ public class ReportPlugin extends MiniPlugin //AddCommand(new ReportDebugCommand(this)); } + @EventHandler + public void onPlayerJoin(PlayerJoinEvent e) + { + _reportManager.onPlayerJoin(e.getPlayer()); + } + @EventHandler public void onPlayerQuit(PlayerQuitEvent e) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java index 34af4972f..c5ba5df0c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportResult.java @@ -6,8 +6,7 @@ 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"), - UNDETERMINED(ChatColor.LIGHT_PURPLE, null, "Undetermined"); + ABUSIVE(ChatColor.RED, "Mark Abusive Report", "Abusive Report"); private ChatColor _color; private String _actionMessage;