L2JMobius

High Five How to make a Scheduler

WereWoofer · 8 · 1202

Offline WereWoofer

  • Heir
  • **
    • Posts: 25
I need a simple Scheduler and i cant make it work...
im even trying to use CHATGPT but i cant make it work...

Need to start a event at 14:00 20:00 02:00 08:00


Online CostyKiller

  • Distinguished King
  • *****
    • Posts: 973
Did you tried with ThreadPool.scheduleAtFixedRate() ?


Offline Paiplayer

  • Knight
  • ***
    • Posts: 74
I need a simple Scheduler and i cant make it work...
im even trying to use CHATGPT but i cant make it work...

Need to start a event at 14:00 20:00 02:00 08:00

I think something like that will do the job:

Consider eventStart() is your event starter:

Import the Calendar:
Code: [Select]
import java.util.Calendar;
Then set up the event every
Code: [Select]
final Calendar calendar = Calendar.getInstance();
if ((calendar.get(Calendar.HOUR_OF_DAY) >= 20) && (calendar.get(Calendar.MINUTE) >= 0))
{
calendar.add(Calendar.DAY_OF_YEAR, 1);
}
int _hour = 2; // starts 2am
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
while (_hour <= 20)  // runs until 8pm
{
calendar.set(Calendar.HOUR_OF_DAY, _hour);
ThreadPool.scheduleAtFixedRate(() -> eventStart(null), calendar.getTimeInMillis() - System.currentTimeMillis(), 86400000); // 86400000 = 1 day
_hour = _hour + 6;
}

Note: if the server starts after 2am it will schedule for all of the events for starting on the next day.
Want a developer? Check here or call me on Discord: PaiPlayer#5051



Online nasseka

  • Distinguished King
  • *****
    • Posts: 1730
    • L2Unknown

Offline Paiplayer

  • Knight
  • ***
    • Posts: 74
i tried it all nothing work x.x

Then you've didn't implemented it correctly. I use this method to schedule TvT on my server and it's working.
Want a developer? Check here or call me on Discord: PaiPlayer#5051


Offline WereWoofer

  • Heir
  • **
    • Posts: 25
Then you've didn't implemented it correctly. I use this method to schedule TvT on my server and it's working.
U simply copy/paste this from chatGPT...