Help with Timed Threads Tick Events

Discussion in 'Plugin Development' started by dwelfman, Jan 1, 2015.

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


    Let's start off with... I'm an experienced Java programmer (25+ years between assembly, c, c++ and java) and have some recent experience with Minecraft (especially the event handling and task scheduling, which are most relevant to my question). So, I'm not looking for anyone to give me specific code for anything... (aka do my work for me). My question is really what is the best way to do something with the constraints of the available API's.

    I need to grab a timer tick and perform different actions at different unrelated intervals. I have worked a test system where I can accomplish this is with scheduling a repeating thread to start-up, check the time and do its thing for that period. My gut has me worried that spawning a repeating task like this has a lot of overhead and could cause lag. I've also looked around extensively to find some sort of timer tick event I can monitor with an event handler instead - again my gut says this would more efficient and the developers should have provided some sort of event like this to monitor. My concerns may actually be a moot point because at worst case the event would only be triggered every 10 seconds (an eternity in computer time).

    Any recommendations as to the best way to handle this timer tick issue?

    Your assistance is appreciated!
  2. Offline


    Bukkit Runnables?
  3. Offline


    I believe what you're looking for is BukkitRunnable

    Example Usage:
    BukkitRunnable run = new BukkitRunnable(){
    public void run(){
    // stuff
    run.runTaskTimer(<plugin>, <initialDelay>, <delay between>);
    or run.runTaskLater(<plugin>, <delay>);
  4. Offline


    Definitely the scheduler API or you can proxy one of the ticking classes if you really want "accuracy."

    In the version at mc-dev, this line is called to tick the classes. MinecraftServer is a Thread runnable that is started by the CraftBukkit Main, however I can't exactly point you to the source since it's DMCA'd. If you slip in an with a bit of reflection, drop in a modified u() method that calls super and performs whatever you want then that could work (however the runnable is finalized in Thread, that could be a little tricky).

    Rather than replacing a runnable, you can replace a WorldServer in one of the Bukkit CraftWorlds with a modified WorldServer. This *should* be more reliable.
Thread Status:
Not open for further replies.

Share This Page