How do I edit the items a player is wearing?
Player is ArmorEquippable which means that you can call methods like: getHelmet(), getChestplate(), etc. Normally these return Optional, so you’ll have to call get() to get the actual ItemStack.
Now that you have the ItemStack, you want to actually modify it, right? Right. So, a majority (99%) of modifying an ItemStack involves using the Data API, which has solved a lot of the heavy lifting revolving having to know the specific class inheritance model of an ItemType to manipulate the “data” on the ItemStack. An example plugin creating ItemStacks with the Data API (albeit a little extra than just generating item stacks) is Flardians.
After that is all done, you have to set the ItemStack back to the Player. This is part of the contractual semantics of SpongeAPI where almost all mutable Objects you receive are copies of the original, and it resolves a lot of synchronization issues with things especially with inventories as they’re especially finicky. That aside, that’s about all there is to it.
p.getItemInHand().get().setQuantity(0);
Inventory inv = p.getInventory();
inv.clear();
p.getHelmet().get().setQuantity(0);
I’m hoping that will work.
Whenever you get an ItemStack from the API, that stack is a copy. So if you make changes to any ItemStack, you’ll need to write them back to the slot where the stack came from.
So in order to make any changes to a persons helmet, you need to call p.setHelmet(newHelmetStack). However, all setters for ArmorEquipable have @Nullable parameters, so you just need to call p.setHelmet(null) in order to strip a Player of his helmet.
For your example it may be that p.getInventory() already includes the equipment slots, so if that is true only p.getInventory().clear() would be necessary. However in that case you’d need to save the other three armor slots which you apparently don’t want to change.