Carpet

Carpet

2M Downloads

add events to track when server is starting / closing (to distinguish between /reload in the same world)

Harveykang opened this issue · 7 comments

commented

It would be better if there were separate "on_ server_ start"(isn't triggered on reload) and "on_ server_ closing" events.

commented

no - but its valid to request to add a folder listing.

commented

For server startup, if you autoload your app just place the code (or call your start function) somewhere outside any function (can't read)

commented

You can use __on_close() for that (it would also trigger if unloading the app manually, but I think it's good enough as long as you aren't constantly loading and unloading it).

There is a lot of non-deterministic behaviour around players when server is closing in minecraft (at least last time I tested). In dedicated servers, the close event will be triggered before players are actually untracked/disconnected, but in singleplayer those will be untracked right before sending the event, still without sending player disconnection events.

commented

For server startup, if you autoload your app just place the code (or call your start function) somewhere outside any function (can't read)

i mean, don't want the code run when entering "/reload", but it doesn't seem to be possible at the moment

commented

hmm. /reload causes all apps to stop and get restarter right after. I find it actually more conventient than running /script load ...
I think handling in the form __on_close() -> for(player('all'), __on_player_disconnects(_)); is adequate.

Not sure what would be the usecase that would favour reload vs. shutdown.

On the other hand - it makes sense to have __on_server_shuts_down() event, don't you think? Is that what you have in mind?

commented

I assume __on_server_starts would need to trigger after all apps and settings apps are loaded, right?

commented

I assume __on_server_starts would need to trigger after all apps and settings apps are loaded, right?

yes, It needs to be used to manipulate the world when server started or

hmm. /reload causes all apps to stop and get restarter right after. I find it actually more conventient than running /script load ...
I think handling in the form __on_close() -> for(player('all'), __on_player_disconnects(_)); is adequate.

Not sure what would be the usecase that would favour reload vs. shutdown.

On the other hand - it makes sense to have __on_server_shuts_down() event, don't you think? Is that what you have in mind?

there are some code that I only want to run when the server is shut down, not when reloading, because that would destory the data I wrote in the file.

btw, if there is a way to delete all the files in app.data, that would be also good^^