Improve InventoryCloseEvent handling. Fixes BUKKIT-3286

Currently there are several cases where a player will have their inventory
screen closed client side but we will not call an event. To correct this
we call the event when the server is the cause of the inventory closing
instead of just when the client is the cause. We also ensure the server is
closing the inventory reliably so we get the events. Additionally this
commit also calls the event when a player disconnects which will handle
kicks, quits, and server shutdown.
This commit is contained in:
Travis Watkins
2013-05-02 06:05:54 -05:00
parent 75641a607e
commit 401a6809be
5 changed files with 18 additions and 12 deletions

View File

@@ -153,6 +153,13 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
--this.invulnerableTicks;
this.activeContainer.b();
// CraftBukkit start - Check inventory status every tick
if (!this.activeContainer.a(this)) { // Should be stillValid
this.closeInventory();
this.activeContainer = this.defaultContainer;
}
// CraftBukkit end
while (!this.removeQueue.isEmpty()) {
int i = Math.min(this.removeQueue.size(), 127);
int[] aint = new int[i];
@@ -651,6 +658,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
}
public void closeInventory() {
CraftEventFactory.handleInventoryCloseEvent(this); // CraftBukkit
this.playerConnection.sendPacket(new Packet101CloseWindow(this.activeContainer.windowId));
this.j();
}