mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-09 06:50:32 +08:00
Improve blocking players from opening inventories while sleeping
This is friendlier to plugins as far as the plugin is concerned, the inventory did open and immediately closed. We avoid sending the packet to client so they don't see the window flash either. If a plugin wants to avoid wasteful fake opens, they should check that the player is not sleeping before opening the inventory.
This commit is contained in:
parent
ac4f6b5022
commit
d847d33684
@ -1,13 +1,31 @@
|
||||
From c002f483dd0b1e1ff710060d73d333c41a9fd844 Mon Sep 17 00:00:00 2001
|
||||
From bae710173ea9e6a616d329d1c3fe9f152a683f16 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/EntityPlayer.java b/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
index d16f3880..c59416e1 100644
|
||||
index d16f3880d5..c3d6447853 100644
|
||||
--- a/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
+++ b/src/main/java/net/minecraft/server/EntityPlayer.java
|
||||
@@ -384,7 +384,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;
|
||||
}
|
||||
@@ -1172,7 +1172,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);
|
||||
@@ -1910,7 +1910,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
|
||||
}
|
||||
|
||||
@ -18,17 +36,27 @@ index d16f3880..c59416e1 100644
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
||||
index 1c88eace..5a79c7f1 100644
|
||||
index 1c88eacea9..c5d3eec4f6 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
||||
@@ -305,6 +305,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
public InventoryView openInventory(Inventory inventory) {
|
||||
if (!(getHandle() instanceof EntityPlayer)) return null;
|
||||
EntityPlayer player = (EntityPlayer) getHandle();
|
||||
+ if (player.isFrozen()) return null; // Paper
|
||||
Container formerContainer = getHandle().activeContainer;
|
||||
@@ -350,7 +350,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
|
||||
ITileInventory iinventory = null;
|
||||
String title = container.getBukkitView().getTitle();
|
||||
|
||||
- player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, new ChatComponentText(title)));
|
||||
+ if (!player.isFrozen()) player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, new ChatComponentText(title))); // Paper
|
||||
getHandle().activeContainer = container;
|
||||
getHandle().activeContainer.addSlotListener(player);
|
||||
}
|
||||
@@ -420,7 +420,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
|
||||
// Now open the window
|
||||
Containers<?> windowType = CraftContainer.getNotchInventoryType(inventory.getTopInventory());
|
||||
String title = inventory.getTitle();
|
||||
- player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, new ChatComponentText(title)));
|
||||
+ if (!player.isFrozen()) player.playerConnection.sendPacket(new PacketPlayOutOpenWindow(container.windowId, windowType, new ChatComponentText(title))); // Paper
|
||||
player.activeContainer = container;
|
||||
player.activeContainer.addSlotListener(player);
|
||||
}
|
||||
--
|
||||
2.25.1.windows.1
|
||||
2.26.2
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user