mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 04:56:50 +01:00
bd38e0318a
Updated Upstream (Bukkit/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 Bukkit Changes: f02baa38 PR-988: Add World#getIntersectingChunks(BoundingBox) 9321d665 Move getItemInUse up to LivingEntity 819eef73 PR-959: Add access to current item's remaining ticks c4fdadb0 SPIGOT-7601: Add AbstractArrow#getItem be8261ca Add support for Java 22 26119676 PR-979: Add more translation keys 66753362 PR-985: Correct book maximum pages and characters per page documentation c8be92fa PR-980: Improve getArmorContents() documentation f1120ee2 PR-983: Expose riptide velocity to PlayerRiptideEvent CraftBukkit Changes: dfaa89bbe PR-1369: Add World#getIntersectingChunks(BoundingBox) 51bbab2b9 Move getItemInUse up to LivingEntity 668e09602 PR-1331: Add access to current item's remaining ticks a639406d1 SPIGOT-7601: Add AbstractArrow#getItem 0398930fc SPIGOT-7602: Allow opening in-world horse and related inventories ffd15611c SPIGOT-7608: Allow empty lists to morph to any PDT list 2188dcfa9 Add support for Java 22 45d6a609f SPIGOT-7604: Revert "SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime" 06d915943 SPIGOT-7365: DamageCause blocked by shield should trigger invulnerableTime ca3bc3707 PR-1361: Add more translation keys 366c3ca80 SPIGOT-7600: EntityChangeBlockEvent is not fired for frog eggs 06d0f9ba8 SPIGOT-7593: Fix sapling growth physics / client-side updates 45c2608e4 PR-1366: Expose riptide velocity to PlayerRiptideEvent 29b6bb79b SPIGOT-7587: Remove fixes for now-resolved MC-142590 and MC-109346
120 lines
9.2 KiB
Diff
120 lines
9.2 KiB
Diff
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
|
|
index d4930c40f03c5f331847bf52736c563a688d7daf..7272dc058c575efee5ac2643ce41b7d12e346e89 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1523,12 +1523,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) {
|
|
@@ -1550,7 +1555,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 6a52789d6e68438c1eaa2fb9af591fa9e1d381e2..7984365c8290ac9e526a413b56e1c8c0841e330c 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftHumanEntity.java
|
|
@@ -360,12 +360,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
|
|
@@ -441,7 +445,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;
|
|
}
|
|
@@ -452,6 +459,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 cd237b81a09b89926b15460eccb503af5267eb34..53c3b2123d6fa78367aef53d6949e58170cb9fce 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1389,10 +1389,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<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);
|
|
+ // 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<net.kyori.adventure.text.@org.jetbrains.annotations.Nullable 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
|
|
}
|
|
@@ -1407,10 +1418,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) {
|