Package net.citizensnpcs.api.trait
Class Trait
java.lang.Object
net.citizensnpcs.api.trait.Trait
- Direct Known Subclasses:
Age
,AllayTrait
,Anchors
,AreaEffectCloudTrait
,ArmadilloTrait
,ArmorStandTrait
,AttributeTrait
,AxolotlTrait
,BatTrait
,BeeTrait
,BoatTrait
,BoatTrait
,BossBarTrait
,BoundingBoxTrait
,CamelTrait
,CatTrait
,ClickRedirectTrait
,CommandTrait
,Controllable
,CurrentLocation
,DisplayTrait
,DropsTrait
,EnderCrystalTrait
,EnderDragonTrait
,EndermanTrait
,EntityPoseTrait
,Equipment
,FollowTrait
,ForcefieldTrait
,FoxTrait
,FrogTrait
,GameModeTrait
,GoatTrait
,Gravity
,HologramTrait
,HomeTrait
,HorseModifiers
,Inventory
,ItemFrameTrait
,LlamaTrait
,LookClose
,MirrorTrait
,MobType
,MountTrait
,MushroomCowTrait
,OcelotModifiers
,Owner
,PacketNPC
,PaintingTrait
,PandaTrait
,ParrotTrait
,PausePathfindingTrait
,PhantomTrait
,PiglinTrait
,PlayerFilter
,PolarBearTrait
,Poses
,Powered
,PufferFishTrait
,RabbitType
,RotationTrait
,Saddle
,ScaledMaxHealthTrait
,ScoreboardTrait
,SheepTrait
,ShopTrait
,ShulkerTrait
,SitTrait
,SkinLayers
,SkinTrait
,SleepTrait
,SlimeSize
,SneakTrait
,SnifferTrait
,SnowmanTrait
,Spawned
,SpellcasterTrait
,TargetableTrait
,Text
,TextDisplayTrait
,TropicalFishTrait
,VillagerProfession
,VillagerTrait
,WardenTrait
,Waypoints
,WitherTrait
,WolfModifiers
,WoolColor
Represents a Trait linked to an
NPC
that can be loaded and saved. This will be kept persisted inside a
NPC
across server restarts. Traits must be registered in Citizens' TraitFactory
.
All traits should have a default constructor with no arguments for persistence purposes.-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal String
getName()
Gets the name of this trait.final NPC
getNPC()
boolean
void
void
Loads a trait.void
onAttach()
Called when the trait has been attached to anNPC
.void
onCopy()
Called when the trait has been newly copied to anNPC
.void
Called just before the attachedNPC
is despawned.void
onDespawn
(DespawnReason reason) Called just before the attachedNPC
is despawned.void
Called just before theNPC
is spawned.void
onRemove()
Called when a trait is removed from the attachedNPC
.void
onRemove
(RemoveReason reason) Called when a trait is removed from the attachedNPC
.void
onSpawn()
Called when anNPC
is spawned.void
run()
Called every tick if overridden.void
Saves a trait.
-
Field Details
-
npc
-
-
Constructor Details
-
Trait
-
-
Method Details
-
getName
Gets the name of this trait.- Returns:
- Name of this trait
-
getNPC
- Returns:
- The
NPC
this trait is attached to. May be null.
-
isRunImplemented
public boolean isRunImplemented() -
linkToNPC
-
load
Loads a trait.- Parameters:
key
- DataKey to load from- Throws:
NPCLoadException
- Thrown if this trait failed to load properly
-
onAttach
public void onAttach() -
onCopy
public void onCopy()Called when the trait has been newly copied to anNPC
. -
onDespawn
public void onDespawn()Called just before the attachedNPC
is despawned.NPC.getEntity()
will be non-null. -
onDespawn
Called just before the attachedNPC
is despawned.NPC.getEntity()
will be non-null. -
onPreSpawn
public void onPreSpawn()Called just before theNPC
is spawned.NPC.getEntity()
will return an unspawned entity. -
onRemove
public void onRemove()Called when a trait is removed from the attachedNPC
. -
onRemove
Called when a trait is removed from the attachedNPC
. -
onSpawn
public void onSpawn()Called when anNPC
is spawned.NPC.getEntity()
will return null until this is called. This is also called onAttach when the NPC is already spawned. -
run
public void run()Called every tick if overridden. -
save
Saves a trait.- Parameters:
key
- DataKey to save to
-