Scheduler help

Discussion in 'Plugin Development' started by Maro, Sep 30, 2012.

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

    Maro

    Hello, I have made a scheduler that goes off at 00.00. But at 00.00 it doesn't stop. Anyone know how to fix this?

    Code:

    Code:
    @Override
        public void onEnable(){
            Calendar m =Calendar.getInstance();
            m.set(Calendar.HOUR_OF_DAY,0);
            m.set(Calendar.MINUTE,0);
            m.set(Calendar.SECOND,0);
            m.set(Calendar.MILLISECOND,0);
     
        int time = (int) (m.getTimeInMillis()            + 86400000      - (new Date()).getTime());
           
        Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
            public void run() {
                System.out.println("Hello");
                }
          }, time / 50, 100 / 50); 
    Console:

    00.00: hello
    00.00 hello
    00.00 hello
    00.00 hello
    00.01 hello

    and it goes like that forever..
     
  2. Use a Delayed task instead...
     
    LucasEmanuel likes this.
  3. Offline

    Hertz

    Yeah use

    Bukkit.getScheduler().scheduleSyncReDelayedTask(this, new Runnable(){
    public void run() {
    System.out.println("Hello");
    }
    }, time / 50, 100 / 50);
     
  4. Offline

    Maro

    The problem is that I want to go off at midnight every midnight, not only once. And delayed tasks only have 3 args..

    Anyone knows how to do it then?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
  5. Bukkit.getScheduler().scheduleSyncReDelayedTask(this, new Runnable(){
    public void run() {
    System.out.println("Hello");
    }
    }, time / 50, 100 / 50);

    the 100 / 50 part says it must go of every 2 ticks after the first wait time, time/50
     
  6. Offline

    Maro

    The method scheduleSyncDelayedTask(Plugin, Runnable, long) in the type BukkitScheduler is not applicable for the arguments (Maro, new Runnable(){}, int, int)
     
  7. Hint: 24 h = 1728000 ticks, not 2.
     
  8. Offline

    Maro

    Thanks everybody! Now it works :D
     
Thread Status:
Not open for further replies.

Share This Page