Solved Disable mob spawning from certain spawners

Discussion in 'Spigot Plugin Development' started by JacksonHogan, Jan 5, 2018.

Thread Status:
Not open for further replies.
  1. I am trying to figure out how to disable mobs being able to spawn from a spawner if there is no EmeraldBlock underneath it. So far this is what I have...

    Code (Text):
    for(World w : Bukkit.getWorlds()){
                        for(Chunk chunk : w.getLoadedChunks()){
                            for(BlockState blockState : chunk.getTileEntities()){
                                if(blockState.getType()==Material.MOB_SPAWNER){
                                    Location loc = blockState.getLocation();
                                    loc.setY(loc.getY()-1);
                                    if(loc.getBlock().getType()!=Material.EMERALD_BLOCK){
                                        CreatureSpawner spawner = (CreatureSpawner) blockState.getBlock();
                                    }
                                }
                            }
                        }
                    }
    I cannot figure out how to actually disable the spawners.
    Any help would be greatly appreciated.
     
  2. Well you could possible check EntitySpawnEvent, check if the reason was SPAWNER, check if there was an emerald block under the spawner

    So if you're wanting to disable Skeleton spawners:
    EntitySpawnEvent
    If(cause == SpawnReason.SPAWNER){
    if(entity instanceof SKELETON){
    // Check for spawners location and check for block underneath
    }
    }
     
  3. https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/entity/CreatureSpawnEvent.html

    Just use that and if the creature is a mob, cancel the spawning.
    This does effect world spawning though.

    You can try checking the mob's coordinates though.
     
  4. Awesome! Thank you very much.
     
Thread Status:
Not open for further replies.