What would be most efficient way to disable certain mobs from spawning? I only want zombies to spawn from all hostile mobs. I feel like doing Code: @EventHandler public void onSpawn(CreatureSpawnEvent e){ EntityType type = e.getEntityType(); if(type == EntityType.CREEPER || type == EntityType.SPIDER || type == EntityType.SKELETON || type == EntityType.ENDERMAN){ e.setCancelled(true); } is kinda unefficient to server and may cause lag
Something more like this? Code: @EventHandler public void onSpawn(CreatureSpawnEvent e){ if(! (e instanceof Zombie)) { e.setCancelled(true); } } }
FozZeW Windy Day Canceling mob spawns creates memory leaks, my suggestion is to kill the entity instead of canceling their spawn or removing them.
I haven't done anything with mob spawning, I just whipped that up outside of an IDE for FozZeW but thats good to know, thanks.
FozZeW Uhh, sure? They both cause memory leaks... NathanWolf http://forums.bukkit.org/threads/important-information-regarding-cancelling-creature-spawns.147007/
Killing the Entity does not magically make the resources allocated for that Entity disappear. Using BKCommonLib it is easily possible to do this, but then again, you need to depend: Code: @EventHandler public void onCreaturePreSpawn(CreaturePreSpawnEvent event) { if (event.getEntityType() == EntityType.CREEPER) { event.setCancelled(true); } } Note how only the Entity Type is passed in with the event, and not the Entity instance itself. This is because this event is fired before actual spawning happens. It is also not accurate, since even though a prespawn might have fired, the creature spawn event is not actually fired in all cases afterwards. Some server logic decides what (allowed) entity to spawn. Note that the same event is re-used over and over again to save resources. That means storing the event or using it as final with a scheduled runnable code using it later on does not work. Link to the custom event The only other way to do this, as linked before, is to disable all mob spawning globally and only allow spawning every now and then, say, every 10 ticks you turn it on for one tick. Turn it on/off by changing the animal/monster spawn limits on the world to 0/nonzero.