Using system time rather than ticks?

Discussion in 'Plugin Development' started by ShakyTom, Nov 8, 2012.

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

    ShakyTom

    Hello,

    I need my plugin to run some code every second.

    I currently use a schedulesyncrepeatingtask, however when the servers tps drops this no longer runs as accurately as I need it to.

    Is there a way to get similar functionality using another method that isn't based on server ticks?

    Thanks
     
  2. Offline

    Ewe Loon

    I dont think so, but here is an option

    in onEnable add

    Long nexttime =System.currentTimeMillis()+1000 ;
    schedule the task to run every 100th of a second

    then in the scheduled task add
    long now=System.currentTimeMillis();
    if (now>nexttime){
    nexttime=now+1000;
    do your stuff here
    }
     
  3. Offline

    Milkywayz

    The task won't run accurately if the server TPS drops as long as it's a Sync task. If you want your task to be unaffected by the main thread being overloaded, and your task doesn't have non-thread safe bukkit method calls, make your task Async. As long as the server it's running on has more than 1 core, it should be fine.

    If the server TPS drops it's usually because the server's main thread is overloading, meaning this won't really fix it, not to mention calling System.currentTimeMillis() so much will just lag even more.
     
    thehutch likes this.
Thread Status:
Not open for further replies.

Share This Page