Class BukkitSchedulerMock
java.lang.Object
be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock
- All Implemented Interfaces:
org.bukkit.scheduler.BukkitScheduler
Mock implementation of a
BukkitScheduler.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAsserts that there were no overdue tasks fromsaveOverdueTasks().<T> @NotNull Future<T> callSyncMethod(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Callable<T> task) voidcancelTask(int taskId) voidcancelTasks(@NotNull org.bukkit.plugin.Plugin plugin) @NotNull Future<?> executeAsyncEvent(@NotNull org.bukkit.event.Event event) Executes an asynchronous event.<T extends org.bukkit.event.Event>
@NotNull Future<?> executeAsyncEvent(T event, @Nullable Consumer<T> func) Executes an asynchronous event.protected intGets the amount of thread currently executing asynchronous tasks.@NotNull List<org.bukkit.scheduler.BukkitWorker> longGet the current tick of the server.@NotNull ExecutorgetMainThreadExecutor(@NotNull org.bukkit.plugin.Plugin plugin) intGets the number of async tasks which are awaiting execution.@NotNull @UnmodifiableView List<org.bukkit.scheduler.BukkitWorker> @NotNull List<org.bukkit.scheduler.BukkitTask> booleanisCurrentlyRunning(int taskId) booleanisQueued(int taskId) voidPerform one tick on the server.voidperformTicks(long ticks) Perform a number of ticks on the server.@NotNull org.bukkit.scheduler.BukkitTaskvoidrunTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task) @NotNull org.bukkit.scheduler.BukkitTaskrunTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task) Deprecated.@NotNull org.bukkit.scheduler.BukkitTaskrunTaskAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task) voidrunTaskAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task) @NotNull org.bukkit.scheduler.BukkitTaskrunTaskAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task) @NotNull org.bukkit.scheduler.BukkitTaskrunTaskLater(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay) voidrunTaskLater(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay) @NotNull org.bukkit.scheduler.BukkitTaskrunTaskLater(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay) @NotNull org.bukkit.scheduler.BukkitTaskrunTaskLaterAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay) voidrunTaskLaterAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay) @NotNull org.bukkit.scheduler.BukkitTaskrunTaskLaterAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay) @NotNull org.bukkit.scheduler.BukkitTaskrunTaskTimer(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay, long period) voidrunTaskTimer(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay, long period) @NotNull org.bukkit.scheduler.BukkitTaskrunTaskTimer(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay, long period) Deprecated.@NotNull org.bukkit.scheduler.BukkitTaskrunTaskTimerAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay, long period) voidrunTaskTimerAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay, long period) @NotNull org.bukkit.scheduler.BukkitTaskrunTaskTimerAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay, long period) voidAdds any active workers to the overdue tasks list.intscheduleAsyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task) Deprecated.intscheduleAsyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay) Deprecated.intscheduleAsyncRepeatingTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay, long period) Deprecated.intscheduleSyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task) intscheduleSyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay) intscheduleSyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task) Deprecated.intscheduleSyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay) Deprecated.intscheduleSyncRepeatingTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay, long period) intscheduleSyncRepeatingTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay, long period) Deprecated.voidsetShutdownTimeout(long timeout) Sets the maximum time to wait for async tasks to finish before terminating them.voidshutdown()Shuts the scheduler down.voidBlocks until all asynchronous event invocations are finished.voidWaits until all asynchronous tasks have finished executing.
-
Constructor Details
-
BukkitSchedulerMock
public BukkitSchedulerMock()
-
-
Method Details
-
setShutdownTimeout
public void setShutdownTimeout(long timeout) Sets the maximum time to wait for async tasks to finish before terminating them.- Parameters:
timeout- The timeout in milliseconds.
-
shutdown
public void shutdown()Shuts the scheduler down. Note that this function will throw exception that where thrown by old asynchronous tasks. -
executeAsyncEvent
@NotNull public @NotNull Future<?> executeAsyncEvent(@NotNull @NotNull org.bukkit.event.Event event) Executes an asynchronous event.- Parameters:
event- The event to execute.- Returns:
- A future representing the task.
-
executeAsyncEvent
@NotNull public <T extends org.bukkit.event.Event> @NotNull Future<?> executeAsyncEvent(@NotNull T event, @Nullable @Nullable Consumer<T> func) Executes an asynchronous event.- Type Parameters:
T- The event type.- Parameters:
event- The event to execute.func- A consumer to call after the event is invoked.- Returns:
- A future representing the task.
-
getCurrentTick
public long getCurrentTick()Get the current tick of the server.- Returns:
- The current tick of the server.
-
performOneTick
public void performOneTick()Perform one tick on the server. -
performTicks
public void performTicks(long ticks) Perform a number of ticks on the server.- Parameters:
ticks- The number of ticks to executed.
-
getNumberOfQueuedAsyncTasks
public int getNumberOfQueuedAsyncTasks()Gets the number of async tasks which are awaiting execution.- Returns:
- The number of async tasks which are pending execution.
-
waitAsyncTasksFinished
public void waitAsyncTasksFinished()Waits until all asynchronous tasks have finished executing. If you have an asynchronous task that runs indefinitely, this function will never return. Note that this will not wait for async events to finish. -
waitAsyncEventsFinished
public void waitAsyncEventsFinished()Blocks until all asynchronous event invocations are finished. -
runTask
@NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task) - Specified by:
runTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTask
@Deprecated(since="1.7.10") @NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.scheduler.BukkitRunnable task) Deprecated.- Specified by:
runTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskLater
@NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTaskLater(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delay) - Specified by:
runTaskLaterin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskTimer
@NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTaskTimer(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period) - Specified by:
runTaskTimerin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskTimer
@Deprecated(since="1.7.10") @NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTaskTimer(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay, long period) Deprecated.- Specified by:
runTaskTimerin interfaceorg.bukkit.scheduler.BukkitScheduler
-
scheduleSyncDelayedTask
public int scheduleSyncDelayedTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delay) - Specified by:
scheduleSyncDelayedTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
scheduleSyncDelayedTask
@Deprecated(since="1.7.10") public int scheduleSyncDelayedTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay) Deprecated.- Specified by:
scheduleSyncDelayedTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
scheduleSyncDelayedTask
public int scheduleSyncDelayedTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task) - Specified by:
scheduleSyncDelayedTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
scheduleSyncDelayedTask
@Deprecated(since="1.7.10") public int scheduleSyncDelayedTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.scheduler.BukkitRunnable task) Deprecated.- Specified by:
scheduleSyncDelayedTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
scheduleSyncRepeatingTask
public int scheduleSyncRepeatingTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period) - Specified by:
scheduleSyncRepeatingTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
scheduleSyncRepeatingTask
@Deprecated(since="1.7.10") public int scheduleSyncRepeatingTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay, long period) Deprecated.- Specified by:
scheduleSyncRepeatingTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
scheduleAsyncDelayedTask
@Deprecated(since="1.5") public int scheduleAsyncDelayedTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delay) Deprecated.- Specified by:
scheduleAsyncDelayedTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
scheduleAsyncDelayedTask
@Deprecated(since="1.5") public int scheduleAsyncDelayedTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task) Deprecated.- Specified by:
scheduleAsyncDelayedTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
scheduleAsyncRepeatingTask
@Deprecated(since="1.5") public int scheduleAsyncRepeatingTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period) Deprecated.- Specified by:
scheduleAsyncRepeatingTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
callSyncMethod
@NotNull public <T> @NotNull Future<T> callSyncMethod(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Callable<T> task) - Specified by:
callSyncMethodin interfaceorg.bukkit.scheduler.BukkitScheduler
-
cancelTask
public void cancelTask(int taskId) - Specified by:
cancelTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
cancelTasks
public void cancelTasks(@NotNull @NotNull org.bukkit.plugin.Plugin plugin) - Specified by:
cancelTasksin interfaceorg.bukkit.scheduler.BukkitScheduler
-
isCurrentlyRunning
public boolean isCurrentlyRunning(int taskId) - Specified by:
isCurrentlyRunningin interfaceorg.bukkit.scheduler.BukkitScheduler
-
isQueued
public boolean isQueued(int taskId) - Specified by:
isQueuedin interfaceorg.bukkit.scheduler.BukkitScheduler
-
getActiveWorkers
- Specified by:
getActiveWorkersin interfaceorg.bukkit.scheduler.BukkitScheduler
-
getPendingTasks
- Specified by:
getPendingTasksin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskAsynchronously
@NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTaskAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task) - Specified by:
runTaskAsynchronouslyin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskAsynchronously
@NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTaskAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.scheduler.BukkitRunnable task) - Specified by:
runTaskAsynchronouslyin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskLater
@NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTaskLater(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay) - Specified by:
runTaskLaterin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskLaterAsynchronously
@NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTaskLaterAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delay) - Specified by:
runTaskLaterAsynchronouslyin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskLaterAsynchronously
@NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTaskLaterAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay) - Specified by:
runTaskLaterAsynchronouslyin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskTimerAsynchronously
@NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTaskTimerAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period) - Specified by:
runTaskTimerAsynchronouslyin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskTimerAsynchronously
@NotNull public @NotNull org.bukkit.scheduler.BukkitTask runTaskTimerAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay, long period) - Specified by:
runTaskTimerAsynchronouslyin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTask
public void runTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task) - Specified by:
runTaskin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskAsynchronously
public void runTaskAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task) - Specified by:
runTaskAsynchronouslyin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskLater
public void runTaskLater(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay) - Specified by:
runTaskLaterin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskLaterAsynchronously
public void runTaskLaterAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay) - Specified by:
runTaskLaterAsynchronouslyin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskTimer
public void runTaskTimer(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay, long period) - Specified by:
runTaskTimerin interfaceorg.bukkit.scheduler.BukkitScheduler
-
runTaskTimerAsynchronously
public void runTaskTimerAsynchronously(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay, long period) - Specified by:
runTaskTimerAsynchronouslyin interfaceorg.bukkit.scheduler.BukkitScheduler
-
getMainThreadExecutor
@NotNull public @NotNull Executor getMainThreadExecutor(@NotNull @NotNull org.bukkit.plugin.Plugin plugin) - Specified by:
getMainThreadExecutorin interfaceorg.bukkit.scheduler.BukkitScheduler
-
getActiveRunningCount
protected int getActiveRunningCount()Gets the amount of thread currently executing asynchronous tasks.- Returns:
- The amount of active task threads.
-
saveOverdueTasks
public void saveOverdueTasks()Adds any active workers to the overdue tasks list. -
getOverdueTasks
@NotNull public @NotNull @UnmodifiableView List<org.bukkit.scheduler.BukkitWorker> getOverdueTasks()- Returns:
- A list of overdue tasks saved by
saveOverdueTasks().
-
assertNoOverdueTasks
public void assertNoOverdueTasks()Asserts that there were no overdue tasks fromsaveOverdueTasks().
-