diff --git a/src/me/yaruma/fightsystem/FightSystem.java b/src/me/yaruma/fightsystem/FightSystem.java index 986a3db..1ccd044 100644 --- a/src/me/yaruma/fightsystem/FightSystem.java +++ b/src/me/yaruma/fightsystem/FightSystem.java @@ -80,6 +80,7 @@ public class FightSystem extends JavaPlugin { pm.registerEvents(new PlayerTeleportListener(), plugin); pm.registerEvents(new ProjectileLaunchListener(), plugin); pm.registerEvents(new PistonListener(), plugin); + pm.registerEvents(new InventoryListener(), plugin); //WinConditions if(Config.AllDead) pm.registerEvents(new WinconditionAllDead(), plugin); diff --git a/src/me/yaruma/fightsystem/listener/InventoryListener.java b/src/me/yaruma/fightsystem/listener/InventoryListener.java new file mode 100644 index 0000000..a5516aa --- /dev/null +++ b/src/me/yaruma/fightsystem/listener/InventoryListener.java @@ -0,0 +1,56 @@ +package me.yaruma.fightsystem.listener; + +import me.yaruma.fightsystem.FightSystem; +import me.yaruma.fightsystem.fight.FightState; +import org.bukkit.event.EventHandler; +import org.bukkit.event.Listener; +import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.event.inventory.InventoryDragEvent; +import org.bukkit.event.inventory.InventoryType; +import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; + +public class InventoryListener implements Listener { + + @EventHandler + public void onInventoryClick(InventoryClickEvent event) { + if(FightSystem.getFightState() == FightState.SETUP){ + event.setCancelled(true); + return; + } + + Inventory clicked = event.getClickedInventory(); + if (event.getClick().isShiftClick()) { + ItemStack clickedOn = event.getCurrentItem(); + + if (clickedOn != null && event.getView().getTopInventory().getType() != InventoryType.CRAFTING && clicked == event.getWhoClicked().getInventory()) { + event.setCancelled(true); + } + }else if (clicked != event.getWhoClicked().getInventory()) { + ItemStack onCursor = event.getCurrentItem(); + + if (onCursor != null && event.getClickedInventory().getType() != InventoryType.PLAYER){ + event.setCancelled(true); + } + } + } + + @EventHandler + public void onInventoryDrag(InventoryDragEvent event) { + if(FightSystem.getFightState() == FightState.SETUP){ + event.setCancelled(true); + return; + } + + if (event.getInventory().getType() != InventoryType.PLAYER) { + int inventorySize = event.getInventory().getSize(); + + for (int i : event.getRawSlots()) { + if (i < inventorySize) { + event.setCancelled(true); + break; + } + } + } + } +}