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
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
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()
void
destroy()
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.void
void
removeTrait
(Class<? extends Trait> traitClass) Removes a trait from this NPC.boolean
void
void
setItemProvider
(Supplier<ItemStack> provider) void
Sets the name of this NPC.protected void
setNameInternal
(String name) void
teleport
(Location location, PlayerTeleportEvent.TeleportCause cause) An alternative tonpc.getEntity().getLocation()
that teleports passengers as well.void
update()
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, despawn, destroy, faceLocation, getBlockBreaker, getEntity, getNavigator, getStoredLocation, getTraitOptional, isFlyable, isHiddenFrom, isProtected, isPushableByFluids, isSpawned, isUpdating, scheduleUpdate, setAlwaysUseNameHologram, setBukkitEntityType, setFlyable, setMoveDestination, setProtected, setSneaking, setUseMinecraftAI, shouldRemoveFromPlayerList, shouldRemoveFromTabList, spawn, spawn, spawn, useMinecraftAI
-
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
-
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. -
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. -
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)
. -
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
-
teleport
Description copied from interface:NPC
An alternative tonpc.getEntity().getLocation()
that teleports passengers as well. -
update
public void update()
-