Class Executor

java.lang.Object
ua.mcchickenstudio.opencreative.coding.blocks.executors.Executor
All Implemented Interfaces:
CodingBlock, ExtensionContent
Direct Known Subclasses:
EntityExecutor, NameableExecutor, PlayerExecutor, WorldExecutor

public abstract class Executor extends Object implements CodingBlock, ExtensionContent

Executor

This class represents Executor that has actions to run. Executor will be executed on events in planet.
Since:
5.0
Version:
6.0
Author:
McChicken Studio
  • Constructor Details

    • Executor

      public Executor(@NotNull @NotNull String id, @NotNull @NotNull ExecutorCategory category)
      Constructor of empty Executor without block data.

      Executing actions will be not able without initialization.

      To initialize, use init(Planet, int, int, int)

      Parameters:
      id - short id of executor that will be used in signs and translations.

      It must be lower-snake-cased, for example: "player_join", "cycle". If some of registered executors has same ID as new, it will be not added.

      category - category of executor.
  • Method Details

    • init

      public void init(@NotNull @NotNull Planet planet, int x, int y, int z)
      Initializes an executor and sets planet and coding block location. Use this method after creating executor.
      Parameters:
      planet - Planet where executor will work.
      x - X from Executor's block location in developers planet.
      y - Y from Executor's block location in developers planet.
      z - Z from Executor's block location in developers planet.
      Throws:
      IllegalStateException - if executor is already initialized.
    • run

      public void run(@NotNull @NotNull WorldEvent event)
      Checks executor, executes actions and sends information about executor.
      Parameters:
      event - Event that occurred in planet.
      Throws:
      IllegalStateException - if executor is not initialized.
    • executeActions

      protected void executeActions(@NotNull @NotNull WorldEvent event)
      Executes all actions with specified event.
      Parameters:
      event - Event that has happened in planet.
    • getBlockCategory

      @NotNull public final @NotNull ExecutorCategory getBlockCategory()
      Returns coding block category of this executor.
      Returns:
      category of executor.
    • getPlanet

      @NotNull public final @NotNull Planet getPlanet()
      Returns planet, that was associated with executor.
      Returns:
      planet.
    • isDebug

      public final boolean isDebug()
      Checks whether is executor block marked for debugging.
      Returns:
      true - for debug, false - not.
    • setDebug

      public final void setDebug(boolean debug)
      Enables or disables sending debug logs about executor and actions inside.
      Parameters:
      debug - true - enabled, false - disabled.
    • getEvent

      public final WorldEvent getEvent()
      Returns last world event of executor.

      When a new event happens, it will be replaced with a new one.

      Returns:
      last world event.
    • getHandler

      public final ActionsHandler getHandler()
    • getActions

      @NotNull public final @NotNull List<Action> getActions()
    • setActions

      public final void setActions(@NotNull @NotNull List<Action> actions)
      Sets actions list for executor.
      Parameters:
      actions - List of actions.
    • increaseCall

      public final void increaseCall()
      Increases calls amount by 1.
    • decreaseCall

      public final void decreaseCall()
      Decreases calls amount by 1.
    • getLastCalls

      public final int getLastCalls()
      Returns how many times executor was called to execute actions.
      Returns:
      amount of last executions.
    • isDisabled

      public final boolean isDisabled()
      Checks whether executor is disabled and cannot be called.
      Returns:
      true - disabled, false - not.
    • getID

      @NotNull public final @NotNull String getID()
      Returns id of executor, that will be used to find it in registry.
      Returns:
      id of executor.
    • getLocaleName

      @NotNull public final @NotNull String getLocaleName()
      Returns localized name of executor.
      Returns:
      localized name.
    • getX

      public final int getX()
      Description copied from interface: CodingBlock
      Returns X coordinate of coding block's location.
      Specified by:
      getX in interface CodingBlock
      Returns:
      X coordinate.
    • getY

      public final int getY()
      Description copied from interface: CodingBlock
      Returns Y coordinate of coding block's location.
      Specified by:
      getY in interface CodingBlock
      Returns:
      Y coordinate.
    • getZ

      public final int getZ()
      Description copied from interface: CodingBlock
      Returns Z coordinate of coding block's location.
      Specified by:
      getZ in interface CodingBlock
      Returns:
      Z coordinate.
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • equals

      public final boolean equals(Object obj)
      Overrides:
      equals in class Object