Class ScheduledTask
java.lang.Object
be.seeseemelk.mockbukkit.scheduler.ScheduledTask
- All Implemented Interfaces:
BukkitTask,BukkitWorker
- Direct Known Subclasses:
RepeatingTask
Mock implementation of a
BukkitTask.-
Constructor Summary
ConstructorsConstructorDescriptionScheduledTask(int id, Plugin plugin, boolean isSync, long scheduledTick, @NotNull Runnable runnable) Constructs a newScheduledTaskwith the provided parameters.ScheduledTask(int id, Plugin plugin, boolean isSync, long scheduledTick, @NotNull Consumer<? super BukkitTask> consumer) Constructs a newScheduledTaskwith the provided parameters. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddOnCancelled(Runnable callback) Adds a callback which is executed when the task is cancelled.voidcancel()@Nullable Consumer<? super BukkitTask> Get the Consumer that will be run.@NotNull PlugingetOwner()@Nullable RunnableGet the task itself that will be run.longGet the tick at which the task is scheduled to run at.int@NotNull ThreadbooleanbooleanbooleanisSync()voidrun()Runs the task if it has not been cancelled.voidsetRunning(boolean running) Sets whether the task is running.protected voidsetScheduledTick(long scheduledTick) Sets the tick at which the task is scheduled to run at.protected voidMarks the task as being submitted to the async thread pool.
-
Constructor Details
-
ScheduledTask
public ScheduledTask(int id, Plugin plugin, boolean isSync, long scheduledTick, @NotNull @NotNull Runnable runnable) Constructs a newScheduledTaskwith the provided parameters.- Parameters:
id- The task ID.plugin- The plugin owning the task.isSync- Whether the task is synchronous.scheduledTick- The tick the task is scheduled to run at.runnable- The runnable to run.
-
ScheduledTask
public ScheduledTask(int id, Plugin plugin, boolean isSync, long scheduledTick, @NotNull @NotNull Consumer<? super BukkitTask> consumer) Constructs a newScheduledTaskwith the provided parameters.- Parameters:
id- The task ID.plugin- The plugin owning the task.isSync- Whether the task is synchronous.scheduledTick- The tick the task is scheduled to run at.consumer- The consumer to run.
-
-
Method Details
-
isRunning
public boolean isRunning()- Returns:
- Whether the task is running.
-
setRunning
@Internal public void setRunning(boolean running) Sets whether the task is running. Should not be used outside ofBukkitSchedulerMock.- Parameters:
running- Whether the task is running.
-
getScheduledTick
public long getScheduledTick()Get the tick at which the task is scheduled to run at.- Returns:
- The tick the task is scheduled to run at.
-
setScheduledTick
protected void setScheduledTick(long scheduledTick) Sets the tick at which the task is scheduled to run at.- Parameters:
scheduledTick- The tick at which the task is scheduled to run at.
-
getRunnable
Get the task itself that will be run.- Returns:
- The task that will be run.
-
getConsumer
Get the Consumer that will be run.- Returns:
- The consumer that will be run.
-
submitted
@Internal protected void submitted()Marks the task as being submitted to the async thread pool. This is used to bypass the #isCancelled check if it gets updated before the task is run. -
run
public void run()Runs the task if it has not been cancelled. -
getTaskId
public int getTaskId()- Specified by:
getTaskIdin interfaceBukkitTask- Specified by:
getTaskIdin interfaceBukkitWorker
-
getOwner
- Specified by:
getOwnerin interfaceBukkitTask- Specified by:
getOwnerin interfaceBukkitWorker
-
getThread
- Specified by:
getThreadin interfaceBukkitWorker
-
isSync
public boolean isSync()- Specified by:
isSyncin interfaceBukkitTask
-
isCancelled
public boolean isCancelled()- Specified by:
isCancelledin interfaceBukkitTask
-
cancel
public void cancel()- Specified by:
cancelin interfaceBukkitTask
-
addOnCancelled
Adds a callback which is executed when the task is cancelled.- Parameters:
callback- The callback which gets executed when the task is cancelled.
-