Package noppes.npcs.api.handler.data
Interface IAction
-
- All Known Subinterfaces:
IConditionalAction
public interface IActionRepresents a single "task" that can be executed over multiple ticks, supports delayed start, limited duration, repeating intervals, data storage, and chaining to neighboring tasks.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description IActionafter(int delay, java.util.function.Consumer<IAction> t)IActionafter(java.lang.String name, int maxDuration, int delay, java.util.function.Consumer<IAction> t)IActionafter(java.lang.String name, int delay, java.util.function.Consumer<IAction> t)IActionafter(java.lang.String name, java.util.function.Consumer<IAction> t)IActionafter(java.util.function.Consumer<IAction> t)voidafter(java.util.function.Consumer<IAction>... tasks)Multiple tasks chained one after another i.e after(task1,task2,task3,...)IActionafter(IAction after)Enqueue another action immediately after this one.voidafter(IAction... actions)Multiple actions chained one after another i.e after(act1,act2,act3,...)IActionbefore(int delay, java.util.function.Consumer<IAction> t)IActionbefore(java.lang.String name, int maxDuration, int delay, java.util.function.Consumer<IAction> t)IActionbefore(java.lang.String name, int delay, java.util.function.Consumer<IAction> t)IActionbefore(java.lang.String name, java.util.function.Consumer<IAction> t)IActionbefore(java.util.function.Consumer<IAction> t)IActionbefore(IAction before)Enqueue another action immediately before this one (pausing this one until done).IConditionalActionconditional(java.lang.String name, java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task)IConditionalActionconditional(java.lang.String name, java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task, java.util.function.Function<IAction,java.lang.Boolean> terminate)IConditionalActionconditional(java.lang.String name, java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task, java.util.function.Function<IAction,java.lang.Boolean> terminateWhen, java.util.function.Consumer<IAction> onTermination)IConditionalActionconditional(java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task)IConditionalActionconditional(java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task, java.util.function.Function<IAction,java.lang.Boolean> terminate)IConditionalActionconditional(java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task, java.util.function.Function<IAction,java.lang.Boolean> terminateWhen, java.util.function.Consumer<IAction> onTermination)IConditionalActionconditional(IConditionalAction after)Enqueue an IConditionalAction on the conditional chainvoidconditional(IConditionalAction... actions)IActioncopyDataTo(IAction copyTo)IActioneverySecond()Executes task every second (Sets updateEvery to 20)IActioneveryTick()Executes task every tick (Sets updateEvery to 1)intgetCount()java.lang.ObjectgetData(java.lang.String key)Retrieve arbitrary per-action data.intgetDuration()java.lang.StringgetIdentifier()IActionManagergetManager()intgetMaxCount()intgetMaxDuration()java.lang.StringgetName()IActiongetNext()IActiongetPrevious()IActionQueuegetQueue()intgetStartAfterTicks()intgetUpdateEvery()booleanhasData(java.lang.String key)booleanisDone()booleanisPaused()booleanisScheduled()voidkill()marks done and safely dumps the action's data and threadvoidmarkDone()Mark this action as complete and de-schedules it from its queue.IActiononce()Execute task only once, mark done equivalent to times(1)IActiononDone(java.util.function.Consumer<IAction> task)IActiononStart(java.util.function.Consumer<IAction> task)IActionparallel(int delay, java.util.function.Consumer<IAction> task)IActionparallel(java.lang.String name, int maxDuration, int delay, java.util.function.Consumer<IAction> t)IActionparallel(java.lang.String name, int startAfterTicks, java.util.function.Consumer<IAction> task)IActionparallel(java.lang.String name, java.util.function.Consumer<IAction> task)IActionparallel(java.util.function.Consumer<IAction> task)voidparallel(java.util.function.Consumer<IAction>... tasks)IActionparallel(IAction after)Enqueue another IAction on the parallel chain which starts firing simultaneously as this.voidparallel(IAction... actions)voidpause()Must callthreadify()before using, else throws exception.IActionpauseFor(int ticks)IActionpauseFor(long millis)voidpauseUntil(java.util.function.Function<IAction,java.lang.Boolean> until)Must callthreadify()before using, else throws exception.java.lang.StringprintData()IActionremoveData(java.lang.String key)voidresume()Resumes thread that was previously paused bypause(),pauseUntil(Function),pauseFor(int)orpauseFor(long)Must be called from a different thread than the IAction one, as that one is paused, so it won't reach this function if it comes after any of the pausing functions.IActionsetData(java.lang.String key, java.lang.Object value)Store arbitrary per-action data.IActionsetMaxDuration(int ticks)IActionsetQueue(IActionQueue queue)IActionsetTask(java.util.function.Consumer<IAction> task)IActionstart()IActionthreadify()Creates a new thread for task to run into.IActiontimes(int n)IActionupdateEvery(int ticks)Set how many ticks between each execution of the action task.
-
-
-
Method Detail
-
getQueue
IActionQueue getQueue()
- Returns:
- the queue this action is scheduled on. null if not scheduled
-
setQueue
IAction setQueue(IActionQueue queue)
- Parameters:
queue- Schedules action on this queue. If action was scheduled on different queue, transfers it over from that to this.- Returns:
-
setTask
IAction setTask(java.util.function.Consumer<IAction> task)
- Parameters:
task- code to execute each time the action fires- Returns:
-
getManager
IActionManager getManager()
- Returns:
- action manager the action is scheduled on
-
isScheduled
boolean isScheduled()
- Returns:
- True if was scheduled in the queues using any of the schedule methods, false if was only created.
-
getCount
int getCount()
- Returns:
- how many times this action’s task has been executed
-
onStart
IAction onStart(java.util.function.Consumer<IAction> task)
- Parameters:
task- Fires right after action gets scheduled at duration 0- Returns:
-
onDone
IAction onDone(java.util.function.Consumer<IAction> task)
- Parameters:
task- Fires right before a marked done action gets removed from it's IActionQueue- Returns:
-
getDuration
int getDuration()
- Returns:
- how many ticks have elapsed since this action actually began (excluding start delay)
-
getName
java.lang.String getName()
- Returns:
- the name given at creation/scheduling time
-
getMaxDuration
int getMaxDuration()
- Returns:
- the maximum number of ticks this action is allowed to run before auto marking done
P.S: If max duration is reached and this IAction's thread (created using
threadify()) is paused by any of the pausing methods, the thread is forcibly resumed and finishes the task execution.
-
setMaxDuration
IAction setMaxDuration(int ticks)
- Parameters:
ticks- max duration default: -1, infinite- Returns:
-
getMaxCount
int getMaxCount()
- Returns:
- the maximum number of counts this action is allowed to run before auto marking done
-
times
IAction times(int n)
- Parameters:
n- max count, task auto marks done after running for n counts default: -1, infinite- Returns:
-
once
IAction once()
Execute task only once, mark done equivalent to times(1)- Returns:
-
markDone
void markDone()
Mark this action as complete and de-schedules it from its queue. Forcibly resumes action if paused or had its thread slept with the IAction pausing methods.
-
isDone
boolean isDone()
- Returns:
- true if
markDone()was called (or maxDuration reached)
-
kill
void kill()
marks done and safely dumps the action's data and thread
-
getData
java.lang.Object getData(java.lang.String key)
Retrieve arbitrary per-action data.- Parameters:
key- a string key- Returns:
- the stored value, or null if not set
-
setData
IAction setData(java.lang.String key, java.lang.Object value)
Store arbitrary per-action data.- Parameters:
key- a string keyvalue- any object to associate with this action
-
removeData
IAction removeData(java.lang.String key)
-
copyDataTo
IAction copyDataTo(IAction copyTo)
- Parameters:
copyTo- copies all of this IAction's data to copyTo- Returns:
-
printData
java.lang.String printData()
- Returns:
- a string containing all the stored data key/values of this IAction
-
hasData
boolean hasData(java.lang.String key)
-
getUpdateEvery
int getUpdateEvery()
- Returns:
- how many ticks between each execution of the action's task Default is 5 ticks (4 times per second)
-
updateEvery
IAction updateEvery(int ticks)
Set how many ticks between each execution of the action task.- Parameters:
ticks- tick interval (e.g. 1 = every tick, 20 = once per second)
-
everyTick
IAction everyTick()
Executes task every tick (Sets updateEvery to 1)- Returns:
-
everySecond
IAction everySecond()
Executes task every second (Sets updateEvery to 20)- Returns:
-
getStartAfterTicks
int getStartAfterTicks()
- Returns:
- how many ticks remain before the action begins (initial delay)
-
pauseFor
IAction pauseFor(int ticks)
- Parameters:
ticks- pauses action for this number of ticks (any subsequent action is paused too) If action was threaded usingthreadify(), sleeps the thread. Can be forcibly resumed usingresume()- Returns:
-
pauseFor
IAction pauseFor(long millis)
-
pause
void pause()
Must callthreadify()before using, else throws exception. Pauses IAction's thread untilresume()is called.
-
pauseUntil
void pauseUntil(java.util.function.Function<IAction,java.lang.Boolean> until)
Must callthreadify()before using, else throws exception. Pauses IAction's thread until the supplied condition is satisfied orresume()is called.
-
resume
void resume()
Resumes thread that was previously paused bypause(),pauseUntil(Function),pauseFor(int)orpauseFor(long)Must be called from a different thread than the IAction one, as that one is paused, so it won't reach this function if it comes after any of the pausing functions.
-
isPaused
boolean isPaused()
- Returns:
- checks if IAction's getStartAfterTicks > 0, or if IAction's thread is paused if threaded Preferably called from a different thread than the IAction one if it's paused.
-
getIdentifier
java.lang.String getIdentifier()
- Returns:
- "{Type} '{Name}'" of action i.e "Action 'one'" or "ConditionalAction 'two'"
-
threadify
IAction threadify()
Creates a new thread for task to run into. Allows for pausing and sleeping just this IAction's thread.
-
start
IAction start()
- Returns:
- starts the IActionManager
-
getNext
IAction getNext()
- Returns:
- the next action in the queue (or null if none or at end)
-
getPrevious
IAction getPrevious()
- Returns:
- the previous action in the queue (or null if none or at front)
-
after
IAction after(IAction after)
Enqueue another action immediately after this one.- Parameters:
after- the action to run next
-
after
void after(IAction... actions)
Multiple actions chained one after another i.e after(act1,act2,act3,...)- Parameters:
actions-
-
after
void after(java.util.function.Consumer<IAction>... tasks)
Multiple tasks chained one after another i.e after(task1,task2,task3,...)- Parameters:
tasks-
-
after
IAction after(java.lang.String name, int maxDuration, int delay, java.util.function.Consumer<IAction> t)
-
before
IAction before(IAction before)
Enqueue another action immediately before this one (pausing this one until done).- Parameters:
before- the action to run prior
-
before
IAction before(java.lang.String name, int maxDuration, int delay, java.util.function.Consumer<IAction> t)
-
conditional
IConditionalAction conditional(IConditionalAction after)
Enqueue an IConditionalAction on the conditional chain- Parameters:
after- the scheduled IConditionalAction
-
conditional
void conditional(IConditionalAction... actions)
-
conditional
IConditionalAction conditional(java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task)
-
conditional
IConditionalAction conditional(java.lang.String name, java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task)
-
conditional
IConditionalAction conditional(java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task, java.util.function.Function<IAction,java.lang.Boolean> terminate)
-
conditional
IConditionalAction conditional(java.lang.String name, java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task, java.util.function.Function<IAction,java.lang.Boolean> terminate)
-
conditional
IConditionalAction conditional(java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task, java.util.function.Function<IAction,java.lang.Boolean> terminateWhen, java.util.function.Consumer<IAction> onTermination)
-
conditional
IConditionalAction conditional(java.lang.String name, java.util.function.Function<IAction,java.lang.Boolean> condition, java.util.function.Consumer<IAction> task, java.util.function.Function<IAction,java.lang.Boolean> terminateWhen, java.util.function.Consumer<IAction> onTermination)
-
parallel
IAction parallel(IAction after)
Enqueue another IAction on the parallel chain which starts firing simultaneously as this.- Parameters:
after- the scheduled parallel action
-
parallel
void parallel(IAction... actions)
-
parallel
void parallel(java.util.function.Consumer<IAction>... tasks)
-
parallel
IAction parallel(java.lang.String name, int startAfterTicks, java.util.function.Consumer<IAction> task)
-
-