[Solved] Villager not deleting

Discussion in 'Spigot Plugin Development' started by TomTheDeveloper, Jul 4, 2015.

  1. TomTheDeveloper

    Supporter

    Hey there guys. Today I stumbled upon an issue I can't fix.

    Here is my code: http://pastebin.com/acC6a3Aq (Also tried .seHealth(0))

    However it is looping through the villagers but it's not teleporting or removing them.... I also placed a debug message System.out.println(villager.getCustomName()) and it did print their names.. though they are not getting removed.

    Extra information: It are custom made villagers that are ridable by using "extend EntityVillager"
     
    #1 TomTheDeveloper, Jul 4, 2015
    Last edited: Jul 4, 2015
  2. The "Villager" class in Spigot is an interface, how are you extending it? Do you mean you are extending CraftVillager or EntityVillager?
     
  3. TomTheDeveloper

    Supporter

    Haha. I mean EntityVillager. I am extending EntityVillager ;)
     
  4. remove the villager from your worldserver
     
    • Agree Agree x 1
  5. If you are extending EntityVillager, try villager.die(). Also, if you can post your custom villager class as well, that would be helpful.
     
  6. TomTheDeveloper

    Supporter

    @magicmq
    http://pastebin.com/qmkPwRDa Here is the villager class.

    In the for loop I am actually using a .getBukkitEntity() (so just a craftEntity) so there is no .die() method. However I will change my code a little bit to try the .die() method from the EntityVillager class out. Thanks
     
  7. TomTheDeveloper

    Supporter

    Hmm .die() is also not working. I am thinking that I made somewhere a terrible mistake that I can't find. But I have no clue at all where....

    Cause it says that the console is removing those villagers...
     
  8. TomTheDeveloper

    Supporter

    That's what I am trying to do sir? Deleting the villager...
     
  9. TomTheDeveloper

    Supporter

    I just discovered that the code is not wrong. It is correct. However when the chunks are unloaded, the plugin is unable to delete the villagers but able to spawn new villagers... Hmm How should I go about fixing this?
     
  10. you have to remove the entity from your worldserver by using getBukkitEntity().remove()
    and getBukkitEntity.getWorld().removeEntity(getBukkitEntity().get...)
     
    • Agree Agree x 2
  11. Yeah, I think you might need to do what @Ploxh4D said, and remove it from the world as well, but I'm not sure as I have removed entities before through entity.remove() just fine without any other code...
     
  12. TomTheDeveloper

    Supporter

    The entity.remove() method just works fine only when the Chunk isn't loaded

    Btw there isn't a method like getWorld().removeEntity(...)
     
  13. what type of getWorld() are you using it must be a WorldServer
     
  14. Is it possible, that the chunk your villager is in isnt loaded? Try to load it:

    Location.getChunk().load();
     
  15. TomTheDeveloper

    Supporter

    The ChunkLoadEvent got the job done
     
  16. villager.remove by

    List<Entity> nearby = p.getNearbyEntities(2, 2, 2);