Skip to content

Commit

Permalink
I guess it was not fixed. Finally fix giving items to players.
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed Mar 16, 2016
1 parent aa53e82 commit 49c7a9b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
21 changes: 15 additions & 6 deletions src/main/java/ch/njol/skript/aliases/ItemType.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class ItemType implements Unit, Iterable<ItemData>, Container<ItemStack>,
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);

/**
Expand Down Expand Up @@ -879,27 +879,36 @@ 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];
}
}
} else {
if (invi instanceof PlayerInventory) {
ItemStack[] tBuf = buf.clone();
buf = new ItemStack[36];
for(int i = 0; i < 36; ++i) {
buf[i] = tBuf[i];
}
}
}

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;
}
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/ch/njol/skript/events/EvtClick.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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();

Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 49c7a9b

Please sign in to comment.