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.
This commit is contained in:
Keir Nellyer 2016-04-08 00:33:29 +01:00
parent c1354081ea
commit 95507a740c
No known key found for this signature in database
GPG Key ID: A2F398FC8175E3D9
3 changed files with 47 additions and 40 deletions

View File

@ -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<String> _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<String> getDescription()
{
return _lore;
}
public static ReportCategory fromId(int id)
{
for (ReportCategory category : values())

View File

@ -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"

View File

@ -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<ReportCategory, ItemStack> ITEM_STACKS = new EnumMap<ReportCategory, ItemStack>(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