Day and Night spawns - notifier?

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

Day and Night spawns - notifier?

Post by Hyrelius »

L2J Revision 9943:
L2JDP Revision 6199:

Hello,

is there a way to make the script react to day and night changes? I know I could use the DayNightSpawnManager to spawn a certain creature, but what I want is to be able to react to the day and night change, because I want to randomly decide the location and re-add the spawn myself.

In GameTimeController I found this:

Code: Select all

        _log.log(Level.CONFIG, getClass().getSimpleName() + ": Started.");                long nextTickTime, sleepTime;        boolean isNight = isNight();                if (isNight)        {            ThreadPoolManager.getInstance().executeAi(new Runnable()            {                @Override                public final void run()                {                    DayNightSpawnManager.getInstance().notifyChangeMode();                }            });        }
This means, that whenever isNight is true a new Runnable is created, which triggers the day and night switch.

I could easily add a listener, which (if registered to it) could notify all scripts about this change - not just DayNightSpawnManager. But I am not sure if this is something, that might be of interest by the L2J-Team. Perhaps there is even a different solution?

I greatly appreciate an answer and would do the job of adding the listener if there's a chance it might become part of L2J.

Hyrelius.
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
User avatar
Zoey76
L2j Inner Circle
L2j Inner Circle
Posts: 7005
Joined: Tue Aug 11, 2009 3:36 am

Re: Day and Night spawns - notifier?

Post by Zoey76 »

I believe the best solution should be a listener that replace the notifications.

That way more stuff can be unhardcoded from core, or at least unified with current scripts in Datapack.
Powered by Eclipse 4.30 🌌 | Eclipse Temurin 21 ☕ | MariaDB 11.3.2 🗃️ | L2J Server 2.6.3.0 - High Five 🚀

🔗 Join our Discord! 🎮💬
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

Re: Day and Night spawns - notifier?

Post by Hyrelius »

Okay I will attempt to write such a listener and will create a patchfile once done. I will also create an interface, that requires a method (e.g. "onDayNightChange") to be implemented before adding it to the listener.

Thanks for the answer!
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
User avatar
UnAfraid
L2j Veteran
L2j Veteran
Posts: 4199
Joined: Mon Jul 23, 2007 4:25 pm
Location: Bulgaria
Contact:

Re: Day and Night spawns - notifier?

Post by UnAfraid »

Here's a patch we prepared to be committed https://gist.github.com/UnAfraid/ca4cfc5ac3f099df63c3
It includes such listener.
Image
Hyrelius
Posts: 257
Joined: Thu Dec 16, 2010 5:16 am

Re: Day and Night spawns - notifier?

Post by Hyrelius »

Hey,

thank you guys!

I had done the changes myself and wanted to contribute them here... too bad you were faster, UnAfraid :D.

Anyway.. from what I see you've made a "DayNightChangeEvent" (what I had done too), but imo there's no particular reason for that, because you can always use GameTimeController.getInstance().isNight() to determine the current setting and there is no further information needed in that Event.

This is what I my diff-file looks like: http://pastebin.com/LJ4fHrWg

Perhaps I am wrong, but I think we do not need a DayNightChangeEvent, because there is no information that has to be transferred using that event.

Greetings,
Hyrelius.
Image
I don't mind helping - however: I only do so if I want to.
No support for other server packs than L2J.
Post Reply