Solved How to remove drops from event.

Discussion in 'Plugin Development' started by DutchJellyV2, Jul 12, 2018 at 4:27 AM.

  1. Offline

    DutchJellyV2

    Hello fellow coders,

    this subject was always confusing to me. How do you remove drops from for example the EntityDeathEvent. There's only a method called: getDrops(), and no method called setDrops(); So how do you set the drops?

    The answer is simple, but more complicated than you might think.
    Code:
    event.getDrops().clear()
    
    This will clear the drops. You can simply modify the returned List<ItemStack> that #getDrops() returns.

    For everyone interested in why this is the case:
    Code:
    //decompiled code from the spigot jar file.
    public class EntityDeathEvent extends EntityEvent
    {
         private static final HandlerList handlers = new HandlerList();
         private final List<ItemStack> drops;
         // and alot more code.
    }
    
    The final keyword means that there's always only one object in that instance. The get() method therefor returns the List that you can modify. Please clearify this if you can, because I recently found out about this.

    Why am I answering my own question? I thought the question just wasn't explained anywhere with some in depth explanation "why" the getDrops.clear() just works.
     

Share This Page