diff --git a/java/noppes/npcs/api/handler/IActionManager.java b/java/noppes/npcs/api/handler/IActionManager.java new file mode 100644 index 0000000..b8dfd34 --- /dev/null +++ b/java/noppes/npcs/api/handler/IActionManager.java @@ -0,0 +1,87 @@ +package noppes.npcs.api.handler; + +import noppes.npcs.api.handler.data.IAction; +import java.util.Queue; +import java.util.function.Consumer; + +/** + * Interface for managing and scheduling actions. + * Provides methods to create, start, stop, and queue actions. + */ +public interface IActionManager { + /** + * Creates a new IAction instance with the specified parameters. + * + * @param name the name of the action. + * @param maxDuration the maximum duration (in ticks) for the action. + * @param startAfterTicks the delay in ticks before the action starts. + * @param action the consumer defining the action's behavior. + * @return a new IAction instance. + */ + IAction createAction(String name, int maxDuration, int startAfterTicks, Consumer action); + + /** + * Starts the action manager, enabling the processing of scheduled actions. + */ + void start(); + + /** + * Stops the action manager, halting the processing of scheduled actions. + */ + void stop(); + + /** + * Schedules an action by adding it to the action queue. + * + * @param action the action to be scheduled. + */ + void addScheduledAction(IAction action); + + /** + * Creates and schedules an action with the given parameters. + * + * @param name the name of the action. + * @param maxDuration the maximum duration (in ticks) for the action. + * @param startAfterTicks the delay in ticks before the action starts. + * @param action the consumer defining the action's behavior. + */ + void addScheduledAction(String name, int maxDuration, int startAfterTicks, Consumer action); + + /** + * Inserts an action into the action queue at the specified index. + * + * @param index the position in the queue where the action should be added. + * @param action the action to insert. + */ + void addScheduledActionAt(int index, IAction action); + + /** + * Schedules an action to be executed immediately after the specified action. + * + * @param after the action after which the new action should run. + * @param toSchedule the action to schedule. + */ + void scheduleActionAfter(IAction after, IAction toSchedule); + + /** + * Retrieves the index of the specified action in the action queue. + * + * @param action the action whose index is to be determined. + * @return the index of the action in the queue, or -1 if not found. + */ + int getActionIndex(IAction action); + + /** + * Gets the current action (the one at the head of the queue). + * + * @return the current action, or null if the queue is empty. + */ + IAction getCurrentAction(); + + /** + * Returns the queue of scheduled actions. + * + * @return the action queue. + */ + Queue getActionQueue(); +} diff --git a/java/noppes/npcs/api/handler/data/IAction.java b/java/noppes/npcs/api/handler/data/IAction.java new file mode 100644 index 0000000..59a710f --- /dev/null +++ b/java/noppes/npcs/api/handler/data/IAction.java @@ -0,0 +1,106 @@ +package noppes.npcs.api.handler.data; + +import java.util.function.Consumer; + +/** + * Represents an action that can be executed over a period of time. + * Provides methods to query its state, update data, and chain scheduling. + */ +public interface IAction { + /** + * Gets the number of times this action has been executed. + * + * @return the execution count. + */ + int getCount(); + + /** + * Gets the elapsed duration (in ticks) since the action began. + * + * @return the duration in ticks. + */ + int getDuration(); + + /** + * Gets the name of this action. + * + * @return the action name. + */ + String getName(); + + /** + * Gets the maximum duration (in ticks) that this action is allowed to run. + * + * @return the maximum duration in ticks. + */ + int getMaxDuration(); + + /** + * Marks the action as completed or not. + * + * @param done true to mark the action as done, false otherwise. + */ + void setDone(boolean done); + + /** + * Checks if the action has been marked as completed. + * + * @return true if the action is done, false otherwise. + */ + boolean isDone(); + + /** + * Retrieves the data associated with the specified key. + * + * @param key the key of the data. + * @return the associated data, or null if not present. + */ + Object getData(String key); + + /** + * Stores data with the specified key. + * + * @param key the key under which the data is stored. + * @param value the data to store. + */ + void addData(String key, Object value); + + /** + * Gets the interval (in ticks) between each update of this action. + * + * @return the number of ticks between updates. + */ + int getUpdateEveryXTick(); + + /** + * Sets the update frequency in ticks. + * + * @param X the number of ticks between each update. + */ + void setUpdateEveryXTick(int X); + + /** + * Gets the number of ticks to wait before starting the action. + * + * @return the delay in ticks before the action starts. + */ + int getStartAfterTicks(); + + /** + * Creates a new IAction instance with the given parameters. + * + * @param name the name of the action. + * @param maxDuration the maximum duration (in ticks) the action can run. + * @param startAfterTicks the delay in ticks before the action starts. + * @param action the consumer defining the action's behavior. + * @return a new IAction instance. + */ + IAction create(String name, int maxDuration, int startAfterTicks, Consumer action); + + /** + * Schedules another action to be executed immediately after this action. + * + * @param action the action to schedule after this one. + */ + void scheduleAfter(IAction action); +}