Class HologramTrait

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

public class HologramTrait extends Trait
Manages a set of holograms attached to the NPC. Holograms are lines of text or items that follow the NPC at some offset (typically vertically offset).
  • Constructor Details

    • HologramTrait

      public HologramTrait()
  • Method Details

    • addLine

      public void addLine(String text)
      Adds a new hologram line which will displayed over an NPC's head.
      Parameters:
      text - The new line to add
    • addLine

      public void addLine(String text, HologramTrait.HologramRenderer hr)
    • addTemporaryLine

      public void addTemporaryLine(String text, int ticks)
      Adds a new hologram line which will displayed over an NPC's head. It will not persist to disk and will last for the specified amount of ticks.
      Parameters:
      text - The new line to add
      ticks - The number of ticks to last for
    • addTemporaryLine

      public void addTemporaryLine(String text, int ticks, HologramTrait.HologramRenderer hr)
    • clear

      public void clear()
      Clears all hologram lines
    • getDefaultBackgroundColor

      public Color getDefaultBackgroundColor()
    • getHologramEntities

      @Deprecated public Collection<Entity> getHologramEntities()
      Deprecated.
    • getHologramRenderers

      public Collection<HologramTrait.HologramRenderer> getHologramRenderers()
    • getLineHeight

      public double getLineHeight()
      Returns:
      The line height between each hologram line, in blocks
    • getLines

      public List<String> getLines()
      Returns:
      the hologram lines, in bottom-up order
    • getNameEntity

      @Deprecated public Entity getNameEntity()
      Deprecated.
    • getNameRenderer

      public HologramTrait.HologramRenderer getNameRenderer()
    • getViewRange

      public int getViewRange()
    • insertLine

      public void insertLine(int idx, String text)
    • load

      public void load(DataKey root)
      Description copied from class: Trait
      Loads a trait.
      Overrides:
      load in class Trait
      Parameters:
      root - DataKey to load from
    • 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
    • onRemove

      public void onRemove()
      Description copied from class: Trait
      Called when a trait is removed from the attached NPC.
      Overrides:
      onRemove 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
    • removeLine

      public void removeLine(int idx)
      Removes the line at the specified index
      Parameters:
      idx -
    • 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
    • save

      public void save(DataKey root)
      Description copied from class: Trait
      Saves a trait.
      Overrides:
      save in class Trait
      Parameters:
      root - DataKey to save to
    • setBackgroundColor

      public void setBackgroundColor(int idx, Color color)
    • setDefaultBackgroundColor

      public void setDefaultBackgroundColor(Color color)
    • setLine

      public void setLine(int idx, String text)
      Sets the hologram line at a specific index
      Parameters:
      idx - The index
      text - The new line
    • setLineHeight

      public void setLineHeight(double height)
      Sets the line height
      Parameters:
      height - The line height in blocks
      See Also:
    • setMargin

      public void setMargin(int idx, String type, double margin)
      Sets the margin of a line at a specific index
      Parameters:
      idx - The line index
      type - The margin type, top or bottom
      margin - The margin
    • setViewRange

      public void setViewRange(int range)