Want a better Minecraft server? Read about SpigotMC here!
Separate names with a comma.
Discussion in 'Spigot Plugin Development' started by RedNinjaPlaysMC, Jun 15, 2016.
How do you clear you entire inventory EXCEPT for the armor slots?
Cycle through the inventory slots and check if it's an armor slot. If it's not, clear it.
How do you do that in code?
I'm not that familiar with "for"
I'm not so sure how to do this for this situation.
you can clear player inventory and check if he has in his in inventory the armors: boots, chestplate, helmet, leggings to not be removed
Player inventories are separated between the inventory and the armor. You only have to clear the first one, no for is required.
But seriously, I think you have to learn more Java if you're "not familiar with for", because you always need this keyword.
What is this supposed to do?
Learn Java, then Spigot API and then you'll know what it means.
I think a iterator would be better in this case.
Just clears your whole inv including the armor slots.
It's seriously not a difficult task. It could even be done by storing their armor, clearing their inventory then setting their armor contents.
Have fun with your broken setArmorContents method that works backwards
Never said it was a good idea
So, how do you do this?
Best way is to do what everyone above suggested and use a for loop. (Also a good place to learn java is here)
How do you put this into code? (BTW, I learnt java like 4 years ago and stopped, now I forgot everything xD)
You can also get the armor contents :
ItemStack armor = player.getInventory().getArmorContents();
Then clear and reput the armor contents :
Any loop is required, but knowing these is very useful.
Has you covered if you actually read it.