接口 BukkitScheduler


public interface BukkitScheduler
Bukkit的任务调度器.

Note:从注释可以看出Bukkit官方不推荐您在异步任务中调用Bukkit的API , 若不得不调用, 需要注意调用的API是否线程安全.

  • 方法详细资料

    • scheduleSyncDelayedTask

      int scheduleSyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay)
      在指定延迟后执行一次任务.

      这个任务将由服务器主线程执行(同步).

      原文:Schedules a once off task to occur after a delay.

      This task will be executed by the main server thread.

      参数:
      plugin - 创建这个任务的插件(拥有者)
      task - 要执行的任务
      delay - 服务器执行任务之前的延迟/tick
      返回:
      任务id(如果为-1则表示执行失败)
    • scheduleSyncDelayedTask

      @Deprecated int scheduleSyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task, long delay)
      参数:
      plugin - 创建这个任务的插件(拥有者)
      task - 要执行的任务
      delay - 服务器执行任务之前的延迟/tick
      返回:
      任务id(如果为-1则表示执行失败)
    • scheduleSyncDelayedTask

      int scheduleSyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task)
      在下一tick执行一次任务.

      .这个任务将由服务器主线程执行(同步).

      原文:Schedules a once off task to occur as soon as possible.

      This task will be executed by the main server thread.

      参数:
      plugin - 创建这个任务的插件(拥有者)
      task - 要执行的任务
      返回:
      任务id(如果为-1则表示执行失败)
    • scheduleSyncDelayedTask

      @Deprecated int scheduleSyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task)
      已过时。
      在下一tick执行一次任务.

      这个任务将由服务器主线程执行(同步).

      原文:Schedules a once off task to occur as soon as possible.

      This task will be executed by the main server thread.

      参数:
      plugin - 创建这个任务的插件(拥有者)
      task - 要执行的任务
      返回:
      任务id(如果为-1则表示执行失败)
    • scheduleSyncRepeatingTask

      int scheduleSyncRepeatingTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period)
      在指定延迟后开始以指定间隔重复执行任务.

      这个任务将由服务器主线程执行(同步).

      原文:Schedules a repeating task.

      This task will be executed by the main server thread.

      参数:
      plugin - 创建这个任务的插件(拥有者)
      task - 要执行的任务
      delay - 开始第一次重复执行之前的延迟/tick
      period - 任务执行的时间
      返回:
      任务id(如果为-1则表示执行失败)
    • scheduleSyncRepeatingTask

      @Deprecated int scheduleSyncRepeatingTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task, long delay, long period)
      参数:
      plugin - 创建这个任务的插件(拥有者)
      task - 要执行的任务
      delay - 开始第一次重复执行之前的延迟/tick
      period - 任务执行的时间
      返回:
      任务id(如果为-1则表示执行失败)
    • scheduleAsyncDelayedTask

      @Deprecated int scheduleAsyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay)
      已过时。
      这个名称具有误导性.因为它没有执行“同步”任务.而是“异步”任务
      异步任务不应访问Bukkit里的任何API. 应着重保证异步任务的线程安全.

      在指定延迟后执行一次任务.此任务将通过由执行器所管理的线程执行.

      原文: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.

      参数:
      plugin - 创建这个任务的插件(拥有者)
      task - 要执行的任务
      delay - 服务器执行任务之前的延迟/tick
      返回:
      任务id(如果为-1则表示执行失败)
    • scheduleAsyncDelayedTask

      @Deprecated int scheduleAsyncDelayedTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task)
      已过时。
      这个名称具有误导性.因为它没有执行“同步”任务.而是“异步”任务
      异步任务不应访问Bukkit里的任何API. 应着重保证异步任务的线程安全.

      执行一次任务.此任务将通过由执行器所管理的线程执行.

      原文: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.

      参数:
      plugin - 创建这个任务的插件(拥有者)
      task - 要执行的任务
      返回:
      任务id(如果为-1则表示执行失败)
    • scheduleAsyncRepeatingTask

      @Deprecated int scheduleAsyncRepeatingTask(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period)
      已过时。
      这个名称具有误导性.因为它没有执行“同步”任务.而是“异步”任务
      异步任务不应访问Bukkit里的任何API. 应着重保证异步任务的线程安全.

      执行一次重复执行的任务.此任务将通过由执行器所管理的线程执行.

      原文: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.

      参数:
      plugin - 创建这个任务的插件(拥有者)
      task - 要执行的任务
      delay - 开始第一次重复执行之前的延迟/tick
      period - 每次任务执行之间的间隔
      返回:
      任务id(如果为-1则表示执行失败)
    • callSyncMethod

      @NotNull <T> @NotNull Future<T> callSyncMethod(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Callable<T> task)
      调用主线程的一个方法并返回Future对象.这个任务将被服务器主线程执行.
      • 注意①:Future.get()方法绝对不能从主线程调用.
      • 注意②:isDone()方法返回true时的延迟平均至少10ms.

      原文: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.
      类型参数:
      T - callable的返回类型
      参数:
      plugin - 创建这个任务的插件(拥有者)
      task - 要执行的任务
      返回:
      与任务相关的Future对象
    • cancelTask

      void cancelTask(int taskId)
      从执行器中取消执行一个任务.

      原文:Removes task from scheduler.

      参数:
      taskId - 要移除的任务的id
    • cancelTasks

      void cancelTasks(@NotNull @NotNull Plugin plugin)
      取消执行特定的插件所请求的所有任务.

      原文:Removes all tasks associated with a particular plugin from the scheduler.

      参数:
      plugin - 要取消所有任务的插件
    • 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.

      参数:
      taskId - 要检测的任务的id

      返回:
      任务是否在运行
    • 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.

      参数:
      taskId - 要检测的任务id

      返回:
      这个任务是否排队等待执行
    • getActiveWorkers

      @NotNull @NotNull List<BukkitWorker> getActiveWorkers()
      返回所有激活的worker.

      这个列表包含了独立线程执行的异步任务.

      原文:Returns a list of all active workers.

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

      返回:
      激活的worker
    • getPendingTasks

      @NotNull @NotNull List<BukkitTask> getPendingTasks()
      返回所有挂起(就绪/阻塞等)的任务.任务的顺序与它们的执行顺序无关.

      原文:Returns a list of all pending tasks. The ordering of the tasks is not related to their order of execution.

      返回:
      待执行/挂起的任务
    • runTask

      返回下一个tick服务器将运行的任务(即于下一tick执行指定任务).

      原文:Returns a task that will run on the next server tick.

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTask

      返回下一个tick服务器将运行的任务(即于下一tick执行指定任务).

      原文:Returns a task that will run on the next server tick.

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTask

      已过时。
      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskAsynchronously

      异步任务不应访问Bukkit里的任何API. 应着重保证异步任务的线程安全.

      返回异步执行的任务.

      原文: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.

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskAsynchronously

      void runTaskAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Consumer<BukkitTask> task) throws IllegalArgumentException
      异步任务不应访问Bukkit里的任何API. 应着重保证异步任务的线程安全.

      返回异步执行的任务.

      原文: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.

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskAsynchronously

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskLater

      返回指定tick过后运行的任务(即延迟执行).

      原文:Returns a task that will run after the specified number of server ticks.

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 服务器执行任务之前的延迟/tick
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskLater

      void runTaskLater(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Consumer<BukkitTask> task, long delay) throws IllegalArgumentException
      返回指定tick过后运行的任务(即延迟执行).

      原文:Returns a task that will run after the specified number of server ticks.

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 服务器执行任务之前的延迟/tick
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskLater

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 服务器执行任务之前的延迟/tick
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskLaterAsynchronously

      @NotNull @NotNull BukkitTask runTaskLaterAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay) throws IllegalArgumentException
      异步任务不应访问Bukkit里的任何API. 应着重保证异步任务的线程安全.

      返回指定tick过后运行的异步任务(即延迟执行).

      原文: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.

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 服务器执行任务之前的延迟/tick
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskLaterAsynchronously

      void runTaskLaterAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Consumer<BukkitTask> task, long delay) throws IllegalArgumentException
      异步任务不应访问Bukkit里的任何API. 应着重保证异步任务的线程安全.

      返回指定tick过后运行的异步任务(即延迟执行).

      原文: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.

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 服务器执行任务之前的延迟/tick
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskLaterAsynchronously

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 服务器执行任务之前的延迟/tick
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskTimer

      @NotNull @NotNull BukkitTask runTaskTimer(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period) throws IllegalArgumentException
      返回一个任务.此任务将在指定tick数值后运行.任务将重复运行直至取消.

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

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 服务器执行任务之前的延迟/tick
      period - 重复执行任务之间的时间间隔
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskTimer

      void runTaskTimer(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Consumer<BukkitTask> task, long delay, long period) throws IllegalArgumentException
      返回一个任务.此任务将在指定tick数值后运行.任务将重复运行直至取消.

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

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 服务器执行任务之前的延迟/tick
      period - 重复执行任务之间的时间间隔
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskTimer

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 服务器执行任务之前的延迟/tick
      period - 重复执行任务之间的时间间隔
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskTimerAsynchronously

      @NotNull @NotNull BukkitTask runTaskTimerAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Runnable task, long delay, long period) throws IllegalArgumentException
      异步任务不应访问Bukkit里的任何API. 应着重保证异步任务的线程安全.

      返回一个异步任务.此任务将在指定tick数值后运行.任务将重复运行直至取消.

      原文: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.

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 在任务首次执行前等待的时间
      period - 重复执行任务之间的时间间隔
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskTimerAsynchronously

      void runTaskTimerAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull Consumer<BukkitTask> task, long delay, long period) throws IllegalArgumentException
      异步任务不应访问Bukkit里的任何API. 应着重保证异步任务的线程安全.

      返回一个异步任务.此任务将在指定tick数值后运行.任务将重复运行直至取消.

      原文: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.

      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 在任务首次执行前等待的时间
      period - 重复执行任务之间的时间间隔
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null
    • runTaskTimerAsynchronously

      @Deprecated @NotNull @NotNull BukkitTask runTaskTimerAsynchronously(@NotNull @NotNull Plugin plugin, @NotNull @NotNull BukkitRunnable task, long delay, long period) throws IllegalArgumentException
      参数:
      plugin - 执行任务的插件
      task - 要运行的任务
      delay - 在任务首次执行前等待的时间
      period - 重复执行任务之间的时间间隔
      返回:
      包含id的BukkitTask
      抛出:
      IllegalArgumentException - 如果插件为null
      IllegalArgumentException - 如果任务为null