1.16.5 I want to select all npc's on my server (Citizens API)

Discussion in 'Spigot Plugin Development' started by Lolmaster5000, Jul 14, 2021.

  1. Hello I want to select all npc's on my server to remove them after every reload/restart, I tried it already with this but it didnt worked:

    Code (Text):
    for (NPC npc : CitizensAPI.getNPCRegistry()) {
  2. When did you called this? In the onEnable method?
  3. yes it is
  4. Did you add Citizen as dependency on your plugin.yml?
    Looking at the Javadoc for CitizensAPI, you could also use deregisterAll()
  5. i got it working now but the code after that doesent call anymore
  6. You must wait a few ticks after final server initialization to do operations on the NPCs (before this, the NPCs are not loaded and so calling NPC#destroy will not do anything.
    To do that, in the onEnable method call:
    Code (Java):
    Bukkit.getScheduler().runTaskLater(this, CitizensAPI.getNPCRegistry()::deregisterAll, 2);
    • Agree Agree x 1