From 17b4c0d7a3e6032eede33e58c18516084e70881f Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Fri, 10 May 2024 19:08:54 +1000 Subject: [PATCH] Restore null page behaviour of signed books even though not strictly allowed by API By: md_5 --- .../bukkit/craftbukkit/inventory/CraftMetaBookSigned.java | 4 ++-- .../org/bukkit/craftbukkit/util/CraftChatMessage.java | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java index 075c01a830..6f16af40eb 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaBookSigned.java @@ -212,7 +212,7 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta { // assert: pages != null String newText = validatePage(text); - pages.set(page - 1, CraftChatMessage.fromStringOrNull(newText, true)); + pages.set(page - 1, CraftChatMessage.fromStringOrEmpty(newText, true)); } @Override @@ -224,7 +224,7 @@ public class CraftMetaBookSigned extends CraftMetaItem implements BookMeta { public void addPage(final String... pages) { for (String page : pages) { page = validatePage(page); - internalAddPage(CraftChatMessage.fromStringOrNull(page, true)); + internalAddPage(CraftChatMessage.fromStringOrEmpty(page, true)); } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java index 30cebceff2..169e383086 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java @@ -177,6 +177,14 @@ public final class CraftChatMessage { return (message == null || message.isEmpty()) ? null : fromString(message, keepNewlines)[0]; } + public static IChatBaseComponent fromStringOrEmpty(String message) { + return fromStringOrEmpty(message, false); + } + + public static IChatBaseComponent fromStringOrEmpty(String message, boolean keepNewlines) { + return fromString(message, keepNewlines)[0]; + } + public static IChatBaseComponent[] fromString(String message) { return fromString(message, false); }