public abstract class Trait extends Object implements org.bukkit.event.Listener, Runnable
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.Modifier and Type | Method and Description |
---|---|
String |
getName()
Gets the name of this trait.
|
NPC |
getNPC() |
boolean |
isRunImplemented() |
void |
linkToNPC(NPC npc) |
void |
load(DataKey key)
Loads a trait.
|
void |
onAttach()
Called when the trait has been attached to an
NPC . |
void |
onCopy()
Called when the trait has been newly copied to an
NPC . |
void |
onDespawn()
Called just before the attached
NPC is despawned. |
void |
onRemove()
Called when a trait is removed from the attached
NPC . |
void |
onSpawn()
Called when an
NPC is spawned. |
void |
run()
Called every tick if overridden.
|
void |
save(DataKey key)
Saves a trait.
|
protected NPC npc
protected Trait(String name)
public final String getName()
public boolean isRunImplemented()
public void linkToNPC(NPC npc)
public void load(DataKey key) throws NPCLoadException
key
- DataKey to load fromNPCLoadException
- Thrown if this trait failed to load properlypublic void onAttach()
public void onCopy()
NPC
.public void onDespawn()
NPC
is despawned. NPC.getEntity()
will be non-null.public void onRemove()
NPC
.public void onSpawn()
NPC
is spawned. NPC.getEntity()
will return null until this is called. This is
also called onAttach when the NPC is already spawned.public void save(DataKey key)
key
- DataKey to save toCopyright © 2021. All rights reserved.