Class WorldVariable
java.lang.Object
ua.mcchickenstudio.opencreative.coding.variables.WorldVariable
WorldVariable
This class represents a variable in world, that has type and stores value.Variables can be local, global, saved.
Local - stores only in ActionsHandler
Global - stores in world while it's loaded
Saved - stores in world forever
-
Constructor Summary
ConstructorsConstructorDescriptionWorldVariable(@NotNull String name, VariableLink.VariableType varType, @NotNull ValueType type, @Nullable Object value, @Nullable ActionsHandler handler) Creates instance of variable, that has name, value, type, value type and actions handler. -
Method Summary
Modifier and TypeMethodDescription@Nullable ActionsHandlerReturns actions handler associated with variable.@NotNull StringgetName()Returns name of variable.intgetSize()Returns a size of variable.@NotNull ValueTypegetType()Returns type of value.@Nullable ObjectgetValue()Returns value of variable.Returns type of variable (local, global, saved).voidSets a new value type to variable.voidSets a new value to variable.toString()
-
Constructor Details
-
WorldVariable
public WorldVariable(@NotNull @NotNull String name, @NotNull VariableLink.VariableType varType, @NotNull @NotNull ValueType type, @Nullable @Nullable Object value, @Nullable @Nullable ActionsHandler handler) Creates instance of variable, that has name, value, type, value type and actions handler.- Parameters:
name- name of variable.varType- type of variable (local, global, saved).type- type of value.value- value.handler- actions handler.
-
-
Method Details
-
getHandler
Returns actions handler associated with variable. Can be null when variable is loaded from storage, or when player creates variable with command.- Returns:
- actions handler, or null.
-
getValue
-
setValue
Sets a new value to variable.- Parameters:
value- new value.
-
getType
-
setType
Sets a new value type to variable.- Parameters:
type- new type.
-
getVarType
Returns type of variable (local, global, saved).- Returns:
- type of variable.
-
getName
-
getSize
public int getSize()Returns a size of variable.If value is map, then keys amount will be added to size.
If value is list, then elements amount will be added to size.
Otherwise, it will return 1.
- Returns:
- size of variable.
-
toString
-