Countdown repeat

Discussion in 'Plugin Development' started by nathanot14, Jul 28, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    nathanot14

    I am making a countdown for a plugin and it works. But I can do it one time and when the countdown stops and I want do it again it doesnt work.

    My script:
    Code:
    ublic class Reload implements Listener {
       
        public static Plugin plugin;
       
        public Reload(Plugin plugin) {
            this.plugin = plugin;
        }
       
        int countdown = 5;
       
        int scheduler;
       
        @EventHandler
        public void onPlayerDropItem(PlayerDropItemEvent e) {
           
            Player p = e.getPlayer();
           
            if(e.getItemDrop().getItemStack().getType() == Material.STICK) {
               
                e.setCancelled(true);
               
                int playerAmmo = SQLStats.getKills(p.getName().toString());
               
                if (playerAmmo == 0) {
                    scheduler = Bukkit.getScheduler().scheduleSyncRepeatingTask(Reload.plugin, new Runnable() {
                       
                        @Override
                        public void run() {
                            if (countdown != 0) {
                                p.sendMessage(ChatColor.GREEN + "" + countdown);
                                countdown--;
                            } else {
                                Bukkit.getScheduler().cancelTask(scheduler);
                            }
                        }       
                    }, 0L, 20L);
                }
            }
        }
    }
     
  2. when cancelling the task. You need to set the countdown back to 5
     
Thread Status:
Not open for further replies.

Share This Page