Files
Purpur/patches/server/0078-Allow-color-codes-in-books.patch
Encode42 1fd37bdec4 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
PaperMC/Paper@1c779c2 Update to 1.18.1 (#7076)
PaperMC/Paper@901fd94 [ci skip] Update README
2021-12-10 16:04:19 -05:00

77 lines
4.5 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 c2e849f37c03839631f621065bf52b4c649e06c5..449f28ae5b6a3572c35d3fe4647ab2b7cf44662b 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1219,13 +1219,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
itemstack1.setTag(nbttagcompound.copy());
}
+ // Purpur start
+ boolean hasPerm = getCraftPlayer().hasPermission("purpur.book.color.edit") || getCraftPlayer().hasPermission("purpur.book.color.sign"); // Purpur
itemstack1.addTagElement("author", StringTag.valueOf(this.player.getName().getString()));
if (this.player.isTextFilteringEnabled()) {
- itemstack1.addTagElement("title", StringTag.valueOf(title.getFiltered()));
+ itemstack1.addTagElement("title", StringTag.valueOf(color(title.getFiltered(), hasPerm)));
} else {
- itemstack1.addTagElement("filtered_title", StringTag.valueOf(title.getFiltered()));
- itemstack1.addTagElement("title", StringTag.valueOf(title.getRaw()));
+ itemstack1.addTagElement("filtered_title", StringTag.valueOf(color(title.getFiltered(), hasPerm)));
+ itemstack1.addTagElement("title", StringTag.valueOf(color(title.getRaw(), hasPerm)));
}
+ // Purpur end
this.updateBookPages(pages, (s) -> {
return Component.Serializer.toJson(new TextComponent(s));
@@ -1237,10 +1240,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
private void updateBookPages(List<TextFilter.FilteredText> list, UnaryOperator<String> unaryoperator, ItemStack itemstack, int slot, ItemStack handItem) { // CraftBukkit
ListTag nbttaglist = new ListTag();
+ // Purpur start
+ boolean hasPerm = getCraftPlayer().hasPermission("purpur.book.color.edit");
if (this.player.isTextFilteringEnabled()) {
- Stream<StringTag> stream = list.stream().map((itextfilter_a) -> { // CraftBukkit - decompile error
- return StringTag.valueOf((String) unaryoperator.apply(itextfilter_a.getFiltered()));
+ Stream<StringTag> stream = list.stream().map(s -> color(s.getFiltered(), hasPerm, false)).map((s) -> { // CraftBukkit - decompile error
+ return StringTag.valueOf((String) unaryoperator.apply(s));
});
+ // Purpur end
Objects.requireNonNull(nbttaglist);
stream.forEach(nbttaglist::add);
@@ -1250,10 +1256,10 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
for (int j = list.size(); i < j; ++i) {
TextFilter.FilteredText itextfilter_a = (TextFilter.FilteredText) list.get(i);
- String s = itextfilter_a.getRaw();
+ String s = color(itextfilter_a.getRaw(), hasPerm, false);
nbttaglist.add(StringTag.valueOf((String) unaryoperator.apply(s)));
- String s1 = itextfilter_a.getFiltered();
+ String s1 = color(itextfilter_a.getFiltered(), hasPerm, false);
if (!s.equals(s1)) {
nbttagcompound.putString(String.valueOf(i), (String) unaryoperator.apply(s1));
@@ -1269,6 +1275,16 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
this.player.getInventory().setItem(slot, CraftEventFactory.handleEditBookEvent(player, slot, handItem, itemstack)); // CraftBukkit // Paper - Don't ignore result (see other callsite for handleEditBookEvent)
}
+ // Purpur start
+ private String color(String str, boolean hasPerm) {
+ return color(str, hasPerm, true);
+ }
+
+ private String color(String str, boolean hasPerm, boolean parseHex) {
+ return hasPerm ? org.bukkit.ChatColor.color(str, parseHex) : str;
+ }
+ // Purpur end
+
@Override
public void handleEntityTagQuery(ServerboundEntityTagQuery packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());