From 95507a740cbaf36f3fd25a88d8d9acb7d2c2b66b Mon Sep 17 00:00:00 2001 From: Keir Nellyer Date: Fri, 8 Apr 2016 00:33:29 +0100 Subject: [PATCH] Move button specific values from ReportCategory to ReportCategoryButton This is done to separate the code out so that we can add a GLOBAL value to the enum for handling of ABUSIVE reports (these types of reports do not have a specific category). In its current state it's is very closely inter-twined. --- .../mineplex/core/report/ReportCategory.java | 42 ++++++------------ .../mineplex/core/report/ReportManager.java | 2 +- .../core/report/ui/ReportCategoryButton.java | 43 +++++++++++++++---- 3 files changed, 47 insertions(+), 40 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportCategory.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportCategory.java index 800937aed..685eb0f2b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportCategory.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportCategory.java @@ -6,6 +6,7 @@ import java.util.List; import org.bukkit.Material; import mineplex.core.common.util.C; +import org.apache.commons.lang3.StringUtils; /** * Contains the reasons a player can be reported for. @@ -14,28 +15,19 @@ import mineplex.core.common.util.C; public enum ReportCategory { - // descriptions borrowed from PunishPage - 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"); + HACKING(0, 3), + CHAT_ABUSE(1, 1); private int _id; private int _notifyThreshold; - private Material _displayMaterial; - private String _title; - private List _lore; - ReportCategory(int id, int notifyThreshold, Material displayMaterial, String title, String... lore) + private String _name; + + ReportCategory(int id, int notifyThreshold) { _id = id; _notifyThreshold = notifyThreshold; - _displayMaterial = displayMaterial; - _title = title; - _lore = new ArrayList<>(); - - // prefix are lore lines - for (String loreLine : lore) { - _lore.add(C.cGray + loreLine); - } + _name = StringUtils.capitalize(name().toLowerCase().replace(" ", "")); } public int getId() @@ -43,26 +35,16 @@ public enum ReportCategory return _id; } + public String getName() + { + return _name; + } + public int getNotifyThreshold() { return _notifyThreshold; } - public Material getItemMaterial() - { - return _displayMaterial; - } - - public String getTitle() - { - return _title; - } - - public List getDescription() - { - return _lore; - } - public static ReportCategory fromId(int id) { for (ReportCategory category : values()) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java index ba262a713..3d90ad704 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ReportManager.java @@ -211,7 +211,7 @@ public class ReportManager { // Report #2 > 5 total reporter(s). JsonMessage message = new JsonMessage(F.main(prefix, String.format("%s - %s (%s)", C.cGoldB + suspectName + C.mBody, - reason, C.cGoldB + report.getCategory().getTitle() + C.mBody)) + reason, C.cGoldB + report.getCategory().getName() + C.mBody)) + "\n" + F.main(prefix, String.format("Reported by %s.", reporter.getName())) + "\n" 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 1067fc08f..9c4074eb4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/report/ui/ReportCategoryButton.java @@ -1,8 +1,15 @@ package mineplex.core.report.ui; +import java.util.Collections; +import java.util.EnumMap; +import java.util.Map; + +import org.bukkit.Material; import org.bukkit.event.inventory.ClickType; +import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.ItemMeta; +import mineplex.core.common.util.C; import mineplex.core.gui.SimpleGuiItem; import mineplex.core.report.ReportCategory; @@ -12,19 +19,37 @@ import mineplex.core.report.ReportCategory; */ public class ReportCategoryButton extends SimpleGuiItem { + // initialize the display items we use + private static Map ITEM_STACKS = new EnumMap(ReportCategory.class) + {{ + ItemStack hackItem = new ItemStack(Material.IRON_SWORD, 1); + ItemMeta hackItemMeta = hackItem.getItemMeta(); + hackItemMeta.setDisplayName(C.cRedB + "Hacking"); + hackItemMeta.setLore(Collections.singletonList(C.cGray + "X-ray, Forcefield, Speed, Fly etc")); + hackItem.setItemMeta(hackItemMeta); + put(ReportCategory.HACKING, hackItem); + + ItemStack chatAbuseItem = new ItemStack(Material.BOOK_AND_QUILL, 1); + ItemMeta chatAbuseItemMeta = chatAbuseItem.getItemMeta(); + chatAbuseItemMeta.setDisplayName(C.cDBlueB + "Chat Abuse"); + chatAbuseItemMeta.setLore(Collections.singletonList("Verbal Abuse, Spam, Harassment, Trolling, etc")); + chatAbuseItem.setItemMeta(chatAbuseItemMeta); + put(ReportCategory.CHAT_ABUSE, chatAbuseItem); + }}; + private ReportCategoryPage _reportCategoryPage; private ReportCategory _category; - public ReportCategoryButton(ReportCategoryPage reportCategoryPage, ReportCategory category) { - super(category.getItemMaterial(), 1, (short) 0); + public ReportCategoryButton(ReportCategoryPage reportCategoryPage, ReportCategory reportCategory) + { + this(reportCategoryPage, reportCategory, ITEM_STACKS.get(reportCategory)); + } - ItemMeta itemMeta = getItemMeta(); - itemMeta.setDisplayName(category.getTitle()); - itemMeta.setLore(category.getDescription()); - setItemMeta(itemMeta); - - this._reportCategoryPage = reportCategoryPage; - this._category = category; + public ReportCategoryButton(ReportCategoryPage reportCategoryPage, ReportCategory reportCategory, ItemStack itemStack) + { + super(itemStack); + _reportCategoryPage = reportCategoryPage; + _category = reportCategory; } @Override