mirror of
https://github.com/PurpurMC/Purpur.git
synced 2026-02-19 01:17:42 +01:00
Upstream has released updates that appear to apply and compile correctly Paper Changes:a219c497bdDont register multiple ASK_SERVER suggestions under one parent node (#7188)329912b816Expose isFuel and canSmelt methods to FurnaceInventory (#7181)7b833ca18fFix bees aging inside hives (#6466)a99a33cdd9Bucketable API (#7204)721f14842f[ci skip] Change test logging settings to log by default (#7203)2d458ee14fCheck player world in endPortalSoundRadius (#6226)686bbd33d4Fix EntityLoadCrossbowEvent Sync Issue (#5739)64f9225c94Fix riding distance statistics (#7021/SPIGOT-6475) (#7033)
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 96f2beae139609535a4ff79809ece95d99d0f01a..cceeff0b32a5b2f9fd625b28cb64c4fc24130b5f 100644
|
|
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
|
@@ -1232,13 +1232,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));
|
|
@@ -1250,10 +1253,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);
|
|
@@ -1263,10 +1269,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));
|
|
@@ -1282,6 +1288,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());
|