Class WorldVariables
java.lang.Object
ua.mcchickenstudio.opencreative.coding.variables.WorldVariables
WorldVariables
This class represents set of world variables. It includes methods for finding and editing variables value.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClears all global variables in world.voidClears all current variables in world.voidgarbageCollector(ActionsHandler actionsHandler) Clears local variables with action handler type.@NotNull Set<WorldVariable> getSet()Returns set of all current variables in world.intReturns total size of variables.@Nullable WorldVariablegetVariable(@NotNull String name, VariableLink.VariableType type, @Nullable ActionsHandler handler) Returns instance of world variable by name, type and actions handler.@Nullable WorldVariablegetVariable(@NotNull VariableLink link, @NotNull Action action) Returns instance of world variable by link.getVariableValue(VariableLink link, Action action) Gets variable value by variable link.voidload()Loads variables from /planet/variables.json file.voidremoveVariable(VariableLink link, Action action) Removes variable by variable link.voidsave()Saves variables with type saved into /planet/variables.json file.booleansetVariableValue(VariableLink link, ValueType type, Object value) Sets variable value to new specified one.voidsetVariableValue(VariableLink link, ValueType type, Object value, ActionsHandler handler, Action action) Sets variable value to new specified one.
-
Constructor Details
-
WorldVariables
-
-
Method Details
-
getVariable
@Nullable public @Nullable WorldVariable getVariable(@NotNull @NotNull VariableLink link, @NotNull @NotNull Action action) Returns instance of world variable by link.- Parameters:
link- link of variable, that contains name and type.action- action, that requested variable.- Returns:
- world variable, or null - if not found.
-
getVariable
@Nullable public @Nullable WorldVariable getVariable(@NotNull @NotNull String name, @NotNull VariableLink.VariableType type, @Nullable @Nullable ActionsHandler handler) Returns instance of world variable by name, type and actions handler.- Parameters:
name- name of variable.type- type of variable (local, global, saved).handler- main actions handler, that stores local variable (local requires handler)- Returns:
- world variable, or null - if not found.
-
setVariableValue
public void setVariableValue(VariableLink link, ValueType type, Object value, ActionsHandler handler, Action action) Sets variable value to new specified one. Used in actions.- Parameters:
link- variable link to set.type- new type of value.value- new value.handler- handler of setting.action- action of setting.
-
setVariableValue
Sets variable value to new specified one.- Parameters:
link- variable link to set.type- new type of value.value- new value.- Returns:
- true - if successfully set, false - failed.
-
getVariableValue
Gets variable value by variable link.- Parameters:
link- link for variable.action- action.- Returns:
- variable - if found, null - variable not exists.
-
removeVariable
Removes variable by variable link.- Parameters:
link- link for variable.action- action.
-
getSet
Returns set of all current variables in world.- Returns:
- set of all variables.
-
clearVariables
public void clearVariables()Clears all current variables in world. -
load
public void load()Loads variables from /planet/variables.json file. -
save
public void save()Saves variables with type saved into /planet/variables.json file. -
getTotalVariablesAmount
public int getTotalVariablesAmount()Returns total size of variables. It includes list and maps elements.- Returns:
- total size of variables.
-
garbageCollector
Clears local variables with action handler type.- Parameters:
actionsHandler- handler.
-
clearGlobalVariables
public void clearGlobalVariables()Clears all global variables in world.
-