Interface NPC

All Superinterfaces:
Agent, Cloneable
All Known Implementing Classes:
AbstractNPC, CitizensNPC

public interface NPC extends Agent, Cloneable
Represents an NPC with optional Traits.
  • Field Details

    • ALWAYS_USE_NAME_HOLOGRAM_METADATA

      static final String ALWAYS_USE_NAME_HOLOGRAM_METADATA
      See Also:
    • AMBIENT_SOUND_METADATA

      static final String AMBIENT_SOUND_METADATA
      The Minecraft ambient sound played. String - Minecraft sound name
      See Also:
    • COLLIDABLE_METADATA

      static final String COLLIDABLE_METADATA
      Whether the NPC is collidable with Players or not. Boolean.
      See Also:
    • DAMAGE_OTHERS_METADATA

      static final String DAMAGE_OTHERS_METADATA
      Whether the NPC can damage other Entities. Boolean.
      See Also:
    • DEATH_SOUND_METADATA

      static final String DEATH_SOUND_METADATA
      The Minecraft sound played when the NPC dies. String - Minecraft sound name.
      See Also:
    • DEFAULT_PROTECTED_METADATA

      static final String DEFAULT_PROTECTED_METADATA
      Whether the NPC is 'protected' i.e. invulnerable to damage. Boolean.
      See Also:
    • DISABLE_DEFAULT_STUCK_ACTION_METADATA

      static final String DISABLE_DEFAULT_STUCK_ACTION_METADATA
      See Also:
    • DROPS_ITEMS_METADATA

      static final String DROPS_ITEMS_METADATA
      Whether the NPC drops its inventory after death. Boolean.
      See Also:
    • FLYABLE_METADATA

      static final String FLYABLE_METADATA
      Whether the NPC is 'flyable' i.e. will fly when pathfinding. Boolean.
      See Also:
    • GLOWING_COLOR_METADATA

      static final String GLOWING_COLOR_METADATA
      The color to glow using Minecraft's scoreboard glowing feature. Should be a Enum.name(). DEPRECATED: use ScoreboardTrait instead
      See Also:
    • GLOWING_METADATA

      static final String GLOWING_METADATA
      Whether the NPC is currently glowing. Boolean.
      See Also:
    • HURT_SOUND_METADATA

      static final String HURT_SOUND_METADATA
      The Minecraft sound to play when hurt. String - Minecraft sound name.
      See Also:
    • ITEM_AMOUNT_METADATA

      static final String ITEM_AMOUNT_METADATA
      The Item amount. Integer.
      See Also:
    • ITEM_DATA_METADATA

      static final String ITEM_DATA_METADATA
      The Item data. Byte.
      See Also:
    • ITEM_ID_METADATA

      static final String ITEM_ID_METADATA
      The Item ID. String.
      See Also:
    • KEEP_CHUNK_LOADED_METADATA

      static final String KEEP_CHUNK_LOADED_METADATA
      Whether to keep chunk loaded. Boolean.
      See Also:
    • LEASH_PROTECTED_METADATA

      static final String LEASH_PROTECTED_METADATA
      Whether the NPC is leashable. Boolean.
      See Also:
    • MINECART_ITEM_DATA_METADATA

      static final String MINECART_ITEM_DATA_METADATA
      The Minecart item data. Byte.
      See Also:
    • MINECART_ITEM_METADATA

      static final String MINECART_ITEM_METADATA
      The Minecart item name.
      See Also:
    • MINECART_OFFSET_METADATA

      static final String MINECART_OFFSET_METADATA
      The Minecart item offset as defined by Minecraft. Minecart.setDisplayBlockOffset(int)
      See Also:
    • NAMEPLATE_VISIBLE_METADATA

      static final String NAMEPLATE_VISIBLE_METADATA
      Whether the NPC's nameplate should be visible. Boolean.
      See Also:
    • PATHFINDER_OPEN_DOORS_METADATA

      static final String PATHFINDER_OPEN_DOORS_METADATA
      Whether to open doors while pathfinding. Boolean.
      See Also:
    • PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA

      @Deprecated static final String PLAYER_SKIN_TEXTURE_PROPERTIES_METADATA
      Deprecated.
      See Also:
    • PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN_METADATA

      @Deprecated static final String PLAYER_SKIN_TEXTURE_PROPERTIES_SIGN_METADATA
      Deprecated.
      See Also:
    • PLAYER_SKIN_USE_LATEST

      @Deprecated static final String PLAYER_SKIN_USE_LATEST
      Deprecated.
      See Also:
    • PLAYER_SKIN_UUID_METADATA

      @Deprecated static final String PLAYER_SKIN_UUID_METADATA
      Deprecated.
      See Also:
    • REMOVE_FROM_PLAYERLIST_METADATA

      static final String REMOVE_FROM_PLAYERLIST_METADATA
      Whether to remove players from the player list. Boolean defaults to true.
      See Also:
    • RESPAWN_DELAY_METADATA

      static final String RESPAWN_DELAY_METADATA
      The Integer delay to respawn in ticks after death. Only works if non-zero.
      See Also:
    • SCOREBOARD_FAKE_TEAM_NAME_METADATA

      static final String SCOREBOARD_FAKE_TEAM_NAME_METADATA
      The fake NPC scoreboard team name because Minecraft requires a team name. Usually will be a random UUID in String form.
      See Also:
    • SHOULD_SAVE_METADATA

      static final String SHOULD_SAVE_METADATA
      Whether to save / persist across server restarts. Boolean.
      See Also:
    • SILENT_METADATA

      static final String SILENT_METADATA
      Whether to suppress sounds. Boolean.
      See Also:
    • SNEAKING_METADATA

      static final String SNEAKING_METADATA
      Whether to sneak. Boolean.
      See Also:
    • SWIMMING_METADATA

      static final String SWIMMING_METADATA
      Whether to allow swimming. Boolean.
      See Also:
    • TARGETABLE_METADATA

      static final String TARGETABLE_METADATA
      Whether to prevent NPC being targeted by hostile mobs. Boolean.
      See Also:
    • USE_MINECRAFT_AI_METADATA

      static final String USE_MINECRAFT_AI_METADATA
      Whether to use Minecraft AI. Boolean.
      See Also:
    • VILLAGER_BLOCK_TRADES

      static final String VILLAGER_BLOCK_TRADES
      Whether to block Minecraft villager trades. Boolean defaults to true.
      See Also:
  • Method Details

    • addRunnable

      void addRunnable(Runnable runnable)
      Adds a Runnable that will run every tick. Note that removal is not yet supported.
      Parameters:
      runnable - Runnable to be added
    • addTrait

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

      void addTrait(Trait trait)
      Adds a trait to this NPC.
      Parameters:
      trait - Trait to add
    • clone

      NPC clone()
      Returns:
      A clone of the NPC. May not be an exact copy depending on the Traits installed.
    • copy

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

      Returns:
      The metadata store of this NPC.
    • despawn

      boolean despawn()
      Despawns this NPC. This is equivalent to calling despawn(DespawnReason) with DespawnReason.PLUGIN.
      Returns:
      Whether this NPC was able to despawn
    • despawn

      boolean despawn(DespawnReason reason)
      Despawns this NPC.
      Parameters:
      reason - The reason for despawning, for use in NPCDespawnEvent
      Returns:
      Whether this NPC was able to despawn
    • destroy

      void destroy()
      Permanently removes this NPC and all data about it from the registry it's attached to.
    • destroy

      void destroy(CommandSender source)
      Permanently removes this NPC and all data about it from the registry it's attached to.
      Parameters:
      source - The source of the removal
    • faceLocation

      void faceLocation(Location location)
      Faces a given Location if the NPC is spawned.
    • getBlockBreaker

      BlockBreaker getBlockBreaker(Block targetBlock, BlockBreaker.BlockBreakerConfiguration config)
    • getDefaultGoalController

      GoalController getDefaultGoalController()
      Gets the default GoalController of this NPC.
      Returns:
      Default goal controller
    • getDefaultSpeechController

      SpeechController getDefaultSpeechController()
      Gets the default SpeechController of this NPC.
      Returns:
      Default speech controller
    • getEntity

      Entity getEntity()
      Gets the Bukkit entity associated with this NPC. This may be null if isSpawned() is false.
      Returns:
      Entity associated with this NPC
    • getFullName

      String getFullName()
      Gets the full name of this NPC.
      Returns:
      Full name of this NPC
    • getId

      int getId()
      Gets the unique ID of this NPC. This is not guaranteed to be globally unique across server sessions.
      Returns:
      ID of this NPC
    • getName

      String getName()
      Gets the name of this NPC with color codes stripped.
      Returns:
      Stripped name of this NPC
    • getNavigator

      Navigator getNavigator()
      Returns:
      The Navigator of this NPC.
    • getOrAddTrait

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

      NPCRegistry getOwningRegistry()
      Returns:
      The NPCRegistry that created this NPC.
    • getStoredLocation

      Location getStoredLocation()
      If the NPC is not spawned, then this method will return the last known location, or null if it has never been spawned. Otherwise, it is equivalent to calling npc.getBukkitEntity().getLocation().
      Returns:
      The stored location, or null if none was found.
    • getTrait

      @Deprecated <T extends Trait> T getTrait(Class<T> trait)
      Deprecated.
      for intransparent naming. Use getOrAddTrait(Class) for the same behavior.
      Gets a trait from the given class. If the NPC does not currently have the trait then it will be created and attached using addTrait(Class) .
      Parameters:
      trait - Trait to get
      Returns:
      Trait with the given name
    • getTraitNullable

      <T extends Trait> T getTraitNullable(Class<T> trait)
      Gets a trait from the given class. If the NPC does not currently have the trait, null will be returned.
      Parameters:
      trait - Trait to get
      Returns:
      Trait with the given name
    • getTraits

      Iterable<Trait> getTraits()
      Returns the currently attached Traits
      Returns:
      An Iterable of the current traits
    • getUniqueId

      UUID getUniqueId()
      Gets the unique id of this NPC. This is guaranteed to be unique for all NPCs.
      Returns:
      The unique id
    • hasTrait

      boolean hasTrait(Class<? extends Trait> trait)
      Checks if this NPC has the given trait.
      Parameters:
      trait - Trait to check
      Returns:
      Whether this NPC has the given trait
    • isFlyable

      boolean isFlyable()
      Returns whether this NPC is flyable or not.
      Returns:
      Whether this NPC is flyable
    • isProtected

      boolean isProtected()
      Gets whether this NPC is protected from damage, movement and other events that players and mobs use to change the entity state of the NPC.
      Returns:
      Whether this NPC is protected
    • isSpawned

      boolean isSpawned()
      Gets whether this NPC is currently spawned.
      Returns:
      Whether this NPC is spawned
    • load

      void load(DataKey key)
      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.
      Parameters:
      key - The root data key
    • removeTrait

      void removeTrait(Class<? extends Trait> trait)
      Removes a trait from this NPC.
      Parameters:
      trait - Trait to remove
    • requiresNameHologram

      boolean requiresNameHologram()
    • save

      void save(DataKey key)
      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 load(DataKey).
      Parameters:
      key - The root data key
    • setAlwaysUseNameHologram

      void setAlwaysUseNameHologram(boolean use)
      Sets whether to always use a name hologram instead of the in-built Minecraft name.
      Parameters:
      use - Whether to use a hologram
    • setBukkitEntityType

      void setBukkitEntityType(EntityType type)
      Sets the EntityType of this NPC. Currently only accepts living entity types, with scope for additional types in the future. The NPC will respawned if currently spawned, or will remain despawned otherwise.
      Parameters:
      type - The new mob type
      Throws:
      IllegalArgumentException - If the type is not a living entity type
    • setFlyable

      void setFlyable(boolean flyable)
      Sets whether this NPC is flyable or not. Note that this is intended for normally ground-based entities only - it will generally have no effect on mob types that were originally flyable.
      Parameters:
      flyable -
    • setName

      void setName(String name)
      Sets the name of this NPC.
      Parameters:
      name - Name to give this NPC
    • setProtected

      void setProtected(boolean isProtected)
      A helper method for using DEFAULT_PROTECTED_METADATA to set the NPC as protected or not protected from damage/entity target events. Equivalent to npc.data().set(NPC.DEFAULT_PROTECTED_METADATA, isProtected);
      Parameters:
      isProtected - Whether the NPC should be protected
    • setUseMinecraftAI

      void setUseMinecraftAI(boolean use)
      Set the NPC to use Minecraft AI where possible. Note that the NPC may not always behave exactly like a Minecraft mob would because of additional Citizens APIs.
    • spawn

      boolean spawn(Location location)
      Attempts to spawn this NPC.
      Parameters:
      location - Location to spawn this NPC
      Returns:
      Whether this NPC was able to spawn at the location
    • spawn

      boolean spawn(Location location, SpawnReason reason)
      Attempts to spawn this NPC.
      Parameters:
      location - Location to spawn this NPC
      reason - Reason for spawning
      Returns:
      Whether this NPC was able to spawn at the location
    • teleport

      void teleport(Location location, PlayerTeleportEvent.TeleportCause cause)
      An alternative to npc.getEntity().getLocation() that teleports passengers as well.
      Parameters:
      location - The destination location
      cause - The cause for teleporting
    • useMinecraftAI

      boolean useMinecraftAI()
      Whether the NPC is currently set to use Minecraft AI. Defaults to false.