From 93a79cd0e646318ee23db6842cbba0acb107c389 Mon Sep 17 00:00:00 2001 From: Wesley Wolfe Date: Sat, 6 Oct 2012 16:23:56 -0500 Subject: 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. --- .../craftbukkit/scheduler/CraftScheduler.java | 28 ++++++++++++++++++++-- .../bukkit/craftbukkit/scheduler/CraftTask.java | 5 ++++ 2 files changed, 31 insertions(+), 2 deletions(-) (limited to 'src') 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 getTaskClass() { return task.getClass(); } + + public void cancel() { + Bukkit.getScheduler().cancelTask(id); + } } -- cgit v1.2.3