接口 BukkitScheduler
-
方法概要
修饰符和类型方法说明<T> Future<T>callSyncMethod(Plugin plugin, Callable<T> task) 调用主线程的一个方法并返回Future对象.这个任务将被服务器主线程执行.void取消执行所有在执行器中的任务.voidcancelTask(int taskId) 从执行器中取消执行一个任务.voidcancelTasks(Plugin plugin) 取消执行特定的插件所请求的所有任务.返回所有激活的worker.返回所有挂起(就绪/阻塞等)的任务.任务的顺序与它们的执行顺序无关.booleanisCurrentlyRunning(int taskId) 检测任务是否正在运行.booleanisQueued(int taskId) 检测这个任务是否正在排队等待执行.返回下一个tick服务器将运行的任务.runTask(Plugin plugin, BukkitRunnable task) 已过时。runTaskAsynchronously(Plugin plugin, Runnable task) 异步任务不应访问Bukkit里的任何API.应着重保证异步任务的线程安全.runTaskAsynchronously(Plugin plugin, BukkitRunnable task) runTaskLater(Plugin plugin, Runnable task, long delay) 返回指定tick过后运行的任务(即延迟执行).runTaskLater(Plugin plugin, BukkitRunnable task, long delay) runTaskLaterAsynchronously(Plugin plugin, Runnable task, long delay) 异步任务不应访问Bukkit里的任何API.应着重保证异步任务的线程安全.runTaskLaterAsynchronously(Plugin plugin, BukkitRunnable task, long delay) runTaskTimer(Plugin plugin, Runnable task, long delay, long period) 返回一个任务.此任务将在指定tick数值后运行.任务将重复运行直至取消.runTaskTimer(Plugin plugin, BukkitRunnable task, long delay, long period) runTaskTimerAsynchronously(Plugin plugin, Runnable task, long delay, long period) 异步任务不应访问Bukkit里的任何API.应着重保证异步任务的线程安全.runTaskTimerAsynchronously(Plugin plugin, BukkitRunnable task, long delay, long period) intscheduleAsyncDelayedTask(Plugin plugin, Runnable task) 已过时。这个名称具有误导性.因为它没有执行“同步”任务.而是“异步”任务intscheduleAsyncDelayedTask(Plugin plugin, Runnable task, long delay) 已过时。这个名称具有误导性.因为它没有执行“同步”任务.而是“异步”任务intscheduleAsyncRepeatingTask(Plugin plugin, Runnable task, long delay, long period) 已过时。这个名称具有误导性.因为它没有执行“同步”任务.而是“异步”任务intscheduleSyncDelayedTask(Plugin plugin, Runnable task) 在下一tick执行一次任务.intscheduleSyncDelayedTask(Plugin plugin, Runnable task, long delay) 在指定延迟后执行一次任务.intscheduleSyncDelayedTask(Plugin plugin, BukkitRunnable task) 已过时。intscheduleSyncDelayedTask(Plugin plugin, BukkitRunnable task, long delay) intscheduleSyncRepeatingTask(Plugin plugin, Runnable task, long delay, long period) 在指定延迟后开始以指定间隔重复执行任务.intscheduleSyncRepeatingTask(Plugin plugin, BukkitRunnable task, long delay, long period)
-
方法详细资料
-
scheduleSyncDelayedTask
在指定延迟后执行一次任务.这个任务将由服务器主线程执行(同步).
原文: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
- 参数:
plugin- 创建这个任务的插件(拥有者)task- 要执行的任务delay- 服务器执行任务之前的延迟/tick- 返回:
- 任务id(如果为-1则表示执行失败)
-
scheduleSyncDelayedTask
在下一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
已过时。在下一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
在指定延迟后开始以指定间隔重复执行任务.这个任务将由服务器主线程执行(同步).
原文:Schedules a repeating task.
This task will be executed by the main server thread.
- 参数:
plugin- 创建这个任务的插件(拥有者)task- 要执行的任务delay- 开始第一次重复执行之前的延迟/tickperiod- 任务执行的时间- 返回:
- 任务id(如果为-1则表示执行失败)
-
scheduleSyncRepeatingTask
@Deprecated int scheduleSyncRepeatingTask(Plugin plugin, BukkitRunnable task, long delay, long period) - 参数:
plugin- 创建这个任务的插件(拥有者)task- 要执行的任务delay- 开始第一次重复执行之前的延迟/tickperiod- 任务执行的时间- 返回:
- 任务id(如果为-1则表示执行失败)
-
scheduleAsyncDelayedTask
已过时。这个名称具有误导性.因为它没有执行“同步”任务.而是“异步”任务异步任务不应访问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
已过时。这个名称具有误导性.因为它没有执行“同步”任务.而是“异步”任务异步任务不应访问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
已过时。这个名称具有误导性.因为它没有执行“同步”任务.而是“异步”任务异步任务不应访问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- 开始第一次重复执行之前的延迟/tickperiod- 每次任务执行之间的间隔- 返回:
- 任务id(如果为-1则表示执行失败)
-
callSyncMethod
调用主线程的一个方法并返回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
取消执行特定的插件所请求的所有任务.原文:Removes all tasks associated with a particular plugin from the scheduler.
- 参数:
plugin- 要取消所有任务的插件
-
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.
- 参数:
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
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
List<BukkitTask> getPendingTasks()返回所有挂起(就绪/阻塞等)的任务.任务的顺序与它们的执行顺序无关.原文:Returns a list of all pending tasks. The ordering of the tasks is not related to their order of execution.
- 返回:
- 激活的worker
-
runTask
返回下一个tick服务器将运行的任务.原文:Returns a task that will run on the next server tick.
- 参数:
plugin- 执行任务的插件task- 要运行的任务- 返回:
- 包含id的BukkitTask
- 抛出:
IllegalArgumentException- 如果插件为nullIllegalArgumentException- 如果任务为null
-
runTask
已过时。- 参数:
plugin- 执行任务的插件task- 要运行的任务- 返回:
- 包含id的BukkitTask
- 抛出:
IllegalArgumentException- 如果插件为nullIllegalArgumentException- 如果任务为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- 如果插件为nullIllegalArgumentException- 如果任务为null
-
runTaskAsynchronously
@Deprecated BukkitTask runTaskAsynchronously(Plugin plugin, BukkitRunnable task) throws IllegalArgumentException - 参数:
plugin- 执行任务的插件task- 要运行的任务- 返回:
- 包含id的BukkitTask
- 抛出:
IllegalArgumentException- 如果插件为nullIllegalArgumentException- 如果任务为null
-
runTaskLater
返回指定tick过后运行的任务(即延迟执行).原文:Returns a task that will run after the specified number of server ticks.
- 参数:
plugin- 执行任务的插件task- 要运行的任务delay- 服务器执行任务之前的延迟/tick- 返回:
- 包含id的BukkitTask
- 抛出:
IllegalArgumentException- 如果插件为nullIllegalArgumentException- 如果任务为null
-
runTaskLater
@Deprecated BukkitTask runTaskLater(Plugin plugin, BukkitRunnable task, long delay) throws IllegalArgumentException - 参数:
plugin- 执行任务的插件task- 要运行的任务delay- 服务器执行任务之前的延迟/tick- 返回:
- 包含id的BukkitTask
- 抛出:
IllegalArgumentException- 如果插件为nullIllegalArgumentException- 如果任务为null
-
runTaskLaterAsynchronously
BukkitTask runTaskLaterAsynchronously(Plugin plugin, 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- 如果插件为nullIllegalArgumentException- 如果任务为null
-
runTaskLaterAsynchronously
@Deprecated BukkitTask runTaskLaterAsynchronously(Plugin plugin, BukkitRunnable task, long delay) throws IllegalArgumentException - 参数:
plugin- 执行任务的插件task- 要运行的任务delay- 服务器执行任务之前的延迟/tick- 返回:
- 包含id的BukkitTask
- 抛出:
IllegalArgumentException- 如果插件为nullIllegalArgumentException- 如果任务为null
-
runTaskTimer
BukkitTask runTaskTimer(Plugin plugin, 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- 服务器执行任务之前的延迟/tickperiod- 重复执行任务之间的时间间隔- 返回:
- 包含id的BukkitTask
- 抛出:
IllegalArgumentException- 如果插件为nullIllegalArgumentException- 如果任务为null
-
runTaskTimer
@Deprecated BukkitTask runTaskTimer(Plugin plugin, BukkitRunnable task, long delay, long period) throws IllegalArgumentException - 参数:
plugin- 执行任务的插件task- 要运行的任务delay- 服务器执行任务之前的延迟/tickperiod- 重复执行任务之间的时间间隔- 返回:
- 包含id的BukkitTask
- 抛出:
IllegalArgumentException- 如果插件为nullIllegalArgumentException- 如果任务为null
-
runTaskTimerAsynchronously
BukkitTask runTaskTimerAsynchronously(Plugin plugin, 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- 如果插件为nullIllegalArgumentException- 如果任务为null
-
runTaskTimerAsynchronously
@Deprecated BukkitTask runTaskTimerAsynchronously(Plugin plugin, BukkitRunnable task, long delay, long period) throws IllegalArgumentException - 参数:
plugin- 执行任务的插件task- 要运行的任务delay- 在任务首次执行前等待的时间period- 重复执行任务之间的时间间隔- 返回:
- 包含id的BukkitTask
- 抛出:
IllegalArgumentException- 如果插件为nullIllegalArgumentException- 如果任务为null
-
BukkitRunnable.runTask(Plugin)