Executing code right after server startup

Discussion in 'Plugin Development' started by MrZoraman, Jul 2, 2013.

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

    MrZoraman

    I have a body of code I need to execute, but it can't execute until after all of the other plugins have been enabled, and needs to execute as soon as possible. I don't want to schedule a delayed task because I have no way of knowing how long the server will take for all of the plugins to fully enable.

    From a similar thread it looks like this code
    Code:
    getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                public void run(){
                        //Code here
                }
            });
    works, but if it does, why does it work? There's no delay time set so I'm not sure what it waits for, unless this is it's one job.

    Thanks!
    -Z
     
  2. Offline

    NoLiver92

    why not put the code in onenable() ?
     
  3. Offline

    LucasEmanuel

    MrZoraman
    As far as I know the scheduler doesn't start working with scheduled task until the server-setup is completed :)
     
  4. Offline

    fireblast709

    giving no delay will default to 0L, iirc. This should mean it is executed in the next tick.
     
  5. Offline

    AndyMcB1

    Bump - I'm interested in why this occurs
     
  6. What fireblast709 said. No delay time means next possible execution which is the next tick. The next possible tick is in this case after all plugins loaded and the server starts its normal routine.
     
  7. Offline

    1Rogue


    Bukkit's scheduler is tick-based, ticks don't start until after the server finishes starting up.

    Being tick-based is why using tasks through Bukkit's scheduler for time-accurate things is a bad idea.
     
  8. Offline

    Bart

    I would stick with the delayed task but if someone joins before your code has not run, cancel the task and then run the code manually before they join.

    If it's a private server the plugin could be made to depend on all others so it loads last and therefore runs the code but I wouldn't recommend it at all
     
Thread Status:
Not open for further replies.

Share This Page