Class Parent<C>

java.lang.Object
privbot.task.SimpleNode<C>
privbot.task.Parent<C>
Type Parameters:
C - context type shared across the task tree
All Implemented Interfaces:
TaskNode<C>

public abstract class Parent<C> extends SimpleNode<C>
Shared parent node that owns a local group of Child tasks and selects the highest-priority eligible child when it executes.

Plugin authors interact with this class by:

The parent itself remains a normal SimpleNode, so it works naturally with TaskNodeRunner and other existing task APIs.
  • Constructor Details

    • Parent

      protected Parent(String name, int priority)
      Parameters:
      name - human-readable name for logging and overlay display
      priority - this group's priority among the runner's top-level nodes (higher wins)
    • Parent

      protected Parent(String name)
      Creates a parent with priority 0.
  • Method Details

    • addChild

      protected final Parent<C> addChild(Child<C> child)
      Adds a child to this group, normally from the subclass constructor. Children with equal priority keep this registration order.
      Returns:
      this parent, for chaining
      Throws:
      IllegalArgumentException - if child is null
    • getChildren

      public final List<Child<C>> getChildren()
      An unmodifiable view of the registered children, in registration order.
    • getActiveChild

      public final Child<C> getActiveChild()
      The child chosen by the last execute(C), or null when none ran or after a reset.
    • getActiveChildName

      public final String getActiveChildName()
      The name of getActiveChild(), or null.
    • shouldExecuteParent

      protected boolean shouldExecuteParent(C ctx)
      Group-level gate, checked before any child. Return false to skip the whole group this tick (no child predicate runs). Same rules as TaskNode.shouldExecute(C): read-only, no dispatch, no waits. Defaults to true.
    • shouldExecute

      public final boolean shouldExecute(C ctx)
      True when shouldExecuteParent(C) passes and at least one enabled child validates. Remembers the highest-priority eligible child for the following execute(C) call. A child whose predicate throws is skipped and passed to its handleError.
      Parameters:
      ctx - the shared context containing state and dependencies
      Returns:
      true if the task should execute, false otherwise
    • execute

      public final boolean execute(C ctx)
      Executes the child remembered by shouldExecute(C) (or selects one again when called without it) and returns that child's result. Only one child runs per call. A child that throws goes to its handleError and the call returns false.
      Parameters:
      ctx - the shared context
      Returns:
      true if the task performed an action (blocks sibling tasks from executing this tick), false otherwise
    • getStatus

      public String getStatus(C ctx)
      The active child's status, or this node's own status when no child is active.
      Specified by:
      getStatus in interface TaskNode<C>
      Overrides:
      getStatus in class SimpleNode<C>
      Parameters:
      ctx - the shared context
      Returns:
      a brief status description. Defaults to TaskNode.getName().
    • reset

      public void reset()
      Clears the active and remembered child and resets every child.
      Specified by:
      reset in interface TaskNode<C>
      Overrides:
      reset in class SimpleNode<C>
    • cleanup

      public void cleanup()
      Calls TaskNode.cleanup() on every child.
      Specified by:
      cleanup in interface TaskNode<C>
      Overrides:
      cleanup in class SimpleNode<C>