I need an integer per player. I created a countdown, but the integer is for all players. When I set a value, this applies to all players. Each player should get their own value.
Does anyone have an idea how to fix this?
My code:
private static final int COUNTDOWN_SECONDS = 6;
private int seconds;
public StartCountdown() {
seconds = COUNTDOWN_SECONDS;
}
@Override
public void start(Player player) {
taskID = Bukkit.getScheduler().scheduleSyncRepeatingTask(Challenge.getInstance(), () -> {
switch(seconds) {
case 5:
player.sendTitle(ChatColor.DARK_RED + "5", "", 10, 20, 30);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
break;
case 4:
player.sendTitle(ChatColor.RED + "4", "", 10, 20, 30);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
break;
case 3:
player.sendTitle(ChatColor.GOLD + "3", "", 10, 20, 30);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
break;
case 2:
player.sendTitle(ChatColor.YELLOW + "2", "", 10, 20, 30);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
break;
case 1:
player.sendTitle(ChatColor.DARK_GREEN + "1", "", 10, 20, 30);
player.playSound(player.getLocation(), Sound.ENTITY_EXPERIENCE_ORB_PICKUP, 1, 1);
break;
case 0:
player.sendTitle(ChatColor.GREEN + "GO", "", 10, 20, 50);
player.playSound(player.getLocation(), Sound.ENTITY_PLAYER_LEVELUP, 1, 1);
seconds = COUNTDOWN_SECONDS;
stop();
break;
default:
break;
}
seconds--;
}, 0, 20);