Interface BukkitScheduler


public interface BukkitScheduler
  • Method Details

    • scheduleSyncDelayedTask

      int scheduleSyncDelayedTask​(Plugin plugin, java.lang.Runnable task, long delay)
      Schedules a once off task to occur after a delay.

      This task will be executed by the main server thread.

      Parameters:
      plugin - Plugin that owns the task
      task - Task to be executed
      delay - Delay in server ticks before executing task
      Returns:
      Task id number (-1 if scheduling failed)
    • scheduleSyncDelayedTask

      @Deprecated int scheduleSyncDelayedTask​(Plugin plugin, BukkitRunnable task, long delay)
      Parameters:
      plugin - Plugin that owns the task
      task - Task to be executed
      delay - Delay in server ticks before executing task
      Returns:
      Task id number (-1 if scheduling failed)
    • scheduleSyncDelayedTask

      int scheduleSyncDelayedTask​(Plugin plugin, java.lang.Runnable task)
      Schedules a once off task to occur as soon as possible.

      This task will be executed by the main server thread.

      Parameters:
      plugin - Plugin that owns the task
      task - Task to be executed
      Returns:
      Task id number (-1 if scheduling failed)
    • scheduleSyncDelayedTask

      @Deprecated int scheduleSyncDelayedTask​(Plugin plugin, BukkitRunnable task)
      Parameters:
      plugin - Plugin that owns the task
      task - Task to be executed
      Returns:
      Task id number (-1 if scheduling failed)
    • scheduleSyncRepeatingTask

      int scheduleSyncRepeatingTask​(Plugin plugin, java.lang.Runnable task, long delay, long period)
      Schedules a repeating task.

      This task will be executed by the main server thread.

      Parameters:
      plugin - Plugin that owns the task
      task - Task to be executed
      delay - Delay in server ticks before executing first repeat
      period - Period in server ticks of the task
      Returns:
      Task id number (-1 if scheduling failed)
    • scheduleSyncRepeatingTask

      @Deprecated int scheduleSyncRepeatingTask​(Plugin plugin, BukkitRunnable task, long delay, long period)
      Parameters:
      plugin - Plugin that owns the task
      task - Task to be executed
      delay - Delay in server ticks before executing first repeat
      period - Period in server ticks of the task
      Returns:
      Task id number (-1 if scheduling failed)
    • scheduleAsyncDelayedTask

      @Deprecated int scheduleAsyncDelayedTask​(Plugin plugin, java.lang.Runnable task, long delay)
      Deprecated.
      This name is misleading, as it does not schedule "a sync" task, but rather, "an async" task
      Asynchronous tasks should never access any API in Bukkit. Great care should be taken to assure the thread-safety of asynchronous tasks.

      Schedules a once off task to occur after a delay. This task will be executed by a thread managed by the scheduler.

      Parameters:
      plugin - Plugin that owns the task
      task - Task to be executed
      delay - Delay in server ticks before executing task
      Returns:
      Task id number (-1 if scheduling failed)
    • scheduleAsyncDelayedTask

      @Deprecated int scheduleAsyncDelayedTask​(Plugin plugin, java.lang.Runnable task)
      Deprecated.
      This name is misleading, as it does not schedule "a sync" task, but rather, "an async" task
      Asynchronous tasks should never access any API in Bukkit. Great care should be taken to assure the thread-safety of asynchronous tasks.

      Schedules a once off task to occur as soon as possible. This task will be executed by a thread managed by the scheduler.

      Parameters:
      plugin - Plugin that owns the task
      task - Task to be executed
      Returns:
      Task id number (-1 if scheduling failed)
    • scheduleAsyncRepeatingTask

      @Deprecated int scheduleAsyncRepeatingTask​(Plugin plugin, java.lang.Runnable task, long delay, long period)
      Deprecated.
      This name is misleading, as it does not schedule "a sync" task, but rather, "an async" task
      Asynchronous tasks should never access any API in Bukkit. Great care should be taken to assure the thread-safety of asynchronous tasks.

      Schedules a repeating task. This task will be executed by a thread managed by the scheduler.

      Parameters:
      plugin - Plugin that owns the task
      task - Task to be executed
      delay - Delay in server ticks before executing first repeat
      period - Period in server ticks of the task
      Returns:
      Task id number (-1 if scheduling failed)
    • callSyncMethod

      <T> java.util.concurrent.Future<T> callSyncMethod​(Plugin plugin, java.util.concurrent.Callable<T> task)
      Calls a method on the main thread and returns a Future object. This task will be executed by the main server thread.
      • Note: The Future.get() methods must NOT be called from the main thread.
      • Note2: There is at least an average of 10ms latency until the isDone() method returns true.
      Type Parameters:
      T - The callable's return type
      Parameters:
      plugin - Plugin that owns the task
      task - Task to be executed
      Returns:
      Future Future object related to the task
    • cancelTask

      void cancelTask​(int taskId)
      Removes task from scheduler.
      Parameters:
      taskId - Id number of task to be removed
    • cancelTasks

      void cancelTasks​(Plugin plugin)
      Removes all tasks associated with a particular plugin from the scheduler.
      Parameters:
      plugin - Owner of tasks to be removed
    • cancelAllTasks

      void cancelAllTasks()
      Removes all tasks from the scheduler.
    • isCurrentlyRunning

      boolean isCurrentlyRunning​(int taskId)
      Check if the task currently running.

      A repeating task might not be running currently, but will be running in the future. A task that has finished, and does not repeat, will not be running ever again.

      Explicitly, a task is running if there exists a thread for it, and that thread is alive.

      Parameters:
      taskId - The task to check.

      Returns:
      If the task is currently running.
    • isQueued

      boolean isQueued​(int taskId)
      Check if the task queued to be run later.

      If a repeating task is currently running, it might not be queued now but could be in the future. A task that is not queued, and not running, will not be queued again.

      Parameters:
      taskId - The task to check.

      Returns:
      If the task is queued to be run.
    • getActiveWorkers

      java.util.List<BukkitWorker> getActiveWorkers()
      Returns a list of all active workers.

      This list contains asynch tasks that are being executed by separate threads.

      Returns:
      Active workers
    • getPendingTasks

      java.util.List<BukkitTask> getPendingTasks()
      Returns a list of all pending tasks. The ordering of the tasks is not related to their order of execution.
      Returns:
      Active workers
    • runTask

      BukkitTask runTask​(Plugin plugin, java.lang.Runnable task) throws java.lang.IllegalArgumentException
      Returns a task that will run on the next server tick.
      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null
    • runTask

      @Deprecated BukkitTask runTask​(Plugin plugin, BukkitRunnable task) throws java.lang.IllegalArgumentException
      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null
    • runTaskAsynchronously

      BukkitTask runTaskAsynchronously​(Plugin plugin, java.lang.Runnable task) throws java.lang.IllegalArgumentException
      Asynchronous tasks should never access any API in Bukkit. Great care should be taken to assure the thread-safety of asynchronous tasks.

      Returns a task that will run asynchronously.

      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null
    • runTaskAsynchronously

      @Deprecated BukkitTask runTaskAsynchronously​(Plugin plugin, BukkitRunnable task) throws java.lang.IllegalArgumentException
      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null
    • runTaskLater

      BukkitTask runTaskLater​(Plugin plugin, java.lang.Runnable task, long delay) throws java.lang.IllegalArgumentException
      Returns a task that will run after the specified number of server ticks.
      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      delay - the ticks to wait before running the task
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null
    • runTaskLater

      @Deprecated BukkitTask runTaskLater​(Plugin plugin, BukkitRunnable task, long delay) throws java.lang.IllegalArgumentException
      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      delay - the ticks to wait before running the task
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null
    • runTaskLaterAsynchronously

      BukkitTask runTaskLaterAsynchronously​(Plugin plugin, java.lang.Runnable task, long delay) throws java.lang.IllegalArgumentException
      Asynchronous tasks should never access any API in Bukkit. Great care should be taken to assure the thread-safety of asynchronous tasks.

      Returns a task that will run asynchronously after the specified number of server ticks.

      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      delay - the ticks to wait before running the task
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null
    • runTaskLaterAsynchronously

      @Deprecated BukkitTask runTaskLaterAsynchronously​(Plugin plugin, BukkitRunnable task, long delay) throws java.lang.IllegalArgumentException
      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      delay - the ticks to wait before running the task
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null
    • runTaskTimer

      BukkitTask runTaskTimer​(Plugin plugin, java.lang.Runnable task, long delay, long period) throws java.lang.IllegalArgumentException
      Returns a task that will repeatedly run until cancelled, starting after the specified number of server ticks.
      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      delay - the ticks to wait before running the task
      period - the ticks to wait between runs
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null
    • runTaskTimer

      @Deprecated BukkitTask runTaskTimer​(Plugin plugin, BukkitRunnable task, long delay, long period) throws java.lang.IllegalArgumentException
      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      delay - the ticks to wait before running the task
      period - the ticks to wait between runs
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null
    • runTaskTimerAsynchronously

      BukkitTask runTaskTimerAsynchronously​(Plugin plugin, java.lang.Runnable task, long delay, long period) throws java.lang.IllegalArgumentException
      Asynchronous tasks should never access any API in Bukkit. Great care should be taken to assure the thread-safety of asynchronous tasks.

      Returns a task that will repeatedly run asynchronously until cancelled, starting after the specified number of server ticks.

      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      delay - the ticks to wait before running the task for the first time
      period - the ticks to wait between runs
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null
    • runTaskTimerAsynchronously

      @Deprecated BukkitTask runTaskTimerAsynchronously​(Plugin plugin, BukkitRunnable task, long delay, long period) throws java.lang.IllegalArgumentException
      Parameters:
      plugin - the reference to the plugin scheduling task
      task - the task to be run
      delay - the ticks to wait before running the task for the first time
      period - the ticks to wait between runs
      Returns:
      a BukkitTask that contains the id number
      Throws:
      java.lang.IllegalArgumentException - if plugin is null
      java.lang.IllegalArgumentException - if task is null