From 30f3e562c8b07d6b1517bc8e52370330a4aa6480 Mon Sep 17 00:00:00 2001 From: bigguy345 Date: Sun, 29 Jun 2025 11:22:43 +0300 Subject: [PATCH] More schedulers and overloading methods !!!! --- .../npcs/api/handler/IActionManager.java | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/java/noppes/npcs/api/handler/IActionManager.java b/java/noppes/npcs/api/handler/IActionManager.java index 2fb6aad..671c468 100644 --- a/java/noppes/npcs/api/handler/IActionManager.java +++ b/java/noppes/npcs/api/handler/IActionManager.java @@ -20,11 +20,11 @@ public interface IActionManager { * * @param name a unique name for this action * @param maxDuration the maximum lifetime of the action in ticks - * @param startAfterTicks number of ticks to wait before the first run + * @param delay number of ticks to wait before the first run * @param action code to execute each time the action "fires" * @return a fresh {@link IAction} object */ - IAction create(String name, int maxDuration, int startAfterTicks, Consumer action); + IAction create(String name, int maxDuration, int delay, Consumer action); IAction create(String name, int delay, Consumer t); @@ -118,6 +118,23 @@ public interface IActionManager { */ IAction scheduleAction(IAction action); + /** + * Convenience for {@link #create(Consumer)} + enqueue. + * + * @param task code to execute each time the task "fires" + * @return the task scheduled + */ + IAction scheduleAction(Consumer task); + + /** + * Convenience for {@link #create(String, Consumer)} + enqueue. + * + * @param delay number of ticks to wait before the first task run + * @param task code to execute each time the task "fires" + * @return the task scheduled + */ + IAction scheduleAction(int delay, Consumer task); + /** * Convenience for {@link #create(String, Consumer)} + enqueue. * @@ -131,22 +148,22 @@ public interface IActionManager { * Convenience for {@link #create(String, int, Consumer)} + enqueue. * * @param name a unique name for this action - * @param startAfterTicks number of ticks to wait before the first task run + * @param delay number of ticks to wait before the first task run * @param task code to execute each time the task "fires" * @return the task scheduled */ - IAction scheduleAction(String name, int startAfterTicks, Consumer task); + IAction scheduleAction(String name, int delay, Consumer task); /** * Convenience for {@link #create(String, int, int, Consumer)} + enqueue. * * @param name a unique name for this action * @param maxDuration the maximum lifetime of the action in ticks - * @param startAfterTicks number of ticks to wait before the first task run + * @param delay number of ticks to wait before the first task run * @param task code to execute each time the task "fires" * @return the task scheduled */ - IAction scheduleAction(String name, int maxDuration, int startAfterTicks, Consumer task); + IAction scheduleAction(String name, int maxDuration, int delay, Consumer task); /** * Insert an action at a specific position in the queue. @@ -255,8 +272,8 @@ public interface IActionManager { /** * Convenience: create and enqueue a normal repeating task. */ - default IAction addTask(String name, int maxDuration, int startAfterTicks, Consumer task) { - return scheduleAction(name, maxDuration, startAfterTicks, task); + default IAction addTask(String name, int maxDuration, int delay, Consumer task) { + return scheduleAction(name, maxDuration, delay, task); } /** @@ -264,11 +281,11 @@ public interface IActionManager { * after the given delay, and then auto-complete. * * @param name a unique name for this action - * @param startAfterTicks delay before it runs (in ticks) + * @param delay delay before it runs (in ticks) * @param task code to execute once */ - default IAction addSingleTask(String name, int startAfterTicks, Consumer task) { - IAction action = create(name, 1, startAfterTicks, act -> { + default IAction addSingleTask(String name, int delay, Consumer task) { + IAction action = create(name, 1, delay, act -> { task.accept(act); act.markDone(); }); @@ -316,9 +333,9 @@ public interface IActionManager { IAction scheduleParallelAction(String name, Consumer task); - IAction scheduleParallelAction(String name, int startAfterTicks, Consumer task); + IAction scheduleParallelAction(String name, int delay, Consumer task); - IAction scheduleParallelAction(String name, int maxDuration, int startAfterTicks, Consumer task); + IAction scheduleParallelAction(String name, int maxDuration, int delay, Consumer task); IActionChain chain();