3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-18 20:40:08 +01:00

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.
Dieser Commit ist enthalten in:
Wesley Wolfe 2012-10-06 16:23:56 -05:00
Ursprung 506a1a0765
Commit 93a79cd0e6
2 geänderte Dateien mit 31 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -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) {

Datei anzeigen

@ -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);
}
}