2015-07-30 16:25:16 +02:00
|
|
|
package com.plotsquared.sponge.util;
|
2015-07-28 13:38:49 +02:00
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
|
|
|
import org.spongepowered.api.service.scheduler.Task;
|
|
|
|
import org.spongepowered.api.service.scheduler.TaskBuilder;
|
|
|
|
|
|
|
|
import com.intellectualcrafters.plot.util.TaskManager;
|
2015-07-30 16:25:16 +02:00
|
|
|
import com.plotsquared.sponge.SpongeMain;
|
2015-07-28 13:38:49 +02:00
|
|
|
|
|
|
|
public class SpongeTaskManager extends TaskManager {
|
|
|
|
|
|
|
|
private AtomicInteger i = new AtomicInteger();
|
|
|
|
|
|
|
|
private HashMap<Integer, Task> tasks = new HashMap<>();
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int taskRepeat(Runnable r, int interval) {
|
|
|
|
int val = i.incrementAndGet();
|
|
|
|
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder();
|
|
|
|
TaskBuilder built = builder.delay(interval).interval(interval).execute(r);
|
|
|
|
Task task = built.submit(SpongeMain.THIS.getPlugin());
|
|
|
|
tasks.put(val, task);
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void taskAsync(Runnable r) {
|
|
|
|
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder();
|
2015-07-30 16:25:16 +02:00
|
|
|
builder.async().execute(r).submit(SpongeMain.THIS.getPlugin());
|
2015-07-28 13:38:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void task(Runnable r) {
|
|
|
|
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder();
|
2015-07-30 16:25:16 +02:00
|
|
|
builder.execute(r).submit(SpongeMain.THIS.getPlugin());
|
2015-07-28 13:38:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void taskLater(Runnable r, int delay) {
|
|
|
|
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder();
|
2015-07-30 16:25:16 +02:00
|
|
|
builder.delay(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
|
2015-07-28 13:38:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void taskLaterAsync(Runnable r, int delay) {
|
|
|
|
TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder();
|
2015-07-30 16:25:16 +02:00
|
|
|
builder.async().delay(delay).execute(r).submit(SpongeMain.THIS.getPlugin());
|
2015-07-28 13:38:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void cancelTask(int i) {
|
|
|
|
Task task = tasks.remove(i);
|
|
|
|
if (task != null) {
|
|
|
|
task.cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|