Class BukkitSchedulerMock
java.lang.Object
be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock
- All Implemented Interfaces:
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 Plugin plugin, @NotNull Callable<T> task) voidcancelTask(int taskId) voidcancelTasks(@NotNull Plugin plugin) @NotNull Future<?> executeAsyncEvent(@NotNull Event event) Executes an asynchronous event.executeAsyncEvent(T event, @Nullable Consumer<T> func) Executes an asynchronous event.protected intGets the amount of thread currently executing asynchronous tasks.@NotNull List<BukkitWorker> longGet the current tick of the server.@NotNull ExecutorgetMainThreadExecutor(@NotNull Plugin plugin) intGets the number of async tasks which are awaiting execution.@NotNull @UnmodifiableView List<BukkitWorker> @NotNull List<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 BukkitTaskvoidrunTask(@NotNull Plugin plugin, @NotNull Consumer<? super BukkitTask> task) @NotNull BukkitTaskrunTask(@NotNull Plugin plugin, @NotNull BukkitRunnable task) Deprecated.@NotNull BukkitTaskrunTaskAsynchronously(@NotNull Plugin plugin, @NotNull Runnable task) voidrunTaskAsynchronously(@NotNull Plugin plugin, @NotNull Consumer<? super BukkitTask> task) @NotNull BukkitTaskrunTaskAsynchronously(@NotNull Plugin plugin, @NotNull BukkitRunnable task) @NotNull BukkitTaskrunTaskLater(@NotNull Plugin plugin, @NotNull Runnable task, long delay) voidrunTaskLater(@NotNull Plugin plugin, @NotNull Consumer<? super BukkitTask> task, long delay) @NotNull BukkitTaskrunTaskLater(@NotNull Plugin plugin, @NotNull BukkitRunnable task, long delay) @NotNull BukkitTaskrunTaskLaterAsynchronously(@NotNull Plugin plugin, @NotNull Runnable task, long delay) voidrunTaskLaterAsynchronously(@NotNull Plugin plugin, @NotNull Consumer<? super BukkitTask> task, long delay) @NotNull BukkitTaskrunTaskLaterAsynchronously(@NotNull Plugin plugin, @NotNull BukkitRunnable task, long delay) @NotNull BukkitTaskrunTaskTimer(@NotNull Plugin plugin, @NotNull Runnable task, long delay, long period) voidrunTaskTimer(@NotNull Plugin plugin, @NotNull Consumer<? super BukkitTask> task, long delay, long period) @NotNull BukkitTaskrunTaskTimer(@NotNull Plugin plugin, @NotNull BukkitRunnable task, long delay, long period) Deprecated.@NotNull BukkitTaskrunTaskTimerAsynchronously(@NotNull Plugin plugin, @NotNull Runnable task, long delay, long period) voidrunTaskTimerAsynchronously(@NotNull Plugin plugin, @NotNull Consumer<? super BukkitTask> task, long delay, long period) @NotNull BukkitTaskrunTaskTimerAsynchronously(@NotNull Plugin plugin, @NotNull BukkitRunnable task, long delay, long period) voidAdds any active workers to the overdue tasks list.intscheduleAsyncDelayedTask(@NotNull Plugin plugin, @NotNull Runnable task) Deprecated.intscheduleAsyncDelayedTask(@NotNull Plugin plugin, @NotNull Runnable task, long delay) Deprecated.intscheduleAsyncRepeatingTask(@NotNull Plugin plugin, @NotNull Runnable task, long delay, long period) Deprecated.intscheduleSyncDelayedTask(@NotNull Plugin plugin, @NotNull Runnable task) intscheduleSyncDelayedTask(@NotNull Plugin plugin, @NotNull Runnable task, long delay) intscheduleSyncDelayedTask(@NotNull Plugin plugin, @NotNull BukkitRunnable task) Deprecated.intscheduleSyncDelayedTask(@NotNull Plugin plugin, @NotNull BukkitRunnable task, long delay) Deprecated.intscheduleSyncRepeatingTask(@NotNull Plugin plugin, @NotNull Runnable task, long delay, long period) intscheduleSyncRepeatingTask(@NotNull Plugin plugin, @NotNull 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
Executes an asynchronous event.- Parameters:
event- The event to execute.- Returns:
- A future representing the task.
-
executeAsyncEvent
@NotNull public <T extends 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 BukkitTask runTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task) - Specified by:
runTaskin interfaceBukkitScheduler
-
runTask
@Deprecated(since="1.7.10") @NotNull public @NotNull BukkitTask runTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task) Deprecated.- Specified by:
runTaskin interfaceBukkitScheduler
-
runTaskLater
@NotNull public @NotNull BukkitTask runTaskLater(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay) - Specified by:
runTaskLaterin interfaceBukkitScheduler
-
runTaskTimer
@NotNull public @NotNull BukkitTask runTaskTimer(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period) - Specified by:
runTaskTimerin interfaceBukkitScheduler
-
runTaskTimer
@Deprecated(since="1.7.10") @NotNull public @NotNull BukkitTask runTaskTimer(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task, long delay, long period) Deprecated.- Specified by:
runTaskTimerin interfaceBukkitScheduler
-
scheduleSyncDelayedTask
public int scheduleSyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay) - Specified by:
scheduleSyncDelayedTaskin interfaceBukkitScheduler
-
scheduleSyncDelayedTask
@Deprecated(since="1.7.10") public int scheduleSyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task, long delay) Deprecated.- Specified by:
scheduleSyncDelayedTaskin interfaceBukkitScheduler
-
scheduleSyncDelayedTask
public int scheduleSyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task) - Specified by:
scheduleSyncDelayedTaskin interfaceBukkitScheduler
-
scheduleSyncDelayedTask
@Deprecated(since="1.7.10") public int scheduleSyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task) Deprecated.- Specified by:
scheduleSyncDelayedTaskin interfaceBukkitScheduler
-
scheduleSyncRepeatingTask
public int scheduleSyncRepeatingTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period) - Specified by:
scheduleSyncRepeatingTaskin interfaceBukkitScheduler
-
scheduleSyncRepeatingTask
@Deprecated(since="1.7.10") public int scheduleSyncRepeatingTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task, long delay, long period) Deprecated.- Specified by:
scheduleSyncRepeatingTaskin interfaceBukkitScheduler
-
scheduleAsyncDelayedTask
@Deprecated(since="1.5") public int scheduleAsyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay) Deprecated.- Specified by:
scheduleAsyncDelayedTaskin interfaceBukkitScheduler
-
scheduleAsyncDelayedTask
@Deprecated(since="1.5") public int scheduleAsyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task) Deprecated.- Specified by:
scheduleAsyncDelayedTaskin interfaceBukkitScheduler
-
scheduleAsyncRepeatingTask
@Deprecated(since="1.5") public int scheduleAsyncRepeatingTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period) Deprecated.- Specified by:
scheduleAsyncRepeatingTaskin interfaceBukkitScheduler
-
callSyncMethod
@NotNull public <T> @NotNull Future<T> callSyncMethod(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Callable<T> task) - Specified by:
callSyncMethodin interfaceBukkitScheduler
-
cancelTask
public void cancelTask(int taskId) - Specified by:
cancelTaskin interfaceBukkitScheduler
-
cancelTasks
- Specified by:
cancelTasksin interfaceBukkitScheduler
-
isCurrentlyRunning
public boolean isCurrentlyRunning(int taskId) - Specified by:
isCurrentlyRunningin interfaceBukkitScheduler
-
isQueued
public boolean isQueued(int taskId) - Specified by:
isQueuedin interfaceBukkitScheduler
-
getActiveWorkers
- Specified by:
getActiveWorkersin interfaceBukkitScheduler
-
getPendingTasks
- Specified by:
getPendingTasksin interfaceBukkitScheduler
-
runTaskAsynchronously
@NotNull public @NotNull BukkitTask runTaskAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task) - Specified by:
runTaskAsynchronouslyin interfaceBukkitScheduler
-
runTaskAsynchronously
@NotNull public @NotNull BukkitTask runTaskAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task) - Specified by:
runTaskAsynchronouslyin interfaceBukkitScheduler
-
runTaskLater
@NotNull public @NotNull BukkitTask runTaskLater(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task, long delay) - Specified by:
runTaskLaterin interfaceBukkitScheduler
-
runTaskLaterAsynchronously
@NotNull public @NotNull BukkitTask runTaskLaterAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay) - Specified by:
runTaskLaterAsynchronouslyin interfaceBukkitScheduler
-
runTaskLaterAsynchronously
@NotNull public @NotNull BukkitTask runTaskLaterAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task, long delay) - Specified by:
runTaskLaterAsynchronouslyin interfaceBukkitScheduler
-
runTaskTimerAsynchronously
@NotNull public @NotNull BukkitTask runTaskTimerAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period) - Specified by:
runTaskTimerAsynchronouslyin interfaceBukkitScheduler
-
runTaskTimerAsynchronously
@NotNull public @NotNull BukkitTask runTaskTimerAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task, long delay, long period) - Specified by:
runTaskTimerAsynchronouslyin interfaceBukkitScheduler
-
runTask
public void runTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Consumer<? super BukkitTask> task) - Specified by:
runTaskin interfaceBukkitScheduler
-
runTaskAsynchronously
public void runTaskAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Consumer<? super BukkitTask> task) - Specified by:
runTaskAsynchronouslyin interfaceBukkitScheduler
-
runTaskLater
public void runTaskLater(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Consumer<? super BukkitTask> task, long delay) - Specified by:
runTaskLaterin interfaceBukkitScheduler
-
runTaskLaterAsynchronously
public void runTaskLaterAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Consumer<? super BukkitTask> task, long delay) - Specified by:
runTaskLaterAsynchronouslyin interfaceBukkitScheduler
-
runTaskTimer
public void runTaskTimer(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Consumer<? super BukkitTask> task, long delay, long period) - Specified by:
runTaskTimerin interfaceBukkitScheduler
-
runTaskTimerAsynchronously
public void runTaskTimerAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Consumer<? super BukkitTask> task, long delay, long period) - Specified by:
runTaskTimerAsynchronouslyin interfaceBukkitScheduler
-
getMainThreadExecutor
- Specified by:
getMainThreadExecutorin interfaceBukkitScheduler
-
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
- Returns:
- A list of overdue tasks saved by
saveOverdueTasks().
-
assertNoOverdueTasks
public void assertNoOverdueTasks()Asserts that there were no overdue tasks fromsaveOverdueTasks().
-