I am doing a minigame plugin for minecraft and i want to make a separated class with a countdown code, and when i need it in item classes, call it and customize the time for the cooldown. Is there a way?
The seconds left are displayed as the Level:
public static void startCountdown(int seconds, Player p) {
int[] countdown = new int[1];
countdown[0] = seconds;
final int[] scheduler = new int[1];
scheduler[0] = Bukkit.getScheduler().scheduleAsyncRepeatingTask(plugin, new Runnable() {
@Override
public void run() {
if (seconds == 0) {
Bukkit.getScheduler().cancelTask(scheduler[0]);
} else {
p.setLevel(countdown[0]);
}
countdown[0] = countdown[0] - 1;
}
}, 0, 20);
}