While looking at player quit related stuff, I saw that the actual "quit reason" is logged to console, but this not exposed via an API.
After a little bit of testing it appears that there are 4 different types of leaving the game, with each having their own log reason:
Based on this, I suggest the addition of the following enum to PlayerQuitEvent:
public enum QuitType {
/**
* The player left on his own behalf.
*/
DISCONNECTED,
/**
* The player was kicked from the server.
*/
KICKED,
/**
* The player has crashed from the server.
*/
CRASHED,
/**
* The player has timed out.
*/
TIMED_OUT
}
and the addition of two new methods inside PlayerQuitEvent:
public QuitType getQuitType() { /* .. */ } - Self explanatorypublic String getCrashReason() { /* .. */ } - Obtain the exception message when a player has crashed. getQuitType() != QuitType.CRASHED.Technically it is possible to implement this as a plugin by adding a custom Appender to the PlayerConnection logger but that seems very hack-ish. (My horrible plugin side code can be found here in case there's interest).
As I'm unable to get a dev environment up and running (damn Windows..) I cannot implement this myself. :(
How would you check if a player crashed?
Aren't kicks supposed to fire PlayerKickEvent, or does that extend PlayerQuitEvent?
Kicks fire both PlayerKickEvent and PlayerQuitEvent since forever? (Just checked out decompiled PlayerConnection & PlayerList classes)
Checking if a player has crashed should be simple by finding usages of PlayerConnection#a(IBaseChatComponent). Somewhere in network related code will be some code that checks if the player left normally or crashed and pass in the proper chat component.
I was doing some work on this but ended up loosing it due to some issues... :disappointed:
This is something that I could see being quite useful. :+1:
@willies952002 If you're fine with using non-official code that may or may not break horribly on you, I linked some code in my main issue submission.
Treat it as NMS code, the slightest change to how player quits/kicks are handled will most likely break this.
the crashed part is not possible.
Most helpful comment
the crashed part is not possible.