summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWesley Wolfe <weswolf@aol.com>2012-10-06 16:23:56 -0500
committerWesley Wolfe <weswolf@aol.com>2012-10-14 01:21:58 -0500
commit93a79cd0e646318ee23db6842cbba0acb107c389 (patch)
treeda4d21bdd6a3d86130009dbc16ce0c3b06fbc3d6
parent506a1a0765b34574bef661f622fd0ab654cea8fb (diff)
downloadcraftbukkit-93a79cd0e646318ee23db6842cbba0acb107c389.tar
craftbukkit-93a79cd0e646318ee23db6842cbba0acb107c389.tar.gz
craftbukkit-93a79cd0e646318ee23db6842cbba0acb107c389.tar.lz
craftbukkit-93a79cd0e646318ee23db6842cbba0acb107c389.tar.xz
craftbukkit-93a79cd0e646318ee23db6842cbba0acb107c389.zip
Implement new scheduler API. Adds BUKKIT-836
The implementation for the new methods mimics the old methods. The final call for the old methods now maps to the new methods with an additional call to get id.
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java28
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java5
2 files changed, 31 insertions, 2 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index bc0cd876..15b15dbf 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -83,19 +83,39 @@ public class CraftScheduler implements BukkitScheduler {
return this.scheduleSyncDelayedTask(plugin, task, 0l);
}
+ public BukkitTask runTask(Plugin plugin, Runnable runnable) {
+ return runTaskLater(plugin, runnable, 0l);
+ }
+
public int scheduleAsyncDelayedTask(final Plugin plugin, final Runnable task) {
return this.scheduleAsyncDelayedTask(plugin, task, 0l);
}
+ public BukkitTask runTaskAsynchronously(Plugin plugin, Runnable runnable) {
+ return runTaskLaterAsynchronously(plugin, runnable, 0l);
+ }
+
public int scheduleSyncDelayedTask(final Plugin plugin, final Runnable task, final long delay) {
return this.scheduleSyncRepeatingTask(plugin, task, delay, -1l);
}
+ public BukkitTask runTaskLater(Plugin plugin, Runnable runnable, long delay) {
+ return runTaskTimer(plugin, runnable, delay, -1l);
+ }
+
public int scheduleAsyncDelayedTask(final Plugin plugin, final Runnable task, final long delay) {
return this.scheduleAsyncRepeatingTask(plugin, task, delay, -1l);
}
+ public BukkitTask runTaskLaterAsynchronously(Plugin plugin, Runnable runnable, long delay) {
+ return runTaskTimer(plugin, runnable, delay, -1l);
+ }
+
public int scheduleSyncRepeatingTask(final Plugin plugin, final Runnable runnable, long delay, long period) {
+ return runTaskTimer(plugin, runnable, delay, period).getTaskId();
+ }
+
+ public BukkitTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) {
validate(plugin, runnable);
if (delay < 0l) {
delay = 0;
@@ -109,6 +129,10 @@ public class CraftScheduler implements BukkitScheduler {
}
public int scheduleAsyncRepeatingTask(final Plugin plugin, final Runnable runnable, long delay, long period) {
+ return runTaskTimerAsynchronously(plugin, runnable, delay, period).getTaskId();
+ }
+
+ public BukkitTask runTaskTimerAsynchronously(Plugin plugin, Runnable runnable, long delay, long period) {
validate(plugin, runnable);
if (delay < 0l) {
delay = 0;
@@ -357,10 +381,10 @@ public class CraftScheduler implements BukkitScheduler {
tailTask.setNext(task);
}
- private int handle(final CraftTask task, final long delay) {
+ private CraftTask handle(final CraftTask task, final long delay) {
task.setNextRun(currentTick + delay);
addTask(task);
- return task.getTaskId();
+ return task;
}
private static void validate(final Plugin plugin, final Object task) {
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
index cfd6fb45..4dd1cb29 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
@@ -1,5 +1,6 @@
package org.bukkit.craftbukkit.scheduler;
+import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.scheduler.BukkitTask;
@@ -79,4 +80,8 @@ class CraftTask implements BukkitTask, Runnable {
Class<? extends Runnable> getTaskClass() {
return task.getClass();
}
+
+ public void cancel() {
+ Bukkit.getScheduler().cancelTask(id);
+ }
}