mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-01 08:20:51 +01:00
e035fd7034
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: cc9aa21a SPIGOT-6399, SPIGOT-7344: Clarify collidable behavior for player entities f23325b6 Add API for per-world simulation distances 26e1774e Add API for per-world view distances 0b541e60 Add PlayerLoginEvent#getRealAddress 5f027d2d PR-949: Add Vector#fromJOML() overloads for read-only vector types CraftBukkit Changes: bcf56171a PR-1321: Clean up some stuff which got missed during previous PRs 7f833a2d1 SPIGOT-7462: Players no longer drop XP after dying near a Sculk Catalyst 752aac669 Implement APIs for per world view and simulation distances 57d7ef433 Preserve empty enchantment tags for glow effect 465ec3fb4 Remove connected check on setScoreboard f90ce621e Use one PermissibleBase for all command blocks 5876cca44 SPIGOT-7550: Fix creation of Arrow instances f03fc3aa3 SPIGOT-7549: ServerTickManager#setTickRate incorrect Precondition 9d7f49b01 SPIGOT-7548: Fix wrong spawn location for experience orb and dropped item Spigot Changes: ed9ba9a4 Drop no longer required patch ignoring -o option 86b5dd6a SPIGOT-7546: Fix hardcoded check for outdated client message aa7cde7a Remove obsolete APIs for per world view and simulation distances 6dff577e Remove obsolete patch preserving empty `ench` tags a3bf95b8 Remove obsolete PlayerLoginEvent#getRealAddress 1b02f5d6 Remove obsolete connected check on setScoreboard patch acf717eb Remove obsolete command block PermissibleBase patch 053fa2a9 Remove redundant patch dealing with null tile entities
121 lines
8.4 KiB
Diff
121 lines
8.4 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 222d41d9d730d245063bc93c1cd5c40b9163ef38..c993553383f3b417884bc161d58a9ab72455a55d 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -1572,12 +1572,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) {
|
|
@@ -1599,7 +1604,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 e0ab2124b339d0053a1d075204ca1070be572e75..c3dbcb317b7d366feb31f707ad1199c60169f07f 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 b21729eea9c65d1262ab9a78cb08278ffc431b7a..a7da88af0a41f16b3a54b28023a5afb6d9396262 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1440,10 +1440,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<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
|
|
}
|
|
|
|
+ @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<net.kyori.adventure.text.@org.jetbrains.annotations.Nullable 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
|
|
}
|
|
@@ -1458,10 +1469,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) {
|