Class Trait

java.lang.Object
net.citizensnpcs.api.trait.Trait
All Implemented Interfaces:
Runnable, Listener
Direct Known Subclasses:
Age, AllayTrait, Anchors, ArmorStandTrait, AxolotlTrait, BeeTrait, BossBarTrait, BoundingBoxTrait, CamelTrait, CatTrait, ClickRedirectTrait, CommandTrait, Controllable, CurrentLocation, DropsTrait, EnderCrystalTrait, EnderDragonTrait, EndermanTrait, Equipment, FollowTrait, FoxTrait, FrogTrait, GameModeTrait, GoatTrait, Gravity, HologramTrait, HomeTrait, HorseModifiers, Inventory, LlamaTrait, LookClose, MirrorTrait, MobType, MountTrait, MushroomCowTrait, OcelotModifiers, Owner, PacketNPC, PaintingTrait, PandaTrait, ParrotTrait, PausePathfindingTrait, PhantomTrait, PiglinTrait, PlayerFilter, PolarBearTrait, Poses, Powered, PufferFishTrait, RabbitType, RotationTrait, Saddle, ScoreboardTrait, SheepTrait, ShopTrait, ShulkerTrait, SitTrait, SkinLayers, SkinTrait, SleepTrait, SlimeSize, SneakTrait, SnifferTrait, SnowmanTrait, Spawned, SpellcasterTrait, Text, TropicalFishTrait, VillagerProfession, VillagerTrait, WardenTrait, Waypoints, WitherTrait, WolfModifiers, WoolColor

public abstract class Trait extends Object implements Listener, Runnable
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 Details

    • npc

      protected NPC npc
  • Constructor Details

    • Trait

      protected Trait(String name)
  • Method Details

    • getName

      public final String getName()
      Gets the name of this trait.
      Returns:
      Name of this trait
    • getNPC

      public final NPC getNPC()
      Returns:
      The NPC this trait is attached to. May be null.
    • isRunImplemented

      public boolean isRunImplemented()
    • linkToNPC

      public void linkToNPC(NPC npc)
    • load

      public void load(DataKey key) throws NPCLoadException
      Loads a trait.
      Parameters:
      key - DataKey to load from
      Throws:
      NPCLoadException - Thrown if this trait failed to load properly
    • onAttach

      public void onAttach()
      Called when the trait has been attached to an NPC. npc will be null until this is called.
    • onCopy

      public void onCopy()
      Called when the trait has been newly copied to an NPC.
    • onDespawn

      public void onDespawn()
      Called just before the attached NPC is despawned. NPC.getEntity() will be non-null.
    • onDespawn

      public void onDespawn(DespawnReason reason)
      Called just before the attached NPC is despawned. NPC.getEntity() will be non-null.
    • onPreSpawn

      public void onPreSpawn()
      Called just before the NPC is spawned. NPC.getEntity() will return an unspawned entity.
    • onRemove

      public void onRemove()
      Called when a trait is removed from the attached NPC.
    • onRemove

      public void onRemove(RemoveReason reason)
      Called when a trait is removed from the attached NPC.
    • onSpawn

      public void onSpawn()
      Called when an NPC 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.
      Specified by:
      run in interface Runnable
    • save

      public void save(DataKey key)
      Saves a trait.
      Parameters:
      key - DataKey to save to