Executing code every day

Discussion in 'Plugin Development' started by ThrustLP, Aug 2, 2016.

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

    ThrustLP

    Hey guys! I basicly need a way to execute code every da. So when the day changes the code shoud be executed (a real world day). When you stop the server at one day and restart it at another day the code should be executed, too. How could I do that?

    Thanks! Tobi
     
  2. Offline

    Zombie_Striker

    @ThrustLP
    1. Use the Date object to get todays date. I will call this instance "today". Update this date when you want to use it to get the current date.
    2. Store the date the server was last on in the config. When the plugin starts up, store this date somewhere. I will call this "lastUp"
    3. When the server starts up, check if the days "lastUp" and "today" are not the same. If they are not, then they are two different days and you can execute some code.
    4. Using a Repeating Task, every hour check if the day has changed. If it has, execute the code.
    5. In either case, set "lastUp" equal to "today" if they are true.
     
Thread Status:
Not open for further replies.

Share This Page