2015-07-31 03:24:01 +10:00
|
|
|
package com.plotsquared.bukkit.util;
|
2015-02-19 17:08:15 +11:00
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.util.TaskManager;
|
2015-07-27 19:50:04 +02:00
|
|
|
import com.plotsquared.bukkit.BukkitMain;
|
2016-02-13 20:01:18 -05:00
|
|
|
import org.bukkit.Bukkit;
|
2015-02-19 17:08:15 +11:00
|
|
|
|
2015-09-13 14:04:31 +10:00
|
|
|
public class BukkitTaskManager extends TaskManager {
|
2016-02-13 20:01:18 -05:00
|
|
|
|
2016-04-05 12:37:11 -04:00
|
|
|
private final BukkitMain bukkitMain;
|
|
|
|
|
|
|
|
public BukkitTaskManager(BukkitMain bukkitMain) {
|
|
|
|
this.bukkitMain = bukkitMain;
|
|
|
|
}
|
|
|
|
|
2015-02-20 17:34:19 +11:00
|
|
|
@Override
|
2016-03-28 19:30:55 -04:00
|
|
|
public int taskRepeat(Runnable runnable, int interval) {
|
2016-04-05 12:37:11 -04:00
|
|
|
return this.bukkitMain.getServer().getScheduler().scheduleSyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
|
2015-02-19 17:08:15 +11:00
|
|
|
}
|
2016-02-13 20:01:18 -05:00
|
|
|
|
2016-03-22 21:41:37 -04:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
@Override
|
2016-03-28 19:30:55 -04:00
|
|
|
public int taskRepeatAsync(Runnable runnable, int interval) {
|
2016-04-05 12:37:11 -04:00
|
|
|
return this.bukkitMain.getServer().getScheduler().scheduleAsyncRepeatingTask(this.bukkitMain, runnable, interval, interval);
|
2015-08-02 21:56:18 +10:00
|
|
|
}
|
2016-02-13 20:01:18 -05:00
|
|
|
|
2015-02-20 17:34:19 +11:00
|
|
|
@Override
|
2016-03-28 19:30:55 -04:00
|
|
|
public void taskAsync(Runnable runnable) {
|
2016-04-05 12:37:11 -04:00
|
|
|
this.bukkitMain.getServer().getScheduler().runTaskAsynchronously(this.bukkitMain, runnable).getTaskId();
|
2015-02-19 17:08:15 +11:00
|
|
|
}
|
2016-02-13 20:01:18 -05:00
|
|
|
|
2015-02-20 17:34:19 +11:00
|
|
|
@Override
|
2016-03-28 19:30:55 -04:00
|
|
|
public void task(Runnable runnable) {
|
2016-04-05 12:37:11 -04:00
|
|
|
this.bukkitMain.getServer().getScheduler().runTask(this.bukkitMain, runnable).getTaskId();
|
2015-02-19 17:08:15 +11:00
|
|
|
}
|
2016-02-13 20:01:18 -05:00
|
|
|
|
2015-02-20 17:34:19 +11:00
|
|
|
@Override
|
2016-03-28 19:30:55 -04:00
|
|
|
public void taskLater(Runnable runnable, int delay) {
|
2016-04-05 12:37:11 -04:00
|
|
|
this.bukkitMain.getServer().getScheduler().runTaskLater(this.bukkitMain, runnable, delay).getTaskId();
|
2015-02-19 17:08:15 +11:00
|
|
|
}
|
2016-02-13 20:01:18 -05:00
|
|
|
|
2015-02-19 21:29:17 +11:00
|
|
|
@Override
|
2016-03-28 19:30:55 -04:00
|
|
|
public void taskLaterAsync(Runnable runnable, int delay) {
|
2016-04-05 12:37:11 -04:00
|
|
|
this.bukkitMain.getServer().getScheduler().runTaskLaterAsynchronously(this.bukkitMain, runnable, delay);
|
2015-02-22 22:30:46 +11:00
|
|
|
}
|
2016-02-13 20:01:18 -05:00
|
|
|
|
2015-02-22 22:30:46 +11:00
|
|
|
@Override
|
2016-03-22 21:41:37 -04:00
|
|
|
public void cancelTask(int task) {
|
2015-09-13 14:04:31 +10:00
|
|
|
if (task != -1) {
|
2015-02-22 22:30:46 +11:00
|
|
|
Bukkit.getScheduler().cancelTask(task);
|
|
|
|
}
|
2015-02-19 21:29:17 +11:00
|
|
|
}
|
2015-02-19 17:08:15 +11:00
|
|
|
}
|