Package me.hsgamer.hscore.variable
Class VariableManager
java.lang.Object
me.hsgamer.hscore.variable.VariableManager
- All Implemented Interfaces:
StringReplacer
The variable manager for the instance
-
Field Summary
FieldsFields inherited from interface me.hsgamer.hscore.common.StringReplacer
DUMMY -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new variable manager with the defaultVariableSessionwith the default ignore char\.VariableManager(char startIgnoreChar, char endIgnoreChar) Create a new variable manager with the defaultVariableSessionwith the user-defined ignore char.VariableManager(Function<String, VariableSession> sessionFunction) Create a new variable manager -
Method Summary
Modifier and TypeMethodDescriptionvoidaddExternalReplacer(StringReplacer replacer) Add an external replacervoidClear all external replacersGet all external replacersGet all variable entriesGet all variablesvoidregister(String prefix, StringReplacer variable) Register new variablevoidregister(String prefix, StringReplacer variable, boolean isWhole) Register new variablevoidremoveExternalReplacer(StringReplacer replacer) Remove an external replacer@Nullable StringReplace a string@Nullable StringReplace a string based on the unique id@NotNull StringsetSingleVariables(@NotNull String message, @Nullable UUID uuid) Replace the variables of the string (single time)@NotNull StringsetVariables(@NotNull String message, @Nullable UUID uuid) Replace the variables of the string until it cannot be replaced anymorevoidunregister(String prefix) Unregister a variableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface me.hsgamer.hscore.common.StringReplacer
replaceOrDefault, replaceOrOriginal, tryReplace
-
Field Details
-
GLOBAL
The global variable manager
-
-
Constructor Details
-
VariableManager
Create a new variable manager- Parameters:
sessionFunction- the function to create a newVariableSessionfrom a string
-
VariableManager
public VariableManager(char startIgnoreChar, char endIgnoreChar) Create a new variable manager with the defaultVariableSessionwith the user-defined ignore char. The defaultVariableSessionuses thePatternto 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 variableendIgnoreChar- the ignore char at the end of the variable
-
VariableManager
public VariableManager()Create a new variable manager with the defaultVariableSessionwith the default ignore char\.
-
-
Method Details
-
register
Register new variable- Parameters:
prefix- the prefixvariable- the replacerisWhole- 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
Register new variable- Parameters:
prefix- the prefixvariable- the Variable object
-
unregister
Unregister a variable- Parameters:
prefix- the prefix
-
getVariables
Get all variables- Returns:
- the variables
-
getVariableEntries
Get all variable entries- Returns:
- the variable entries
-
addExternalReplacer
Add an external replacer- Parameters:
replacer- the external string replacer
-
removeExternalReplacer
Remove an external replacer- Parameters:
replacer- the external string replacer
-
clearExternalReplacers
public void clearExternalReplacers()Clear all external replacers -
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 stringuuid- 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 stringuuid- the unique id- Returns:
- the replaced string
-
replace
Description copied from interface:StringReplacerReplace a string- Specified by:
replacein interfaceStringReplacer- 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:StringReplacerReplace a string based on the unique id- Specified by:
replacein interfaceStringReplacer- Parameters:
original- the original stringuuid- the unique id- Returns:
- the replaced string
-