Files
Purpur/patches/server/0083-Allow-color-codes-in-books.patch
BillyGalbreath 296267da93 Updated Upstream (Paper)
Upstream has released updates that appear to apply and compile correctly

Paper Changes:
eb11845f8 Fix creating worlds with "invalid" names (Fixes #5331)
e4d8a6279 Implement Keyed on World
bcb63dab7 [CI-SKIP] [Auto] Rebuild Patches
48342b06c Allow signs that are inside of the spawn protection to be right clicked to use their run_command tag
c229f90c1 Add Block#isValidTool
20e709c1d Add recipe to cook events
2dcf8bff4 legacy formatting will be the death of me
f597fea0d legacy formatting is worse than walking around in wet socks
7f72c4675 Use implementation-provided legacy serializer for events
27a8d99ec Adventure 4.7.0
e65bd35a1 Respect teams in legacy chat name if configured (#5321)
b31089a92 Updated Upstream (Bukkit/CraftBukkit/Spigot) (#5325)
a52b30814 Fix title swapping fadeIn and stay
54ec85949 Prevent grindstones from overstacking items
d7795080c Fix NPE for AIR in meta operations in ItemStack
2e70796c7 [CI-SKIP] Improve documentation of PreCreatureSpawnEvent (#5244)
7bb92e750 [CI-SKIP] Add JavaDoc links to Tag class pointing to custom Paper tags (#5285)
28cd686bf fix per-world difficulty command (#5306)
be7cde2c7 [CI-SKIP] Always check PATH for JDK (#5315)
2021-03-09 17:52:38 -06:00

55 lines
2.9 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/PlayerConnection.java b/src/main/java/net/minecraft/server/PlayerConnection.java
index 4d0dcbcc00e44c4912302dd0e7331471f33cb370..70cb98b3db5f9966e91da0ccd81e7610455a4f4e 100644
--- a/src/main/java/net/minecraft/server/PlayerConnection.java
+++ b/src/main/java/net/minecraft/server/PlayerConnection.java
@@ -1058,7 +1058,8 @@ public class PlayerConnection implements PacketListenerPlayIn {
if (itemstack.getItem() == Items.WRITABLE_BOOK) {
NBTTagList nbttaglist = new NBTTagList();
- list.stream().map(NBTTagString::a).forEach(nbttaglist::add);
+ boolean hasPerm = getPlayer().hasPermission("purpur.book.color.edit"); // Purpur - edit book
+ list.stream().map(s -> s = color(s, hasPerm, false)).map(NBTTagString::a).forEach(nbttaglist::add); // Purpur - edit book
ItemStack old = itemstack.cloneItemStack(); // CraftBukkit
itemstack.a("pages", (NBTBase) nbttaglist);
CraftEventFactory.handleEditBookEvent(player, i, old, itemstack); // CraftBukkit
@@ -1076,13 +1077,14 @@ public class PlayerConnection implements PacketListenerPlayIn {
itemstack1.setTag(nbttagcompound.clone());
}
+ boolean hasPerm = getPlayer().hasPermission("purpur.book.color.edit") || getPlayer().hasPermission("purpur.book.color.sign"); // Purpur
itemstack1.a("author", (NBTBase) NBTTagString.a(this.player.getDisplayName().getString()));
- itemstack1.a("title", (NBTBase) NBTTagString.a(s));
+ itemstack1.a("title", (NBTBase) NBTTagString.a(color(s, hasPerm))); // Purpur - sign book
NBTTagList nbttaglist = new NBTTagList();
Iterator iterator = list.iterator();
while (iterator.hasNext()) {
- String s1 = (String) iterator.next();
+ String s1 = color((String) iterator.next(), hasPerm);// Purpur - sign book
ChatComponentText chatcomponenttext = new ChatComponentText(s1);
String s2 = IChatBaseComponent.ChatSerializer.a((IChatBaseComponent) chatcomponenttext);
@@ -1094,6 +1096,16 @@ public class PlayerConnection implements PacketListenerPlayIn {
}
}
+ // 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 a(PacketPlayInEntityNBTQuery packetplayinentitynbtquery) {
PlayerConnectionUtils.ensureMainThread(packetplayinentitynbtquery, this, this.player.getWorldServer());