Spawn mob in world with no players

Discussion in 'Plugin Development' started by Hex_27, Jun 24, 2015.

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

    Hex_27

    I'm making a plugin to respawn an enderdragon with a command from the console, but it only spawns when there are players in the end world. If there isn't the dragon simply doesn't spawn. This is my spawnDragon method.

    Code:
        public void spawnDragon(int level, ItemStack drop, World world){
            if(dragworld.get(world) == null&&
                    dragworld.get(world) == null){
            Bukkit.broadcastMessage(ChatColor.GREEN + "" + ChatColor.BOLD + "A level " + level + " dragon has spawned in " + world.getName());
            Bukkit.broadcastMessage(ChatColor.AQUA + "======Special Effects======");
            Bukkit.broadcastMessage(ChatColor.AQUA + "Resistant Scales: You can only do a maximum of " + (20-level) + " damage at a time to the dragon");
            Bukkit.broadcastMessage(ChatColor.AQUA + "Ancient Grudge: Previous kingdom that slayed the dragon will get double damage from the dragon");
            if(level > 2){
                Bukkit.broadcastMessage(ChatColor.AQUA + "Ender Corruption: All players in the end get poison and blindness.");
            }
           
           
            final EnderDragon dragon = (EnderDragon) world.spawnEntity(new Location(world,29,109,1), EntityType.ENDER_DRAGON);
            int health = (int) dragon.getMaxHealth() + level*100;
            dragon.setMaxHealth(health);
            dragon.setHealth(1);
            this.dragons.put(dragon, level);
            this.dragworld.put(world, dragon);
            this.dragondrops.put(dragon, drop);
        }
        }
     
  2. The problem is probably that you don't load the chunks, because when there are no players there are no chunks loaded. When you get the location where you want to spawn the EnderDragon just do location.getChunk().load(); This will load the chunk, but you need to make sure that the chunk isn't loaded before you do that, so put it in a if statement with location.getChunk().isLoaded(); Do this before you spawn the enderdragon and you're done.
     
Thread Status:
Not open for further replies.

Share This Page