Interface Task

All Known Implementing Classes:
PluginTask

public interface Task
Interface representing a unit of work in a TaskPlugin.

Tasks encapsulate discrete actions that can be validated and executed. They form the building blocks of task-based plugins, allowing for modular and reusable automation logic.

Each task has two main methods:

Example implementation:


 public class EatFoodTask implements Task {
     @Override
     public boolean validate() {
         // Only eat when health is low
         return Players.getLocal().getHealthPercent() < 50;
     }

     @Override
     public int execute() {
         // Find and eat food
         Item food = Inventory.getFirst(ItemID.SHARK);
         if (food != null) {
             food.interact("Eat");
         }
         return 600; // Wait 600ms before next task
     }
 }
 

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    int
    Executes the task's action.
    default boolean
    Determines whether this task should have dependencies injected.
    default boolean
    Determines whether this task blocks subsequent task execution.
    default boolean
    Determines whether this task should be registered to the event bus.
    boolean
    Validates whether this task should be executed.
  • Method Details

    • validate

      boolean validate()
      Validates whether this task should be executed.

      This method is called each loop iteration to determine if the task's conditions are met. Return true if the task should execute, false otherwise.

      Returns:
      true if the task should execute, false otherwise
    • execute

      int execute()
      Executes the task's action.

      This method is called when validate() returns true. Implement the task's logic here.

      Returns:
      the delay in milliseconds before the next task can execute. For blocking tasks, this determines the delay before the next loop iteration.
    • isBlocking

      default boolean isBlocking()
      Determines whether this task blocks subsequent task execution.

      Blocking tasks prevent other tasks from being collected and executed in the same loop iteration. The delay returned by a blocking task's execute() method becomes the loop delay.

      Non-blocking tasks allow multiple tasks to execute in sequence within a single loop iteration.

      Returns:
      true if this task is blocking (default), false otherwise
    • subscribe

      default boolean subscribe()
      Determines whether this task should be registered to the event bus.

      When true, the task will receive events from the event bus, allowing it to respond to game events.

      Returns:
      true if the task should subscribe to events, false otherwise (default)
    • inject

      default boolean inject()
      Determines whether this task should have dependencies injected.

      When true, the task will have its fields annotated with @Inject populated by the dependency injection framework.

      Returns:
      true if the task should have dependencies injected, false otherwise (default)