geforkt von Mirrors/Paper
2641c02193
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: 69fa4695 Add some missing deprecation annotations f850da2e Update Maven plugins/versions 8d8400db Use regular compiler seeing as ECJ doesn't support Java 21 JRE c29e1688 Revert "BUILDTOOLS-676: Downgrade Maven compiler version" 07bce714 SPIGOT-7355: More field renames and fixes 6a8ea764 Fix bad merge in penultimate commit 50a7920c Fix imports in previous commit 83640dd1 PR-995: Add required feature to MinecraftExperimental for easy lookups fc1f96cf BUILDTOOLS-676: Downgrade Maven compiler version CraftBukkit Changes: 90f1059ba Fix item placement 661afb43c SPIGOT-7633: Clearer error message for missing particle data 807b465b3 SPIGOT-7634: Armadillo updates infrequently 590cf09a8 Fix unit tests always seeing Mojang server as unavailable 7c7ac5eb2 SPIGOT-7636: Fix clearing ItemMeta 4a72905cf SPIGOT-7635: Fix Player#transfer and cookie methods ebb50e136 Fix incorrect Vault implementation b33fed8b7 Update Maven plugins/versions 6f00f0608 SPIGOT-7632: Control middle clicking chest does not copy contents db821f405 Use regular compiler seeing as ECJ doesn't support Java 21 JRE 8a2976737 Revert "BUILDTOOLS-676: Downgrade Maven compiler version" 0297f87bb SPIGOT-7355: More field renames and fixes 2d03bdf6a SPIGOT-7629: Fix loading banner patterns e77951fac Fix equality of deserialized display names c66f3e4fd SPIGOT-7631: Fix deserialisation of BlockStateMeta 9c2c7be8d SPIGOT-7630: Fix crash saving unticked leashed entities 8c1e7c841 PR-1384: Disable certain PlayerProfile tests, if Mojang's services or internet are not available ced93d572 SPIGOT-7626: sendSignChange() has no effect c77362cae SPIGOT-7625: ItemStack with lore cannot be serialized in 1.20.5 ff2004387 SPIGOT-7620: Fix server crash when hoppers transfer items to double chests 8b4abeb03 BUILDTOOLS-676: Downgrade Maven compiler version
213 Zeilen
13 KiB
Diff
213 Zeilen
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 e79329ee9b02a11b55253cf2ce4e08b2fc39a43f..c5b89c3149b869a3358434490a001f0f45f716fb 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1247,7 +1247,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 - Inventory close reason
|
|
}
|
|
}
|
|
}
|
|
@@ -2234,7 +2234,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 - Inventory close reason
|
|
}
|
|
}
|
|
// 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 84e8ab9bdd4911412732e490ff8d10ba93d67f45..e073b48ed6cbefc503216615f54d09b309217d80 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -688,7 +688,7 @@ public class ServerPlayer extends Player {
|
|
}
|
|
// Paper end - Configurable container update tick rate
|
|
if (!this.level().isClientSide && !this.containerMenu.stillValid(this)) {
|
|
- this.closeContainer();
|
|
+ this.closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper - Inventory close reason
|
|
this.containerMenu = this.inventoryMenu;
|
|
}
|
|
|
|
@@ -908,7 +908,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 - Inventory close reason
|
|
}
|
|
|
|
net.kyori.adventure.text.Component deathMessage = event.deathMessage() != null ? event.deathMessage() : net.kyori.adventure.text.Component.empty(); // Paper - Adventure
|
|
@@ -1549,7 +1549,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 - Inventory close reason
|
|
}
|
|
|
|
// this.nextContainerCounter(); // CraftBukkit - moved up
|
|
@@ -1577,7 +1577,13 @@ public class ServerPlayer extends Player {
|
|
|
|
@Override
|
|
public void closeContainer() {
|
|
- CraftEventFactory.handleInventoryCloseEvent(this); // CraftBukkit
|
|
+ // Paper start - Inventory close reason
|
|
+ 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 - Inventory close reason
|
|
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 66ca4d1f28143d1e4ce99532c6c2bd64cde67024..18a0dc407331cc3c85dc84580419e0c241e72435 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -2606,10 +2606,15 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
|
|
|
@Override
|
|
public void handleContainerClose(ServerboundContainerClosePacket packet) {
|
|
+ // Paper start - Inventory close reason
|
|
+ this.handleContainerClose(packet, org.bukkit.event.inventory.InventoryCloseEvent.Reason.PLAYER);
|
|
+ }
|
|
+ public void handleContainerClose(ServerboundContainerClosePacket packet, org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
|
+ // Paper end - Inventory close reason
|
|
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());
|
|
|
|
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 d25c762e449e2bce20487454ad52363b35b9af96..3273c3f06c142d4e3c947ca846459f4a8e5eefd8 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -517,7 +517,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 - Inventory close reason
|
|
}
|
|
|
|
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() : io.papermc.paper.adventure.PaperAdventure.asAdventure(entityplayer.getDisplayName()))); // Paper - Adventure
|
|
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 4e1c032c7cdca81021c280a15db89e63a90ffe42..9cc9c6f7e211d9cf42a050f3a265d0bceaf7fd40 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -277,7 +277,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 - Inventory close reason
|
|
this.containerMenu = this.inventoryMenu;
|
|
}
|
|
|
|
@@ -496,6 +496,13 @@ public abstract class Player extends LivingEntity {
|
|
|
|
}
|
|
|
|
+ // Paper start - Inventory close reason; unused code, but to keep signatures aligned
|
|
+ public void closeContainer(org.bukkit.event.inventory.InventoryCloseEvent.Reason reason) {
|
|
+ closeContainer();
|
|
+ this.containerMenu = this.inventoryMenu;
|
|
+ }
|
|
+ // Paper end - Inventory close reason
|
|
+
|
|
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 dd3377a4f69e5ac10905e52d0eecc2427e72d856..c79607a2f45b7a487a95cf98b9b0eb6b36501410 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 - Inventory close reason
|
|
}
|
|
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 - Inventory close reason
|
|
+ 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 - Inventory close reason
|
|
|
|
@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 6015ceaa922fd246bb2561a20a8d894444490094..c9af0b1ebf43cbd85d557bd053ef31eb9a975746 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1260,7 +1260,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 - Inventory close reason
|
|
}
|
|
|
|
// 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 f3fd59843e7517eb38bfa06b58445728d2a80001..63fec320871781d92f5ec552aac7fc08b2009f59 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1259,7 +1259,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 - Inventory close reason
|
|
}
|
|
|
|
CraftServer server = player.level().getCraftServer();
|
|
@@ -1446,8 +1446,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());
|
|
}
|