3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 21:40:06 +01:00

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.
Dieser Commit ist enthalten in:
Travis Watkins 2013-05-02 06:05:54 -05:00
Ursprung 75641a607e
Commit 401a6809be
5 geänderte Dateien mit 18 neuen und 12 gelöschten Zeilen

Datei anzeigen

@ -149,12 +149,6 @@ public abstract class EntityMinecartContainer extends EntityMinecartAbstract imp
} }
public void c(int i) { public void c(int i) {
// CraftBukkit start
for (HumanEntity human : transaction) {
((org.bukkit.craftbukkit.entity.CraftHumanEntity) human).getHandle().closeInventory();
}
// CraftBukkit end
this.b = false; this.b = false;
super.c(i); super.c(i);
} }

Datei anzeigen

@ -153,6 +153,13 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
--this.invulnerableTicks; --this.invulnerableTicks;
this.activeContainer.b(); 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()) { while (!this.removeQueue.isEmpty()) {
int i = Math.min(this.removeQueue.size(), 127); int i = Math.min(this.removeQueue.size(), 127);
int[] aint = new int[i]; int[] aint = new int[i];
@ -651,6 +658,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
} }
public void closeInventory() { public void closeInventory() {
CraftEventFactory.handleInventoryCloseEvent(this); // CraftBukkit
this.playerConnection.sendPacket(new Packet101CloseWindow(this.activeContainer.windowId)); this.playerConnection.sendPacket(new Packet101CloseWindow(this.activeContainer.windowId));
this.j(); this.j();
} }

Datei anzeigen

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

Datei anzeigen

@ -250,6 +250,8 @@ public abstract class PlayerList {
if (entityplayer.playerConnection.disconnected) return null; // CraftBukkit - exploitsies fix 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 // 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."); PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(this.cserver.getPlayer(entityplayer), "\u00A7e" + entityplayer.name + " left the game.");
this.cserver.getPluginManager().callEvent(playerQuitEvent); this.cserver.getPluginManager().callEvent(playerQuitEvent);
entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage()); entityplayer.getBukkitEntity().disconnect(playerQuitEvent.getQuitMessage());

Datei anzeigen

@ -58,6 +58,7 @@ import org.bukkit.event.block.BlockIgniteEvent.IgniteCause;
import org.bukkit.event.entity.*; import org.bukkit.event.entity.*;
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason; import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.bukkit.event.inventory.InventoryOpenEvent; import org.bukkit.event.inventory.InventoryOpenEvent;
import org.bukkit.event.inventory.PrepareItemCraftEvent; import org.bukkit.event.inventory.PrepareItemCraftEvent;
import org.bukkit.event.player.*; import org.bukkit.event.player.*;
@ -665,4 +666,10 @@ public class CraftEventFactory {
world.getServer().getPluginManager().callEvent(event); world.getServer().getPluginManager().callEvent(event);
return 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());
}
} }