Class AbstractNPC

java.lang.Object
net.citizensnpcs.api.npc.AbstractNPC
All Implemented Interfaces:
Cloneable, Agent, NPC
Direct Known Subclasses:
CitizensNPC

public abstract class AbstractNPC extends Object implements NPC
  • Field Details

    • coloredNameComponentCache

      protected Object coloredNameComponentCache
    • coloredNameStringCache

      protected String coloredNameStringCache
    • traits

      protected final Map<Class<? extends Trait>,Trait> traits
  • Constructor Details

  • Method Details

    • addRunnable

      public void addRunnable(Runnable runnable)
      Description copied from interface: NPC
      Adds a Runnable that will run every tick. Note that removal is not yet supported.
      Specified by:
      addRunnable in interface NPC
      Parameters:
      runnable - Runnable to be added
    • addTrait

      public void addTrait(Class<? extends Trait> clazz)
      Description copied from interface: NPC
      Adds a trait to this NPC. This will use the TraitFactory defined for this NPC to construct and attach a trait using NPC.addTrait(Trait).
      Specified by:
      addTrait in interface NPC
      Parameters:
      clazz - The class of the trait to add
    • addTrait

      public void addTrait(Trait trait)
      Description copied from interface: NPC
      Adds a trait to this NPC.
      Specified by:
      addTrait in interface NPC
      Parameters:
      trait - Trait to add
    • clone

      public NPC clone()
      Specified by:
      clone in interface NPC
      Overrides:
      clone in class Object
      Returns:
      A clone of the NPC. May not be an exact copy depending on the Traits installed.
    • copy

      public NPC copy()
      Specified by:
      copy in interface NPC
      Returns:
      A clone of the NPC. May not be an exact copy depending on the Traits installed.
    • data

      public MetadataStore data()
      Specified by:
      data in interface NPC
      Returns:
      The metadata store of this NPC.
    • destroy

      public void destroy()
      Description copied from interface: NPC
      Permanently removes this NPC and all data about it from the registry it's attached to.
      Specified by:
      destroy in interface NPC
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • getDefaultGoalController

      public GoalController getDefaultGoalController()
      Description copied from interface: NPC
      Gets the default GoalController of this NPC.
      Specified by:
      getDefaultGoalController in interface NPC
      Returns:
      Default goal controller
    • getDefaultSpeechController

      public SpeechController getDefaultSpeechController()
      Description copied from interface: NPC
      Gets the default SpeechController of this NPC.
      Specified by:
      getDefaultSpeechController in interface NPC
      Returns:
      Default speech controller
    • getEntityType

      protected EntityType getEntityType()
    • getFullName

      public String getFullName()
      Description copied from interface: NPC
      Gets the full name of this NPC.
      Specified by:
      getFullName in interface NPC
      Returns:
      Full name of this NPC
    • getId

      public int getId()
      Description copied from interface: NPC
      Gets the unique ID of this NPC. This is not guaranteed to be globally unique across server sessions.
      Specified by:
      getId in interface NPC
      Returns:
      ID of this NPC
    • getItemProvider

      public Supplier<ItemStack> getItemProvider()
      Specified by:
      getItemProvider in interface NPC
      See Also:
    • getMinecraftUniqueId

      public UUID getMinecraftUniqueId()
      Description copied from interface: NPC
      For certain mob types (currently, Players) it is beneficial to change the UUID slightly to signal to the client that the mob is an NPC not a real mob. This will return NPC.getUniqueId() with the necessary changes for the current mob type.
      Specified by:
      getMinecraftUniqueId in interface NPC
      Returns:
      The client unique ID.
    • getName

      public String getName()
      Description copied from interface: NPC
      Gets the name of this NPC with color codes stripped.
      Specified by:
      getName in interface NPC
      Returns:
      Stripped name of this NPC
    • getOrAddTrait

      public <T extends Trait> T getOrAddTrait(Class<T> clazz)
      Description copied from interface: NPC
      Gets a trait from the given class. If the NPC does not currently have the trait then it will be created and attached using NPC.addTrait(Class) .
      Specified by:
      getOrAddTrait in interface NPC
      Parameters:
      clazz - Trait to get
      Returns:
      Trait with the given name
    • getOwningRegistry

      public NPCRegistry getOwningRegistry()
      Specified by:
      getOwningRegistry in interface NPC
      Returns:
      The NPCRegistry that created this NPC.
    • getRawName

      public String getRawName()
      Specified by:
      getRawName in interface NPC
    • getTrait

      public <T extends Trait> T getTrait(Class<T> trait)
      Description copied from interface: NPC
      Gets a trait from the given class. If the NPC does not currently have the trait then it will be created and attached using NPC.addTrait(Class) .
      Specified by:
      getTrait in interface NPC
      Parameters:
      trait - Trait class
      Returns:
      Trait with the given class
    • getTraitFor

      protected Trait getTraitFor(Class<? extends Trait> clazz)
    • getTraitNullable

      public <T extends Trait> T getTraitNullable(Class<T> clazz)
      Description copied from interface: NPC
      Gets the trait instance with the given class. If the NPC does not currently have the trait, null will be returned.
      Specified by:
      getTraitNullable in interface NPC
      Parameters:
      clazz - Trait class
      Returns:
      Trait with the given class
    • getTraits

      public Iterable<Trait> getTraits()
      Description copied from interface: NPC
      Returns the currently attached Traits
      Specified by:
      getTraits in interface NPC
      Returns:
      An Iterable of the current traits
    • getUniqueId

      public UUID getUniqueId()
      Description copied from interface: NPC
      Gets the unique id of this NPC. This is guaranteed to be unique for all NPCs.
      Specified by:
      getUniqueId in interface NPC
      Returns:
      The unique id
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • hasTrait

      public boolean hasTrait(Class<? extends Trait> trait)
      Description copied from interface: NPC
      Checks if this NPC has the given trait.
      Specified by:
      hasTrait in interface NPC
      Parameters:
      trait - Trait to check
      Returns:
      Whether this NPC has the given trait
    • load

      public void load(DataKey root)
      Description copied from interface: NPC
      Loads the NPC from the given DataKey. This reloads all traits, respawns the NPC and sets it up for execution. Should not be called often.
      Specified by:
      load in interface NPC
      Parameters:
      root - The root data key
    • removeTrait

      public void removeTrait(Class<? extends Trait> traitClass)
      Description copied from interface: NPC
      Removes a trait from this NPC.
      Specified by:
      removeTrait in interface NPC
      Parameters:
      traitClass - Trait to remove
    • requiresNameHologram

      public boolean requiresNameHologram()
      Specified by:
      requiresNameHologram in interface NPC
    • save

      public void save(DataKey root)
      Description copied from interface: NPC
      Saves the NPC to the given DataKey. This includes all metadata, traits, and spawn information that will allow it to respawn at a later time via NPC.load(DataKey).
      Specified by:
      save in interface NPC
      Parameters:
      root - The root data key
    • setItemProvider

      public void setItemProvider(Supplier<ItemStack> provider)
      Description copied from interface: NPC
      For item-type NPCs, set a Supplier of the ItemStack to use when spawning the NPC.
      Specified by:
      setItemProvider in interface NPC
      Parameters:
      provider - The supplier
    • setName

      public void setName(String name)
      Description copied from interface: NPC
      Sets the name of this NPC.
      Specified by:
      setName in interface NPC
      Parameters:
      name - Name to give this NPC
    • setNameInternal

      protected void setNameInternal(String name)
    • teleport

      public void teleport(Location location, PlayerTeleportEvent.TeleportCause cause)
      Description copied from interface: NPC
      An alternative to npc.getEntity().getLocation() that teleports passengers as well.
      Specified by:
      teleport in interface NPC
      Parameters:
      location - The destination location
      cause - The cause for teleporting
    • update

      public void update()