clearing inventory is bugging.

Discussion in 'Plugin Development' started by bennie3211, Nov 6, 2014.

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

    bennie3211

    Hello Bukkit,

    I've a little problem with clearing my player's inventory. If I use this:

    Code:java
    1.  
    2. pl.getInventory().clear();
    3. pl.getInventory().setArmorContents(new ItemStack[] {null, null, null, null});


    it removes everything from the player expect the item the player is holding. Anyone can tell me how to solve this? If you need more from my code tell me!

    Version: This server is running CraftBukkit version git-Bukkit-1.7.9-R0.2-24-g07d4558-b3116jnks (MC: 1.7.10) (Implementing API version 1.7.10-R0.1-SNAPSHOT)
     
  2. Offline

    rete25iscool

    Code:java
    1. pl.getInventory().setItemInHand(null);
     
  3. Offline

    Watto

    Get the item in hand a remove it seperatly?
     
  4. Offline

    EnchantedMiners

    Watto Just
    Code:java
    1. p.getInventory().setContents(null);
    2. p.getInventory().getArmorInventoryContent().setArmorInventoryContent(null);
     
  5. Offline

    Watto

  6. Offline

    bennie3211

    If i do pl.getInventory().setContens(null); it will throw a NPE. About pl.getInventory().getArmorInventoryContent().setArmorInventoryContent(null); this one doesn't exists.

    I have added pl.getItemInHand(): & pl.updateInventory(); and now everything gets removed, but if the player holds an item in his hand an get the item again by clicking a sign, he has 2 of them. This happens only if the player hold the item. I don't know how?!
     
  7. Offline

    EnchantedMiners

    bennie3211 those codes should work properly i use them on every plugin i make that needs to remove inventory and the armor content i am not 100% sure because i wrote that without looking at bukkit documents but it should look something like that try p.setArmorInventoryContent(null) or something like that
     
  8. Offline

    bennie3211

    EnchantedMiners Its working, it clears the player inventory (correctly) but there is a duplicate glitch right now :l When the player hold an item in his hand, and there inventory gets cleared, they can click on that slot again and the item will appear again, and yes, I added setItemInHand(null); and still it gives the glitch :l
     
Thread Status:
Not open for further replies.

Share This Page