The CraftBukkit code that auto repairs corrupted tile entities never was updated for Trapped Chest.
If a Trapped Chest gets its Tile Entity corrupted, it will crash the server every time the chunk is loaded.
This will now fix Trapped Chests too.
Instead of doing an unsafe cast, actually check if the HumanEntity supplied is a CraftHumanEntity. Plugins adding custom HumanEntities to the viewers of an inventory will end up crashing the server when the Chunk containing the block which contains the inventory unloads, since the original cast is unchecked here.
I'm not sure if there was a reason for casting to CraftHumanEntity, so I kept it, but HumanEntity, as I'm sure you know, has a closeInventory() method you could call instead of getting the CraftBukkit handle. There's probably a reason behind it, though.
I tried to follow the formatting conventions, but I may have missed something.
Tested the easily reproducible issue using this patch compiled, and it works fine; no crashes in sight.
When the connection between a minecraft client and a server
(e.g. me and the spigot test server) is bad sometimes two placement
packets will arrive at the same time. When the extra one gets canceled
any blocks placed against it get rejected by the server causing the
whole chain to disappear. This fixes this by allowing more packets
to occur whilst making the window wider (since the client seems to be
capped at about one placement every 100ms on a normal connection)
This code was added in 1c84a5dd8c to alleviate some crashes. Since then we have improved our thread safety and detection of unsafe thread behaviour and as such there is no need to incur thhis performance hit anymore.