Clearing Inventory except for Armor.

Discussion in 'Spigot Plugin Development' started by RedNinjaPlaysMC, Jun 15, 2016.

  1. How do you clear you entire inventory EXCEPT for the armor slots?
  2. Cycle through the inventory slots and check if it's an armor slot. If it's not, clear it.
  3. How do you do that in code?
  4. I'm not that familiar with "for"
  5. I'm not so sure how to do this for this situation.
  6. you can clear player inventory and check if he has in his in inventory the armors: boots, chestplate, helmet, leggings to not be removed
  7. Player inventories are separated between the inventory and the armor. You only have to clear the first one, no for is required.
    Code (Java):
    player.getInventory().setContents(new ItemStack[36]);
    But seriously, I think you have to learn more Java if you're "not familiar with for", because you always need this keyword.
    • Agree Agree x 1
  8. What is this supposed to do?
  9. Learn Java, then Spigot API and then you'll know what it means.
    • Agree Agree x 1
  10. I think a iterator would be better in this case.
  11. Code (Text):
    player.getInventory().setContents(new ItemStack[36]);
    Just clears your whole inv including the armor slots.
  12. It's seriously not a difficult task. It could even be done by storing their armor, clearing their inventory then setting their armor contents.
  13. Have fun with your broken setArmorContents method that works backwards ;)
  14. Never said it was a good idea
  15. Best way is to do what everyone above suggested and use a for loop. (Also a good place to learn java is here)
  16. How do you put this into code? (BTW, I learnt java like 4 years ago and stopped, now I forgot everything xD)
  17. You can also get the armor contents :
    Code (Java):
    ItemStack[] armor = player.getInventory().getArmorContents();
    Then clear and reput the armor contents :
    Code (Java):
    Any loop is required, but knowing these is very useful.