diff --git a/src/main/java/cn/citycraft/ProtectItem/commands/CommandBan.java b/src/main/java/cn/citycraft/ProtectItem/commands/CommandBan.java index 2d36d6b..fb1eb02 100644 --- a/src/main/java/cn/citycraft/ProtectItem/commands/CommandBan.java +++ b/src/main/java/cn/citycraft/ProtectItem/commands/CommandBan.java @@ -8,6 +8,7 @@ import org.bukkit.inventory.ItemStack; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.ProtectItem.ProtectItem; +import cn.citycraft.ProtectItem.utils.ActionType; public class CommandBan extends BaseCommand { ProtectItem plugin; @@ -16,6 +17,7 @@ public class CommandBan extends BaseCommand { super("ban"); this.plugin = main; setOnlyPlayerExecutable(); + setPermission("pi.ban"); setDescription("§c封禁手持物品"); setPossibleArguments("<封禁类型>"); } @@ -24,7 +26,22 @@ public class CommandBan extends BaseCommand { public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { final Player p = (Player) sender; final ItemStack item = p.getItemInHand(); - plugin.getItemManager().addbanItem(item); + final String itemname = plugin.getItemManager().getItemName(item); + switch (args.length) { + case 0: + plugin.getItemManager().banItem(item); + p.sendMessage("当前物品 " + itemname + " 已被禁封!"); + return; + case 1: + + try { + final ActionType action = Enum.valueOf(ActionType.class, args[0]); + plugin.getItemManager().banItem(item, action); + p.sendMessage("当前物品 " + itemname + " 已被禁封 操作" + action.toString() + "!"); + } catch (final Exception e) { + p.sendMessage("未知的操作类型" + args[0] + "!"); + } + } } } diff --git a/src/main/java/cn/citycraft/ProtectItem/commands/CommandUnban.java b/src/main/java/cn/citycraft/ProtectItem/commands/CommandUnban.java index e7300ad..f9afb75 100644 --- a/src/main/java/cn/citycraft/ProtectItem/commands/CommandUnban.java +++ b/src/main/java/cn/citycraft/ProtectItem/commands/CommandUnban.java @@ -3,9 +3,12 @@ package cn.citycraft.ProtectItem.commands; import org.bukkit.command.Command; import org.bukkit.command.CommandException; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import cn.citycraft.PluginHelper.commands.BaseCommand; import cn.citycraft.ProtectItem.ProtectItem; +import cn.citycraft.ProtectItem.utils.ActionType; public class CommandUnban extends BaseCommand { ProtectItem plugin; @@ -14,13 +17,31 @@ public class CommandUnban extends BaseCommand { super("unban"); this.plugin = main; setOnlyPlayerExecutable(); + setPermission("pi.unban"); setDescription("§a解禁手持物品"); setPossibleArguments("<解禁类型>"); } @Override public void execute(final CommandSender sender, final Command command, final String label, final String[] args) throws CommandException { + final Player p = (Player) sender; + final ItemStack item = p.getItemInHand(); + final String itemname = plugin.getItemManager().getItemName(item); + switch (args.length) { + case 0: + plugin.getItemManager().unBanItem(item); + p.sendMessage("当前物品 " + itemname + " 已被解禁!"); + return; + case 1: + try { + final ActionType action = Enum.valueOf(ActionType.class, args[0]); + plugin.getItemManager().unBanItem(item, action); + p.sendMessage("当前物品 " + itemname + " 已被解禁 操作" + action.toString() + "!"); + } catch (final Exception e) { + p.sendMessage("未知的操作类型" + args[0] + "!"); + } + } } } diff --git a/src/main/java/cn/citycraft/ProtectItem/utils/ItemManager.java b/src/main/java/cn/citycraft/ProtectItem/utils/ItemManager.java index 569948b..c84dbd5 100644 --- a/src/main/java/cn/citycraft/ProtectItem/utils/ItemManager.java +++ b/src/main/java/cn/citycraft/ProtectItem/utils/ItemManager.java @@ -22,11 +22,11 @@ public class ItemManager { itemlist = (HashMap>) itemconfig.get("banitems"); } - public void addbanItem(final ItemStack item) { - addbanItem(item, null); + public void banItem(final ItemStack item) { + banItem(item, new ActionType[] {}); } - public void addbanItem(final ItemStack item, final ActionType[] action) { + public void banItem(final ItemStack item, final ActionType... action) { final String itemname = getItemName(item); if (itemlist.containsKey(itemname)) { final List actlist = itemlist.get(itemname); @@ -35,15 +35,20 @@ public class ItemManager { actlist.add(actionType); } } + itemlist.put(itemname, actlist); } else { itemlist.put(itemname, Arrays.asList(action)); } itemconfig.set("banitems", itemlist); + itemconfig.save(); } public boolean canAction(final ItemStack i, final ActionType action) { final String itemname = getItemName(i); final List actlist = itemlist.get(itemname); + if (actlist == null) { + return true; + } final Boolean result = actlist.contains(action); return result; } @@ -56,7 +61,22 @@ public class ItemManager { public boolean hasActionPerm(final Player p, final ItemStack i, final ActionType action) { final String itemname = getItemName(i); - final String perm = String.format("%s.%s", itemname, action.toString().toLowerCase()); - return p.hasPermission(itemname + ".*") ? true : p.hasPermission(perm); + final String perm = String.format("pi.%s.%s", itemname, action.toString().toLowerCase()); + return p.hasPermission("pi" + itemname + ".*") ? true : p.hasPermission(perm); } + + public void unBanItem(final ItemStack item) { + final String itemname = getItemName(item); + itemlist.remove(itemname); + } + + public void unBanItem(final ItemStack item, final ActionType... action) { + final String itemname = getItemName(item); + if (itemlist.containsKey(itemname)) { + final List actlist = itemlist.get(itemname); + actlist.removeAll(Arrays.asList(action)); + itemlist.put(itemname, actlist); + } + } + } diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fda7e8b..a616950 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,7 +7,13 @@ website: http://ci.citycraft.cn:8800/jenkins/job/${project.artifactId}/ commands: pishow: description: 物品保护插件 - usage: 使用/pishow 查看物品名称! + usage: 使用/pi 查看物品名称! permissions: pi.bypass: + default: op + pi.reload: + default: op + pi.ban: + default: op + pi.unban: default: op \ No newline at end of file