Bukkit/CraftBukkit — pull request #1349 by desht (2014-02-27 12:47:12+00:00)
Title: [C] Fix NPE and client disconnect when PlayerEditBookEvent handler sets book item to null. Fixes BUKKIT-5443

#### Description:
##### The Issue:
When a handler for a PlayerEditBookEvent sets the book item to null (e.g. ``event.getPlayer().getInventory().setItem(event.getSlot(), null)``), an NPE will be thrown in CraftEventFactory.handleEditBookEvent() because it is not checking that the held item is non-null before checking the item's type. This exception is propagated to PlayerConnection.a(PacketPlayInCustomPayload), causing a client disconnection.

##### Justification for this PR:
This PR fixes the above problem by ensuring a null comparison is made first.

##### PR Breakdown:
In CraftEventFactory.handleEditBookEvent(), after the event handler returns, it is possible that a plugin cleared the player's item in hand. The comparison at CraftEventFactory:713 has been updated to ensure that the item is not null before going ahead and checking that its type is still BOOK_AND_QUILL.

##### Testing Results and Materials:
See test plugin here: https://dl.dropboxusercontent.com/u/12467600/testplugin.jar - this simply sets the player's relevant inventory item slot to null whenever an attempt to edit/sign a book is made. Without this PR, CraftBukkit will log an NPE, and disconnect the client with a "Invalid book data!" error. With this PR, everything proceeds as expected; the book item is removed from the player and no exception is thrown.

##### Relevant PR(s):
None.

##### JIRA Ticket:
BUKKIT-5443 - https://bukkit.atlassian.net/browse/BUKKIT-5443