mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-19 09:27:43 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes: 12dec20 Bump paerweight to 1.1.7 e33ed89 Get short commit ref using a more proper method 7d6147d Remove now unneeded patch due to paperweight 1.1.7 e72fa41 Update task dependency for includeMappings so the new task isn't skipped 0ad5526 Trim whitspace off of git hash (oops) Tuinity Changes: e878ba9 Update paper 2bd2849 Bring back fix codec spam patch
77 lines
4.5 KiB
Diff
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 857ec4fe7f0bc721cd8649062a14fa58331db3c0..be953d756c6263221a7fa06ca0835bbfd63bd14a 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -1220,13 +1220,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", (Tag) StringTag.valueOf(this.player.getName().getString()));
|
|
if (this.player.isTextFilteringEnabled()) {
|
|
- itemstack1.addTagElement("title", (Tag) StringTag.valueOf(title.getFiltered()));
|
|
+ itemstack1.addTagElement("title", (Tag) StringTag.valueOf(color(title.getFiltered(), hasPerm)));
|
|
} else {
|
|
- itemstack1.addTagElement("filtered_title", (Tag) StringTag.valueOf(title.getFiltered()));
|
|
- itemstack1.addTagElement("title", (Tag) StringTag.valueOf(title.getRaw()));
|
|
+ itemstack1.addTagElement("filtered_title", (Tag) StringTag.valueOf(color(title.getFiltered(), hasPerm)));
|
|
+ itemstack1.addTagElement("title", (Tag) StringTag.valueOf(color(title.getRaw(), hasPerm)));
|
|
}
|
|
+ // Purpur end
|
|
|
|
this.a(pages, (s) -> {
|
|
return Component.Serializer.toJson((Component) (new TextComponent(s)));
|
|
@@ -1238,10 +1241,13 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
|
|
private void a(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);
|
|
@@ -1251,10 +1257,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));
|
|
@@ -1270,6 +1276,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());
|