diff options
author | Travis Watkins <amaranth@ubuntu.com> | 2013-05-02 06:05:54 -0500 |
---|---|---|
committer | Travis Watkins <amaranth@ubuntu.com> | 2013-05-02 06:28:51 -0500 |
commit | 401a6809be71112f35f811fedb79e1210c87a656 (patch) | |
tree | 7f0d7067f91972743d37a55839d42ef2aab756c5 /src/main/java | |
parent | 75641a607e6878dfd98f808e4f7b01441c3dea18 (diff) | |
download | craftbukkit-401a6809be71112f35f811fedb79e1210c87a656.tar craftbukkit-401a6809be71112f35f811fedb79e1210c87a656.tar.gz craftbukkit-401a6809be71112f35f811fedb79e1210c87a656.tar.lz craftbukkit-401a6809be71112f35f811fedb79e1210c87a656.tar.xz craftbukkit-401a6809be71112f35f811fedb79e1210c87a656.zip |
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.
Diffstat (limited to 'src/main/java')
5 files changed, 18 insertions, 12 deletions
diff --git a/src/main/java/net/minecraft/server/EntityMinecartContainer.java b/src/main/java/net/minecraft/server/EntityMinecartContainer.java index 16a47454..c207076d 100644 --- a/src/main/java/net/minecraft/server/EntityMinecartContainer.java +++ b/src/main/java/net/minecraft/server/EntityMinecartContainer.java @@ -149,12 +149,6 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp } public void c(int i) { - // CraftBukkit start - for (HumanEntity human : transaction) { - ((org.bukkit.craftbukkit.entity.CraftHumanEntity) human).getHandle().closeInventory(); - } - // CraftBukkit end - this.b = false; super.c(i); } diff --git a/src/main/java/net/minecraft/server/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java index 3b08937a..7de5b48b 100644 --- a/src/main/java/net/minecraft/server/EntityPlayer.java +++ b/src/main/java/net/minecraft/server/EntityPlayer.java @@ -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(); } diff --git a/src/main/java/net/minecraft/server/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java index 55873f59..5d103824 100644 --- a/src/main/java/net/minecraft/server/PlayerConnection.java +++ b/src/main/java/net/minecraft/server/PlayerConnection.java @@ -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(); } diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java index 9e574bec..b7e327bc 100644 --- a/src/main/java/net/minecraft/server/PlayerList.java +++ b/src/main/java/net/minecraft/server/PlayerList.java @@ -250,6 +250,8 @@ public abstract class PlayerList { if (entityplayer.playerConnection.disconnected) return null; // CraftBukkit - exploitsies fix // CraftBukkit start - Quitting must be before we do final save of data, in case plugins need to modify it + org.bukkit.craftbukkit.event.CraftEventFactory.handleInventoryCloseEvent(entityplayer); + PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(this.cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.name + " left the game."); this.cserver.getPluginManager().callEvent(playerQuitEvent); entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage()); diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java index 07970c00..56582bc5 100644 --- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java +++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java @@ -58,6 +58,7 @@ import org.bukkit.event.block.BlockIgniteEvent.IgniteCause; import org.bukkit.event.entity.*; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.EntityDamageEvent.DamageCause; +import org.bukkit.event.inventory.InventoryCloseEvent; import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.event.player.*; @@ -665,4 +666,10 @@ public class CraftEventFactory { world.getServer().getPluginManager().callEvent(event); return event; } + + public static void handleInventoryCloseEvent(EntityHuman human) { + InventoryCloseEvent event = new InventoryCloseEvent(human.activeContainer.getBukkitView()); + human.world.getServer().getPluginManager().callEvent(event); + human.activeContainer.transferTo(human.defaultContainer, human.getBukkitEntity()); + } } |