Cancelling CreatureSpawnEvent ?

Discussion in 'Plugin Development' started by ThunderWaffeMC, Jul 16, 2014.

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

    ThunderWaffeMC

    Hi. I'm using the following code to cancel spawning of different mobs and spawn a zombie instead:

    Code:java
    1.  
    2. @SuppressWarnings("deprecation")
    3. @EventHandler
    4. public void onMonsterSpawn(CreatureSpawnEvent event) {
    5. if(event.getCreatureType() == CreatureType.SPIDER) {
    6. event.setCancelled(true);
    7. event.getEntity().getWorld().spawnEntity(event.getEntity().getLocation(), EntityType.ZOMBIE); }
    8. }
    9.  


    This code generates a lot of server lag (probably a memory leak) and I'm unsure of how to fix the problem. Is there anywhere work around to do the same thing or to cover up the lag?

    Thanks!
     
  2. Offline

    Onlineids

    ThunderWaffeMC Doesnt seem to lag for me?

    ThunderWaffeMC Maybe its the check time everytime a mob spawns because I dont have that

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  3. Offline

    NathanWolf

    This is a classic issue with mob spawning - MC will constantly try to rebalance mobs, so this event fires like crazy if you keep canceling it.

    The only way I know around this that seems to work well is moving the mob somewhere instead of canceling the event- but I don't know how plugins like MultiVerse and WorldGuard handle it, might be worth looking at their code!
     
    ThunderWaffeMC likes this.
Thread Status:
Not open for further replies.

Share This Page