Skip to content

Instantly share code, notes, and snippets.

@gepron1x
Created February 7, 2021 11:12
Show Gist options
  • Save gepron1x/fc1f137899c76aeb804d73c3738378e7 to your computer and use it in GitHub Desktop.
Save gepron1x/fc1f137899c76aeb804d73c3738378e7 to your computer and use it in GitHub Desktop.
public class TimerTask {
private static final TaskScheduler scheduler = ProxyServer.getInstance().getScheduler();
private ScheduledTask timer;
private int count;
private TimeUnit timeUnit;
private final Runnable runnable;
public TimerTask(TimeUnit timeUnit, int time, Runnable r) {
this.count = time;
this.timeUnit = timeUnit;
this.runnable = r;
}
public void schedule() {
timer = scheduler.schedule(SouthSideAuth.get(), () -> {
count--;
if(count <= 0) {
runnable.run();
scheduler.cancel(timer);
}
}, 1, 1, timeUnit);
}
public int howManyLeft() {
return count;
}
public TimeUnit getTimeUnit() {
return timeUnit;
}
public void cancel() {
timer.cancel();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment