Paper: PlayerQuitEvent.QuitType API suggestion

Created on 28 Apr 2016  路  5Comments  路  Source: PaperMC/Paper

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:

  • Leaving normally: "Disconnected"
  • Timing out: "TImed out"
  • Being kicked from the server: Kick message
  • Crashing: Exception message

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 explanatory
  • public String getCrashReason() { /* .. */ } - Obtain the exception message when a player has crashed. IllegalStateException UnsupportedOperationException if 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. :(

feature

Most helpful comment

the crashed part is not possible.

All 5 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ShelLuser picture ShelLuser  路  3Comments

devcat picture devcat  路  3Comments

TNTUP picture TNTUP  路  3Comments

successed picture successed  路  3Comments

molor picture molor  路  3Comments