Package net.citizensnpcs.api.npc
Interface NPC
- All Known Implementing Classes:
- AbstractNPC,- CitizensNPC
Represents an NPC with optional 
Traits.- 
Nested Class SummaryNested Classes
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddRunnable(Runnable runnable) Adds aRunnablethat will run every tick.voidAdds a trait to this NPC.voidAdds a trait to this NPC.clone()copy()data()default booleandespawn()Despawns this NPC.booleandespawn(DespawnReason reason) Despawns this NPC.voiddestroy()Permanently removes this NPC and all data about it from the registry it's attached to.default voiddestroy(CommandSender source) Permanently removes this NPC and all data about it from the registry it's attached to.voidfaceLocation(Location location) Faces a givenLocationif the NPC is spawned.getBlockBreaker(Block targetBlock, BlockBreaker.BlockBreakerConfiguration config) Creates aBlockBreakerthat allows you to break blocks using the Minecraft breaking algorithm.Gets the defaultGoalControllerof this NPC.Gets the defaultSpeechControllerof this NPC.Gets the Bukkit entity associated with this NPC.Gets the full name of this NPC.intgetId()Gets the unique ID of this 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.getName()Gets the name of this NPC with color codes stripped.<T extends Trait>
 TgetOrAddTrait(Class<T> trait) Gets a trait from the given class.If the NPC is not spawned, then this method will return the last known location, or null if it has never been spawned.<T extends Trait>
 TDeprecated.for intransparent naming.<T extends Trait>
 TgetTraitNullable(Class<T> trait) Gets the trait instance with the given class.default <T extends Trait>
 com.google.common.base.Optional<T> getTraitOptional(Class<T> trait) Gets the trait instance with the given class.Returns the currently attachedTraitsGets the unique id of this NPC.booleanChecks if this NPC has the given trait.default booleanReturns whether this NPC is flyable or not.default booleanisHiddenFrom(Player player) Returns whether the given player can see the NPC (i.e. receive packets about it).default booleanGets whether this NPC is protected from damage, movement and other events that players and mobs use to change the entity state of the NPC.default booleanGets whether this NPC is pushable by fluids.booleanGets whether this NPC is currently spawned.booleanisUpdating(NPC.NPCUpdate update) voidvoidremoveTrait(Class<? extends Trait> trait) Removes a trait from this NPC.booleanvoidvoidscheduleUpdate(NPC.NPCUpdate update) default voidsetAlwaysUseNameHologram(boolean use) Sets whether to always use a name hologram instead of the in-built Minecraft name.voidSets theEntityTypeof this NPC.default voidsetFlyable(boolean flyable) Sets whether this NPC is flyable or not.voidsetItemProvider(Supplier<ItemStack> supplier) voidsetMoveDestination(Location destination) Set the destination location to walk towards in a straight line using Minecraft movement.voidSets the name of this NPC.default voidsetProtected(boolean isProtected) A helper method to set the NPC as protected or not protected from damage/entity target events.voidsetSneaking(boolean sneaking) default voidsetUseMinecraftAI(boolean use) Set the NPC to use Minecraft AI where possible.booleanbooleandefault booleanAttempts to spawn this NPC.default booleanspawn(Location location, SpawnReason reason) Attempts to spawn this NPC.booleanspawn(Location at, SpawnReason reason, Consumer<Entity> callback) Attempts to spawn this NPC.voidteleport(Location location, PlayerTeleportEvent.TeleportCause cause) An alternative tonpc.getEntity().getLocation()that teleports passengers as well.default booleanWhether the NPC is currently set to use Minecraft AI.
- 
Method Details- 
addRunnableAdds aRunnablethat will run every tick. Note that removal is not yet supported.- Parameters:
- runnable- Runnable to be added
 
- 
addTraitAdds a trait to this NPC. This will use theTraitFactorydefined for this NPC to construct and attach a trait usingaddTrait(Trait).- Parameters:
- trait- The class of the trait to add
 
- 
addTraitAdds a trait to this NPC.- Parameters:
- trait- Trait to add
 
- 
cloneNPC clone()- Returns:
- A clone of the NPC. May not be an exact copy depending on the Traits installed.
 
- 
copyNPC copy()- Returns:
- A clone of the NPC. May not be an exact copy depending on the Traits installed.
 
- 
dataMetadataStore data()- Returns:
- The metadata store of this NPC.
 
- 
despawndefault boolean despawn()Despawns this NPC. This is equivalent to callingdespawn(DespawnReason)withDespawnReason.PLUGIN.- Returns:
- Whether this NPC was able to despawn
 
- 
despawnDespawns this NPC.- Parameters:
- reason- The reason for despawning, for use in- NPCDespawnEvent
- Returns:
- Whether this NPC was able to despawn
 
- 
destroyvoid destroy()Permanently removes this NPC and all data about it from the registry it's attached to.
- 
destroyPermanently removes this NPC and all data about it from the registry it's attached to.- Parameters:
- source- The source of the removal
 
- 
faceLocationFaces a givenLocationif the NPC is spawned.
- 
getBlockBreakerCreates aBlockBreakerthat allows you to break blocks using the Minecraft breaking algorithm.
- 
getDefaultGoalControllerGoalController getDefaultGoalController()Gets the defaultGoalControllerof this NPC.- Returns:
- Default goal controller
 
- 
getDefaultSpeechControllerSpeechController getDefaultSpeechController()Gets the defaultSpeechControllerof this NPC.- Returns:
- Default speech controller
 
- 
getEntityEntity getEntity()Gets the Bukkit entity associated with this NPC. This may benullifisSpawned()is false.- Returns:
- Entity associated with this NPC
 
- 
getFullNameString getFullName()Gets the full name of this NPC.- Returns:
- Full name of this NPC
 
- 
getIdint getId()Gets the unique ID of this NPC. This is not guaranteed to be globally unique across server sessions.- Returns:
- ID of this NPC
 
- 
getItemProvider- See Also:
 
- 
getMinecraftUniqueIdUUID getMinecraftUniqueId()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 returngetUniqueId()with the necessary changes for the current mob type.- Returns:
- The client unique ID.
 
- 
getNameString getName()Gets the name of this NPC with color codes stripped.- Returns:
- Stripped name of this NPC
 
- 
getOrAddTraitGets a trait from the given class. If the NPC does not currently have the trait then it will be created and attached usingaddTrait(Class).- Parameters:
- trait- Trait to get
- Returns:
- Trait with the given name
 
- 
getOwningRegistryNPCRegistry getOwningRegistry()- Returns:
- The NPCRegistrythat created this NPC.
 
- 
getRawNameString getRawName()
- 
getStoredLocationLocation 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 callingnpc.getBukkitEntity().getLocation().- Returns:
- The stored location, or nullif none was found.
 
- 
getTraitDeprecated.for intransparent naming. UsegetOrAddTrait(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 usingaddTrait(Class).- Parameters:
- trait- Trait class
- Returns:
- Trait with the given class
 
- 
getTraitNullableGets the trait instance with the given class. If the NPC does not currently have the trait,nullwill be returned.- Parameters:
- trait- Trait class
- Returns:
- Trait with the given class
 
- 
getTraitOptionalGets the trait instance with the given class. If the NPC does not currently have the trait,Optional.absent()will be returned.- Parameters:
- trait- Trait class
- Returns:
- Trait with the given class
 
- 
getTraitsReturns the currently attachedTraits- Returns:
- An Iterable of the current traits
 
- 
getUniqueIdUUID getUniqueId()Gets the unique id of this NPC. This is guaranteed to be unique for all NPCs.- Returns:
- The unique id
 
- 
hasTraitChecks if this NPC has the given trait.- Parameters:
- trait- Trait to check
- Returns:
- Whether this NPC has the given trait
 
- 
isFlyabledefault boolean isFlyable()Returns whether this NPC is flyable or not.- Returns:
- Whether this NPC is flyable
 
- 
isHiddenFromReturns whether the given player can see the NPC (i.e. receive packets about it).- Parameters:
- player- The player to check
- Returns:
- Whether the NPC is hidden from the player
 
- 
isProtecteddefault 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
 
- 
isPushableByFluidsdefault boolean isPushableByFluids()Gets whether this NPC is pushable by fluids.- Returns:
- Whether this NPC is pushable by fluids
 
- 
isSpawnedboolean isSpawned()Gets whether this NPC is currently spawned.- Returns:
- Whether this NPC is spawned
 
- 
isUpdating
- 
loadLoads theNPCfrom the givenDataKey. This reloads all traits, respawns the NPC and sets it up for execution. Should not be called often.- Parameters:
- key- The root data key
 
- 
removeTraitRemoves a trait from this NPC.- Parameters:
- trait- Trait to remove
 
- 
requiresNameHologramboolean requiresNameHologram()
- 
saveSaves theNPCto the givenDataKey. This includes all metadata, traits, and spawn information that will allow it to respawn at a later time viaload(DataKey).- Parameters:
- key- The root data key
 
- 
scheduleUpdate
- 
setAlwaysUseNameHologramdefault 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
 
- 
setBukkitEntityTypeSets theEntityTypeof this NPC. The NPC will respawned if currently spawned, or will remain despawned otherwise.- Parameters:
- type- The new mob type
 
- 
setFlyabledefault 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-
 
- 
setItemProvider- Parameters:
- supplier- The supplier
 
- 
setMoveDestinationSet the destination location to walk towards in a straight line using Minecraft movement. Should be called every tick.- Parameters:
- destination- The destination- Location
 
- 
setNameSets the name of this NPC.- Parameters:
- name- Name to give this NPC
 
- 
setProtecteddefault void setProtected(boolean isProtected) A helper method to set the NPC as protected or not protected from damage/entity target events. Equivalent tonpc.data().set(NPC.Metadata#DEFAULT_PROTECTED_METADATA, isProtected);- Parameters:
- isProtected- Whether the NPC should be protected
 
- 
setSneakingvoid setSneaking(boolean sneaking) 
- 
setUseMinecraftAIdefault 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.
- 
shouldRemoveFromPlayerListboolean shouldRemoveFromPlayerList()
- 
shouldRemoveFromTabListboolean shouldRemoveFromTabList()- Returns:
- Whether to remove the NPC from the tablist. Only applicable for Player-type NPCs.
 
- 
spawnAttempts to spawn this NPC.- Parameters:
- location- Location to spawn this NPC
- Returns:
- Whether this NPC was able to spawn at the location
 
- 
spawnAttempts 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
 
- 
spawnAttempts to spawn this NPC.- Parameters:
- reason- Reason for spawning
- callback- The callback to run once entity is spawned
- location- Location to spawn this NPC
- Returns:
- Whether this NPC was able to spawn at the location
 
- 
teleportAn alternative tonpc.getEntity().getLocation()that teleports passengers as well.- Parameters:
- location- The destination location
- cause- The cause for teleporting
 
- 
useMinecraftAIdefault boolean useMinecraftAI()Whether the NPC is currently set to use Minecraft AI. Defaults to false.
 
-