Class CitizensNPCRegistry

java.lang.Object
net.citizensnpcs.npc.CitizensNPCRegistry
All Implemented Interfaces:
Iterable<NPC>, NPCRegistry

public class CitizensNPCRegistry extends Object implements NPCRegistry
  • Constructor Details

    • CitizensNPCRegistry

      public CitizensNPCRegistry(NPCDataStore store)
    • CitizensNPCRegistry

      public CitizensNPCRegistry(NPCDataStore store, String registryName)
  • Method Details

    • createNPC

      public NPC createNPC(EntityType type, String name)
      Description copied from interface: NPCRegistry
      Creates an despawned NPC.
      Specified by:
      createNPC in interface NPCRegistry
      Parameters:
      type - EntityType to assign to the NPC
      name - Name to give the NPC
      Returns:
      Created NPC
    • createNPC

      public NPC createNPC(EntityType type, String name, Location loc)
      Description copied from interface: NPCRegistry
      Creates an spawned NPC at the given location.
      Specified by:
      createNPC in interface NPCRegistry
      Parameters:
      type - EntityType to assign to the NPC
      name - Name to give the NPC
      loc - The location to spawn at
      Returns:
      Created NPC
    • createNPC

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

      public NPC createNPCUsingItem(EntityType type, String name, ItemStack item)
      Description copied from interface: NPCRegistry
      Creates an despawned NPC using the given ItemStack to configure it if possible.
      Specified by:
      createNPCUsingItem in interface NPCRegistry
      Parameters:
      type - EntityType to assign to the NPC
      name - Name to give the NPC
      item - ItemStack to configure with
      Returns:
      Created NPC
    • deregister

      public void deregister(NPC npc)
      Description copied from interface: NPCRegistry
      Deregisters the NPC and removes all data about it from the data store.
      Specified by:
      deregister in interface NPCRegistry
      Parameters:
      npc - The NPC to deregister
    • deregisterAll

      public void deregisterAll()
      Description copied from interface: NPCRegistry
      Deregisters all NPCs from this registry. NPCRegistry.deregister(NPC)
      Specified by:
      deregisterAll in interface NPCRegistry
    • despawnNPCs

      public void despawnNPCs(DespawnReason reason)
      Description copied from interface: NPCRegistry
      Despawn all NPCs within the registry.
      Specified by:
      despawnNPCs in interface NPCRegistry
      Parameters:
      reason - The reason to despawn
    • getById

      public NPC getById(int id)
      Description copied from interface: NPCRegistry
      Gets the NPC with the given ID if it exists.
      Specified by:
      getById in interface NPCRegistry
      Parameters:
      id - ID of the NPC
      Returns:
      NPC with the given ID (may or may not be spawned)
    • getByUniqueId

      public NPC getByUniqueId(UUID uuid)
      Description copied from interface: NPCRegistry
      Gets the NPC with the given unique ID if it exists.
      Specified by:
      getByUniqueId in interface NPCRegistry
      Parameters:
      uuid - UUID of the NPC
      Returns:
      NPC with the given ID (may or may not be spawned)
    • getByUniqueIdGlobal

      public NPC getByUniqueIdGlobal(UUID uuid)
      Description copied from interface: NPCRegistry
      Gets the NPC with the given unique ID if it exists, otherwise null.
      Specified by:
      getByUniqueIdGlobal in interface NPCRegistry
      Parameters:
      uuid - ID of the NPC
      Returns:
      NPC with the given UUID
    • getName

      public String getName()
      Description copied from interface: NPCRegistry
      Gets the name of the registry. Not null.
      Specified by:
      getName in interface NPCRegistry
    • getNPC

      public NPC getNPC(Entity entity)
      Description copied from interface: NPCRegistry
      Tries to convert the given Entity to a spawned NPC.
      Specified by:
      getNPC in interface NPCRegistry
      Parameters:
      entity - Entity to get the NPC from
      Returns:
      NPC from the given entity or null if not found.
    • isNPC

      public boolean isNPC(Entity entity)
      Description copied from interface: NPCRegistry
      Checks whether the given Entity is convertable to an NPC.
      Specified by:
      isNPC in interface NPCRegistry
      Parameters:
      entity - Entity to check
      Returns:
      Whether the given entity is an NPC
    • iterator

      public Iterator<NPC> iterator()
      Specified by:
      iterator in interface Iterable<NPC>
    • saveToStore

      public void saveToStore()
      Description copied from interface: NPCRegistry
      Saves the NPCs to the internal NPCDataStore
      Specified by:
      saveToStore in interface NPCRegistry
    • sorted

      public Iterable<NPC> sorted()
      Description copied from interface: NPCRegistry
      Returns a sorted view of this registry, sorted by NPC id.
      Specified by:
      sorted in interface NPCRegistry
      Returns:
      A sorted view of the registry