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

@@ -27,7 +27,6 @@ import org.bukkit.event.Event;
import org.bukkit.event.block.Action;
import org.bukkit.event.block.SignChangeEvent;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryType.SlotType;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerAnimationEvent;
@@ -1144,11 +1143,7 @@ public class PlayerConnection extends Connection {
public void handleContainerClose(Packet101CloseWindow packet101closewindow) {
if (this.player.dead) return; // CraftBukkit
// CraftBukkit start
InventoryCloseEvent event = new InventoryCloseEvent(this.player.activeContainer.getBukkitView());
server.getPluginManager().callEvent(event);
this.player.activeContainer.transferTo(this.player.defaultContainer, getPlayer());
// CraftBukkit end
CraftEventFactory.handleInventoryCloseEvent(this.player); // CraftBukkit
this.player.j();
}