Getting disconnect reason

Discussion in 'Plugin Development' started by iSexyChocobo, Jun 22, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    iSexyChocobo

    Hi! I'd like to find out why a player disconnected (or more precisely, if his disconnect reason was "disconnect.quitting" or not.)

    To do this, as Bukkit doesn't have a method for it, I'd like to check the logs for the latest disconnect reason by that player.

    File logfile = new File("server.log");
    if (!logfile.exists()) {
    logfile.createNewFile();
    }
    String logstring = logfile.toString();

    uh.. Then I need the LATEST message saying player.getName() + " lost connection: disconnect.quitting" and if no such message exists, just return;

    #help
     
  2. Offline

    aaomidi

  3. Offline

    iSexyChocobo

    aaomidi

    I think that only returns the quit message send to the entire server.. not the reason that shows up in console.
     
  4. Offline

    iSexyChocobo

  5. Offline

    iSexyChocobo

  6. Offline

    xize

    iSexyChocobo

    if I'm correct either one of those 2 events PlayerQuitEvent or PlayerKickEvent has also a getReason() when the player disconnects that reason is the exact string what is printed in the console so you can try to use a contains() there since the reason is a string, but minecraft changes their quit reasons quite ofently so if you would want to have compatability between 1.6 or lower and from 1.7 and higher you may want to look into that, things like connection.disconnect, or end of stream is now Time out I geuss but not 100% sure.
     
  7. Offline

    stirante

    iSexyChocobo If you want really precise reason you can play a bit with NMS (i don't recommend it becouse it can break with some plugins). Add class extending PlayerConnection class and override public void a(IChatBaseComponent reason) method. This way if player just hit disconnect button you will receive Disconnected, but if minecraft client will close minecraft with windows close button you will receive something like "Internal Exception: java.io.IOException: Istniejące połączenie zostało gwałtownie zamknięte przez zdalnego hosta". Last part of message is translated depending on server system language. In my case polish.
    https://github.com/Bukkit/CraftBukk...t/minecraft/server/PlayerConnection.java#L686
     
  8. Offline

    iSexyChocobo

    xize

    No such thing as getReason for quit event. Might be one for kick event but that's not what I'm interested in.

    stirante

    Thank you! I'll play around with that
     
Thread Status:
Not open for further replies.

Share This Page