Last active
May 27, 2021 10:08
-
-
Save kBULOSU/a69b0aa57456498210e8bbc6c62a5a8f to your computer and use it in GitHub Desktop.
A spigot countdown task class
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
import org.bukkit.scheduler.BukkitRunnable; | |
import java.util.function.IntConsumer; | |
public class CountdownTask extends BukkitRunnable { | |
private int counter; | |
private final IntConsumer countdownAction; | |
private final Runnable completionAction; | |
public CountdownTask(final int limit, final IntConsumer countdownAction, final Runnable completionAction) { | |
this.counter = limit; | |
this.countdownAction = countdownAction; | |
this.completionAction = completionAction; | |
} | |
@Override | |
public void run() { | |
if (--this.counter == 0) { | |
this.completionAction.run(); | |
this.cancel(); | |
} | |
this.countdownAction.accept(this.counter); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment