Interface IAction

All Known Subinterfaces:
IRuntimeAction, IUndoableAction
All Known Implementing Classes:
ActionAddRecipe, ActionAddShiftedTooltip, ActionAddTooltip, ActionAddTrade, ActionAddWanderingTrade, ActionClearTooltip, ActionKnownTag, ActionKnownTagAdd, ActionKnownTagClear, ActionKnownTagCreate, ActionKnownTagModify, ActionKnownTagRemove, ActionLootModifier, ActionModifyAttribute, ActionModifyShiftedTooltip, ActionModifyTooltip, ActionRecipeBase, ActionRegisterLootModifier, ActionRemoveAll, ActionRemoveAllGenericRecipes, ActionRemoveGenericRecipeBase, ActionRemoveGenericRecipeByModId, ActionRemoveGenericRecipeByName, ActionRemoveGenericRecipeByOutput, ActionRemoveGenericRecipeByRegex, ActionRemoveLootModifier, ActionRemoveRecipe, ActionRemoveRecipeByModid, ActionRemoveRecipeByName, ActionRemoveRecipeByOutput, ActionRemoveRecipeByOutputInput, ActionRemoveRecipeByRegex, ActionRemoveRegexTooltip, ActionRemoveTrade, ActionRemoveWanderingTrade, ActionReplaceRecipe, ActionSetBlockProperty, ActionSetBurnTime, ActionSetCauldronInteraction, ActionSetCompostable, ActionSetFood, ActionSetItemProperty, ActionTag, ActionTooltipBase, ActionTradeBase, ActionUnknownTag, ActionUnknownTagAdd, ActionUnknownTagClear, ActionUnknownTagCreate, ActionUnknownTagModify, ActionUnknownTagRemove, ActionWholeRegistryBase, ReplacerAction

public interface IAction
Represents an action that is to be executed through a ZenCode script.

All methods that are exposed to ZenCode should use classes that implement this interface or one of its sub-interfaces as required by semantics to ensure proper logging and rollback if necessary.

If an action should be executed on every game reload and not only during the first run of a loader, refer to IRuntimeAction instead. If the action requires some additional code to be run to correctly rollback changes, refer to IUndoableAction.

Since:
9.1.0
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Applies the action, executing all code necessary.
    default boolean
    Ensures that an action is only applied on a certain loader.
    Gets a human-readable description of the action.
    default CodePosition
    Retrieves the position in the script file where the action was created.
    default boolean
    Determines whether an action should be applied for scripts loading in the given IScriptLoadSource.
    default boolean
    validate(org.apache.logging.log4j.Logger logger)
    Validates the action, ensuring no erroneous information is present.
  • Method Details

    • apply

      void apply()
      Applies the action, executing all code necessary.
      Since:
      9.1.0
    • describe

      String describe()
      Gets a human-readable description of the action.

      This message is used for logging and to surface information to the user when something goes wrong. It is thus customary to describe the action as accurately as possible without being too verbose.

      It is not allowed to return a null or otherwise empty description for the action: doing so will raise an error at runtime.

      Returns:
      A description of the current action.
      Since:
      9.1.0
    • validate

      default boolean validate(org.apache.logging.log4j.Logger logger)
      Validates the action, ensuring no erroneous information is present.

      Implementations should validate all action information and log errors using the provided Logger if anything is incorrect. It is highly suggested to specify exactly what is wrong in the most precise yet brief way possible, to ensure script writers know why their actions are not being applied.

      If validation fails for whatever reason, apply() will not be called.

      Parameters:
      logger - Logger object on which to log errors or warnings.
      Returns:
      Whether the action is valid (true) or not (false).
      Since:
      9.1.0
    • shouldApplyOn

      default boolean shouldApplyOn(IScriptLoadSource source)
      Determines whether an action should be applied for scripts loading in the given IScriptLoadSource.
      Parameters:
      source - The IScriptLoadSource responsible for loading the scripts.
      Returns:
      If the action should be applied.
      Since:
      9.1.0
    • getDeclaredScriptPosition

      @Nonnull default CodePosition getDeclaredScriptPosition()
      Retrieves the position in the script file where the action was created.

      The created CodePosition will always be a virtual position, meaning that its contents cannot be accessed.

      Returns:
      The CodePosition where the action was created on, or CodePosition.UNKNOWN if the information cannot be retrieved.
      Since:
      9.1.0
    • assertLoader

      default boolean assertLoader(IScriptLoader loader)
      Ensures that an action is only applied on a certain loader.

      This method is not meant to be overridden, but rather used as an additional check in shouldApplyOn(IScriptLoadSource) if needed.

      If the check fails, this method will also log a warning stating the script position where the error occurred if possible (see getDeclaredScriptPosition()) and which loader is the one the action is supposed to be ran on.

      Parameters:
      loader - THe IScriptLoader the action should be only applied on.
      Returns:
      If this loader matches the one specified as a parameter.
      Since:
      9.1.0