Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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.
  • Loading branch information...
commit eebc275bf7c5e7147053567aa1ad87bca16455d5 1 parent 8ca1962
Wesley Wolfe authored October 06, 2012
28  src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -83,19 +83,39 @@ public int scheduleSyncDelayedTask(final Plugin plugin, final Runnable task) {
83 83
         return this.scheduleSyncDelayedTask(plugin, task, 0l);
84 84
     }
85 85
 
  86
+    public BukkitTask runTask(Plugin plugin, Runnable runnable) {
  87
+        return runTaskLater(plugin, runnable, 0l);
  88
+    }
  89
+
86 90
     public int scheduleAsyncDelayedTask(final Plugin plugin, final Runnable task) {
87 91
         return this.scheduleAsyncDelayedTask(plugin, task, 0l);
88 92
     }
89 93
 
  94
+    public BukkitTask runTaskAsynchronously(Plugin plugin, Runnable runnable) {
  95
+        return runTaskLaterAsynchronously(plugin, runnable, 0l);
  96
+    }
  97
+
90 98
     public int scheduleSyncDelayedTask(final Plugin plugin, final Runnable task, final long delay) {
91 99
         return this.scheduleSyncRepeatingTask(plugin, task, delay, -1l);
92 100
     }
93 101
 
  102
+    public BukkitTask runTaskLater(Plugin plugin, Runnable runnable, long delay) {
  103
+        return runTaskTimer(plugin, runnable, delay, -1l);
  104
+    }
  105
+
94 106
     public int scheduleAsyncDelayedTask(final Plugin plugin, final Runnable task, final long delay) {
95 107
         return this.scheduleAsyncRepeatingTask(plugin, task, delay, -1l);
96 108
     }
97 109
 
  110
+    public BukkitTask runTaskLaterAsynchronously(Plugin plugin, Runnable runnable, long delay) {
  111
+        return runTaskTimer(plugin, runnable, delay, -1l);
  112
+    }
  113
+
98 114
     public int scheduleSyncRepeatingTask(final Plugin plugin, final Runnable runnable, long delay, long period) {
  115
+        return runTaskTimer(plugin, runnable, delay, period).getTaskId();
  116
+    }
  117
+
  118
+    public BukkitTask runTaskTimer(Plugin plugin, Runnable runnable, long delay, long period) {
99 119
         validate(plugin, runnable);
100 120
         if (delay < 0l) {
101 121
             delay = 0;
@@ -109,6 +129,10 @@ public int scheduleSyncRepeatingTask(final Plugin plugin, final Runnable runnabl
109 129
     }
110 130
 
111 131
     public int scheduleAsyncRepeatingTask(final Plugin plugin, final Runnable runnable, long delay, long period) {
  132
+        return runTaskTimerAsynchronously(plugin, runnable, delay, period).getTaskId();
  133
+    }
  134
+
  135
+    public BukkitTask runTaskTimerAsynchronously(Plugin plugin, Runnable runnable, long delay, long period) {
112 136
         validate(plugin, runnable);
113 137
         if (delay < 0l) {
114 138
             delay = 0;
@@ -357,10 +381,10 @@ private void addTask(final CraftTask task) {
357 381
         tailTask.setNext(task);
358 382
     }
359 383
 
360  
-    private int handle(final CraftTask task, final long delay) {
  384
+    private CraftTask handle(final CraftTask task, final long delay) {
361 385
         task.setNextRun(currentTick + delay);
362 386
         addTask(task);
363  
-        return task.getTaskId();
  387
+        return task;
364 388
     }
365 389
 
366 390
     private static void validate(final Plugin plugin, final Object task) {
5  src/main/java/org/bukkit/craftbukkit/scheduler/CraftTask.java
... ...
@@ -1,5 +1,6 @@
1 1
 package org.bukkit.craftbukkit.scheduler;
2 2
 
  3
+import org.bukkit.Bukkit;
3 4
 import org.bukkit.plugin.Plugin;
4 5
 import org.bukkit.scheduler.BukkitTask;
5 6
 
@@ -79,4 +80,8 @@ void setNext(CraftTask next) {
79 80
     Class<? extends Runnable> getTaskClass() {
80 81
         return task.getClass();
81 82
     }
  83
+
  84
+    public void cancel() {
  85
+        Bukkit.getScheduler().cancelTask(id);
  86
+    }
82 87
 }

0 notes on commit eebc275

Please sign in to comment.
Something went wrong with that request. Please try again.