Solved Item in hand will not set

Discussion in 'Spigot Plugin Development' started by Epixel, Apr 1, 2018.

  1. Hello, I'm trying to set the item in the hand of a player to be a bowl, but it just wont do it. I've tried putting in an updateInventory(), but it still doesn't work. I've also tried changing it to air, and then to bowl, but that didn't work either. I've searched all over the forums and it seems like I've tried everything. It broadcasts "hand = bowl" so I know that the code is being fired.
    Code (Text):

            ItemStack bowl = new ItemStack(Material.BOWL, 1);
            player.setItemInHand(bowl);
            player.updateInventory();
            Bukkit.broadcastMessage("hand = bowl");
     
  2. It's because you didn't add the item to the players inventory.
    It should work like that:

    Code (Text):
    ItemStack bowl = new ItemStack(Material.BOWL, 1);
    player.getInventory().addItem(bowl);
    player.setItemInHand(bowl);
    Bukkit.broadcastMessage("hand = bowl");
    Hope so it helps you. :)
     
    • Like Like x 1
  3. Thanks for helping!
     
  4. No problem ;)
    If something still doesn't work, just contact me again. :D
     
  5. just curious: what will happen when the inv is full?