Easiest way to make repeating/delayed tasks?

Discussion in 'Plugin Development' started by bobnixon1, Sep 5, 2013.

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

    bobnixon1

    what is the easiest way to make a delayed or repeating task?
     
  2. Offline

    leimekiller

  3. Offline

    bobnixon1

  4. Offline

    Chinwe

    Code:
    new BukkitRunnable()
    {
      public void run()
      {
        // do your stuff here
      }
     
    }.runTaskLater(plugin, delay in ticks);
    That will delay your code, if you want to repeat it, replace the last line with:
    Code:
    }.runTaskTimer(plugin, delay, interval between repeats (in ticks));
    And you can cancel it from within itself too, eg, if you want to repeat something 10 times:

    Code:
    new BukkitRunnable()
    {
      int count = 10;
      public void run()
      {
        // do your stuff here
     
        count--;
        if (count == 0) cancel();
      }
     
    }.runTaskLater(plugin, delay in ticks);
     
    bobnixon1 likes this.
  5. Offline

    moo3oo3oo3

    where do I place that?
     
  6. Offline

    Dragonphase

    moo3oo3oo3

    Wherever you want to use it. I should point out that you should not call any Bukkit API asynchronously.
     
  7. Offline

    teej107

Thread Status:
Not open for further replies.

Share This Page