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.
This commit is contained in:
Keir 2015-10-24 03:41:03 +01:00
parent c719d693dd
commit 29587b93f7
7 changed files with 154 additions and 3 deletions

View File

@ -40,6 +40,11 @@ public abstract class CommandBase<PluginType extends MiniPlugin> implements ICom
_aliases = Arrays.asList(aliases);
}
public PluginType getPlugin()
{
return Plugin;
}
public Collection<String> Aliases()
{
return _aliases;

View File

@ -0,0 +1,12 @@
package mineplex.core.report;
/**
* Contains all the reasons a player can be reported for.
*/
public enum Category
{
HACKING,
CHAT_ABUSE
}

View File

@ -15,7 +15,7 @@ public class ReportPlugin extends MiniPlugin
public ReportPlugin(JavaPlugin plugin, String serverName)
{
super("ReportPlugin", plugin);
super("Report", plugin);
instance = plugin;
}

View File

@ -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<ReportPlugin>
if (reportedPlayer != null)
{
ReportManager.getInstance().reportPlayer(player, reportedPlayer, reason);
new ReportPage(getPlugin(), player, reportedPlayer, reason);
}
else
{

View File

@ -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);
}
}

View File

@ -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<Integer, Category> CATEGORY_SLOTS = Collections.unmodifiableMap(new HashMap<Integer, Category>(){{
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<Integer, IButton> _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<Integer, Category> 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();
}
}
}

View File

@ -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);