Repeated Tasks

Discussion in 'Plugin Development' started by Lionhard, Jan 11, 2014.

Thread Status:
Not open for further replies.
  1. Hello all,

    I have a little question about the Scheduler thing. I need something, to repeatly, every 5 minutes for example, run a method if a boolean is set to true.
    Example:
    A player kills a 10 zombies and then a boolean requiredZombiesKilled will set to true.
    Then somewhere I check if requiredZombiesKilled is true and if, it prints a message you have successfully killed 10 zombies! and after 5 minutes it sends again you have successfully killed 10 zombies! and so on. If he types /ok (just an example) the boolean will be set to false and the messages will stop showing up. If he kills again 10 zombies, the boolean will be again true and the messages again appear.

    Can someone tell me how to do this?

    Thank you in advance, Lionhard
     
  2. Code:
    Bukkit.getServer().getScheduler().runTaskTimer(plugin, new Runnable() {
        public void run() {
            if (boolean) doMethod();
        }
    }, 0L, 6000L);
    
    Change the 0L to 6000L if you don't want to run the run() method instantly and then start the timer every 5 minutes. The reason it's 6000L is because each second is 20 ticks, and 5 minutes has 300 seconds so 20 * 300 = 6000
     
  3. KingFaris11 Oh, ok, thanks! But, why that L? what for stands that?
     
  4. L stands for Long. Writing L after a number indicates the number is Long.

    123L (123 in long)
    0.123f (123 in float)
    0.123 (123 in double)
    123 (123 in int)
     
    KingFaris11 likes this.
  5. Louis1234567890987654321 aahh ok thanks for the info!

    Actually, can someone help me where to put that? (into the onEnable method, or just somewhere in the class, idk :D)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  6. Depends on when you want it to start, but in your case I think you'd do it in the onEnable. Sorry for the late reply, Bukkit Forums didn't alert me...
     
    Lionhard likes this.
  7. KingFaris11 Yeah, thanks anyways, I got it already. ;)
     
    KingFaris11 likes this.
Thread Status:
Not open for further replies.

Share This Page