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,BossBarTrait,BoundingBoxTrait,CamelTrait,CatTrait,ChickenTrait,ClickRedirectTrait,CommandTrait,Controllable,CowTrait,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,PigTrait,PlayerFilter,PolarBearTrait,Poses,PotionEffectsTrait,Powered,PufferFishTrait,RabbitType,RotationTrait,Saddle,ScaledMaxHealthTrait,ScoreboardTrait,SheepTrait,ShopTrait,ShulkerTrait,SitTrait,SkinLayers,SkinTrait,SleepTrait,SlimeSize,SneakTrait,SnifferTrait,SnowmanTrait,Spawned,SpellcasterTrait,TargetableTrait,Text,TextDisplayTrait,TropicalFishTrait,VexTrait,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
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal StringgetName()Gets the name of this trait.final NPCgetNPC()booleanvoidvoidLoads a trait.voidonAttach()Called when the trait has been attached to anNPC.voidonCopy()Called when the trait has been newly copied to anNPC.voidCalled just before the attachedNPCis despawned.voidonDespawn(DespawnReason reason) Called just before the attachedNPCis despawned.voidCalled just before theNPCis spawned.voidonRemove()Called when a trait is removed from the attachedNPC.voidonRemove(RemoveReason reason) Called when a trait is removed from the attachedNPC.voidonSpawn()Called when anNPCis spawned.voidrun()Called every tick if overridden.voidSaves 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
NPCthis 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 attachedNPCis despawned.NPC.getEntity()will be non-null. -
onDespawn
Called just before the attachedNPCis despawned.NPC.getEntity()will be non-null. -
onPreSpawn
public void onPreSpawn()Called just before theNPCis 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 anNPCis 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
-