mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-04 02:01:44 +01:00
0e441c7960
This reverts commit 53ef67b88d
.
Seems to be having undesired impact, will need to polish more.
49 lines
2.4 KiB
Diff
49 lines
2.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: wea_ondara <wea_ondara@alpenblock.net>
|
|
Date: Sat, 2 Nov 2019 22:25:40 +0100
|
|
Subject: [PATCH] Fix serialization of colors from components
|
|
|
|
This patch fixes the serialization of display names, item lores and
|
|
other things which use strings with color codes. The old implementation
|
|
deleted the color codes at the beginning of the resulting string if it
|
|
matched the default color passed to the conversion function. This
|
|
resulted in items having a black display name losing the black color
|
|
code in the beginning of the text when the item was serialized (e.g.
|
|
saving an ItemStack in a Yaml config).
|
|
|
|
Spigot has now made the issue worse and expanded the scope to more places.
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
|
|
index 2e162b9ea31c8bf81cfa5282566b37fc29537f51..b67f3ac106e76a5f51a1ec9d8dfd2bfecebaa439 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java
|
|
@@ -172,9 +172,19 @@ public final class CraftChatMessage {
|
|
if (component == null) return "";
|
|
StringBuilder out = new StringBuilder();
|
|
|
|
+ // Paper start - fix deletion of color codes at the beginning of result string
|
|
+ boolean first = true;
|
|
for (IChatBaseComponent c : (Iterable<IChatBaseComponent>) component) {
|
|
ChatModifier modi = c.getChatModifier();
|
|
- out.append(modi.getColor() == null ? defaultColor : modi.getColor());
|
|
+ if (first) {
|
|
+ if (modi.getColor() != null) {
|
|
+ out.append(modi.getColor());
|
|
+ }
|
|
+ first = false;
|
|
+ } else {
|
|
+ out.append(modi.getColor() == null ? defaultColor : modi.getColor());
|
|
+ }
|
|
+ // Paper end
|
|
if (modi.isBold()) {
|
|
out.append(EnumChatFormat.BOLD);
|
|
}
|
|
@@ -192,7 +202,7 @@ public final class CraftChatMessage {
|
|
}
|
|
out.append(c.getText());
|
|
}
|
|
- return out.toString().replaceFirst("^(" + defaultColor + ")*", "");
|
|
+ return out.toString(); // Paper - fix deletion of color codes at the beginning of result string
|
|
}
|
|
|
|
public static IChatBaseComponent fixComponent(IChatBaseComponent component) {
|