aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0896-Add-titleOverride-to-InventoryOpenEvent.patch
diff options
context:
space:
mode:
authorJake Potrebic <[email protected]>2024-05-29 13:58:57 -0700
committerGitHub <[email protected]>2024-05-29 22:58:57 +0200
commita31dc90741ed9c121a13a3c124c9ebf5bafd0da7 (patch)
tree81963bd94fe7772ee08bd21710230de21b6b25da /patches/server/0896-Add-titleOverride-to-InventoryOpenEvent.patch
parented85aac53cfd93d29fa24e6071dbdddd0e49624b (diff)
downloadPaper-a31dc90741ed9c121a13a3c124c9ebf5bafd0da7.tar.gz
Paper-a31dc90741ed9c121a13a3c124c9ebf5bafd0da7.zip
Several fixes and new api for experience merging/stacking (#9242)
Diffstat (limited to 'patches/server/0896-Add-titleOverride-to-InventoryOpenEvent.patch')
-rw-r--r--patches/server/0896-Add-titleOverride-to-InventoryOpenEvent.patch120
1 files changed, 120 insertions, 0 deletions
diff --git a/patches/server/0896-Add-titleOverride-to-InventoryOpenEvent.patch b/patches/server/0896-Add-titleOverride-to-InventoryOpenEvent.patch
new file mode 100644
index 0000000000..e00de009ff
--- /dev/null
+++ b/patches/server/0896-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 88ea8ed1b81ece6315bc8dcde04b5fa1bb6a7d04..9179434d490bc8546ba3a35434998b9fc916e6b2 100644
+--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
++++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
+@@ -1618,12 +1618,17 @@ public class ServerPlayer extends Player {
+ this.nextContainerCounter();
+ AbstractContainerMenu container = factory.createMenu(this.containerCounter, this.getInventory(), this);
+
++ Component title = null; // Paper - Add titleOverride to InventoryOpenEvent
+ // CraftBukkit start - Inventory open hook
+ if (container != null) {
+ container.setTitle(factory.getDisplayName());
+
+ boolean cancelled = false;
+- container = CraftEventFactory.callInventoryOpenEvent(this, container, cancelled);
++ // Paper start - Add titleOverride to InventoryOpenEvent
++ 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 - Add titleOverride to InventoryOpenEvent
+ if (container == null && !cancelled) { // Let pre-cancelled events fall through
+ // SPIGOT-5263 - close chest if cancelled
+ if (factory instanceof Container) {
+@@ -1645,7 +1650,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 - Prevent opening inventories when frozen
++ if (!this.isImmobile()) this.connection.send(new ClientboundOpenScreenPacket(container.containerId, container.getType(), Objects.requireNonNullElseGet(title, container::getTitle))); // Paper - Add titleOverride to InventoryOpenEvent
+ // 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 3d36d79a4e7f16f6face3465cdf54656984f3ebc..41f3cdec7deabf34358b8087df77169f85a5b919 100644
+--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
++++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+@@ -358,12 +358,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 - Add titleOverride to InventoryOpenEvent
++ final com.mojang.datafixers.util.Pair<net.kyori.adventure.text.Component, AbstractContainerMenu> result = CraftEventFactory.callInventoryOpenEventWithTitle(player, container);
++ container = result.getSecond();
++ // Paper end - Add titleOverride to InventoryOpenEvent
+ 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 - Add titleOverride to InventoryOpenEvent
+
+ //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 - Prevent opening inventories when frozen
+@@ -439,7 +443,10 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
+ }
+
+ // Trigger an INVENTORY_OPEN event
+- container = CraftEventFactory.callInventoryOpenEvent(player, container);
++ // Paper start - Add titleOverride to InventoryOpenEvent
++ final com.mojang.datafixers.util.Pair<net.kyori.adventure.text.Component, AbstractContainerMenu> result = CraftEventFactory.callInventoryOpenEventWithTitle(player, container);
++ container = result.getSecond();
++ // Paper end - Add titleOverride to InventoryOpenEvent
+ if (container == null) {
+ return;
+ }
+@@ -450,6 +457,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 - Add titleOverride to InventoryOpenEvent
+ //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 - Prevent opening inventories when frozen
+ 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 ae4a7249adfe707693dea4d2748590b869c2d4f9..31c35ccbd84fab60fcf30d0d00f1ee38c05e78ca 100644
+--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
++++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+@@ -1381,10 +1381,21 @@ public class CraftEventFactory {
+ }
+
+ public static AbstractContainerMenu callInventoryOpenEvent(ServerPlayer player, AbstractContainerMenu container) {
+- return CraftEventFactory.callInventoryOpenEvent(player, container, false);
++ // Paper start - Add titleOverride to InventoryOpenEvent
++ 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 - Add titleOverride to InventoryOpenEvent
+ }
+
++ @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 - Add titleOverride to InventoryOpenEvent
++ 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 - Add titleOverride to InventoryOpenEvent
+ 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 - Inventory close reason
+ }
+@@ -1399,10 +1410,10 @@ public class CraftEventFactory {
+
+ if (event.isCancelled()) {
+ container.transferTo(player.containerMenu, craftPlayer);
+- return null;
++ return com.mojang.datafixers.util.Pair.of(null, null); // Paper - Add titleOverride to InventoryOpenEvent
+ }
+
+- return container;
++ return com.mojang.datafixers.util.Pair.of(event.titleOverride(), container); // Paper - Add titleOverride to InventoryOpenEvent
+ }
+
+ public static ItemStack callPreCraftEvent(Container matrix, Container resultInventory, ItemStack result, InventoryView lastCraftView, boolean isRepair) {