Class ScriptExecutor
java.lang.Object
privbot.task.ScriptExecutor
Runs script logic on a dedicated thread so that
sleep() and
sleepUntil() block only the script — never the client (game-tick)
thread.
Usage:
ScriptExecutor executor = new ScriptExecutor("my-plugin-worker", () -> {
maintenance.tick(context);
TaskNode<MyContext> node = GameThread.ensure(runner::selectNode);
runner.executeNode(node);
});
executor.start();
// In onGameTick (client thread):
executor.signalTick();
// On shutdown:
executor.stop();
When a game tick fires while the script thread is still busy (e.g. inside
a sleepUntil), the tick is queued. On wake the script processes
exactly one tick and drains any extras, so it always works with
the latest game state rather than replaying stale ticks.
-
Constructor Summary
ConstructorsConstructorDescriptionScriptExecutor(String name, Runnable tickWork) Owned by the plugin that wrotetickWork: a lambda or method reference is defined in its host class's loader, so a plugin's own lambda names the plugin.ScriptExecutor(String name, Runnable tickWork, ClassLoader ownerLoader) -
Method Summary
-
Constructor Details
-
ScriptExecutor
Owned by the plugin that wrotetickWork: a lambda or method reference is defined in its host class's loader, so a plugin's own lambda names the plugin. Framework code that builds the tick work itself must useScriptExecutor(String, Runnable, ClassLoader)— its lambda would name shared-lib instead.- Parameters:
name- thread name (shown in thread dumps)tickWork- the work to run each tick; select on the client thread and execute here
-
ScriptExecutor
- Parameters:
name- thread name (shown in thread dumps)tickWork- the work to run each tick; select on the client thread and execute hereownerLoader- classloader of the plugin this executor runs for;nullreports nothing
-
-
Method Details
-
start
public void start()Starts the script thread. Safe to call multiple times — subsequent calls are ignored while the thread is alive. -
signalTick
public void signalTick()Called fromonGameTick()on the client thread. Wakes the script thread to process one tick. -
stop
public void stop()Stops the script thread. Blocks up to 2 seconds for a clean shutdown.Interrupts the worker, so a node inside a sleep or a marshalled read unwinds (sleeps return false,
GameThread.ensurereturns null). Called from the worker itself it returns without joining. -
isRunning
public boolean isRunning()Returns true if the script thread is alive. False afterstop(), even when the old thread had not exited within the 2 s join.
-