Bukkit/Bukkit — pull request #726 by dualspiral (2012-12-04 22:21:03+00:00)
Title: Add PlayerQuitReason enum to PlayerQuitEvent

Adds feature requested in BUKKIT-429. https://bukkit.atlassian.net/browse/BUKKIT-429
CraftBukkit PR to follow shortly.

This change adds a PlayerQuitReason to the PlayerQuitEvent as an enum. When the event is called, CraftBukkit converts the "disconnect." string (or, in the case of a player being kicked, "disconnect.kicked") into an enum (I have included all "disconnect.*" messages I could find in CB, but if a new one is added, it'll fallback to PlayerQuitReason.UNKNOWN) and sends it to the server.

Plugins can then access the reason the player quit through the PlayerQuitEvent.getQuitReason() method. A fallback constructor remains in place, just in case another plugin is calling the event, this defaults to "PlayerQuitReason.UNKNOWN" every time.

A small test plugin is available for this change, source code can be found at dualspiral/quittest@58af03d99ce28f75b83bb0bc8e5e690bd57c8e91

The motivation for this change arises from developing a plugin to customize quit messages dependent on the reason a player quit. Currently, the only method that I've seen that has done this is through scraping the console, and sometimes, it does not catch the disconnect reason. Embedding this in Bukkit and CraftBukkit will solve this issue, should it be allowed.