diff --git a/src/main/java/ch/njol/skript/aliases/ItemType.java b/src/main/java/ch/njol/skript/aliases/ItemType.java index a85d7c60da2..3e9a9982d42 100644 --- a/src/main/java/ch/njol/skript/aliases/ItemType.java +++ b/src/main/java/ch/njol/skript/aliases/ItemType.java @@ -74,7 +74,7 @@ public class ItemType implements Unit, Iterable, Container, public final static boolean itemMetaSupported = Skript.supports("org.bukkit.inventory.meta.ItemMeta"); // Minecraft < 1.9 (1.9 has bug fixed) - public final static boolean invSizeWorkaround = !Skript.isRunningMinecraft(1, 9); + public final static boolean oldInvSize = !Skript.isRunningMinecraft(1, 9); public final static boolean rawNamesSupported = Skript.isRunningMinecraft(1, 8); /** @@ -879,11 +879,11 @@ public boolean addTo(final Inventory invi) { ItemStack[] buf = invi.getContents(); if (buf == null) return false; - Skript.info("buf is " + Arrays.toString(buf)); + //Skript.info("buf is " + Arrays.toString(buf)); - if (invSizeWorkaround) { // MC < 1.9 + ItemStack[] tBuf = buf.clone(); + if (oldInvSize) { // MC < 1.9 if (buf.length > 36) { - ItemStack[] tBuf = buf.clone(); buf = new ItemStack[35]; for(int i = 0; i < 35; ++i) { buf[i] = tBuf[i]; @@ -891,7 +891,6 @@ public boolean addTo(final Inventory invi) { } } else { if (invi instanceof PlayerInventory) { - ItemStack[] tBuf = buf.clone(); buf = new ItemStack[36]; for(int i = 0; i < 36; ++i) { buf[i] = tBuf[i]; @@ -899,7 +898,17 @@ public boolean addTo(final Inventory invi) { } } - final boolean b = addTo(buf); + final boolean b = addTo(buf); + + if (!oldInvSize) { + if (invi instanceof PlayerInventory) { + buf = Arrays.copyOf(buf, tBuf.length); + for (int i = tBuf.length - 5; i < tBuf.length; ++i) { + buf[i] = tBuf[i]; + } + } + } + invi.setContents(buf); return b; } diff --git a/src/main/java/ch/njol/skript/events/EvtClick.java b/src/main/java/ch/njol/skript/events/EvtClick.java index b44318943ce..f0f5acb539c 100644 --- a/src/main/java/ch/njol/skript/events/EvtClick.java +++ b/src/main/java/ch/njol/skript/events/EvtClick.java @@ -102,9 +102,17 @@ public boolean check(final Event e) { final Entity entity; if (e instanceof PlayerInteractEntityEvent) { - if (Skript.isRunningMinecraft(1, 9)) { // If player has empty hand, no BOTH hands trigger the event (might be a bug?) - ItemStack mainHand = ((PlayerInteractEntityEvent) e).getPlayer().getInventory().getItemInMainHand(); - if (((PlayerInteractEntityEvent) e).getHand() == EquipmentSlot.OFF_HAND && (mainHand == null || mainHand.getType() == Material.AIR)) return false; + PlayerInteractEntityEvent clickEvent = ((PlayerInteractEntityEvent) e); + if (Skript.isRunningMinecraft(1, 9)) { // If player has empty hand, BOTH hands trigger the event (might be a bug?) + ItemStack mainHand = clickEvent.getPlayer().getInventory().getItemInMainHand(); + ItemStack offHand = clickEvent.getPlayer().getInventory().getItemInOffHand(); + + Player player = clickEvent.getPlayer(); + @SuppressWarnings("null") + boolean useOffHand = checkOffHandUse(mainHand, offHand, click, player); + if ((useOffHand && clickEvent.getHand() == EquipmentSlot.HAND) || (!useOffHand && clickEvent.getHand() == EquipmentSlot.OFF_HAND)) { + return false; + } } if (click == LEFT || types == null) // types == null will be handled by the PlayerInteractEvent that is fired as well @@ -113,7 +121,7 @@ public boolean check(final Event e) { block = null; } else if (e instanceof PlayerInteractEvent) { PlayerInteractEvent clickEvent = ((PlayerInteractEvent) e); - if (Skript.isRunningMinecraft(1, 9)) { // If player has empty hand, no BOTH hands trigger the event (might be a bug?) + if (Skript.isRunningMinecraft(1, 9)) { // If player has empty hand, BOTH hands trigger the event (might be a bug?) ItemStack mainHand = clickEvent.getPlayer().getInventory().getItemInMainHand(); ItemStack offHand = clickEvent.getPlayer().getInventory().getItemInOffHand(); @@ -217,7 +225,7 @@ private boolean checkOffHandUse(ItemStack mainHand, ItemStack offHand, int click offUsable = true; } - if ((mainHand == null || mainHand.getType() == Material.AIR) && offUsable) return true; + if (mainHand == null || mainHand.getType() == Material.AIR) return true; switch (mainHand.getType()) { case BOW: case EGG: