Why is CREATURE_SPAWN triggered when breaking blocks?

Discussion in 'Plugin Development' started by Derek Peterson, Mar 27, 2011.

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

    Derek Peterson

    I've noticed something *extremely* strange in the latest commit of the BukkitAPI (commit # a5b07e7355e39223e19d)

    CREATURE_SPAWN is being triggered each time a block is broken. I have absolutely no idea why this should be happening. It took me an hour to determine which event was triggering when it shouldn't be, but I've narrowed it down to this.

    Steps to replicate:
    1. register for CREATURE_SPAWN
    2. cancel the event unconditionally in onCreatureSpawn
    3. try breaking a block

    The block will act as though BlockBreakEvent was cancelled, when it was really CreatureSpawnEvent which was cancelled.
     
  2. Offline

    Intelli

    Are you preventing the "player", etc, from spawning?
    That was my issue. Make sure you're properly checking to limit mobs.

    (Otherwise, you can't break blocks, drop items, etc)

    No more chickens, without messing stuff up:
    Code:
    @Override
    public void onCreatureSpawn(CreatureSpawnEvent event) {
    Entity entity = event.getEntity();
    if (event.getCreatureType() == CreatureType.CHICKEN){
    event.setCancelled(true);
    }
    }
    
     
  3. Offline

    jblaske

    I agree, this event shouldn't trigger when you log in or a block is broken.

    Since I only care about creatures spawning in my plugin, I added this code to keep it from stopping blocks from dropping items.

    Code:
    public @Override void onCreatureSpawn(CreatureSpawnEvent event)
        {
            if(!event.isCancelled() && isCreature(event.getCreatureType()))
            {
    
            ...Do Code Here...
    
            }
        }
    This is my isCreature() function as well, for the sake of completeness.
    Code:
    private boolean isCreature(CreatureType ct)
        {
            boolean result = false;
    
            if(ct != null)
            {
                switch(ct)
                {
                case CHICKEN:
                    result = true;
                    break;
                case COW:
                    result = true;
                    break;
                case CREEPER:
                    result = true;
                    break;
                case GHAST:
                    result = true;
                    break;
                case GIANT:
                    result = true;
                    break;
                case PIG:
                    result = true;
                    break;
                case PIG_ZOMBIE:
                    result = true;
                    break;
                case SHEEP:
                    result = true;
                    break;
                case SKELETON:
                    result = true;
                    break;
                case SLIME:
                    result = true;
                    break;
                case SPIDER:
                    result = true;
                    break;
                case SQUID:
                    result = true;
                    break;
                case ZOMBIE:
                    result = true;
                    break;
                }
            }
    
            return result;
        }
     
Thread Status:
Not open for further replies.

Share This Page