Class FollowTrait

java.lang.Object
net.citizensnpcs.api.trait.Trait
net.citizensnpcs.trait.FollowTrait
All Implemented Interfaces:
Runnable, Listener

public class FollowTrait extends Trait
Persists a Player to follow while spawned. Optionally allows protecting of the player as well.
  • Constructor Details

    • FollowTrait

      public FollowTrait()
  • Method Details

    • getFollowingPlayer

      public Player getFollowingPlayer()
    • isActive

      public boolean isActive()
      Returns whether the trait is actively following a Player.
    • isEnabled

      public boolean isEnabled()
    • onDespawn

      public void onDespawn()
      Description copied from class: Trait
      Called just before the attached NPC is despawned. NPC.getEntity() will be non-null.
      Overrides:
      onDespawn in class Trait
    • onSpawn

      public void onSpawn()
      Description copied from class: Trait
      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.
      Overrides:
      onSpawn in class Trait
    • run

      public void run()
      Description copied from class: Trait
      Called every tick if overridden.
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Trait
    • toggle

      public boolean toggle(OfflinePlayer player, boolean protect)
      Toggles and/or sets the OfflinePlayer to follow and whether to protect them (similar to wolves in Minecraft, attack whoever attacks the player). Will toggle if the OfflinePlayer is the player currently being followed.
      Parameters:
      player - the player to follow
      protect - whether to protect the player
      Returns:
      whether the trait is enabled