Solved How to remove all compasses from the player drops?

Discussion in 'Spigot Plugin Development' started by Diaburo, Jun 21, 2021.

  1. I'm trying many things but none works...
    Code (Java):
    public void onPlayerDeath(PlayerDeathEvent event) {
            if (speedrunner != null) {
                for (int slots = 0; slots <= 40; slots++) {
                    if (event.getDrops().contains(Material.COMPASS)) {
                        event.getDrops().remove(slots);
                    }
                }
            }
        }
     
  2. Code (Text):
    @EventHandler
    public void onPlayerDeath(PlayerDeathEvent event) {
      List <ItemStack> list = event.getDrops();
      Iterator<ItemStack> i = list.iterator();
      while(i.hasNext()) {
        ItemStack item = i.next();
        if(item.getType == Material.COMPASS)
          i.remove();
      }
    }
     
  3. Code (Java):
        @EventHandler
        public void onPlayerDeath(PlayerDeathEvent event) {
            event.getDrops().removeIf(itemStack -> itemStack.getType() == Material.COMPASS);
        }
    Get drops, remove from list if it's a compass
     
    • Like Like x 1
  4. Both works perfectly, ty!