Package net.citizensnpcs.api.npc
Class AbstractNPC
java.lang.Object
net.citizensnpcs.api.npc.AbstractNPC
- Direct Known Subclasses:
CitizensNPC
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.citizensnpcs.api.npc.NPC
NPC.Metadata, NPC.NPCUpdate
-
Field Summary
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractNPC
(UUID uuid, int id, String name, NPCRegistry registry) -
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.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.boolean
Gets the defaultGoalController
of this NPC.Gets the defaultSpeechController
of this NPC.protected EntityType
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> clazz) Gets a trait from the given class.<T extends Trait>
TGets a trait from the given class.protected Trait
getTraitFor
(Class<? extends Trait> clazz) <T extends Trait>
TgetTraitNullable
(Class<T> clazz) Gets the trait instance with the given class.Returns the currently attachedTrait
sGets the unique id of this NPC.int
hashCode()
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.void
void
removeTrait
(Class<? extends Trait> traitClass) Removes a trait from this NPC.boolean
void
void
setAlwaysUseNameHologram
(boolean use) Sets whether to always use a name hologram instead of the in-built Minecraft name.void
setFlyable
(boolean flyable) Sets whether this NPC is flyable or not.void
setItemProvider
(Supplier<ItemStack> provider) void
Sets the name of this NPC.protected void
setNameInternal
(String name) void
setProtected
(boolean isProtected) A helper method to set the NPC as protected or not protected from damage/entity target events.void
setUseMinecraftAI
(boolean use) Set the NPC to use Minecraft AI where possible.void
teleport
(Location location, PlayerTeleportEvent.TeleportCause cause) An alternative tonpc.getEntity().getLocation()
that teleports passengers as well.protected void
void
update()
boolean
Whether the NPC is currently set to use Minecraft AI.Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.citizensnpcs.api.npc.NPC
despawn, faceLocation, getBlockBreaker, getEntity, getNavigator, getStoredLocation, getTraitOptional, isSpawned, isUpdating, scheduleUpdate, setBukkitEntityType, setMoveDestination, setSneaking, shouldRemoveFromPlayerList, shouldRemoveFromTabList, spawn, spawn
-
Field Details
-
coloredNameComponentCache
-
coloredNameStringCache
-
traits
-
-
Constructor Details
-
AbstractNPC
-
-
Method Details
-
addRunnable
Description copied from interface:NPC
Adds aRunnable
that will run every tick. Note that removal is not yet supported.- Specified by:
addRunnable
in interfaceNPC
- Parameters:
runnable
- Runnable to be added
-
addTrait
Description copied from interface:NPC
Adds a trait to this NPC. This will use theTraitFactory
defined for this NPC to construct and attach a trait usingNPC.addTrait(Trait)
. -
addTrait
Description copied from interface:NPC
Adds a trait to this NPC. -
clone
-
copy
-
data
-
despawn
public boolean despawn()Description copied from interface:NPC
Despawns this NPC. This is equivalent to callingNPC.despawn(DespawnReason)
withDespawnReason.PLUGIN
. -
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. -
destroy
Description copied from interface:NPC
Permanently removes this NPC and all data about it from the registry it's attached to. -
equals
-
getDefaultGoalController
Description copied from interface:NPC
Gets the defaultGoalController
of this NPC.- Specified by:
getDefaultGoalController
in interfaceNPC
- Returns:
- Default goal controller
-
getDefaultSpeechController
Description copied from interface:NPC
Gets the defaultSpeechController
of this NPC.- Specified by:
getDefaultSpeechController
in interfaceNPC
- Returns:
- Default speech controller
-
getEntityType
-
getFullName
Description copied from interface:NPC
Gets the full name of this NPC.- Specified by:
getFullName
in interfaceNPC
- 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. -
getItemProvider
- Specified by:
getItemProvider
in interfaceNPC
- See Also:
-
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 returnNPC.getUniqueId()
with the necessary changes for the current mob type.- Specified by:
getMinecraftUniqueId
in interfaceNPC
- Returns:
- The client unique ID.
-
getName
Description copied from interface:NPC
Gets the name of this NPC with color codes stripped. -
getOrAddTrait
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 usingNPC.addTrait(Class)
.- Specified by:
getOrAddTrait
in interfaceNPC
- Parameters:
clazz
- Trait to get- Returns:
- Trait with the given name
-
getOwningRegistry
- Specified by:
getOwningRegistry
in interfaceNPC
- Returns:
- The
NPCRegistry
that created this NPC.
-
getRawName
- Specified by:
getRawName
in interfaceNPC
-
getTrait
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 usingNPC.addTrait(Class)
. -
getTraitFor
-
getTraitNullable
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 interfaceNPC
- Parameters:
clazz
- Trait class- Returns:
- Trait with the given class
-
getTraits
Description copied from interface:NPC
Returns the currently attachedTrait
s -
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 interfaceNPC
- Returns:
- The unique id
-
hashCode
public int hashCode() -
hasTrait
Description copied from interface:NPC
Checks if this NPC has the given trait. -
isFlyable
public boolean isFlyable()Description copied from interface:NPC
Returns whether this NPC is flyable or not. -
isHiddenFrom
Description copied from interface:NPC
Returns whether the given player can see the NPC (i.e. receive packets about it).- Specified by:
isHiddenFrom
in interfaceNPC
- Parameters:
player
- The player to check- Returns:
- Whether the NPC is hidden from the player
-
isProtected
public boolean isProtected()Description copied from interface:NPC
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.- Specified by:
isProtected
in interfaceNPC
- Returns:
- Whether this NPC is protected
-
isPushableByFluids
public boolean isPushableByFluids()Description copied from interface:NPC
Gets whether this NPC is pushable by fluids.- Specified by:
isPushableByFluids
in interfaceNPC
- Returns:
- Whether this NPC is pushable by fluids
-
load
Description copied from interface:NPC
-
removeTrait
Description copied from interface:NPC
Removes a trait from this NPC.- Specified by:
removeTrait
in interfaceNPC
- Parameters:
traitClass
- Trait to remove
-
requiresNameHologram
public boolean requiresNameHologram()- Specified by:
requiresNameHologram
in interfaceNPC
-
save
Description copied from interface:NPC
Saves theNPC
to the givenDataKey
. This includes all metadata, traits, and spawn information that will allow it to respawn at a later time viaNPC.load(DataKey)
. -
setAlwaysUseNameHologram
public void setAlwaysUseNameHologram(boolean use) Description copied from interface:NPC
Sets whether to always use a name hologram instead of the in-built Minecraft name.- Specified by:
setAlwaysUseNameHologram
in interfaceNPC
- Parameters:
use
- Whether to use a hologram
-
setFlyable
public void setFlyable(boolean flyable) Description copied from interface:NPC
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.- Specified by:
setFlyable
in interfaceNPC
- Parameters:
flyable
-
-
setItemProvider
Description copied from interface:NPC
- Specified by:
setItemProvider
in interfaceNPC
- Parameters:
provider
- The supplier
-
setName
Description copied from interface:NPC
Sets the name of this NPC. -
setNameInternal
-
setProtected
public void setProtected(boolean isProtected) Description copied from interface:NPC
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);
- Specified by:
setProtected
in interfaceNPC
- Parameters:
isProtected
- Whether the NPC should be protected
-
setUseMinecraftAI
public void setUseMinecraftAI(boolean use) Description copied from interface:NPC
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.- Specified by:
setUseMinecraftAI
in interfaceNPC
-
teleport
Description copied from interface:NPC
An alternative tonpc.getEntity().getLocation()
that teleports passengers as well. -
unloadEvents
protected void unloadEvents() -
update
public void update() -
useMinecraftAI
public boolean useMinecraftAI()Description copied from interface:NPC
Whether the NPC is currently set to use Minecraft AI. Defaults to false.- Specified by:
useMinecraftAI
in interfaceNPC
-