Bukkit/CraftBukkit — pull request #1139 by ausbin (2013-04-17 19:03:48+00:00)
Title: [C] Set the player's new spawn point before sending a PlayerBedLeaveEvent. Adds BUKKIT-1916

The PlayerBedLeaveEvent is fired when a player leaves a bed (duh), but it's currently sent *before* the player's new bed spawn point is set. This makes it hard for a plugin to detect when a player has set his spawn point by sleeping in a bed.

This patch simply moves the chunk of CraftBukkit code that sends the PlayerBedLeaveEvent under the Notchcode that sets the player's spawn point. It allows PlayerLeaveBedEvent handlers in plugins to compare a stored bed spawn point (possibly from a PlayerBedEnterEvent handler) against the player's new bed spawn location (which might have been changed by sleeping in the bed). [Here](https://github.com/ausbin/smartbed/blob/master/adams/austin/smartbed/SmartBed.java#L32)'s a good usage example.

Bug report (not created by me and almost a year old, but still valid): [BUKKIT-1916](https://bukkit.atlassian.net/browse/BUKKIT-1916)