Class WorldVariables

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

public final class WorldVariables extends Object

WorldVariables

This class represents set of world variables. It includes methods for finding and editing variables value.
  • Constructor Details

    • WorldVariables

      public WorldVariables(Planet planet)
  • 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

      public boolean setVariableValue(VariableLink link, ValueType type, Object value)
      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

      public Object getVariableValue(VariableLink link, Action action)
      Gets variable value by variable link.
      Parameters:
      link - link for variable.
      action - action.
      Returns:
      variable - if found, null - variable not exists.
    • removeVariable

      public void removeVariable(VariableLink link, Action action)
      Removes variable by variable link.
      Parameters:
      link - link for variable.
      action - action.
    • getSet

      @NotNull public @NotNull Set<WorldVariable> 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

      public void garbageCollector(ActionsHandler actionsHandler)
      Clears local variables with action handler type.
      Parameters:
      actionsHandler - handler.
    • clearGlobalVariables

      public void clearGlobalVariables()
      Clears all global variables in world.