scheduleSyncRepeatingTask cancelling...?

Discussion in 'Plugin Development' started by ZanderMan9, Jul 12, 2014.

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

    ZanderMan9

    I need to create a simple countdown. I'm using getServer().getScheduler blah blah....
    My question is, how do I stop the task once my timer reaches 0? All I need is the code for stopping it, everything else I can handle myself :)

    It doesn't look as if there is a way...
    If there is, I'd really appreciate it if you could tell me!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  2. Offline

    izarooni

    Code:java
    1. int i = getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    2.  
    3. public void run() {
    4. // Code. . .
    5. }
    6. }, 20L, 20L);


    And to cancel:
    Code:java
    1. Bukkit.getScheduler().cancelTask(i);


    I'd explain but I'm not good at explaining.
     
  3. ZanderMan9
    You could use izarooni 's way, or you can do something along the lines of this:

    Code:java
    1. new BukkitRunnable(){
    2. public void run(){
    3. this.cancel();
    4. }
    5. }.runTaskTimer(plugin, delay, interval);
     
  4. Offline

    ZanderMan9

    Thanks guys! I'll try both ways.
     
Thread Status:
Not open for further replies.

Share This Page