Interface IAction

  • All Known Subinterfaces:
    IConditionalAction

    public interface IAction
    Represents 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 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 key
        value - 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 using threadify(), sleeps the thread. Can be forcibly resumed using resume()
        Returns:
      • pauseFor

        IAction pauseFor​(long millis)
      • pause

        void pause()
        Must call threadify() before using, else throws exception. Pauses IAction's thread until resume() is called.
      • pauseUntil

        void pauseUntil​(java.util.function.Function<IAction,​java.lang.Boolean> until)
        Must call threadify() before using, else throws exception. Pauses IAction's thread until the supplied condition is satisfied or resume() is called.
      • resume

        void resume()
        Resumes thread that was previously paused by pause(), pauseUntil(Function), pauseFor(int) or pauseFor(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)
      • after

        IAction after​(java.lang.String name,
                      int delay,
                      java.util.function.Consumer<IAction> t)
      • after

        IAction after​(int delay,
                      java.util.function.Consumer<IAction> t)
      • after

        IAction after​(java.lang.String name,
                      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)
      • before

        IAction before​(java.lang.String name,
                       int delay,
                       java.util.function.Consumer<IAction> t)
      • before

        IAction before​(int delay,
                       java.util.function.Consumer<IAction> t)
      • before

        IAction before​(java.lang.String name,
                       java.util.function.Consumer<IAction> t)
      • conditional

        IConditionalAction conditional​(IConditionalAction after)
        Enqueue an IConditionalAction on the conditional chain
        Parameters:
        after - the scheduled IConditionalAction
      • 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

        IAction parallel​(java.util.function.Consumer<IAction> task)
      • parallel

        void parallel​(java.util.function.Consumer<IAction>... tasks)
      • parallel

        IAction parallel​(int delay,
                         java.util.function.Consumer<IAction> task)
      • parallel

        IAction parallel​(java.lang.String name,
                         java.util.function.Consumer<IAction> task)
      • parallel

        IAction parallel​(java.lang.String name,
                         int startAfterTicks,
                         java.util.function.Consumer<IAction> task)
      • parallel

        IAction parallel​(java.lang.String name,
                         int maxDuration,
                         int delay,
                         java.util.function.Consumer<IAction> t)