Merge pull request #95 from mworzala/double_click_oob

Inventory double click ArrayIndexOutOfBoundsException
This commit is contained in:
TheMode 2021-01-02 13:14:21 +01:00 committed by GitHub
commit 1715de67d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 11 deletions

View File

@ -564,7 +564,7 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
public boolean dragging(@NotNull Player player, int slot, int button) {
final PlayerInventory playerInventory = player.getInventory();
final boolean isInWindow = isClickInWindow(slot);
final ItemStack clicked = slot != 999 ?
final ItemStack clicked = slot != -999 ?
(isInWindow ? getItemStack(slot) : playerInventory.getItemStack(slot, offset)) :
ItemStack.getAirItem();
final ItemStack cursor = getCursorItem(player);
@ -611,13 +611,8 @@ public class Inventory implements InventoryModifier, InventoryClickHandler, View
// Looping through player inventory
new InventoryClickLoopHandler(0, PlayerInventory.INVENTORY_SIZE - 9, 1,
PlayerInventoryUtils::convertToPacketSlot,
index -> playerInventory.getItemStack(index, offset),
(index, itemStack) -> playerInventory.setItemStack(index, offset, itemStack)),
// Player hot bar
new InventoryClickLoopHandler(0, 9, 1,
PlayerInventoryUtils::convertToPacketSlot,
index -> playerInventory.getItemStack(index, offset),
(index, itemStack) -> playerInventory.setItemStack(index, offset, itemStack)));
index -> playerInventory.getItemStack(index, PlayerInventoryUtils.OFFSET),
(index, itemStack) -> playerInventory.setItemStack(index, 9, itemStack)));
if (clickResult == null)
return false;

View File

@ -49,7 +49,6 @@ public final class PlayerInventoryUtils {
case 8:
return BOOTS_SLOT;
}
//System.out.println("ENTRY: " + slot + " | " + offset);
final int rowSize = 9;
slot -= offset;
if (slot >= rowSize * 3 && slot < rowSize * 4) {
@ -57,7 +56,6 @@ public final class PlayerInventoryUtils {
} else {
slot = slot + rowSize;
}
//System.out.println("CONVERT: " + slot);
return slot;
}
@ -68,7 +66,7 @@ public final class PlayerInventoryUtils {
* @return a slot id which can be used for packets
*/
public static int convertToPacketSlot(int slot) {
if (slot > -1 && slot < 9) { // Held bar 0-9
if (slot > -1 && slot < 9) { // Held bar 0-8
slot = slot + 36;
} else if (slot > 8 && slot < 36) { // Inventory 9-35
slot = slot;