From eb4300d9e16bba03b39145cf6fbf491868223a05 Mon Sep 17 00:00:00 2001 From: Aikar Date: Mon, 1 Jun 2020 23:15:47 -0400 Subject: [PATCH] Updated Upstream (Bukkit/CraftBukkit) Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing My recent work on serialization is now in CraftBukkit so was able to drop the patch and Paper is now consistent with upstream. Bukkit Changes: e2699636 Move API notes to more obvious location CraftBukkit Changes: 1b2830a3 SPIGOT-4441: Fix serializing Components to and from Legacy --- ...ialization-of-colors-from-components.patch | 143 ------------------ .../Implement-Player-Client-Options-API.patch | 2 +- ...nilla-per-world-scoreboard-coloring-.patch | 15 +- ...to-current-Chunk-for-Entity-and-Bloc.patch | 4 +- ...oleAppender-for-console-improvements.patch | 2 +- work/Bukkit | 2 +- work/CraftBukkit | 2 +- 7 files changed, 7 insertions(+), 163 deletions(-) delete mode 100644 Spigot-Server-Patches/Fix-serialization-of-colors-from-components.patch diff --git a/Spigot-Server-Patches/Fix-serialization-of-colors-from-components.patch b/Spigot-Server-Patches/Fix-serialization-of-colors-from-components.patch deleted file mode 100644 index b870d586df..0000000000 --- a/Spigot-Server-Patches/Fix-serialization-of-colors-from-components.patch +++ /dev/null @@ -1,143 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Aikar -Date: Sun, 31 May 2020 21:55:52 -0400 -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. - -Original work by (but impl pretty much fully changed): -Co-Authored-By: wea_ondara - -diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java -+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftChatMessage.java -@@ -0,0 +0,0 @@ public final class CraftChatMessage { - case 1: - EnumChatFormat format = formatMap.get(match.toLowerCase(java.util.Locale.ENGLISH).charAt(1)); - if (format == EnumChatFormat.RESET) { -- modifier = new ChatModifier(); -+ modifier = new ChatModifier().setColor(format); // Paper - } else if (format.isFormat()) { - switch (format) { - case BOLD: -@@ -0,0 +0,0 @@ public final class CraftChatMessage { - break; - case 2: - if (keepNewlines) { -- currentChatComponent.addSibling(new ChatComponentText("\n")); -+ // Paper start - retain formatting for new lines -+ ChatComponentText ichatbasecomponent = new ChatComponentText("\n"); -+ ichatbasecomponent.setChatModifier(modifier.clone()); -+ currentChatComponent.addSibling(ichatbasecomponent); -+ // Paper end - } else { - currentChatComponent = null; - } -@@ -0,0 +0,0 @@ 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 hadColor = false; - for (IChatBaseComponent c : (Iterable) component) { - ChatModifier modi = c.getChatModifier(); -- out.append(modi.getColor() == null ? defaultColor : modi.getColor()); -+ EnumChatFormat color = modi.getColor(); -+ if (!c.getText().isEmpty() || color != null) { -+ if (color != null) { -+ out.append(color); -+ hadColor = true; -+ } else if (hadColor) { -+ out.append(ChatColor.RESET); -+ hadColor = false; -+ } -+ } -+ // Paper end - if (modi.isBold()) { - out.append(EnumChatFormat.BOLD); - } -@@ -0,0 +0,0 @@ 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) { -diff --git a/src/test/java/org/bukkit/craftbukkit/CraftChatMessageTest.java b/src/test/java/org/bukkit/craftbukkit/CraftChatMessageTest.java -new file mode 100644 -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 ---- /dev/null -+++ b/src/test/java/org/bukkit/craftbukkit/CraftChatMessageTest.java -@@ -0,0 +0,0 @@ -+package org.bukkit.craftbukkit; -+ -+import net.minecraft.server.IChatBaseComponent; -+import org.bukkit.craftbukkit.util.CraftChatMessage; -+import org.bukkit.support.AbstractTestingBase; -+import org.junit.Test; -+ -+import static org.junit.Assert.assertEquals; -+ -+public class CraftChatMessageTest extends AbstractTestingBase { -+ @Test -+ public void testSimpleStrings() { -+ testString("§fFoo"); -+ testString("Foo"); -+ testString("Foo§bBar"); -+ testString("Foo§bBar"); -+ testString("§fFoo§bBar"); -+ testString("§fFoo§bBar§rBaz"); -+ testString("§rFoo"); -+ testString("Test§0\n§0\n§5Test"); -+ } -+ -+ @Test -+ public void testComponents() { -+ testComponent("Foo§bBar§rBaz", create("Foo", "§bBar", "Baz")); -+ testComponent("§fFoo§bBar§rBaz", create("", "§fFoo", "§bBar", "Baz")); -+ testComponent("§fFoo§bBar§rBaz", create("", "§fFoo", "§bBar", "", "Baz")); -+ testComponent("§fFoo§bBar§rBaz", create("§fFoo", "§bBar", "Baz")); -+ testComponent("Foo§bBar§rBaz", create("", "Foo", "§bBar", "Baz")); -+ testComponent("§fFoo§bBar§rBaz", create("§fFoo", "§bBar", "Baz")); -+ testComponent("F§foo§bBar§rBaz", create("F§foo", "§bBar", "Baz")); -+ } -+ -+ private IChatBaseComponent create(String txt, String ...rest) { -+ IChatBaseComponent cmp = toComp(txt); -+ for (String s : rest) { -+ cmp.addSibling(toComp(s)); -+ } -+ -+ return cmp; -+ } -+ -+ private IChatBaseComponent toComp(String txt) { -+ return CraftChatMessage.fromString(txt, true)[0]; -+ } -+ -+ private void testString(String expected) { -+ IChatBaseComponent cmp = toComp(expected); -+ String actual = CraftChatMessage.fromComponent(cmp); -+ assertEquals(expected, actual); -+ } -+ -+ private void testComponent(String expected, IChatBaseComponent components) { -+ String actual = CraftChatMessage.fromComponent(components); -+ assertEquals(expected, actual); -+ -+ IChatBaseComponent expectedCmp = toComp(expected); -+ String actualExpectedCmp = CraftChatMessage.fromComponent(expectedCmp); -+ assertEquals(expected, actualExpectedCmp); -+ } -+} diff --git a/Spigot-Server-Patches/Implement-Player-Client-Options-API.patch b/Spigot-Server-Patches/Implement-Player-Client-Options-API.patch index c2a4a04419..c27a59fd82 100644 --- a/Spigot-Server-Patches/Implement-Player-Client-Options-API.patch +++ b/Spigot-Server-Patches/Implement-Player-Client-Options-API.patch @@ -173,7 +173,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +import net.minecraft.server.EntityHuman; import net.minecraft.server.EntityLiving; import net.minecraft.server.EntityPlayer; - import net.minecraft.server.EnumChatFormat; + import net.minecraft.server.EnumColor; @@ -0,0 +0,0 @@ public class CraftPlayer extends CraftHumanEntity implements Player { public void setViewDistance(int viewDistance) { throw new NotImplementedException("Per-Player View Distance APIs need further understanding to properly implement (There are per world view distances though!)"); // TODO diff --git a/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch b/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch index 8efff059d6..1085d226c7 100644 --- a/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch +++ b/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch @@ -39,7 +39,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + if (this.player.getWorld().paperConfig.useVanillaScoreboardColoring) { + IChatBaseComponent nameFromTeam = ScoreboardTeam.a(this.player.getScoreboardTeam(), ((CraftPlayer) player).getHandle().getDisplayName()); + // Explicitly add a RESET here, vanilla uses components for this now... -+ displayName = CraftChatMessage.fromComponent(nameFromTeam, EnumChatFormat.WHITE) + org.bukkit.ChatColor.RESET; ++ displayName = CraftChatMessage.fromComponent(nameFromTeam) + org.bukkit.ChatColor.RESET; + } + + s = String.format(event.getFormat(), displayName, event.getMessage()); @@ -47,16 +47,3 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 minecraftServer.console.sendMessage(s); if (((LazyPlayerSet) event.getRecipients()).isLazy()) { for (Object recipient : minecraftServer.getPlayerList().players) { -diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java -index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 ---- a/src/main/java/net/minecraft/server/PlayerList.java -+++ b/src/main/java/net/minecraft/server/PlayerList.java -@@ -0,0 +0,0 @@ public abstract class PlayerList { - } - // CraftBukkit start - chatmessage.a(EnumChatFormat.YELLOW); -- String joinMessage = CraftChatMessage.fromComponent(chatmessage); -+ String joinMessage = CraftChatMessage.fromComponent(chatmessage, EnumChatFormat.WHITE); - - playerconnection.a(entityplayer.locX(), entityplayer.locY(), entityplayer.locZ(), entityplayer.yaw, entityplayer.pitch); - this.players.add(entityplayer); diff --git a/Spigot-Server-Patches/Store-reference-to-current-Chunk-for-Entity-and-Bloc.patch b/Spigot-Server-Patches/Store-reference-to-current-Chunk-for-Entity-and-Bloc.patch index ead2509fa5..e81295396c 100644 --- a/Spigot-Server-Patches/Store-reference-to-current-Chunk-for-Entity-and-Bloc.patch +++ b/Spigot-Server-Patches/Store-reference-to-current-Chunk-for-Entity-and-Bloc.patch @@ -178,8 +178,8 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/ index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java -@@ -0,0 +0,0 @@ import net.minecraft.server.EntityZombieVillager; - import net.minecraft.server.EnumChatFormat; +@@ -0,0 +0,0 @@ import net.minecraft.server.EntityZombieHusk; + import net.minecraft.server.EntityZombieVillager; import net.minecraft.server.IChatBaseComponent; import net.minecraft.server.NBTTagCompound; +import org.bukkit.Chunk; // Paper diff --git a/Spigot-Server-Patches/Use-TerminalConsoleAppender-for-console-improvements.patch b/Spigot-Server-Patches/Use-TerminalConsoleAppender-for-console-improvements.patch index 4d628783c1..f333ad19c2 100644 --- a/Spigot-Server-Patches/Use-TerminalConsoleAppender-for-console-improvements.patch +++ b/Spigot-Server-Patches/Use-TerminalConsoleAppender-for-console-improvements.patch @@ -239,7 +239,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @Override public void sendMessage(IChatBaseComponent ichatbasecomponent) { - MinecraftServer.LOGGER.info(ichatbasecomponent.getString()); -+ MinecraftServer.LOGGER.info(org.bukkit.craftbukkit.util.CraftChatMessage.fromComponent(ichatbasecomponent, net.minecraft.server.EnumChatFormat.WHITE));// Paper - Log message with colors ++ MinecraftServer.LOGGER.info(org.bukkit.craftbukkit.util.CraftChatMessage.fromComponent(ichatbasecomponent));// Paper - Log message with colors } public KeyPair getKeyPair() { diff --git a/work/Bukkit b/work/Bukkit index d6db283966..e269963640 160000 --- a/work/Bukkit +++ b/work/Bukkit @@ -1 +1 @@ -Subproject commit d6db283966d16725450e506b1d43be39a2173426 +Subproject commit e2699636407094a6e25843907291cde511fbb19d diff --git a/work/CraftBukkit b/work/CraftBukkit index aae46f82ea..1b2830a3b3 160000 --- a/work/CraftBukkit +++ b/work/CraftBukkit @@ -1 +1 @@ -Subproject commit aae46f82eab8ae0bd855d94209083df2144818e4 +Subproject commit 1b2830a3b3aa5ecf4d2f44696654fc028a2c53a0