Class BukkitSchedulerMock

java.lang.Object
be.seeseemelk.mockbukkit.scheduler.BukkitSchedulerMock
All Implemented Interfaces:
org.bukkit.scheduler.BukkitScheduler

public class BukkitSchedulerMock extends Object implements org.bukkit.scheduler.BukkitScheduler
Mock implementation of a BukkitScheduler.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Asserts that there were no overdue tasks from saveOverdueTasks().
    <T> @NotNull Future<T>
    callSyncMethod(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Callable<T> task)
     
    void
    cancelTask(int taskId)
     
    void
    cancelTasks(@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 int
    Gets the amount of thread currently executing asynchronous tasks.
    @NotNull List<org.bukkit.scheduler.BukkitWorker>
     
    long
    Get the current tick of the server.
    @NotNull Executor
    getMainThreadExecutor(@NotNull org.bukkit.plugin.Plugin plugin)
     
    int
    Gets the number of async tasks which are awaiting execution.
    @NotNull @UnmodifiableView List<org.bukkit.scheduler.BukkitWorker>
     
    @NotNull List<org.bukkit.scheduler.BukkitTask>
     
    boolean
    isCurrentlyRunning(int taskId)
     
    boolean
    isQueued(int taskId)
     
    void
    Perform one tick on the server.
    void
    performTicks(long ticks)
    Perform a number of ticks on the server.
    @NotNull org.bukkit.scheduler.BukkitTask
    runTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task)
     
    void
    runTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task)
     
    @NotNull org.bukkit.scheduler.BukkitTask
    runTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task)
    Deprecated.
    @NotNull org.bukkit.scheduler.BukkitTask
    runTaskAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task)
     
    void
    runTaskAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task)
     
    @NotNull org.bukkit.scheduler.BukkitTask
    runTaskAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task)
     
    @NotNull org.bukkit.scheduler.BukkitTask
    runTaskLater(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay)
     
    void
    runTaskLater(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay)
     
    @NotNull org.bukkit.scheduler.BukkitTask
    runTaskLater(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay)
     
    @NotNull org.bukkit.scheduler.BukkitTask
    runTaskLaterAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay)
     
    void
    runTaskLaterAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay)
     
    @NotNull org.bukkit.scheduler.BukkitTask
    runTaskLaterAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay)
     
    @NotNull org.bukkit.scheduler.BukkitTask
    runTaskTimer(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay, long period)
     
    void
    runTaskTimer(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay, long period)
     
    @NotNull org.bukkit.scheduler.BukkitTask
    runTaskTimer(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay, long period)
    Deprecated.
    @NotNull org.bukkit.scheduler.BukkitTask
    runTaskTimerAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay, long period)
     
    void
    runTaskTimerAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Consumer<? super org.bukkit.scheduler.BukkitTask> task, long delay, long period)
     
    @NotNull org.bukkit.scheduler.BukkitTask
    runTaskTimerAsynchronously(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay, long period)
     
    void
    Adds any active workers to the overdue tasks list.
    int
    scheduleAsyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task)
    Deprecated.
    int
    scheduleAsyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay)
    Deprecated.
    int
    scheduleAsyncRepeatingTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay, long period)
    Deprecated.
    int
    scheduleSyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task)
     
    int
    scheduleSyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay)
     
    int
    scheduleSyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task)
    Deprecated.
    int
    scheduleSyncDelayedTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay)
    Deprecated.
    int
    scheduleSyncRepeatingTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull Runnable task, long delay, long period)
     
    int
    scheduleSyncRepeatingTask(@NotNull org.bukkit.plugin.Plugin plugin, @NotNull org.bukkit.scheduler.BukkitRunnable task, long delay, long period)
    Deprecated.
    void
    setShutdownTimeout(long timeout)
    Sets the maximum time to wait for async tasks to finish before terminating them.
    void
    Shuts the scheduler down.
    void
    Blocks until all asynchronous event invocations are finished.
    void
    Waits until all asynchronous tasks have finished executing.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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:
      runTask in interface org.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:
      runTask in interface org.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:
      runTaskLater in interface org.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:
      runTaskTimer in interface org.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:
      runTaskTimer in interface org.bukkit.scheduler.BukkitScheduler
    • scheduleSyncDelayedTask

      public int scheduleSyncDelayedTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delay)
      Specified by:
      scheduleSyncDelayedTask in interface org.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:
      scheduleSyncDelayedTask in interface org.bukkit.scheduler.BukkitScheduler
    • scheduleSyncDelayedTask

      public int scheduleSyncDelayedTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task)
      Specified by:
      scheduleSyncDelayedTask in interface org.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:
      scheduleSyncDelayedTask in interface org.bukkit.scheduler.BukkitScheduler
    • scheduleSyncRepeatingTask

      public int scheduleSyncRepeatingTask(@NotNull @NotNull org.bukkit.plugin.Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period)
      Specified by:
      scheduleSyncRepeatingTask in interface org.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:
      scheduleSyncRepeatingTask in interface org.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:
      scheduleAsyncDelayedTask in interface org.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:
      scheduleAsyncDelayedTask in interface org.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:
      scheduleAsyncRepeatingTask in interface org.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:
      callSyncMethod in interface org.bukkit.scheduler.BukkitScheduler
    • cancelTask

      public void cancelTask(int taskId)
      Specified by:
      cancelTask in interface org.bukkit.scheduler.BukkitScheduler
    • cancelTasks

      public void cancelTasks(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      Specified by:
      cancelTasks in interface org.bukkit.scheduler.BukkitScheduler
    • isCurrentlyRunning

      public boolean isCurrentlyRunning(int taskId)
      Specified by:
      isCurrentlyRunning in interface org.bukkit.scheduler.BukkitScheduler
    • isQueued

      public boolean isQueued(int taskId)
      Specified by:
      isQueued in interface org.bukkit.scheduler.BukkitScheduler
    • getActiveWorkers

      @NotNull public @NotNull List<org.bukkit.scheduler.BukkitWorker> getActiveWorkers()
      Specified by:
      getActiveWorkers in interface org.bukkit.scheduler.BukkitScheduler
    • getPendingTasks

      @NotNull public @NotNull List<org.bukkit.scheduler.BukkitTask> getPendingTasks()
      Specified by:
      getPendingTasks in interface org.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:
      runTaskAsynchronously in interface org.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:
      runTaskAsynchronously in interface org.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:
      runTaskLater in interface org.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:
      runTaskLaterAsynchronously in interface org.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:
      runTaskLaterAsynchronously in interface org.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:
      runTaskTimerAsynchronously in interface org.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:
      runTaskTimerAsynchronously in interface org.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:
      runTask in interface org.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:
      runTaskAsynchronously in interface org.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:
      runTaskLater in interface org.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:
      runTaskLaterAsynchronously in interface org.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:
      runTaskTimer in interface org.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:
      runTaskTimerAsynchronously in interface org.bukkit.scheduler.BukkitScheduler
    • getMainThreadExecutor

      @NotNull public @NotNull Executor getMainThreadExecutor(@NotNull @NotNull org.bukkit.plugin.Plugin plugin)
      Specified by:
      getMainThreadExecutor in interface org.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 from saveOverdueTasks().