2023-08-26 21:28:42 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
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
2024-01-24 15:57:53 +01:00
index dc99cf246bfca6543f4e53b0102770d0fd94250f..3450e5a31437ce17a5b4499b8d08ce0b2623704d 100644
2023-08-26 21:28:42 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
2024-01-23 15:43:48 +01:00
@@ -1568,12 +1568,17 @@ public class ServerPlayer extends Player {
2023-08-26 21:28:42 +02:00
this.nextContainerCounter();
AbstractContainerMenu container = factory.createMenu(this.containerCounter, this.getInventory(), this);
2024-01-14 16:31:39 +01:00
+ Component title = null; // Paper - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
// CraftBukkit start - Inventory open hook
if (container != null) {
container.setTitle(factory.getDisplayName());
boolean cancelled = false;
- container = CraftEventFactory.callInventoryOpenEvent(this, container, cancelled);
2024-01-14 16:31:39 +01:00
+ // Paper start - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
+ 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());
2024-01-14 16:31:39 +01:00
+ // Paper end - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
if (container == null && !cancelled) { // Let pre-cancelled events fall through
// SPIGOT-5263 - close chest if cancelled
if (factory instanceof Container) {
2024-01-23 15:43:48 +01:00
@@ -1595,7 +1600,7 @@ public class ServerPlayer extends Player {
2023-08-26 21:28:42 +02:00
} else {
// CraftBukkit start
this.containerMenu = container;
2024-01-21 12:11:43 +01:00
- if (!this.isImmobile()) this.connection.send(new ClientboundOpenScreenPacket(container.containerId, container.getType(), container.getTitle())); // Paper - Prevent opening inventories when frozen
2024-01-14 16:31:39 +01:00
+ if (!this.isImmobile()) this.connection.send(new ClientboundOpenScreenPacket(container.containerId, container.getType(), Objects.requireNonNullElseGet(title, container::getTitle))); // Paper - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
// 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
2024-01-21 19:37:09 +01:00
index 94c2ea713e0614de570458f6b9c418a3d67d14b5..acbb64010cd59668aa1bcb52ff1220789cadb1d3 100644
2023-08-26 21:28:42 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
Updated Upstream (Bukkit/CraftBukkit) (#10034)
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:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
@@ -357,12 +357,16 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
2023-08-26 21:28:42 +02:00
Preconditions.checkArgument(windowType != null, "Unknown windowType");
AbstractContainerMenu container = new CraftContainer(inventory, player, player.nextContainerCounter());
- container = CraftEventFactory.callInventoryOpenEvent(player, container);
2024-01-14 16:31:39 +01:00
+ // Paper start - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
+ final com.mojang.datafixers.util.Pair<net.kyori.adventure.text.Component, AbstractContainerMenu> result = CraftEventFactory.callInventoryOpenEventWithTitle(player, container);
+ container = result.getSecond();
2024-01-14 16:31:39 +01:00
+ // Paper end - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
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
2024-01-14 16:31:39 +01:00
+ if (result.getFirst() != null) adventure$title = result.getFirst(); // Paper - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
//player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
2024-01-21 12:11:43 +01:00
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
Updated Upstream (Bukkit/CraftBukkit) (#10034)
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:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
@@ -438,7 +442,10 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
2023-08-26 21:28:42 +02:00
}
// Trigger an INVENTORY_OPEN event
- container = CraftEventFactory.callInventoryOpenEvent(player, container);
2024-01-14 16:31:39 +01:00
+ // Paper start - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
+ final com.mojang.datafixers.util.Pair<net.kyori.adventure.text.Component, AbstractContainerMenu> result = CraftEventFactory.callInventoryOpenEventWithTitle(player, container);
+ container = result.getSecond();
2024-01-14 16:31:39 +01:00
+ // Paper end - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
if (container == null) {
return;
}
Updated Upstream (Bukkit/CraftBukkit) (#10034)
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:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
@@ -449,6 +456,7 @@ public class CraftHumanEntity extends CraftLivingEntity implements HumanEntity {
2023-08-26 21:28:42 +02:00
//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
2024-01-21 19:37:09 +01:00
+ if (result.getFirst() != null) adventure$title = result.getFirst(); // Paper - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
//player.connection.send(new ClientboundOpenScreenPacket(container.containerId, windowType, CraftChatMessage.fromString(title)[0])); // Paper - comment
2024-01-21 12:11:43 +01:00
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
2023-08-26 21:28:42 +02:00
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
2024-01-21 19:37:09 +01:00
index 51cf0a068d17c0b6eaee38bb1af5b3c470de5875..3865e6c7af0203ff9a366571a276b8af43b97c7c 100644
2023-08-26 21:28:42 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2024-01-21 12:11:43 +01:00
@@ -1438,10 +1438,21 @@ public class CraftEventFactory {
2023-08-26 21:28:42 +02:00
}
public static AbstractContainerMenu callInventoryOpenEvent(ServerPlayer player, AbstractContainerMenu container) {
- return CraftEventFactory.callInventoryOpenEvent(player, container, false);
2024-01-14 16:31:39 +01:00
+ // Paper start - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
+ return callInventoryOpenEventWithTitle(player, container).getSecond();
+ }
+ public static com.mojang.datafixers.util.Pair<net.kyori.adventure.text.@org.jetbrains.annotations.Nullable Component, @org.jetbrains.annotations.Nullable AbstractContainerMenu> callInventoryOpenEventWithTitle(ServerPlayer player, AbstractContainerMenu container) {
+ return CraftEventFactory.callInventoryOpenEventWithTitle(player, container, false);
2024-01-14 16:31:39 +01:00
+ // Paper end - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
}
+ @Deprecated @io.papermc.paper.annotation.DoNotUse // Paper - use method that acknowledges title overrides
public static AbstractContainerMenu callInventoryOpenEvent(ServerPlayer player, AbstractContainerMenu container, boolean cancelled) {
2024-01-14 16:31:39 +01:00
+ // Paper start - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
+ return callInventoryOpenEventWithTitle(player, container, cancelled).getSecond();
+ }
+ public static com.mojang.datafixers.util.Pair<net.kyori.adventure.text.@org.jetbrains.annotations.Nullable Component, @org.jetbrains.annotations.Nullable AbstractContainerMenu> callInventoryOpenEventWithTitle(ServerPlayer player, AbstractContainerMenu container, boolean cancelled) {
2024-01-14 16:31:39 +01:00
+ // Paper end - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
if (player.containerMenu != player.inventoryMenu) { // fire INVENTORY_CLOSE if one already open
2024-01-21 19:37:09 +01:00
player.connection.handleContainerClose(new ServerboundContainerClosePacket(player.containerMenu.containerId), InventoryCloseEvent.Reason.OPEN_NEW); // Paper - Inventory close reason
2023-08-26 21:28:42 +02:00
}
2024-01-21 12:11:43 +01:00
@@ -1456,10 +1467,10 @@ public class CraftEventFactory {
2023-08-26 21:28:42 +02:00
if (event.isCancelled()) {
container.transferTo(player.containerMenu, craftPlayer);
- return null;
2024-01-14 16:31:39 +01:00
+ return com.mojang.datafixers.util.Pair.of(null, null); // Paper - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
}
- return container;
2024-01-14 16:31:39 +01:00
+ return com.mojang.datafixers.util.Pair.of(event.titleOverride(), container); // Paper - Add titleOverride to InventoryOpenEvent
2023-08-26 21:28:42 +02:00
}
public static ItemStack callPreCraftEvent(Container matrix, Container resultInventory, ItemStack result, InventoryView lastCraftView, boolean isRepair) {