Villagers Despawning

Discussion in 'Plugin Development' started by GeorgeeeHD, Oct 28, 2014.

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

    GeorgeeeHD

    I have these villagers in the spawn for my server that do stuff when you right click them. The way if have it setup is onEnable() it spawns them in and onDisable() removes them, however, when I start up the server, if nobody is online, they do not spawn in. Anyone know why this happens or how to fix?
     
  2. Offline

    TheCodingCat

    code please for on Enable and on disable
     
  3. Offline

    GeorgeeeHD

    TheCodingCat
    It's literally just spawning a few villagers.

    Code:java
    1. public void spawnNPCs() {
    2.  
    3. Location[] locations = new Location[] {
    4. new Location(Bukkit.getWorld("world"), 17.5, 63, 17.5, 135, 0),
    5. new Location(Bukkit.getWorld("world"), -14.5, 63, 19.5, -135, 0),
    6. new Location(Bukkit.getWorld("world"), -18.5, 63, 15.5, -135, 0),
    7. new Location(Bukkit.getWorld("world"), -16.5, 63, -16.5, -135, 0),
    8. new Location(Bukkit.getWorld("world"), 17.5, 63, -16.5, -135, 0)
    9. };
    10.  
    11. String[] names = new String[] {
    12. ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "Shop",
    13. ChatColor.GREEN + "" + ChatColor.BOLD + "Join Event",
    14. ChatColor.RED + "" + ChatColor.BOLD + "Leave Event",
    15. ChatColor.BLUE + "" + ChatColor.BOLD + "Join Raffle",
    16. ChatColor.YELLOW + "" + ChatColor.BOLD + "Visit The Buycraft"
    17. };
    18.  
    19. for(int i = 0 ; i < locations.length ; i++) {
    20. Villager villager = Bukkit.getWorld("world").spawn(locations[i], Villager.class);
    21. villager.setProfession(Villager.Profession.LIBRARIAN);
    22. villager.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, Integer.MAX_VALUE, 10, true));
    23. villager.setCustomName(names[i]);
    24. villager.setCustomNameVisible(true);
    25. villagers.put(villager, locations[i]);
    26. }
    27.  
    28. }[/i][/i][/i]
     
  4. Offline

    jpjunho

    GeorgeeeHD
    Try loading the chunk of the location
     
  5. Offline

    jensdeboom

    GeorgeeeHD if none is online, the chunk isnt loaded so no villagers can be spawned. Try loading the chunk first or spawn the villagers on PlayerLoginEvent and delay it with 1 tick. Big sub btw :p
     
  6. Offline

    GeorgeeeHD

    jpjunho
    Didn't work :(

    jensdeboom
    :D, loading the chunks had no effect on it btw

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

    TheCodingCat

    set to the villager removeFarAway to false, and cancel the event that de pawns entities (if available)
     
  8. Offline

    GeorgeeeHD

    TheCodingCat
    Still didn't work, and pretty sure there is no event that catches the despawning of an entity.
     
  9. Offline

    TheCodingCat

    why are you removing them onDisable? I must ask GeorgeeeHD
     
  10. Offline

    GeorgeeeHD

    TheCodingCat
    Well I have a Map of the Villager and their Location so that when a player nudges them, I can move them back to their original position. I remove them so that when I reload the server, it makes fresh villagers and puts them in the Map, this prevents duplicate villagers
     
Thread Status:
Not open for further replies.

Share This Page