Class TaskQueue
java.lang.Object
io.github.bakedlibs.dough.scheduling.TaskQueue
This class provides useful utilities to schedule Tasks (sync and async).
Tasks are added into a Queue and then run sequentially via
execute(Plugin)
You can provide a delay between the individual tasks via the ticks argument in
thenRun(int, Runnable)
If you need to access the index of your current task (whether it is the first, last or xth task) you can use
the methods with IntConsumer as an argument, otherwise just use the ones with Runnable- Author:
- TheBusyBiscuit
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidUse this method to execute the final Task Queue.voidThis method will make the task run the given callback until eternity.voidthenLoop(IntConsumer consumer) This method will make the task run the given callback until eternity.voidthenLoopAsynchronously(Runnable runnable) This method will make the task run the given callback until eternity.voidthenLoopAsynchronously(IntConsumer consumer) This method will make the task run the given callback until eternity.voidthenLoopEvery(int ticks, Runnable runnable) This method will make the task run the given callback until eternity.voidthenLoopEvery(int ticks, IntConsumer consumer) This method will make the task run the given callback until eternity.voidthenLoopEveryAsynchronously(int ticks, Runnable runnable) This method will make the task run the given callback until eternity.voidthenLoopEveryAsynchronously(int ticks, IntConsumer consumer) This method will make the task run the given callback until eternity.thenRepeat(int iterations, Runnable runnable) This method will schedule the given Task with no delay and synchronously.thenRepeat(int iterations, IntConsumer consumer) This method will schedule the given Task with no delay and synchronously.thenRepeatAsynchronously(int iterations, Runnable runnable) This method will schedule the given Task with no delay and asynchronously.thenRepeatAsynchronously(int iterations, IntConsumer consumer) This method will schedule the given Task with no delay and asynchronously.thenRepeatEvery(int ticks, int iterations, Runnable runnable) This method will schedule the given Task with the given delay and synchronously.thenRepeatEvery(int ticks, int iterations, IntConsumer consumer) This method will schedule the given Task with the given delay and synchronously.thenRepeatEveryAsynchronously(int ticks, int iterations, Runnable runnable) This method will schedule the given Task with the given delay and asynchronously.thenRepeatEveryAsynchronously(int ticks, int iterations, IntConsumer consumer) This method will schedule the given Task with the given delay and asynchronously.This method will schedule the given Task with the given delay and synchronously.thenRun(int ticks, IntConsumer consumer) This method will schedule the given Task with the given delay and synchronously.This method will schedule the given Task with no delay and synchronously.thenRun(IntConsumer consumer) This method will schedule the given Task with no delay and synchronously.thenRunAsynchronously(int ticks, Runnable runnable) This method will schedule the given Task with the given delay and synchronously.thenRunAsynchronously(int ticks, IntConsumer consumer) This method will schedule the given Task with the given delay and asynchronously.thenRunAsynchronously(Runnable runnable) This method will schedule the given Task with no delay and asynchronously.thenRunAsynchronously(IntConsumer consumer) This method will schedule the given Task with no delay and asynchronously.thenWait(int ticks) This method will make the Queue just do nothing for the given amount of ticks.
-
Constructor Details
-
TaskQueue
public TaskQueue()
-
-
Method Details
-
execute
Use this method to execute the final Task Queue. You should add the tasks before-hand. AnIllegalStateExceptionwill be thrown if the queue is empty.- Parameters:
plugin- The plugin that is performing this execution
-
thenRun
This method will schedule the given Task with no delay and synchronously. Use theIntegerparameter in yourIntConsumerto determine the task's index.- Parameters:
consumer- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRun
This method will schedule the given Task with no delay and synchronously.- Parameters:
runnable- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRunAsynchronously
This method will schedule the given Task with no delay and asynchronously. Use theIntegerparameter in yourIntConsumerto determine the task's index.- Parameters:
consumer- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRunAsynchronously
This method will schedule the given Task with no delay and asynchronously.- Parameters:
runnable- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRun
This method will schedule the given Task with the given delay and synchronously. Use theIntegerparameter in yourIntConsumerto determine the task's index.- Parameters:
ticks- The time to wait before running this task after the previous one.consumer- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRun
This method will schedule the given Task with the given delay and synchronously.- Parameters:
ticks- The time to wait before running this task after the previous one.runnable- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRunAsynchronously
This method will schedule the given Task with the given delay and asynchronously. Use theIntegerparameter in yourIntConsumerto determine the task's index.- Parameters:
ticks- The time to wait before running this task after the previous one.consumer- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRunAsynchronously
This method will schedule the given Task with the given delay and synchronously.- Parameters:
ticks- The time to wait before running this task after the previous one.runnable- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRepeat
This method will schedule the given Task with no delay and synchronously. The task will be repeated for the given amount of iterations. Use theIntegerparameter in yourIntConsumerto determine the task's index.- Parameters:
iterations- The amount of times to repeat this taskconsumer- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRepeat
This method will schedule the given Task with no delay and synchronously. The task will be repeated for the given amount of iterations.- Parameters:
iterations- The amount of times to repeat this taskrunnable- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRepeatAsynchronously
This method will schedule the given Task with no delay and asynchronously. The task will be repeated for the given amount of iterations. Use theIntegerparameter in yourIntConsumerto determine the task's index.- Parameters:
iterations- The amount of times to repeat this taskconsumer- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRepeatAsynchronously
This method will schedule the given Task with no delay and asynchronously. The task will be repeated for the given amount of iterations.- Parameters:
iterations- The amount of times to repeat this taskrunnable- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRepeatEvery
This method will schedule the given Task with the given delay and synchronously. The task will be repeated for the given amount of iterations. Use theIntegerparameter in yourIntConsumerto determine the task's index.- Parameters:
ticks- The delay between executions (including the start delay)iterations- The amount of times to repeat this taskconsumer- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRepeatEvery
This method will schedule the given Task with the given delay and synchronously. The task will be repeated for the given amount of iterations.- Parameters:
ticks- The delay between executions (including the start delay)iterations- The amount of times to repeat this taskrunnable- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRepeatEveryAsynchronously
@Nonnull public TaskQueue thenRepeatEveryAsynchronously(int ticks, int iterations, @Nonnull IntConsumer consumer) This method will schedule the given Task with the given delay and asynchronously. The task will be repeated for the given amount of iterations. Use theIntegerparameter in yourIntConsumerto determine the task's index.- Parameters:
ticks- The delay between executions (including the start delay)iterations- The amount of times to repeat this taskconsumer- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenRepeatEveryAsynchronously
@Nonnull public TaskQueue thenRepeatEveryAsynchronously(int ticks, int iterations, @Nonnull Runnable runnable) This method will schedule the given Task with the given delay and asynchronously. The task will be repeated for the given amount of iterations.- Parameters:
ticks- The delay between executions (including the start delay)iterations- The amount of times to repeat this taskrunnable- The callback to run- Returns:
- The current instance of
TaskQueue
-
thenLoop
This method will make the task run the given callback until eternity. The task will be run with no delay and synchronously. Do not add other tasks after calling this method.- Parameters:
consumer- The callback to run
-
thenLoop
This method will make the task run the given callback until eternity. The task will be run with no delay and synchronously. Do not add other tasks after calling this method.- Parameters:
runnable- The callback to run
-
thenLoopAsynchronously
This method will make the task run the given callback until eternity. The task will be run with no delay and asynchronously. Do not add other tasks after calling this method.- Parameters:
consumer- The callback to run
-
thenLoopAsynchronously
This method will make the task run the given callback until eternity. The task will be run with no delay and asynchronously. Do not add other tasks after calling this method.- Parameters:
runnable- The callback to run
-
thenLoopEvery
This method will make the task run the given callback until eternity. The task will be run with the given delay and synchronously. Do not add other tasks after calling this method.- Parameters:
ticks- The delay between executions (including the start delay)consumer- The callback to run
-
thenLoopEvery
This method will make the task run the given callback until eternity. The task will be run with the given delay and synchronously. Do not add other tasks after calling this method.- Parameters:
ticks- The delay between executions (including the start delay)runnable- The callback to run
-
thenLoopEveryAsynchronously
This method will make the task run the given callback until eternity. The task will be run with the given delay and asynchronously. Do not add other tasks after calling this method.- Parameters:
ticks- The delay between executions (including the start delay)consumer- The callback to run
-
thenLoopEveryAsynchronously
This method will make the task run the given callback until eternity. The task will be run with the given delay and asynchronously. Do not add other tasks after calling this method.- Parameters:
ticks- The delay between executions (including the start delay)runnable- The callback to run
-
thenWait
This method will make the Queue just do nothing for the given amount of ticks. You should not really be using this method but it exists.- Parameters:
ticks- The amount of ticks to wait for- Returns:
- The current instance of
TaskQueue
-