Also check out-of-bounds on player inventory

This commit is contained in:
Camotoy 2021-03-08 18:17:14 -05:00
parent ffae69471d
commit d80372e0b4
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F

View file

@ -28,6 +28,7 @@ package org.geysermc.connector.inventory;
import lombok.Getter; import lombok.Getter;
import lombok.NonNull; import lombok.NonNull;
import lombok.Setter; import lombok.Setter;
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.network.session.GeyserSession; import org.geysermc.connector.network.session.GeyserSession;
public class PlayerInventory extends Inventory { public class PlayerInventory extends Inventory {
@ -55,10 +56,18 @@ public class PlayerInventory extends Inventory {
} }
public GeyserItemStack getItemInHand() { public GeyserItemStack getItemInHand() {
if (36 + heldItemSlot > this.size) {
GeyserConnector.getInstance().getLogger().debug("Held item slot was larger than expected!");
return GeyserItemStack.EMPTY;
}
return items[36 + heldItemSlot]; return items[36 + heldItemSlot];
} }
public void setItemInHand(@NonNull GeyserItemStack item) { public void setItemInHand(@NonNull GeyserItemStack item) {
if (36 + heldItemSlot > this.size) {
GeyserConnector.getInstance().getLogger().debug("Held item slot was larger than expected!");
return;
}
items[36 + heldItemSlot] = item; items[36 + heldItemSlot] = item;
} }