"Time" for signs

Discussion in 'Plugin Development' started by TheTrixsta, Jun 8, 2012.

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

    TheTrixsta

    Im making a rental plugin for a server and im not totally sure on how to do the timer for this or how to update the sign.

    I want to set a number on the sign that will represent days and after every real life day I want to subtract a day from the sign and update the sign? Thing is im not a timer person and I dont use them much. I also dont know where to update the sign. Any help?
     
  2. so, you want to use big real life time and update it? that would be something hard, using schedular can cause small time mistaken, using threads would cause thread safety, so you will need to combine those 2
     
  3. Offline

    Technius

    This will be a bit more difficult... Contrary to what ferrybig said, you will need to use a SEPERATE thread. Not schedule it.

    Put this thread in your "scheduling" class.
    Code:
    private class CheckThread extends Thread
    {
        public void run()
        {
            for(;;)
            {
                sleep(1000*60*60*24);
                //code
            }
        }
    }
    "Schedule" it.
    Code:
    CheckThread ct = null;
    public void schedule()
    {
        ct = new CheckThread();
        ct.start();
    }
    "Unschedule" it.
    Code:
    public void unschedule()
    {
        ct.join();//Untested: It may not be needed
        ct.stop();//Yes, this is deprecated, but it works.
    }
     
  4. you still need the schedular if you want to call at the "//code" bukkit methodes, or else you get data curruption
    EDIT: you can also interupt the hread to stop it, more safe and notdepreded
     
Thread Status:
Not open for further replies.

Share This Page