Trying to remove Item from slot number

Discussion in 'Plugin Development' started by Zen3515, Nov 25, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Zen3515

    Code:java
    1. private void removethisItemnameFormInventory(Player player,String s,int selectedSlot)
    2. {
    3. player.sendMessage("Removing " + s);
    4. for(int i = 0; i <= 35; i++)
    5. {
    6. if (player.getInventory().getItem(i) != null)
    7. {
    8. player.sendMessage("1Check at : " + String.valueOf(i) + " Found "
    9. + player.getInventory().getItem(i).getItemMeta().getDisplayName());
    10. if(player.getInventory().getItem(i).getItemMeta().getDisplayName() != null
    11. && player.getInventory().getItem(i).getItemMeta().getDisplayName().contains(s))
    12. {
    13. player.sendMessage("2At = " + String.valueOf(i) + "Selected slot is" + String.valueOf(selectedSlot));
    14. if (i != selectedSlot)
    15. {
    16. player.sendMessage("3At i != selectedSlot");
    17. player.getInventory().clear(i);
    18. }
    19. }
    20. }
    21. }
    22. }


    For my case is this
    289.png
    I got this messages.
    "Removing ItemB"
    "1Check at : 0 Found ItemB"
    "2At = 0Selected slot is1"
    "3At i != selectedSlot"
    "1Check at : 1 Found ItemB"
    "2At = 1Selected slot is1"

    But both Items still not remove why?
    I had tried:
    player.getInventory().clear(i);
    player.getInventory().setItem(i, null);
    player.getInventory().setItem(i, new ItemStack(Material.AIR));
    player.getInventory().setItem(i, new ItemStack(Material.AIR , 0));

    all above code doesn't work.
    How to remove ItemStack from slot number
    Please anyone help me ?
     
  2. Offline

    MarinD99

    Wouldn't that be just removing the lapis block from the player's inventory completely?
     
  3. Offline

    viper_monster

    MarinD99, well I think I have misunderstood what he wants then :p
     
    MarinD99 likes this.
  4. Offline

    L33m4n123

    try updating the inventory after you set it to air / cleared the slot.
     
  5. Offline

    Zen3515

    The method updateInventory() from the type Player is deprecated
     
  6. Offline

    L33m4n123

    Its been deprecated since ages.

    deprecated doesn't mean that it is not working

    Only means that they plan on replacing it / not supporting it in the future but for now it works and will work most likely until they find a better replacement
     
Thread Status:
Not open for further replies.

Share This Page