Solved Custom tick scheduler.

Discussion in 'Plugin Development' started by Remi1115, Oct 11, 2012.

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

    Remi1115

    I haven't worked with Schedulers before, so that's why I'm asking this question. I've already read the Wiki article on Schedulers but I don't think it covers the thing that I want to use it for.

    In my plugin (that I'm creating just for fun) I want to have a custom tick, a method that gets called every second. I will use it for things like countdowns (checking if there's a countdown, and if there is one, count it down), but also for player checks (making sure players aren't in an area where they shouldn't be in).

    From what I've heard it's dangerous to work with schedulers if you don't know what you're doing. So: What kind of scheduler should I use for this, and what should I look out for when using it?

    Remi1115
     
  2. Offline

    maxp0wer789

    Code:
    public class Timer implements Runnable {
     
    public void run() {
    //This method is invoked when the task ticks.
    //With the given parameters every second.
    }
     
    }
    Code:
    long initialDelay = 20l;
    long frequency = 20l;
    myPluginObj.getServer().getSheduler().sheduleSyncRepeatingTask(myPluginObj, new Timer(), initialDelay, frequency);
    All of this should be in the tutorial so I don't know what exactly you are looking for.

    Edit: MrBluebear3 thx for reminding me it's ticks not millis :p
     
    Remi1115 likes this.
  3. Offline

    Hoolean

    You can easily use a scheduler; just make a SyncRepeating one and set the delay as 20L (about a second).
     
    Remi1115 likes this.
  4. Offline

    Remi1115

    Thanks both.
    I wasn't sure which I had to pick, also because I haven't worked with any sort of Timers before in Java.
    I'm gonna try it out. I'll report it back if I got it to work.

    I got it to work, and exactly how I wanted it to work.
    Thanks again. Solved!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 29, 2016
Thread Status:
Not open for further replies.

Share This Page