Class Trait

All Implemented Interfaces:
Runnable, Listener
Direct Known Subclasses:
Age, AllayTrait, Anchors, ArmorStandTrait, AxolotlTrait, BeeTrait, BossBarTrait, CatTrait, ClickRedirectTrait, CommandTrait, Controllable, CurrentLocation, DropsTrait, EnderCrystalTrait, EndermanTrait, Equipment, FollowTrait, FoxTrait, FrogTrait, GameModeTrait, GoatTrait, Gravity, HologramTrait, HorseModifiers, Inventory, LlamaTrait, LookClose, MobType, MountTrait, MushroomCowTrait, OcelotModifiers, Owner, PandaTrait, ParrotTrait, PhantomTrait, PiglinTrait, PolarBearTrait, Poses, Powered, PufferFishTrait, RabbitType, Saddle, ScoreboardTrait, ScriptTrait, SheepTrait, ShopTrait, ShulkerTrait, SitTrait, SkinLayers, SkinTrait, SleepTrait, SlimeSize, SmoothRotationTrait, SneakTrait, SnowmanTrait, Spawned, Speech, Text, TropicalFishTrait, VillagerProfession, VillagerTrait, 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.
      Name of this trait
    • getNPC

      public final NPC getNPC()
      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.
      key - DataKey to load from
      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.
    • 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.
    • 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.
      key - DataKey to save to