Class WorldVariable

java.lang.Object
ua.mcchickenstudio.opencreative.coding.variables.WorldVariable

public final class WorldVariable extends Object

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 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

      @Nullable public @Nullable ActionsHandler 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

      @Nullable public @Nullable Object getValue()
      Returns value of variable.
      Returns:
      value of variable.
    • setValue

      public void setValue(@Nullable @Nullable Object value)
      Sets a new value to variable.
      Parameters:
      value - new value.
    • getType

      @NotNull public @NotNull ValueType getType()
      Returns type of value.
      Returns:
      value type.
    • setType

      public void setType(@NotNull @NotNull ValueType type)
      Sets a new value type to variable.
      Parameters:
      type - new type.
    • getVarType

      @NotNull public VariableLink.VariableType getVarType()
      Returns type of variable (local, global, saved).
      Returns:
      type of variable.
    • getName

      @NotNull public @NotNull String getName()
      Returns name of variable.
      Returns:
      name of variable.
    • 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

      public String toString()
      Overrides:
      toString in class Object