Interface NPCRegistry

All Superinterfaces:
Iterable<NPC>
All Known Implementing Classes:
CitizensNPCRegistry

public interface NPCRegistry extends Iterable<NPC>
Controls the registration and lookup of a set of NPCs.
  • Method Details

    • createNPC

      NPC createNPC(EntityType type, String name)
      Creates an despawned NPC.
      Parameters:
      type - EntityType to assign to the NPC
      name - Name to give the NPC
      Returns:
      Created NPC
    • createNPC

      NPC createNPC(EntityType type, String name, Location loc)
      Creates an spawned NPC at the given location.
      Parameters:
      type - EntityType to assign to the NPC
      name - Name to give the NPC
      loc - The location to spawn at
      Returns:
      Created NPC
    • createNPC

      NPC createNPC(EntityType type, UUID uuid, int id, String name)
      Creates an NPC with the given id. WARNING: may overwrite any existing NPC in the registry with the same ID.
      Parameters:
      type - The EntityType of the NPC.
      id - The NPC ID
      name - The NPC name
      Returns:
      The created NPC
    • createNPCUsingItem

      NPC createNPCUsingItem(EntityType type, String name, ItemStack item)
      Creates an despawned NPC using the given ItemStack to configure it if possible.
      Parameters:
      type - EntityType to assign to the NPC
      name - Name to give the NPC
      item - ItemStack to configure with
      Returns:
      Created NPC
    • deregister

      void deregister(NPC npc)
      Deregisters the NPC and removes all data about it from the data store.
      Parameters:
      npc - The NPC to deregister
    • deregisterAll

      void deregisterAll()
      Deregisters all NPCs from this registry. deregister(NPC)
    • despawnNPCs

      void despawnNPCs(DespawnReason reason)
      Despawn all NPCs within the registry.
      Parameters:
      reason - The reason to despawn
    • getById

      NPC getById(int id)
      Gets the NPC with the given ID if it exists.
      Parameters:
      id - ID of the NPC
      Returns:
      NPC with the given ID (may or may not be spawned)
    • getByUniqueId

      NPC getByUniqueId(UUID uuid)
      Gets the NPC with the given unique ID if it exists.
      Parameters:
      uuid - UUID of the NPC
      Returns:
      NPC with the given ID (may or may not be spawned)
    • getByUniqueIdGlobal

      NPC getByUniqueIdGlobal(UUID uuid)
      Gets the NPC with the given unique ID if it exists, otherwise null.
      Parameters:
      uuid - ID of the NPC
      Returns:
      NPC with the given UUID
    • getName

      String getName()
      Gets the name of the registry. Not null.
    • getNPC

      NPC getNPC(Entity entity)
      Tries to convert the given Entity to a spawned NPC.
      Parameters:
      entity - Entity to get the NPC from
      Returns:
      NPC from the given entity or null if not found.
    • isNPC

      boolean isNPC(Entity entity)
      Checks whether the given Entity is convertable to an NPC.
      Parameters:
      entity - Entity to check
      Returns:
      Whether the given entity is an NPC
    • saveToStore

      void saveToStore()
      Saves the NPCs to the internal NPCDataStore
    • sorted

      Iterable<NPC> sorted()
      Returns a sorted view of this registry, sorted by NPC id.
      Returns:
      A sorted view of the registry