I have been trying to make my plugin put the items it gives you into an empty slot but it just is not working. Code: ItemStack StoneSword = new ItemStack(Material.STONE_SWORD, 1); PlayerInventory pi = player.getInventory(); pi.firstEmpty(StoneSword); } It keeps giving me an error after I put the Itemstack StoneSword in the parentheses. I just want it so it will put the items in an empty slot. Any help please?
Try changing it to: Code:java ItemStack StoneSword = new ItemStack(Material.STONE_SWORD, 1);PlayerInventory pi = player.getInventory();int slot = pi.firstEmpty();pi.setItem(slot, StoneSword); Atleast that's how I do it.
Okay, it works when I have one item but when I have multiple items with one command it only give me the leather boots... Heres the new code: Code:java ItemStack StoneSword = new ItemStack(Material.STONE_SWORD, 1); ItemStack LeatherHelmet = new ItemStack(Material.LEATHER_HELMET, 1); ItemStack LeatherChestplate = new ItemStack(Material.LEATHER_CHESTPLATE, 1); ItemStack LeatherLeggings = new ItemStack(Material.LEATHER_LEGGINGS, 1); ItemStack LeatherBoots = new ItemStack(Material.LEATHER_BOOTS, 1); PlayerInventory pi = player.getInventory(); int slot = pi.firstEmpty(); pi.setItem(slot, StoneSword); pi.setItem(slot, LeatherHelmet); pi.setItem(slot, LeatherChestplate); pi.setItem(slot, LeatherLeggings); pi.setItem(slot, LeatherBoots);
Just use pi.addItem versus setItem- the inventory will automatically put the items in the next available slots. What you are doing there is getting the first available slot once, then putting 5 different items in it, each one replacing the last.