Package net.citizensnpcs.api.npc
Interface NPC
- All Known Implementing Classes:
AbstractNPC,CitizensNPC
Represents an NPC with optional
Traits.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier 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
-
addRunnable
Adds aRunnablethat will run every tick. Note that removal is not yet supported.- Parameters:
runnable- Runnable to be added
-
addTrait
Adds 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
-
addTrait
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
MetadataStore data()- Returns:
- The metadata store of this NPC.
-
despawn
default boolean despawn()Despawns this NPC. This is equivalent to callingdespawn(DespawnReason)withDespawnReason.PLUGIN.- Returns:
- Whether this NPC was able to despawn
-
despawn
Despawns this NPC.- Parameters:
reason- The reason for despawning, for use inNPCDespawnEvent- 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
Permanently removes this NPC and all data about it from the registry it's attached to.- Parameters:
source- The source of the removal
-
faceLocation
Faces a givenLocationif the NPC is spawned. -
getBlockBreaker
Creates aBlockBreakerthat allows you to break blocks using the Minecraft breaking algorithm. -
getDefaultGoalController
GoalController getDefaultGoalController()Gets the defaultGoalControllerof this NPC.- Returns:
- Default goal controller
-
getDefaultSpeechController
SpeechController getDefaultSpeechController()Gets the defaultSpeechControllerof this NPC.- Returns:
- Default speech controller
-
getEntity
Entity getEntity()Gets the Bukkit entity associated with this NPC. This may benullifisSpawned()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
-
getItemProvider
- See Also:
-
getMinecraftUniqueId
UUID 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.
-
getName
String getName()Gets the name of this NPC with color codes stripped.- Returns:
- Stripped name of this NPC
-
getOrAddTrait
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 to get- Returns:
- Trait with the given name
-
getOwningRegistry
NPCRegistry getOwningRegistry()- Returns:
- The
NPCRegistrythat created this NPC.
-
getRawName
String getRawName() -
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 callingnpc.getBukkitEntity().getLocation().- Returns:
- The stored location, or
nullif none was found.
-
getTrait
Deprecated.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
-
getTraitNullable
Gets 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
-
getTraitOptional
Gets 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
-
getTraits
Returns the currently attachedTraits- 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
Checks if this NPC has the given trait.- Parameters:
trait- Trait to check- Returns:
- Whether this NPC has the given trait
-
isFlyable
default boolean isFlyable()Returns whether this NPC is flyable or not.- Returns:
- Whether this NPC is flyable
-
isHiddenFrom
Returns 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
-
isProtected
default 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
-
isPushableByFluids
default boolean isPushableByFluids()Gets whether this NPC is pushable by fluids.- Returns:
- Whether this NPC is pushable by fluids
-
isSpawned
boolean isSpawned()Gets whether this NPC is currently spawned.- Returns:
- Whether this NPC is spawned
-
isUpdating
-
load
Loads 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
-
removeTrait
Removes a trait from this NPC.- Parameters:
trait- Trait to remove
-
requiresNameHologram
boolean requiresNameHologram() -
save
Saves 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
-
setAlwaysUseNameHologram
default 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
Sets theEntityTypeof this NPC. The NPC will respawned if currently spawned, or will remain despawned otherwise.- Parameters:
type- The new mob type
-
setFlyable
default 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
-
setMoveDestination
Set the destination location to walk towards in a straight line using Minecraft movement. Should be called every tick.- Parameters:
destination- The destinationLocation
-
setName
Sets the name of this NPC.- Parameters:
name- Name to give this NPC
-
setProtected
default 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
-
setSneaking
void setSneaking(boolean sneaking) -
setUseMinecraftAI
default 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. -
shouldRemoveFromPlayerList
boolean shouldRemoveFromPlayerList() -
shouldRemoveFromTabList
boolean shouldRemoveFromTabList()- Returns:
- Whether to remove the NPC from the tablist. Only applicable for
Player-type NPCs.
-
spawn
Attempts to spawn this NPC.- Parameters:
location- Location to spawn this NPC- Returns:
- Whether this NPC was able to spawn at the location
-
spawn
Attempts to spawn this NPC.- Parameters:
location- Location to spawn this NPCreason- Reason for spawning- Returns:
- Whether this NPC was able to spawn at the location
-
spawn
Attempts to spawn this NPC.- Parameters:
reason- Reason for spawningcallback- The callback to run once entity is spawnedlocation- Location to spawn this NPC- Returns:
- Whether this NPC was able to spawn at the location
-
teleport
An alternative tonpc.getEntity().getLocation()that teleports passengers as well.- Parameters:
location- The destination locationcause- The cause for teleporting
-
useMinecraftAI
default boolean useMinecraftAI()Whether the NPC is currently set to use Minecraft AI. Defaults to false.
-