mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-24 08:06:41 +01:00
dcc290167f
Upstream has released updates that appear to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: dea9ce0a SPIGOT-7198: Add Sittable interface to Camel CraftBukkit Changes: eecb4c0dc SPIGOT-7196: Exception loading alternate worlds 0ff61e8fa SPIGOT-7198: Add Sittable interface to Camel 676441aac PR-1121: Handle additional missing SpawnEggs in MetaSpawnEgg e85280e02 Handle missing SpawnEggs in MetaSpawnEgg Spigot Changes: d90018e0 SPIGOT-7199: NPE loading or creating world with custom chunk generator
220 lines
13 KiB
Diff
220 lines
13 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Tue, 3 Jul 2018 21:56:23 -0400
|
|
Subject: [PATCH] InventoryCloseEvent Reason API
|
|
|
|
Allows you to determine why an inventory was closed, enabling plugin developers
|
|
to "confirm" things based on if it was player triggered close or not.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index d17808f6c565712dac31b0db7a4b6baed2dbdf21..8b28de5755ad4fe50903837700feed32e4530afd 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1309,7 +1309,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
for (net.minecraft.world.level.block.entity.BlockEntity tileentity : chunk.getBlockEntities().values()) {
|
|
if (tileentity instanceof net.minecraft.world.Container) {
|
|
for (org.bukkit.entity.HumanEntity h : Lists.newArrayList(((net.minecraft.world.Container) tileentity).getViewers())) {
|
|
- h.closeInventory();
|
|
+ h.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNLOADED); // Paper
|
|
}
|
|
}
|
|
}
|
|
@@ -2269,7 +2269,7 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
// Spigot Start
|
|
if (entity.getBukkitEntity() instanceof org.bukkit.inventory.InventoryHolder && (!(entity instanceof ServerPlayer) || entity.getRemovalReason() != Entity.RemovalReason.KILLED)) { // SPIGOT-6876: closeInventory clears death message
|
|
for (org.bukkit.entity.HumanEntity h : Lists.newArrayList(((org.bukkit.inventory.InventoryHolder) entity.getBukkitEntity()).getInventory().getViewers())) {
|
|
- h.closeInventory();
|
|
+ h.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNLOADED); // Paper
|
|
}
|
|
}
|
|
// Spigot End
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index 0e64cb9969453832c5d08b112cafb9ef835f9a2a..cd392d316f35ac488c49ad8c34c0273bbccc6a1c 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -633,7 +633,7 @@ public class ServerPlayer extends Player {
|
|
}
|
|
// Paper end
|
|
if (!this.level.isClientSide && !this.containerMenu.stillValid(this)) {
|
|
- this.closeContainer();
|
|
+ this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper
|
|
this.containerMenu = this.inventoryMenu;
|
|
}
|
|
|
|
@@ -826,7 +826,7 @@ public class ServerPlayer extends Player {
|
|
|
|
// SPIGOT-943 - only call if they have an inventory open
|
|
if (this.containerMenu != this.inventoryMenu) {
|
|
- this.closeContainer();
|
|
+ this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DEATH); // Paper
|
|
}
|
|
|
|
net.kyori.adventure.text.Component deathMessage = event.deathMessage() != null ? event.deathMessage() : net.kyori.adventure.text.Component.empty(); // Paper - Adventure
|
|
@@ -1472,7 +1472,7 @@ public class ServerPlayer extends Player {
|
|
}
|
|
// CraftBukkit end
|
|
if (this.containerMenu != this.inventoryMenu) {
|
|
- this.closeContainer();
|
|
+ this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.OPEN_NEW); // Paper
|
|
}
|
|
|
|
// this.nextContainerCounter(); // CraftBukkit - moved up
|
|
@@ -1500,7 +1500,13 @@ public class ServerPlayer extends Player {
|
|
|
|
@Override
|
|
public void closeContainer() {
|
|
- CraftEventFactory.handleInventoryCloseEvent(this); // CraftBukkit
|
|
+ // Paper start
|
|
+ this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNKNOWN);
|
|
+ }
|
|
+ @Override
|
|
+ public void closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
|
+ CraftEventFactory.handleInventoryCloseEvent(this, reason); // CraftBukkit
|
|
+ // Paper end
|
|
this.connection.send(new ClientboundContainerClosePacket(this.containerMenu.containerId));
|
|
this.doCloseContainer();
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
index d1adb186bf9c79b99967da9c7d9aa20ba85c64e2..a646264c34592f3a7512e94399ba15490381095d 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -217,6 +217,7 @@ import org.bukkit.event.inventory.ClickType;
|
|
import org.bukkit.event.inventory.CraftItemEvent;
|
|
import org.bukkit.event.inventory.InventoryAction;
|
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
|
+import org.bukkit.event.inventory.InventoryCloseEvent; // Paper
|
|
import org.bukkit.event.inventory.InventoryCreativeEvent;
|
|
import org.bukkit.event.inventory.InventoryType.SlotType;
|
|
import org.bukkit.event.inventory.SmithItemEvent;
|
|
@@ -2657,10 +2658,15 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Tic
|
|
|
|
@Override
|
|
public void handleContainerClose(ServerboundContainerClosePacket packet) {
|
|
+ // Paper start
|
|
+ handleContainerClose(packet, InventoryCloseEvent.Reason.PLAYER);
|
|
+ }
|
|
+ public void handleContainerClose(ServerboundContainerClosePacket packet, InventoryCloseEvent.Reason reason) {
|
|
+ // Paper end
|
|
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
|
|
|
|
if (this.player.isImmobile()) return; // CraftBukkit
|
|
- CraftEventFactory.handleInventoryCloseEvent(this.player); // CraftBukkit
|
|
+ CraftEventFactory.handleInventoryCloseEvent(this.player, reason); // CraftBukkit // Paper
|
|
|
|
this.player.doCloseContainer();
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 216ad4d729d8996bb4f5bc696fd168f65b076994..0f33c4bf3cb52f192d5dfe8b55a72c7a5a2f9311 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -516,7 +516,7 @@ public abstract class PlayerList {
|
|
// CraftBukkit start - Quitting must be before we do final save of data, in case plugins need to modify it
|
|
// See SPIGOT-5799, SPIGOT-6145
|
|
if (entityplayer.containerMenu != entityplayer.inventoryMenu) {
|
|
- entityplayer.closeContainer();
|
|
+ entityplayer.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.DISCONNECT); // Paper
|
|
}
|
|
|
|
PlayerQuitEvent playerQuitEvent = new PlayerQuitEvent(entityplayer.getBukkitEntity(), net.kyori.adventure.text.Component.translatable("multiplayer.player.left", net.kyori.adventure.text.format.NamedTextColor.YELLOW, io.papermc.paper.configuration.GlobalConfiguration.get().messages.useDisplayNameInQuitMessage ? entityplayer.getBukkitEntity().displayName() : net.kyori.adventure.text.Component.text(entityplayer.getScoreboardName())));
|
|
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
index 26709e64ffbe1a41516908e4b3fc9d21d4c0dff0..a46a6b76b6821be9d8983633cd0c6b9fa3aa349c 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -265,7 +265,7 @@ public abstract class Player extends LivingEntity {
|
|
this.updateIsUnderwater();
|
|
super.tick();
|
|
if (!this.level.isClientSide && this.containerMenu != null && !this.containerMenu.stillValid(this)) {
|
|
- this.closeContainer();
|
|
+ this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper
|
|
this.containerMenu = this.inventoryMenu;
|
|
}
|
|
|
|
@@ -488,6 +488,13 @@ public abstract class Player extends LivingEntity {
|
|
|
|
}
|
|
|
|
+ // Paper start - unused code, but to keep signatures aligned
|
|
+ public void closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
|
+ closeContainer();
|
|
+ this.containerMenu = this.inventoryMenu;
|
|
+ }
|
|
+ // Paper end
|
|
+
|
|
public void closeContainer() {
|
|
this.containerMenu = this.inventoryMenu;
|
|
}
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
index 7ea4a2d4e691e0a0a4d9ef3189a29a4a4ca4374b..883b6245f44f3fb82d7678e1092177ca646d484a 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
@@ -377,7 +377,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
|
if (((ServerPlayer) this.getHandle()).connection == null) return;
|
|
if (this.getHandle().containerMenu != this.getHandle().inventoryMenu) {
|
|
// fire INVENTORY_CLOSE if one already open
|
|
- ((ServerPlayer) this.getHandle()).connection.handleContainerClose(new ServerboundContainerClosePacket(this.getHandle().containerMenu.containerId));
|
|
+ ((ServerPlayer) this.getHandle()).connection.handleContainerClose(new ServerboundContainerClosePacket(this.getHandle().containerMenu.containerId), org.bukkit.event.inventory.InventoryCloseEvent.Reason.OPEN_NEW); // Paper
|
|
}
|
|
ServerPlayer player = (ServerPlayer) this.getHandle();
|
|
AbstractContainerMenu container;
|
|
@@ -447,8 +447,14 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
|
|
|
@Override
|
|
public void closeInventory() {
|
|
- this.getHandle().closeContainer();
|
|
+ // Paper start
|
|
+ this.getHandle().closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.PLUGIN);
|
|
}
|
|
+ @Override
|
|
+ public void closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
|
+ getHandle().closeContainer(reason);
|
|
+ }
|
|
+ // Paper end
|
|
|
|
@Override
|
|
public boolean isBlocking() {
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
index 3259d4ecad831f68a742517d2e85a1062035712b..aae49c0a8a6672b0b2753c88a61df5f1c9436699 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1160,7 +1160,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
|
|
|
// Close any foreign inventory
|
|
if (this.getHandle().containerMenu != this.getHandle().inventoryMenu) {
|
|
- this.getHandle().closeContainer();
|
|
+ this.getHandle().closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.TELEPORT); // Paper
|
|
}
|
|
|
|
// Check if the fromWorld and toWorld are the same.
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index 03637eb7237a4caeb01bc84bda65a8c6513b2014..d2129225afbf617dbaeeeb2e783eea5ff33792db 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1229,7 +1229,7 @@ public class CraftEventFactory {
|
|
|
|
public static AbstractContainerMenu callInventoryOpenEvent(ServerPlayer player, AbstractContainerMenu container, boolean cancelled) {
|
|
if (player.containerMenu != player.inventoryMenu) { // fire INVENTORY_CLOSE if one already open
|
|
- player.connection.handleContainerClose(new ServerboundContainerClosePacket(player.containerMenu.containerId));
|
|
+ player.connection.handleContainerClose(new ServerboundContainerClosePacket(player.containerMenu.containerId), InventoryCloseEvent.Reason.OPEN_NEW); // Paper
|
|
}
|
|
|
|
CraftServer server = player.level.getCraftServer();
|
|
@@ -1395,8 +1395,18 @@ public class CraftEventFactory {
|
|
return event;
|
|
}
|
|
|
|
+ // Paper start
|
|
+ /**
|
|
+ * Incase plugins hooked into this or Spigot adds a new inventory close event. Prefer to pass a reason
|
|
+ * @param human
|
|
+ */
|
|
+ @Deprecated
|
|
public static void handleInventoryCloseEvent(net.minecraft.world.entity.player.Player human) {
|
|
- InventoryCloseEvent event = new InventoryCloseEvent(human.containerMenu.getBukkitView());
|
|
+ handleInventoryCloseEvent(human, org.bukkit.event.inventory.InventoryCloseEvent.Reason.UNKNOWN);
|
|
+ }
|
|
+ public static void handleInventoryCloseEvent(net.minecraft.world.entity.player.Player human, org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
|
+ // Paper end
|
|
+ InventoryCloseEvent event = new InventoryCloseEvent(human.containerMenu.getBukkitView(), reason); // Paper
|
|
human.level.getCraftServer().getPluginManager().callEvent(event);
|
|
human.containerMenu.transferTo(human.inventoryMenu, human.getBukkitEntity());
|
|
}
|