Check if slot has item?

Discussion in 'Spigot Plugin Development' started by kinukin, Jun 9, 2017.

  1. How can I check if a slot has an item in it?

    Thank you
  2. by using

    Code (Text):

    ItemStack itemStack = inventory.getItem(slot);
    Note, that this would also be null if the slot is empty.
  3. Just a small example

    Code (Text):
        public void event(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            PlayerInventory inv = p.getInventory();
            for (ItemStack i : inv.getContents()) {
                if (i == null) {
                    //your code