From 29587b93f7eeac34c3127d41a09347cae1ef7c25 Mon Sep 17 00:00:00 2001 From: Keir Date: Sat, 24 Oct 2015 03:41:03 +0100 Subject: [PATCH] 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);