mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-03 05:26:50 +01:00
Fix creative ArrayIndexOutOfBoundsException. Fixes BUKKIT-4305
When a Player drops an ItemStack while in creative mode by placing it outside of their inventory window, the slot number in the packet is -1. The check that was added to avoid throwing InventoryCreativeEvent excessively didn't take this into account, and would cause an ArrayIndexOutOfBoundsException to be thrown when attempting to get the slot specified by the packet. This change shorts the invocation of player.defaultContainer.getSlot( packet107setcreativeslot.b) to only occur if the slot id is within the range of the Inventory. This prevents attempting to get the slot from a location that is actually outside of the Inventory.
This commit is contained in:
parent
991218a339
commit
bf4796d39e
1 changed files with 29 additions and 33 deletions
|
@ -1459,10 +1459,7 @@ public class PlayerConnection extends Connection {
|
||||||
boolean flag3 = itemstack == null || itemstack.getData() >= 0 && itemstack.getData() >= 0 && itemstack.count <= 64 && itemstack.count > 0;
|
boolean flag3 = itemstack == null || itemstack.getData() >= 0 && itemstack.getData() >= 0 && itemstack.count <= 64 && itemstack.count > 0;
|
||||||
|
|
||||||
// CraftBukkit start - Call click event
|
// CraftBukkit start - Call click event
|
||||||
if (flag1 || flag) { // Insist on valid slot
|
if (flag || (flag1 && !ItemStack.matches(this.player.defaultContainer.getSlot(packet107setcreativeslot.slot).getItem(), packet107setcreativeslot.b))) { // Insist on valid slot
|
||||||
ItemStack existingItem = this.player.defaultContainer.getSlot(packet107setcreativeslot.slot).getItem();
|
|
||||||
// Client assumes that the server forgets the contents of the inventory. It doesn't.
|
|
||||||
if (!ItemStack.matches(existingItem, packet107setcreativeslot.b)) {
|
|
||||||
|
|
||||||
org.bukkit.entity.HumanEntity player = this.player.getBukkitEntity();
|
org.bukkit.entity.HumanEntity player = this.player.getBukkitEntity();
|
||||||
InventoryView inventory = new CraftInventoryView(player, player.getInventory(), this.player.defaultContainer);
|
InventoryView inventory = new CraftInventoryView(player, player.getInventory(), this.player.defaultContainer);
|
||||||
|
@ -1499,7 +1496,6 @@ public class PlayerConnection extends Connection {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
// CraftBukkit end
|
// CraftBukkit end
|
||||||
|
|
||||||
if (flag1 && flag2 && flag3) {
|
if (flag1 && flag2 && flag3) {
|
||||||
|
|
Loading…
Reference in a new issue