Check if task is running

Discussion in 'Plugin Development' started by ThrustLP, Apr 2, 2016.

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


    Hello guys! I have a fairly simple part of code here with a command and an scheduler. So whenever I type the command the task counts down from X to 0 and then does something. My problem is that if I type the command twice there are two tasks running. So I want to send the player a message and cancel starting a new task when there is already one running. Here is my code:

        int cd; //Is defined where it belongs to 

                    cd = Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, new Runnable() {
                        Integer amount = Integer.valueOf(15);
                        public void run() {
                            if(amount != 0){
                                Bukkit.broadcastMessage(amount + " seconds left!");
                                amount --;
                            }else if(amount == 0){
                    }, 20, 20);
    So everything works fine, the only thing that I want to add is a check if the task is already running.

    How can I do that?

    Thank you so much and have a nice day!

  2. Offline


  3. Offline


    Is it just me, or this is decompiled code?
    I don't see any reason why you use the object Integer rather than the primitive int.
Thread Status:
Not open for further replies.

Share This Page