Cancelling a task after a certain time of running

Discussion in 'Plugin Development' started by MagmaticBacca, Aug 8, 2015.

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

    MagmaticBacca

    The Title is self explanatory how would i cancel a task after about 10 seconds of running it? This may seem a bit noobish that i dont know how to do this but i couldnt really find any tutorials on how to do this.
     
  2. If you mean a repeating task:
    Code:
    long period = 30;
    
    
    new BukkitRunnable() {
    int i = 0;
    
    public void run()  {
    
    if (i >= 20 * 10 /*10 seconds*/) {
    cancel();
    return;
    }
    
    //your code
    
    i += period;
    }
    }.runTaskTimer(plugin, 0, period);
     
  3. Offline

    caderape

Thread Status:
Not open for further replies.

Share This Page