aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/1012-Add-titleOverride-to-InventoryOpenEvent.patch
diff options
context:
space:
mode:
authorTomTom <[email protected]>2023-11-03 15:05:57 +0100
committerGitHub <[email protected]>2023-11-03 14:05:57 +0000
commit487109fddc74813b81bf17dfe8ec7be443963d9d (patch)
tree8fbfe1ec07553dc9149882389257d948b0486e02 /patches/server/1012-Add-titleOverride-to-InventoryOpenEvent.patch
parent8493340be4fa69fa9369719272e5dff1b7a2f455 (diff)
downloadPaper-487109fddc74813b81bf17dfe8ec7be443963d9d.tar.gz
Paper-487109fddc74813b81bf17dfe8ec7be443963d9d.zip
Readd 0414 use distance map to optimise entity tracker (#9868)
Diffstat (limited to 'patches/server/1012-Add-titleOverride-to-InventoryOpenEvent.patch')
-rw-r--r--patches/server/1012-Add-titleOverride-to-InventoryOpenEvent.patch120
1 files changed, 120 insertions, 0 deletions
diff --git a/patches/server/1012-Add-titleOverride-to-InventoryOpenEvent.patch b/patches/server/1012-Add-titleOverride-to-InventoryOpenEvent.patch
new file mode 100644
index 0000000000..f9b2542b7c
--- /dev/null
+++ b/patches/server/1012-Add-titleOverride-to-InventoryOpenEvent.patch
@@ -0,0 +1,120 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: Jake Potrebic <[email protected]>
+Date: Fri, 4 Mar 2022 12:45:03 -0800
+Subject: [PATCH] Add titleOverride to InventoryOpenEvent
+
+
+diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
+index 7838c7e051b1c4966e5a10289577d60a58ab16dd..872bd74b581249a8132ec5c37dfdd9e699bfbafa 100644
+--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
++++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
+@@ -1560,12 +1560,17 @@ public class ServerPlayer extends Player {
+ this.nextContainerCounter();
+ AbstractContainerMenu container = factory.createMenu(this.containerCounter, this.getInventory(), this);
+
++ Component title = null; // Paper
+ // CraftBukkit start - Inventory open hook
+ if (container != null) {
+ container.setTitle(factory.getDisplayName());
+
+ boolean cancelled = false;
+- container = CraftEventFactory.callInventoryOpenEvent(this, container, cancelled);
++ // Paper start
++ final com.mojang.datafixers.util.Pair<net.kyori.adventure.text.Component, AbstractContainerMenu> result = CraftEventFactory.callInventoryOpenEventWithTitle(this, container, cancelled);
++ container = result.getSecond();
++ title = PaperAdventure.asVanilla(result.getFirst());
++ // Paper end
+ if (container == null && !cancelled) { // Let pre-cancelled events fall through
+ // SPIGOT-5263 - close chest if cancelled
+ if (factory instanceof Container) {
+@@ -1587,7 +1592,7 @@ public class ServerPlayer extends Player {
+ } else {
+ // CraftBukkit start
+ this.containerMenu = container;
+- if (!this.isImmobile()) this.connection.send(new ClientboundOpenScreenPacket(container.containerId, container.getType(), container.getTitle())); // Paper
++ if (!this.isImmobile()) this.connection.send(new ClientboundOpenScreenPacket(container.containerId, container.getType(), Objects.requireNonNullElseGet(title, container::getTitle))); // Paper
+ // CraftBukkit end
+ this.initMenu(container);
+ return OptionalInt.of(this.containerCounter);
+diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+index 8a6095850cece3203eeae474dbf32090f698a32e..aefb9879b2edadfb4b21d80135d713b9d34c9941 100644
+--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+@@ -357,12 +357,16 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
+ Preconditions.checkArgument(windowType != null, "Unknown windowType");
+ AbstractContainerMenu container = new CraftContainer(inventory, player, player.nextContainerCounter());
+
+- container = CraftEventFactory.callInventoryOpenEvent(player, container);
++ // Paper start
++ final com.mojang.datafixers.util.Pair<net.kyori.adventure.text.Component, AbstractContainerMenu> result = CraftEventFactory.callInventoryOpenEventWithTitle(player, container);
++ container = result.getSecond();
++ // Paper end
+ if (container == null) return;
+
+ //String title = container.getBukkitView().getTitle(); // Paper - comment
+ net.kyori.adventure.text.Component adventure$title = container.getBukkitView().title(); // Paper
+ if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(container.getBukkitView().getTitle()); // Paper
++ if (result.getFirst() != null) adventure$title = result.getFirst(); // Paper
+
+ //player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
+ if (!player.isImmobile()) player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
+@@ -438,7 +442,10 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
+ }
+
+ // Trigger an INVENTORY_OPEN event
+- container = CraftEventFactory.callInventoryOpenEvent(player, container);
++ // Paper start
++ final com.mojang.datafixers.util.Pair<net.kyori.adventure.text.Component, AbstractContainerMenu> result = CraftEventFactory.callInventoryOpenEventWithTitle(player, container);
++ container = result.getSecond();
++ // Paper end
+ if (container == null) {
+ return;
+ }
+@@ -449,6 +456,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
+ //String title = inventory.getTitle(); // Paper - comment
+ net.kyori.adventure.text.Component adventure$title = inventory.title(); // Paper
+ if (adventure$title == null) adventure$title = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(inventory.getTitle()); // Paper
++ if (result.getFirst() != null) adventure$title = result.getFirst(); // Paper
+ //player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
+ if (!player.isImmobile()) player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, io.papermc.paper.adventure.PaperAdventure.asVanilla(adventure$title))); // Paper
+ player.containerMenu = container;
+diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+index 975f4fe01ce0c3f98c4467927242558a66bc19f3..249e3f703ef1b40b5401f167d4c30faafb69bb5b 100644
+--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
++++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+@@ -1441,10 +1441,21 @@ public class CraftEventFactory {
+ }
+
+ public static AbstractContainerMenu callInventoryOpenEvent(ServerPlayer player, AbstractContainerMenu container) {
+- return CraftEventFactory.callInventoryOpenEvent(player, container, false);
++ // Paper start
++ return callInventoryOpenEventWithTitle(player, container).getSecond();
++ }
++ public static com.mojang.datafixers.util.Pair<[email protected] Component, @org.jetbrains.annotations.Nullable AbstractContainerMenu> callInventoryOpenEventWithTitle(ServerPlayer player, AbstractContainerMenu container) {
++ return CraftEventFactory.callInventoryOpenEventWithTitle(player, container, false);
++ // Paper end
+ }
+
++ @Deprecated @io.papermc.paper.annotation.DoNotUse // Paper - use method that acknowledges title overrides
+ public static AbstractContainerMenu callInventoryOpenEvent(ServerPlayer player, AbstractContainerMenu container, boolean cancelled) {
++ // Paper start
++ return callInventoryOpenEventWithTitle(player, container, cancelled).getSecond();
++ }
++ public static com.mojang.datafixers.util.Pair<[email protected] Component, @org.jetbrains.annotations.Nullable AbstractContainerMenu> callInventoryOpenEventWithTitle(ServerPlayer player, AbstractContainerMenu container, boolean cancelled) {
++ // Paper end
+ if (player.containerMenu != player.inventoryMenu) { // fire INVENTORY_CLOSE if one already open
+ player.connection.handleContainerClose(new ServerboundContainerClosePacket(player.containerMenu.containerId), InventoryCloseEvent.Reason.OPEN_NEW); // Paper
+ }
+@@ -1459,10 +1470,10 @@ public class CraftEventFactory {
+
+ if (event.isCancelled()) {
+ container.transferTo(player.containerMenu, craftPlayer);
+- return null;
++ return com.mojang.datafixers.util.Pair.of(null, null); // Paper - title override
+ }
+
+- return container;
++ return com.mojang.datafixers.util.Pair.of(event.titleOverride(), container); // Paper - title override
+ }
+
+ public static ItemStack callPreCraftEvent(Container matrix, Container resultInventory, ItemStack result, InventoryView lastCraftView, boolean isRepair) {