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
Fields inherited from interface me.hsgamer.hscore.common.StringReplacer
DUMMY
-
Constructor Summary
ConstructorDescriptionCreate a new variable manager with the defaultVariableSession
with the default ignore char\
.VariableManager
(char startIgnoreChar, char endIgnoreChar) Create a new variable manager with the defaultVariableSession
with the user-defined ignore char.VariableManager
(Function<String, VariableSession> sessionFunction) Create a new variable manager -
Method Summary
Modifier and TypeMethodDescriptionvoid
addExternalReplacer
(StringReplacer replacer) Add an external replacervoid
Clear all external replacersGet all external replacersGet all variable entriesGet all variablesvoid
register
(String prefix, StringReplacer variable) Register new variablevoid
register
(String prefix, StringReplacer variable, boolean isWhole) Register new variablevoid
removeExternalReplacer
(StringReplacer replacer) Remove an external replacer@Nullable String
Replace a string@Nullable String
Replace a string based on the unique id@NotNull String
setSingleVariables
(@NotNull String message, @Nullable UUID uuid) Replace the variables of the string (single time)@NotNull String
setVariables
(@NotNull String message, @Nullable UUID uuid) Replace the variables of the string until it cannot be replaced anymorevoid
unregister
(String prefix) Unregister a variableMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods 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 newVariableSession
from a string
-
VariableManager
public VariableManager(char startIgnoreChar, char endIgnoreChar) Create a new variable manager with the defaultVariableSession
with the user-defined ignore char. The defaultVariableSession
uses thePattern
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 variableendIgnoreChar
- the ignore char at the end of the variable
-
VariableManager
public VariableManager()Create a new variable manager with the defaultVariableSession
with 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:StringReplacer
Replace a string- Specified by:
replace
in 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:StringReplacer
Replace a string based on the unique id- Specified by:
replace
in interfaceStringReplacer
- Parameters:
original
- the original stringuuid
- the unique id- Returns:
- the replaced string
-