From fd9e2776ce5601da967b4087f6c7acdaa0bb3bba Mon Sep 17 00:00:00 2001 From: virustotalop Date: Sun, 27 Jan 2019 02:52:38 -0800 Subject: [PATCH] Fixed logic with index out of bound clicking Fixed logic with index out of bound clicking, should now be handled by the trident listener instead. If the item is out of bounds then we should just pass an itemwrapper with a null itemstack and then the trident listener handles the code correctly. --- .../bukkit/InventoryClickListener.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryClickListener.java b/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryClickListener.java index 207f48818..3d0623fd8 100644 --- a/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryClickListener.java +++ b/src/main/java/com/clubobsidian/dynamicgui/listener/bukkit/InventoryClickListener.java @@ -15,7 +15,6 @@ */ package com.clubobsidian.dynamicgui.listener.bukkit; -import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -39,21 +38,18 @@ public class InventoryClickListener implements Listener { @EventHandler public void onInventoryClick(InventoryClickEvent e) { - if(e.getInventory() == null) + Inventory inventory = e.getInventory(); + if(inventory == null) return; - - int slot = e.getSlot(); - if(e.getSlot() < 0 || e.getSlot() > e.getInventory().getSize() && e.getClick() != ClickType.CREATIVE) - { - return; - } + int slot = e.getSlot(); + int rawSlot = e.getRawSlot(); InventoryView view = InventoryView.TOP; - if(e.getRawSlot() >= e.getInventory().getSize()) + if(rawSlot >= e.getInventory().getSize()) { view = InventoryView.BOTTOM; } - + if(e.getWhoClicked() instanceof Player) { Click clickType = null; @@ -63,9 +59,14 @@ public void onInventoryClick(InventoryClickEvent e) } Player player = (Player) e.getWhoClicked(); - InventoryWrapper inventoryWrapper = new BukkitInventoryWrapper(e.getInventory()); + InventoryWrapper inventoryWrapper = new BukkitInventoryWrapper(inventory); PlayerWrapper playerWrapper = new BukkitPlayerWrapper(player); - ItemStack itemStack = e.getInventory().getItem(slot); + ItemStack itemStack = null; + if(slot > 0 && slot < inventory.getSize()) + { + itemStack = e.getInventory().getItem(slot); + } + ItemStackWrapper itemStackWrapper = null; if(itemStack == null) {