geforkt von Mirrors/Paper
29b17a892d
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: 5efeb7bd Also update compiler version c13b867a Update some Maven plugin versions deb28d9f PR-837: Add more bell API e938d62a PR-819: Allow Player#sendBlockDamage() to specify a source entity 0e75532c PR-818: Add more Guardian API, particularly for its laser a10155aa PR-839: Add BlockData#rotate and BlockData#mirror 77e690b4 PR-836: Add missing API for explosive minecarts 60722059 PR-832: Allow getting chunks without generating them and optimize chunk data request for ungenerated chunks 0a2c4b4b PR-834: Add Player#sendHurtAnimation() CraftBukkit Changes: be8682aa8 Also update compiler version 08e305f5b Update some Maven plugin versions 187bdd463 PR-1160: Add more bell API 2f8e5bc7c PR-1145: Allow Player#sendBlockDamage() to specify a source entity bcbb61b36 PR-1144: Add more Guardian API, particularly for its laser 722ddff6d PR-1162: Add BlockData#rotate and BlockData#mirror 80998277c PR-1159: Add missing API for explosive minecarts 1fddefce1 PR-1155: Allow getting chunks without generating them and optimize chunk data request for ungenerated chunks 20e8a486f PR-1157: Add Player#sendHurtAnimation() Spigot Changes: b31949f2 Rebuild patches
221 Zeilen
13 KiB
Diff
221 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 65110445ff8a245742c4f7a7055f544ff6344f75..718a403799246228e085280cb539236b01720d4b 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1308,7 +1308,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
|
|
}
|
|
}
|
|
}
|
|
@@ -2268,7 +2268,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 67b0a9f8e8f122c406057c5db225fa6a03dd624c..9e4c827bba4c87595db8cb8896b77558b3feadf5 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -639,7 +639,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;
|
|
}
|
|
|
|
@@ -832,7 +832,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
|
|
@@ -1451,7 +1451,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
|
|
@@ -1479,7 +1479,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 5e710c7efef73c1caec0a16ff2e5f128ec4beb54..2bfcd1fbd18656f80ca0356d4f4c45e2bcfb3a55 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -219,6 +219,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;
|
|
@@ -2672,10 +2673,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 2cde0807c224f008bd2e652ff8a46244ebc53059..2f18121596b957202dfd8227b995ea0615ecf773 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -523,7 +523,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() : 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 2961e08fc315a0d5f3b95de9d127948da07e66c8..9c12fc197c5367a35acda4155707c602f043e571 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -268,7 +268,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;
|
|
}
|
|
|
|
@@ -491,6 +491,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 787ccb37a39bb506cf9fd8d54cf772b346981f85..f5b3190ffb9e9f92977afc9e40ddfa155d054865 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 b1b4513d9b86195b8c96c49990cb2bf6d3951506..9592da53e4b2ec28c71887ef68a0327c0e3ec119 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
|
@@ -1240,7 +1240,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 fea90633f10bad7498f8f5e90093eee2a09df549..8a856d7c65e1002d32fa5b2619606e9d08d7286b 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1252,7 +1252,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();
|
|
@@ -1426,8 +1426,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());
|
|
}
|