Removing a drop from a mob

Discussion in 'Plugin Development' started by randomman159, Nov 15, 2011.

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

    randomman159

    I am getting this error message :


    23:27:32 [SEVERE] Could not pass event ENTITY_DEATH to MyPlugin
    java.util.ConcurrentModificationException
    at java.util.AbstractList$Itr.checkForComodification(Unknown Source)
    at java.util.AbstractList$Itr.next(Unknown Source)
    at randomman159.MyPlugin.OMCEntityListener.onEntityDeath(OMCEntity
    Listener.java:27)


    The code is simply :

    Code:
    for (ItemStack d : event.getDrops())
                {
                    if (d.getType() == Material.COOKED_BEEF)
                        event.getDrops().remove(d);
                }

    Any ideas? Or better ways of stopping a mob from dropping an item?
     
  2. Offline

    halley

    The ConcurrentModificationException means you cannot modify the collection event.getDrops() (a List) while you're iterating over the same collection.

    I'm not even sure you should be trying to modify that collection directly at all. The event is missing a setDrops() manipulator, and the event will be forwarded to other plugins/listeners who may have only allowed/denied the event on the basis of the drops.

    If you really want to persist anyway, try changing the offending ItemStack to something benign-- change that cookedbeef to pork, for example. The alternative would be to mark the event as cancelled-- no drops at all, but maybe no death either.
     
  3. Offline

    randomman159

    Code:
    ArrayList<ItemStack> remove = new ArrayList<ItemStack>();
    
                for (ItemStack d : event.getDrops())
                {
                    if (d.getType() == Material.RAW_BEEF || d.getType() == Material.COOKED_BEEF)
                        remove.add(d);
                }
    
                for (ItemStack d : remove)
                {
                    event.getDrops().remove(d);
                }
    This solved my problem. Thanks anyway!
     
Thread Status:
Not open for further replies.

Share This Page