Files
Purpur/patches/server/0071-Allow-color-codes-in-books.patch
granny 7f6f667142 Updated Upstream (Pufferfish)
Upstream has released updates that appear to apply and compile correctly

Pufferfish Changes:
pufferfish-gg/Pufferfish@f05b0e9 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@9a82b86 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@c6ec7a0 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@c789f72 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@9ddaa1a Updated Upstream (Paper)
pufferfish-gg/Pufferfish@3554f78 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@a9e9d99 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@09a2f81 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@63ce67d Updated Upstream (Paper)
pufferfish-gg/Pufferfish@8abd47b Updated Upstream (Paper)
pufferfish-gg/Pufferfish@3415da0 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@cfa3c61 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@0a8641d 1.21.3 Update
pufferfish-gg/Pufferfish@784d72f Updated Upstream (Paper)
pufferfish-gg/Pufferfish@40e1ad0 Updated Upstream (Paper)
pufferfish-gg/Pufferfish@95ef348 Make iterator counting in IteratorSafeOrderedReferenceSet thread-safe for async mob spawning (#109)
pufferfish-gg/Pufferfish@34c0042 Updated Upstream (Paper)
2024-11-30 20:49:52 -08:00

90 lines
5.4 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: William Blake Galbreath <blake.galbreath@gmail.com>
Date: Tue, 3 Nov 2020 01:25:06 -0600
Subject: [PATCH] Allow color codes in books
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index f48b13b9b57e3a25e8afeb37f54e883fd1cadf4d..99a023e87428ee200fcb3b663c2ab6a1077b3bf0 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1249,10 +1249,14 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
Objects.requireNonNull(list);
optional.ifPresent(list::add);
list.addAll(packet.pages());
+ // Purpur start
+ boolean hasEditPerm = getCraftPlayer().hasPermission("purpur.book.color.edit");
+ boolean hasSignPerm = hasEditPerm || getCraftPlayer().hasPermission("purpur.book.color.sign");
+ // Purpur end
Consumer<List<FilteredText>> consumer = optional.isPresent() ? (list1) -> {
- this.signBook((FilteredText) list1.get(0), list1.subList(1, list1.size()), i);
+ this.signBook((FilteredText) list1.get(0), list1.subList(1, list1.size()), i, hasSignPerm); // Purpur
} : (list1) -> {
- this.updateBookContents(list1, i);
+ this.updateBookContents(list1, i, hasEditPerm); // Purpur
};
this.filterTextPacket((List) list).thenAcceptAsync(consumer, this.server);
@@ -1260,13 +1264,18 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
}
private void updateBookContents(List<FilteredText> pages, int slotId) {
+ // Purpur start
+ updateBookContents(pages, slotId, false);
+ }
+ private void updateBookContents(List<FilteredText> pages, int slotId, boolean hasPerm) {
+ // Purpur end
// CraftBukkit start
ItemStack handItem = this.player.getInventory().getItem(slotId);
ItemStack itemstack = handItem.copy();
// CraftBukkit end
if (itemstack.has(DataComponents.WRITABLE_BOOK_CONTENT)) {
- List<Filterable<String>> list1 = pages.stream().map(this::filterableFromOutgoing).toList();
+ List<Filterable<String>> list1 = pages.stream().map(filteredText -> filterableFromOutgoing(filteredText).map(s -> color(s, hasPerm))).toList(); // Purpur
itemstack.set(DataComponents.WRITABLE_BOOK_CONTENT, new WritableBookContent(list1));
this.player.getInventory().setItem(slotId, CraftEventFactory.handleEditBookEvent(this.player, slotId, handItem, itemstack)); // CraftBukkit // Paper - Don't ignore result (see other callsite for handleEditBookEvent)
@@ -1274,6 +1283,11 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
}
private void signBook(FilteredText title, List<FilteredText> pages, int slotId) {
+ // Purpur start
+ signBook(title, pages, slotId, false);
+ }
+ private void signBook(FilteredText title, List<FilteredText> pages, int slotId, boolean hasPerm) {
+ // Purpur end
ItemStack itemstack = this.player.getInventory().getItem(slotId);
if (itemstack.has(DataComponents.WRITABLE_BOOK_CONTENT)) {
@@ -1281,10 +1295,10 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
itemstack1.remove(DataComponents.WRITABLE_BOOK_CONTENT);
List<Filterable<Component>> list1 = (List<Filterable<Component>>) (List) pages.stream().map((filteredtext1) -> { // CraftBukkit - decompile error
- return this.filterableFromOutgoing(filteredtext1).map(Component::literal);
+ return this.filterableFromOutgoing(filteredtext1).map(s -> hexColor(s, hasPerm)); // Purpur
}).toList();
- itemstack1.set(DataComponents.WRITTEN_BOOK_CONTENT, new WrittenBookContent(this.filterableFromOutgoing(title), this.player.getName().getString(), 0, list1, true));
+ itemstack1.set(DataComponents.WRITTEN_BOOK_CONTENT, new WrittenBookContent(this.filterableFromOutgoing(title).map(s -> color(s, hasPerm)), this.player.getName().getString(), 0, list1, true)); // Purpur
CraftEventFactory.handleEditBookEvent(this.player, slotId, itemstack, itemstack1); // CraftBukkit
this.player.getInventory().setItem(slotId, itemstack); // CraftBukkit - event factory updates the hand book
}
@@ -1294,6 +1308,16 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
return this.player.isTextFilteringEnabled() ? Filterable.passThrough(message.filteredOrEmpty()) : Filterable.from(message);
}
+ // Purpur start
+ private Component hexColor(String str, boolean hasPerm) {
+ return hasPerm ? PaperAdventure.asVanilla(net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacyAmpersand().deserialize(str)) : Component.literal(str);
+ }
+
+ private String color(String str, boolean hasPerm) {
+ return hasPerm ? org.bukkit.ChatColor.color(str, false) : str;
+ }
+ // Purpur end
+
@Override
public void handleEntityTagQuery(ServerboundEntityTagQueryPacket packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.serverLevel());