Class VariableManager

java.lang.Object
me.hsgamer.hscore.variable.VariableManager
All Implemented Interfaces:
StringReplacer

public class VariableManager extends Object implements StringReplacer
The variable manager for the instance
  • Field Details

    • GLOBAL

      public static final VariableManager GLOBAL
      The global variable manager
  • Constructor Details

    • VariableManager

      public VariableManager(Function<String,VariableSession> sessionFunction)
      Create a new variable manager
      Parameters:
      sessionFunction - the function to create a new VariableSession from a string
    • VariableManager

      public VariableManager(char startIgnoreChar, char endIgnoreChar)
      Create a new variable manager with the default VariableSession with the user-defined ignore char. The default VariableSession uses the Pattern to check for variables with the format {variable}. Developers can add the ignore char to the start and end of the variable to ignore it.
      Parameters:
      startIgnoreChar - the ignore char at the start of the variable
      endIgnoreChar - the ignore char at the end of the variable
    • VariableManager

      public VariableManager()
      Create a new variable manager with the default VariableSession with the default ignore char \.
  • Method Details

    • register

      public void register(String prefix, StringReplacer variable, boolean isWhole)
      Register new variable
      Parameters:
      prefix - the prefix
      variable - the replacer
      isWhole - whether the manager should check the whole string matches the prefix, set it to false if you want to check if the prefix is at the beginning of the string
    • register

      public void register(String prefix, StringReplacer variable)
      Register new variable
      Parameters:
      prefix - the prefix
      variable - the Variable object
    • unregister

      public void unregister(String prefix)
      Unregister a variable
      Parameters:
      prefix - the prefix
    • getVariables

      public Map<String,StringReplacer> getVariables()
      Get all variables
      Returns:
      the variables
    • getVariableEntries

      public List<Variable> getVariableEntries()
      Get all variable entries
      Returns:
      the variable entries
    • addExternalReplacer

      public void addExternalReplacer(StringReplacer replacer)
      Add an external replacer
      Parameters:
      replacer - the external string replacer
    • removeExternalReplacer

      public void removeExternalReplacer(StringReplacer replacer)
      Remove an external replacer
      Parameters:
      replacer - the external string replacer
    • clearExternalReplacers

      public void clearExternalReplacers()
      Clear all external replacers
    • getExternalReplacers

      public List<StringReplacer> getExternalReplacers()
      Get all external replacers
      Returns:
      the external replacers
    • setVariables

      @NotNull public @NotNull String setVariables(@NotNull @NotNull String message, @Nullable @Nullable UUID uuid)
      Replace the variables of the string until it cannot be replaced anymore
      Parameters:
      message - the string
      uuid - the unique id
      Returns:
      the replaced string
    • setSingleVariables

      @NotNull public @NotNull String setSingleVariables(@NotNull @NotNull String message, @Nullable @Nullable UUID uuid)
      Replace the variables of the string (single time)
      Parameters:
      message - the string
      uuid - the unique id
      Returns:
      the replaced string
    • replace

      @Nullable public @Nullable String replace(@NotNull @NotNull String original)
      Description copied from interface: StringReplacer
      Replace a string
      Specified by:
      replace in interface StringReplacer
      Parameters:
      original - the original string
      Returns:
      the replaced string
    • replace

      @Nullable public @Nullable String replace(@NotNull @NotNull String original, @NotNull @NotNull UUID uuid)
      Description copied from interface: StringReplacer
      Replace a string based on the unique id
      Specified by:
      replace in interface StringReplacer
      Parameters:
      original - the original string
      uuid - the unique id
      Returns:
      the replaced string