Class TabPlaceholder

java.lang.Object
me.neznamy.tab.shared.placeholders.TabPlaceholder
All Implemented Interfaces:
me.neznamy.tab.api.placeholder.Placeholder
Direct Known Subclasses:
PlayerPlaceholderImpl, RelationalPlaceholderImpl, ServerPlaceholderImpl

public abstract class TabPlaceholder extends Object implements me.neznamy.tab.api.placeholder.Placeholder
General collection of variables and functions shared between all placeholder types
  • Field Details

    • identifier

      protected final String identifier
      Placeholder's identifier including %
    • replacements

      protected final PlaceholderReplacementPattern replacements
      Configured placeholder output replacements
    • parents

      protected final List<String> parents
      List of placeholders using this placeholder as a nested placeholder, mutual tracking allows faster parent placeholder changes when a nested placeholder changed value.
  • Constructor Details

    • TabPlaceholder

      protected TabPlaceholder(String identifier, int refresh)
      Constructs new instance with given parameters and loads placeholder output replacements
      Parameters:
      identifier - placeholder's identifier, must start and end with %
      refresh - refresh interval in milliseconds, must be divisible by 50 or equal to -1 for trigger placeholders
  • Method Details

    • set

      public String set(String string, me.neznamy.tab.api.TabPlayer player)
      Replaces this placeholder in given string and returns output. If the entered string is equal to the placeholder identifier or does not contain the identifier at all, value is returned directly without calling String#replace for better performance.
      Parameters:
      string - string to replace this placeholder in
      player - player to set placeholder for
      Returns:
      string with this placeholder replaced
    • getNestedPlaceholders

      public List<String> getNestedPlaceholders(String output)
      Returns all nested placeholders in provided output. If no placeholders are detected, returns empty list.
      Parameters:
      output - output to check
      Returns:
      List of nested placeholders in provided output
    • setPlaceholders

      protected String setPlaceholders(String text, me.neznamy.tab.api.TabPlayer p)
      Applies all nested placeholders in output
      Parameters:
      text - replaced placeholder
      p - player to replace for
      Returns:
      text with replaced placeholders in output
    • getReplacements

      public PlaceholderReplacementPattern getReplacements()
      Returns placeholder output replacement pattern
      Returns:
      placeholder output replacement pattern
    • markAsUsed

      public void markAsUsed()
      Marks this placeholder as used, which sets active to true and if onActivation is not null, runs it.
    • updateParents

      public void updateParents(me.neznamy.tab.api.TabPlayer player)
      Updates all placeholders that use this placeholder as a nested placeholder
      Parameters:
      player - Player to update placeholders for.
    • updateFromNested

      public abstract void updateFromNested(me.neznamy.tab.api.TabPlayer player)
      Updates the placeholder with force mark for requested player
      Parameters:
      player - player to update placeholder for
    • getLastValue

      public abstract String getLastValue(me.neznamy.tab.api.TabPlayer player)
      Returns last known value of defined player
      Parameters:
      player - player to get value of
      Returns:
      last known value for specified player
    • getIdentifier

      public String getIdentifier()
      Specified by:
      getIdentifier in interface me.neznamy.tab.api.placeholder.Placeholder
    • getRefresh

      public int getRefresh()
      Specified by:
      getRefresh in interface me.neznamy.tab.api.placeholder.Placeholder
    • unload

      public void unload()
      Specified by:
      unload in interface me.neznamy.tab.api.placeholder.Placeholder
    • enableTriggerMode

      public void enableTriggerMode(Runnable onActivation, Runnable onDisable)
      Specified by:
      enableTriggerMode in interface me.neznamy.tab.api.placeholder.Placeholder