Package net.citizensnpcs.api.npc
Interface NPC
- All Known Implementing Classes:
AbstractNPC
,CitizensNPC
Represents an NPC with optional
Trait
s.-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addRunnable
(Runnable runnable) Adds aRunnable
that will run every tick.void
Adds a trait to this NPC.void
Adds a trait to this NPC.clone()
copy()
data()
boolean
despawn()
Despawns this NPC.boolean
despawn
(DespawnReason reason) Despawns this NPC.void
destroy()
Permanently removes this NPC and all data about it from the registry it's attached to.void
destroy
(CommandSender source) Permanently removes this NPC and all data about it from the registry it's attached to.void
faceLocation
(Location location) Faces a givenLocation
if the NPC is spawned.getBlockBreaker
(Block targetBlock, BlockBreaker.BlockBreakerConfiguration config) Creates aBlockBreaker
that allows you to break blocks using the Minecraft breaking algorithm.Gets the defaultGoalController
of this NPC.Gets the defaultSpeechController
of this NPC.Gets the Bukkit entity associated with this NPC.Gets the full name of this NPC.int
getId()
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 attachedTrait
sGets the unique id of this NPC.boolean
Checks if this NPC has the given trait.boolean
Returns whether this NPC is flyable or not.boolean
isHiddenFrom
(Player player) Returns whether the given player can see the NPC (i.e.boolean
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.boolean
Gets whether this NPC is pushable by fluids.boolean
Gets whether this NPC is currently spawned.boolean
isUpdating
(NPC.NPCUpdate update) void
void
removeTrait
(Class<? extends Trait> trait) Removes a trait from this NPC.boolean
void
void
scheduleUpdate
(NPC.NPCUpdate update) void
setAlwaysUseNameHologram
(boolean use) Sets whether to always use a name hologram instead of the in-built Minecraft name.void
Sets theEntityType
of this NPC.void
setFlyable
(boolean flyable) Sets whether this NPC is flyable or not.void
setItemProvider
(Supplier<ItemStack> supplier) void
setMoveDestination
(Location destination) Set the target movement destination location to walk towards using Minecraft movement.void
Sets the name of this NPC.void
setProtected
(boolean isProtected) A helper method to set the NPC as protected or not protected from damage/entity target events.void
setSneaking
(boolean sneaking) void
setUseMinecraftAI
(boolean use) Set the NPC to use Minecraft AI where possible.boolean
boolean
Attempts to spawn this NPC.boolean
spawn
(Location location, SpawnReason reason) Attempts to spawn this NPC.void
teleport
(Location location, PlayerTeleportEvent.TeleportCause cause) An alternative tonpc.getEntity().getLocation()
that teleports passengers as well.boolean
Whether the NPC is currently set to use Minecraft AI.
-
Method Details
-
addRunnable
Adds aRunnable
that 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 theTraitFactory
defined 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
Trait
s installed.
-
copy
NPC copy()- Returns:
- A clone of the NPC. May not be an exact copy depending on the
Trait
s installed.
-
data
MetadataStore data()- Returns:
- The metadata store of this NPC.
-
despawn
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 givenLocation
if the NPC is spawned. -
getBlockBreaker
Creates aBlockBreaker
that allows you to break blocks using the Minecraft breaking algorithm. -
getDefaultGoalController
GoalController getDefaultGoalController()Gets the defaultGoalController
of this NPC.- Returns:
- Default goal controller
-
getDefaultSpeechController
SpeechController getDefaultSpeechController()Gets the defaultSpeechController
of this NPC.- Returns:
- Default speech controller
-
getEntity
Entity getEntity()Gets the Bukkit entity associated with this NPC. This may benull
ifisSpawned()
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
NPCRegistry
that 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
null
if 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,null
will 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 attachedTrait
s- 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
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
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
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 theNPC
from 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 theNPC
to 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
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 theEntityType
of this NPC. The NPC will respawned if currently spawned, or will remain despawned otherwise.- Parameters:
type
- The new mob 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
-
-
setItemProvider
- Parameters:
supplier
- The supplier
-
setMoveDestination
Set the target movement destination location to walk towards using Minecraft movement. Should be set every tick.- Parameters:
destination
- The destinationLocation
-
setName
Sets the name of this NPC.- Parameters:
name
- Name to give this NPC
-
setProtected
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
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. -
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
-
teleport
An alternative tonpc.getEntity().getLocation()
that teleports passengers as well.- Parameters:
location
- The destination locationcause
- The cause for teleporting
-
useMinecraftAI
boolean useMinecraftAI()Whether the NPC is currently set to use Minecraft AI. Defaults to false.
-