`__on_player_disconnects` does not run when on an integrated server.
James103 opened this issue ยท 3 comments
As of Carpet mod 1.4.56 and Minecraft 1.18.1, when you save and exit the game, the integrated server stops, but it does not fire the __on_player_disconnects
event for you. I believe this used to work in previous versions (including 1.16.x).
To reproduce:
- Create or join a singleplayer world.
/script load event_test
- Save and exit.
- Notice that in the logs,
__on_start
and__on_close
were run, but not__on_player_disconnects
(__on_player_connects
does run as well, but it needsstay_loaded
to be true for a Scarpet app) - Start a dedicated server.
/script load event_test
on the dedicated server.- Start the client and join the local server.
- Disconnect from the server.
- Notice the resulting output in the logs.
For example, an offline progress system for a server needs to store when the player was last online (i.e. when the player disconnected from the server). Optimizing this fully requires the use of __on_player_disconnects
, but that is currently blocked by this bug.
Well technically on singleplayer __on_player_disconnects
and __on_close
are the same thing...
However I do agree that this doesn't work with, say, bots, and also the title says integrated servers, and while I think those are only singleplayer, I could be mistaken.
Well it appears that __on_player_disconnects
is handled by ServerPlayNetworkHandler_coreMixin
, and name makes me suspect that it's only ever triggered in the context of a server.
I've looked into it more, and it should be triggered in the ClientLevel#disconnect()
function, but there you can't get a ServerPlayer
variable required to trigger the function, you only get a LocalPlayer
type variable (which makes sense), so without a big refactor I don't think it would work.