Working with drops on death?

Discussion in 'Plugin Development' started by KarimAKL, Aug 13, 2018.

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

    KarimAKL

    I've been trying to make a plugin where when a player dies they don't drop specific items but i can't seem to get it working and i've tried searching around aswell but couldn't find anything. :/
    Example:
    Code:Java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent event) {
    3. Iterator<ItemStack> drops = event.getDrops().iterator();
    4. while (drops.hasNext()) {
    5. if (drops.next()./*is special item*/) {
    6. drops.remove();
    7. }
    8. }
    9. }

    What i'm trying to do is get the list of drops and remove the items from the list of drops and hope that it would make it stay in the player's inventory instead of removing it completely.
     
  2. Offline

    Zombie_Striker

    @KarimAKL
    The iterator is not the same as the List. When removing an item, call "evetn.getDrops().remove(....)"
     
  3. Offline

    KarimAKL

    @Zombie_Striker I see, i tried changing it to this:
    Code:Java
    1. @EventHandler
    2. public void onDeath(PlayerDeathEvent event) {
    3. Iterator<ItemStack> drops = event.getDrops().iterator();
    4. while (drops.hasNext()) {
    5. if (drops.next() != null && drops.next().getType() != Material.AIR && drops.next()./*is special item*/) {
    6. event.getDrops().remove(drops.next());
    7. }
    8. }
    9. }

    EDIT: Nvm, no error now. Just had to check for null first, i've changed the code above to current aswell. But it still doesn't work, using the code above it comes with no errors or stacktraces but all the items still drop.
     
    Last edited by a moderator: Aug 13, 2018
Thread Status:
Not open for further replies.

Share This Page