Paper/Spigot-Server-Patches/0441-Prevent-opening-inventories-when-frozen.patch
Aikar e403d6aafc
[Auto] Updated Upstream (CraftBukkit)
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

CraftBukkit Changes:
a0149bf16 SPIGOT-6480: Players cannot take books from lecterns that were opened by plugins
2021-05-29 05:07:34 -04:00

60 lines
4.5 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Shane Freeder <theboyetronic@gmail.com>
Date: Mon, 13 Apr 2020 07:31:44 +0100
Subject: [PATCH] Prevent opening inventories when frozen
diff --git a/src/main/java/net/minecraft/server/level/EntityPlayer.java b/src/main/java/net/minecraft/server/level/EntityPlayer.java
index 79003f43c4f15a7e5dd51587bc8c2f477bedb1b2..5382dfbad7a33670268d5d713cf3bdd425bbe885 100644
--- a/src/main/java/net/minecraft/server/level/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/level/EntityPlayer.java
@@ -560,7 +560,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
containerUpdateDelay = world.paperConfig.containerUpdateTickRate;
}
// Paper end
- if (!this.world.isClientSide && !this.activeContainer.canUse(this)) {
+ if (!this.world.isClientSide && this.activeContainer != this.defaultContainer && (isFrozen() || !this.activeContainer.canUse(this))) { // Paper - auto close while frozen
this.closeInventory(org.bukkit.event.inventory.InventoryCloseEvent.Reason.CANT_USE); // Paper
this.activeContainer = this.defaultContainer;
}
@@ -1407,7 +1407,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
} else {
// CraftBukkit start
this.activeContainer = container;
- this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, container.getType(), container.getTitle()));
+ if (!isFrozen()) this.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, container.getType(), container.getTitle())); // Paper
// CraftBukkit end
container.addSlotListener(this);
return OptionalInt.of(this.containerCounter);
@@ -2209,7 +2209,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
}
@Override
- protected boolean isFrozen() {
+ public boolean isFrozen() { // Paper - protected > public
return super.isFrozen() || (this.playerConnection != null && this.playerConnection.isDisconnected()); // Paper
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
index 3b3e6076f2565e02fa6f13e369094f8b6cac5382..3bfb93890259210afd2f5e226cef100d26a11628 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
@@ -324,7 +324,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
if (adventure$title == null) adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(container.getBukkitView().getTitle()); // Paper
//player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, CraftChatMessage.fromString(title)[0])); // Paper // Paper - comment
- player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
+ if (!player.isFrozen()) player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
getHandle().activeContainer = container;
getHandle().activeContainer.addSlotListener(player);
}
@@ -398,7 +398,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
net.kyori.adventure.text.Component adventure$title = inventory.title(); // Paper
if (adventure$title == null) adventure$title = io.papermc.paper.adventure.PaperAdventure.LEGACY_SECTION_UXRC.deserialize(inventory.getTitle()); // Paper
//player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
- player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
+ if (!player.isFrozen()) player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
player.activeContainer = container;
player.activeContainer.addSlotListener(player);
}