Interface TaskNode<C>

Type Parameters:
C - the context type shared across all nodes in the tree
All Known Implementing Classes:
Child, CompositeTaskNode, Parent, SimpleNode

public interface TaskNode<C>
Base interface for all task nodes in the PrivBot task framework.

A task node represents a self-contained, testable unit of automation logic that can be composed into trees using CompositeTaskNode or grouped through Parent/Child. Task nodes follow a state machine pattern with clear entry/exit conditions.

The generic type parameter C is the shared context object that all tasks in a tree receive. Each plugin defines its own context type containing the state and dependencies its tasks need (e.g., VerzikContext, SlayerContext).

For simple single-tick tasks, extend SimpleNode instead of implementing this interface directly.

Usage Example:


 public class EatFoodTask extends SimpleNode<MyContext> {
     public EatFoodTask() {
         super("Eat Food", 80);
     }

     @Override
     public boolean shouldExecute(MyContext ctx) {
         return ctx.combat.isInCombat()
             && ctx.inventory.contains("Shark");
     }

     @Override
     public boolean execute(MyContext ctx) {
         return ctx.inventory.eatFirst("Shark");
     }
 }
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Cleanup lifecycle hook called when the script shuts down or the tree is torn down.
    boolean
    execute(C ctx)
    Executes the task's main logic.
    Gets a human-readable name for this task.
    default int
    Gets the numeric priority of this task.
    default String
    getStatus(C ctx)
    Gets the current status description for overlay/GUI display.
    boolean
    Checks if the task has completed its current cycle.
    default boolean
    Returns whether this task node is enabled.
    void
    Resets the task's internal state.
    boolean
    Checks if this task should currently execute.
  • Method Details

    • shouldExecute

      boolean shouldExecute(C ctx)
      Checks if this task should currently execute. This represents the entry condition for the task.
      Parameters:
      ctx - the shared context containing state and dependencies
      Returns:
      true if the task should execute, false otherwise
    • execute

      boolean execute(C ctx)
      Executes the task's main logic. Called when shouldExecute(C) returns true.
      Parameters:
      ctx - the shared context
      Returns:
      true if the task performed an action (blocks sibling tasks from executing this tick), false otherwise
    • isComplete

      boolean isComplete(C ctx)
      Checks if the task has completed its current cycle. Used for tasks that span multiple ticks (e.g., walking to a destination, waiting for an animation to finish).
      Parameters:
      ctx - the shared context
      Returns:
      true if the task has completed, false if still in progress
    • reset

      void reset()
      Resets the task's internal state. Called when transitioning phases, restarting the script, or when the parent composite node resets.
    • getPriority

      default int getPriority()
      Gets the numeric priority of this task. Higher numbers run first. Equal priorities keep registration order.
      Returns:
      the task priority (higher = more important). Default is 0.
    • getName

      String getName()
      Gets a human-readable name for this task. Used for debugging, logging, and overlay display.
      Returns:
      the task name
    • getStatus

      default String getStatus(C ctx)
      Gets the current status description for overlay/GUI display. Override to provide dynamic status messages (e.g., "Walking to bank (15 tiles)").
      Parameters:
      ctx - the shared context
      Returns:
      a brief status description. Defaults to getName().
    • isEnabled

      default boolean isEnabled()
      Returns whether this task node is enabled. Disabled nodes are skipped by CompositeTaskNode during execution.
      Returns:
      true if this node is enabled, false if it should be skipped
    • cleanup

      default void cleanup()
      Cleanup lifecycle hook called when the script shuts down or the tree is torn down. Override to release resources held by this node.