Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
BukkitScheduler.java
1 package org.bukkit.scheduler;
2 
3 import org.bukkit.plugin.Plugin;
4 import java.util.concurrent.Callable;
5 import java.util.concurrent.Future;
6 import java.util.List;
7 
8 public interface BukkitScheduler {
9 
10  /**
11  * Schedules a once off task to occur after a delay.
12  * <p>
13  * This task will be executed by the main server thread.
14  *
15  * @param plugin Plugin that owns the task
16  * @param task Task to be executed
17  * @param delay Delay in server ticks before executing task
18  * @return Task id number (-1 if scheduling failed)
19  */
20  public int scheduleSyncDelayedTask(Plugin plugin, Runnable task, long delay);
21 
22  /**
23  * Schedules a once off task to occur as soon as possible.
24  * <p>
25  * This task will be executed by the main server thread.
26  *
27  * @param plugin Plugin that owns the task
28  * @param task Task to be executed
29  * @return Task id number (-1 if scheduling failed)
30  */
31  public int scheduleSyncDelayedTask(Plugin plugin, Runnable task);
32 
33  /**
34  * Schedules a repeating task.
35  * <p>
36  * This task will be executed by the main server thread.
37  *
38  * @param plugin Plugin that owns the task
39  * @param task Task to be executed
40  * @param delay Delay in server ticks before executing first repeat
41  * @param period Period in server ticks of the task
42  * @return Task id number (-1 if scheduling failed)
43  */
44  public int scheduleSyncRepeatingTask(Plugin plugin, Runnable task, long delay, long period);
45 
46  /**
47  * <b>Asynchronous tasks should never access any API in Bukkit. Great care
48  * should be taken to assure the thread-safety of asynchronous tasks.</b>
49  * <p>
50  * Schedules a once off task to occur after a delay. This task will be
51  * executed by a thread managed by the scheduler.
52  *
53  * @param plugin Plugin that owns the task
54  * @param task Task to be executed
55  * @param delay Delay in server ticks before executing task
56  * @return Task id number (-1 if scheduling failed)
57  * @deprecated This name is misleading, as it does not schedule "a sync"
58  * task, but rather, "an async" task
59  */
60  @Deprecated
61  public int scheduleAsyncDelayedTask(Plugin plugin, Runnable task, long delay);
62 
63  /**
64  * <b>Asynchronous tasks should never access any API in Bukkit. Great care
65  * should be taken to assure the thread-safety of asynchronous tasks.</b>
66  * <p>
67  * Schedules a once off task to occur as soon as possible. This task will
68  * be executed by a thread managed by the scheduler.
69  *
70  * @param plugin Plugin that owns the task
71  * @param task Task to be executed
72  * @return Task id number (-1 if scheduling failed)
73  * @deprecated This name is misleading, as it does not schedule "a sync"
74  * task, but rather, "an async" task
75  */
76  @Deprecated
77  public int scheduleAsyncDelayedTask(Plugin plugin, Runnable task);
78 
79  /**
80  * <b>Asynchronous tasks should never access any API in Bukkit. Great care
81  * should be taken to assure the thread-safety of asynchronous tasks.</b>
82  * <p>
83  * Schedules a repeating task. This task will be executed by a thread
84  * managed by the scheduler.
85  *
86  * @param plugin Plugin that owns the task
87  * @param task Task to be executed
88  * @param delay Delay in server ticks before executing first repeat
89  * @param period Period in server ticks of the task
90  * @return Task id number (-1 if scheduling failed)
91  * @deprecated This name is misleading, as it does not schedule "a sync"
92  * task, but rather, "an async" task
93  */
94  @Deprecated
95  public int scheduleAsyncRepeatingTask(Plugin plugin, Runnable task, long delay, long period);
96 
97  /**
98  * Calls a method on the main thread and returns a Future object. This
99  * task will be executed by the main server thread.
100  * <ul>
101  * <li>Note: The Future.get() methods must NOT be called from the main
102  * thread.
103  * <li>Note2: There is at least an average of 10ms latency until the
104  * isDone() method returns true.
105  * </ul>
106  * @param <T> The callable's return type
107  * @param plugin Plugin that owns the task
108  * @param task Task to be executed
109  * @return Future Future object related to the task
110  */
111  public <T> Future<T> callSyncMethod(Plugin plugin, Callable<T> task);
112 
113  /**
114  * Removes task from scheduler.
115  *
116  * @param taskId Id number of task to be removed
117  */
118  public void cancelTask(int taskId);
119 
120  /**
121  * Removes all tasks associated with a particular plugin from the
122  * scheduler.
123  *
124  * @param plugin Owner of tasks to be removed
125  */
126  public void cancelTasks(Plugin plugin);
127 
128  /**
129  * Removes all tasks from the scheduler.
130  */
131  public void cancelAllTasks();
132 
133  /**
134  * Check if the task currently running.
135  * <p>
136  * A repeating task might not be running currently, but will be running in
137  * the future. A task that has finished, and does not repeat, will not be
138  * running ever again.
139  * <p>
140  * Explicitly, a task is running if there exists a thread for it, and that
141  * thread is alive.
142  *
143  * @param taskId The task to check.
144  * <p>
145  * @return If the task is currently running.
146  */
147  public boolean isCurrentlyRunning(int taskId);
148 
149  /**
150  * Check if the task queued to be run later.
151  * <p>
152  * If a repeating task is currently running, it might not be queued now
153  * but could be in the future. A task that is not queued, and not running,
154  * will not be queued again.
155  *
156  * @param taskId The task to check.
157  * <p>
158  * @return If the task is queued to be run.
159  */
160  public boolean isQueued(int taskId);
161 
162  /**
163  * Returns a list of all active workers.
164  * <p>
165  * This list contains asynch tasks that are being executed by separate
166  * threads.
167  *
168  * @return Active workers
169  */
170  public List<BukkitWorker> getActiveWorkers();
171 
172  /**
173  * Returns a list of all pending tasks. The ordering of the tasks is not
174  * related to their order of execution.
175  *
176  * @return Active workers
177  */
178  public List<BukkitTask> getPendingTasks();
179 
180  /**
181  * Returns a task that will run on the next server tick.
182  *
183  * @param plugin the reference to the plugin scheduling task
184  * @param task the task to be run
185  * @return a BukkitTask that contains the id number
186  * @throws IllegalArgumentException if plugin is null
187  * @throws IllegalArgumentException if task is null
188  */
189  public BukkitTask runTask(Plugin plugin, Runnable task) throws IllegalArgumentException;
190 
191  /**
192  * <b>Asynchronous tasks should never access any API in Bukkit. Great care
193  * should be taken to assure the thread-safety of asynchronous tasks.</b>
194  * <p>
195  * Returns a task that will run asynchronously.
196  *
197  * @param plugin the reference to the plugin scheduling task
198  * @param task the task to be run
199  * @return a BukkitTask that contains the id number
200  * @throws IllegalArgumentException if plugin is null
201  * @throws IllegalArgumentException if task is null
202  */
203  public BukkitTask runTaskAsynchronously(Plugin plugin, Runnable task) throws IllegalArgumentException;
204 
205  /**
206  * Returns a task that will run after the specified number of server
207  * ticks.
208  *
209  * @param plugin the reference to the plugin scheduling task
210  * @param task the task to be run
211  * @param delay the ticks to wait before running the task
212  * @return a BukkitTask that contains the id number
213  * @throws IllegalArgumentException if plugin is null
214  * @throws IllegalArgumentException if task is null
215  */
216  public BukkitTask runTaskLater(Plugin plugin, Runnable task, long delay) throws IllegalArgumentException;
217 
218  /**
219  * <b>Asynchronous tasks should never access any API in Bukkit. Great care
220  * should be taken to assure the thread-safety of asynchronous tasks.</b>
221  * <p>
222  * Returns a task that will run asynchronously after the specified number
223  * of server ticks.
224  *
225  * @param plugin the reference to the plugin scheduling task
226  * @param task the task to be run
227  * @param delay the ticks to wait before running the task
228  * @return a BukkitTask that contains the id number
229  * @throws IllegalArgumentException if plugin is null
230  * @throws IllegalArgumentException if task is null
231  */
232  public BukkitTask runTaskLaterAsynchronously(Plugin plugin, Runnable task, long delay) throws IllegalArgumentException;
233 
234  /**
235  * Returns a task that will repeatedly run until cancelled, starting after
236  * the specified number of server ticks.
237  *
238  * @param plugin the reference to the plugin scheduling task
239  * @param task the task to be run
240  * @param delay the ticks to wait before running the task
241  * @param period the ticks to wait between runs
242  * @return a BukkitTask that contains the id number
243  * @throws IllegalArgumentException if plugin is null
244  * @throws IllegalArgumentException if task is null
245  */
246  public BukkitTask runTaskTimer(Plugin plugin, Runnable task, long delay, long period) throws IllegalArgumentException;
247 
248  /**
249  * <b>Asynchronous tasks should never access any API in Bukkit. Great care
250  * should be taken to assure the thread-safety of asynchronous tasks.</b>
251  * <p>
252  * Returns a task that will repeatedly run asynchronously until cancelled,
253  * starting after the specified number of server ticks.
254  *
255  * @param plugin the reference to the plugin scheduling task
256  * @param task the task to be run
257  * @param delay the ticks to wait before running the task for the first
258  * time
259  * @param period the ticks to wait between runs
260  * @return a BukkitTask that contains the id number
261  * @throws IllegalArgumentException if plugin is null
262  * @throws IllegalArgumentException if task is null
263  */
264  public BukkitTask runTaskTimerAsynchronously(Plugin plugin, Runnable task, long delay, long period) throws IllegalArgumentException;
265 }
List< BukkitWorker > getActiveWorkers()
int scheduleSyncRepeatingTask(Plugin plugin, Runnable task, long delay, long period)
BukkitTask runTaskLaterAsynchronously(Plugin plugin, Runnable task, long delay)
int scheduleAsyncDelayedTask(Plugin plugin, Runnable task, long delay)
public< T > Future< T > callSyncMethod(Plugin plugin, Callable< T > task)
BukkitTask runTaskAsynchronously(Plugin plugin, Runnable task)
int scheduleAsyncRepeatingTask(Plugin plugin, Runnable task, long delay, long period)
boolean isCurrentlyRunning(int taskId)
BukkitTask runTaskTimer(Plugin plugin, Runnable task, long delay, long period)
BukkitTask runTask(Plugin plugin, Runnable task)
BukkitTask runTaskTimerAsynchronously(Plugin plugin, Runnable task, long delay, long period)
BukkitTask runTaskLater(Plugin plugin, Runnable task, long delay)
List< BukkitTask > getPendingTasks()
int scheduleSyncDelayedTask(Plugin plugin, Runnable task, long delay)