package com.plotsquared.sponge; 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; public class SpongeTaskManager extends TaskManager { private AtomicInteger i = new AtomicInteger(); private HashMap 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(); builder.async().execute(r); } @Override public void task(Runnable r) { TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); builder.execute(r); } @Override public void taskLater(Runnable r, int delay) { TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); builder.delay(delay).execute(r); } @Override public void taskLaterAsync(Runnable r, int delay) { TaskBuilder builder = SpongeMain.THIS.getGame().getScheduler().getTaskBuilder(); builder.async().delay(delay).execute(r); } @Override public void cancelTask(int i) { Task task = tasks.remove(i); if (task != null) { task.cancel(); } } }