diff --git a/pom.xml b/pom.xml
index ecbeb2a..f2ee8ec 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
pw.yumc
MenuProtect
- 1.1
+ 1.2
MenuProtect
${project.name}
diff --git a/src/main/java/pw/yumc/MenuProtect/MenuProtect.java b/src/main/java/pw/yumc/MenuProtect/MenuProtect.java
index f7e739d..b414e72 100644
--- a/src/main/java/pw/yumc/MenuProtect/MenuProtect.java
+++ b/src/main/java/pw/yumc/MenuProtect/MenuProtect.java
@@ -1,7 +1,6 @@
package pw.yumc.MenuProtect;
import org.bukkit.Bukkit;
-import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.java.JavaPlugin;
import cn.citycraft.PluginHelper.config.FileConfig;
@@ -9,18 +8,17 @@ import pw.yumc.MenuProtect.listen.ProtectListener;
import pw.yumc.MenuProtect.utils.MarkUtil;
public class MenuProtect extends JavaPlugin {
- FileConfig config;
+ FileConfig config;
- @Override
- public void onEnable() {
- final PluginManager pm = Bukkit.getPluginManager();
- pm.registerEvents(new ProtectListener(this), this);
- this.getLogger().info("菜单物品保护已开启!");
- }
+ @Override
+ public void onEnable() {
+ Bukkit.getPluginManager().registerEvents(new ProtectListener(this), this);
+ this.getLogger().info("菜单物品保护已开启!");
+ }
- @Override
- public void onLoad() {
- config = new FileConfig(this);
- MarkUtil.marks = config.getStringList("MarkList");
- }
+ @Override
+ public void onLoad() {
+ config = new FileConfig(this);
+ MarkUtil.marks = config.getStringList("MarkList");
+ }
}
diff --git a/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java b/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java
index a8ffd09..9907eaa 100644
--- a/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java
+++ b/src/main/java/pw/yumc/MenuProtect/listen/ProtectListener.java
@@ -6,13 +6,8 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
-import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryMoveItemEvent;
-import org.bukkit.event.inventory.InventoryPickupItemEvent;
-import org.bukkit.event.player.PlayerItemHeldEvent;
-import org.bukkit.event.player.PlayerPickupItemEvent;
-import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
@@ -27,14 +22,14 @@ public class ProtectListener implements Listener {
this.plugin = plugin;
}
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ @EventHandler(priority = EventPriority.MONITOR)
public void onInvClose(final InventoryCloseEvent e) {
if (e.getPlayer() instanceof Player) {
handlerPlayerInventory((Player) e.getPlayer());
}
}
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
+ @EventHandler(priority = EventPriority.MONITOR)
public void onInvMove(final InventoryMoveItemEvent e) {
final ItemStack ci = e.getItem();
if (MarkUtil.hasMark(ci)) {
@@ -42,48 +37,14 @@ public class ProtectListener implements Listener {
}
}
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onInvPickup(final InventoryPickupItemEvent e) {
- final ItemStack ci = e.getItem().getItemStack();
- if (MarkUtil.hasMark(ci)) {
- e.setCancelled(true);
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onItemClick(final InventoryClickEvent e) {
- final Player p = (Player) e.getWhoClicked();
- final ItemStack ci = e.getCurrentItem();
- final Inventory inv = e.getInventory();
- if (inv.getHolder() == null) {
- return;
- }
- final int solt = e.getSlot();
- try {
- if (MarkUtil.hasMark(ci)) {
- inv.setItem(solt, new ItemStack(Material.AIR));
- p.closeInventory();
+ private ItemStack[] handlerItems(final ItemStack[] cis) {
+ for (int i = 0; i < cis.length; i++) {
+ final ItemStack itemStack = cis[i];
+ if (MarkUtil.hasMark(itemStack)) {
+ cis[i] = new ItemStack(Material.AIR);
}
- } catch (final Exception ex) {
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPlayerHandlerItem(final PlayerItemHeldEvent e) {
- final PlayerInventory inv = e.getPlayer().getInventory();
- final int newslot = e.getNewSlot();
- final ItemStack newItem = inv.getItem(newslot);
- if (MarkUtil.hasMark(newItem)) {
- inv.setItem(newslot, new ItemStack(Material.AIR));
- }
- }
-
- @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
- public void onPlayerPickup(final PlayerPickupItemEvent e) {
- final ItemStack ci = e.getItem().getItemStack();
- if (MarkUtil.hasMark(ci)) {
- e.setCancelled(true);
}
+ return cis;
}
private void handlerPlayerInventory(final Player p) {
@@ -91,14 +52,8 @@ public class ProtectListener implements Listener {
@Override
public void run() {
final PlayerInventory inv = p.getInventory();
- final ItemStack[] cis = inv.getArmorContents();
- for (int i = 0; i < cis.length; i++) {
- final ItemStack itemStack = cis[i];
- if (MarkUtil.hasMark(itemStack)) {
- cis[i] = new ItemStack(Material.AIR);
- }
- }
- inv.setArmorContents(cis);
+ inv.setArmorContents(handlerItems(inv.getArmorContents()));
+ inv.setContents(handlerItems(inv.getContents()));
}
});
}