Created
February 7, 2021 11:12
-
-
Save gepron1x/fc1f137899c76aeb804d73c3738378e7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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