From 3ccbdd3c85e54cc12430a7ec0a5639522d8db167 Mon Sep 17 00:00:00 2001 From: Aikar Date: Thu, 9 Jul 2020 20:31:04 -0400 Subject: [PATCH] Only convert lore lines that actually look legacy Spigot stored previous componenents as new ChatComponentText("legacy codes") which this patch aimed to convert to the new format. However, the impl ended up converting all lines. If a plugin had a section symbol in the lore that isn't a color conversion, it would make trigger this process every single time. So now we will only process it if the pattern looks like the legacy bukkit format Fixes #3869 --- ...pdate-itemstack-legacy-name-and-lore.patch | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Spigot-Server-Patches/Update-itemstack-legacy-name-and-lore.patch b/Spigot-Server-Patches/Update-itemstack-legacy-name-and-lore.patch index 7df7d8a6ad..c21c341007 100644 --- a/Spigot-Server-Patches/Update-itemstack-legacy-name-and-lore.patch +++ b/Spigot-Server-Patches/Update-itemstack-legacy-name-and-lore.patch @@ -28,24 +28,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + if (display.hasKeyOfType("Lore", 9)) { + NBTTagList list = display.getList("Lore", 8); -+ boolean legacy = false; + for (int index = 0; index < list.size(); index++) { + String json = list.getString(index); -+ if (json != null && json.contains("\u00A7")) { -+ legacy = true; -+ break; -+ } -+ } -+ if (legacy) { -+ NBTTagList lore = new NBTTagList(); -+ for (int index = 0; index < list.size(); index++) { -+ String json = list.getString(index); ++ if (json != null && json.contains("\u00A7")) { // Only try if it has legacy in the unparsed json + try { -+ lore.add(convert(json)); -+ } catch (JsonParseException ignore) { ++ list.set(index, convert(json)); ++ } catch (JsonParseException e) { ++ list.set(index, NBTTagString.create(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(new ChatComponentText("")))); + } + } -+ display.set("Lore", lore); + } + } + } @@ -53,7 +44,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + private NBTTagString convert(String json) { + IChatBaseComponent component = IChatBaseComponent.ChatSerializer.jsonToComponent(json); -+ if (component != null) { ++ if (component instanceof ChatComponentText && component.getText().contains("\u00A7") && component.getSiblings().isEmpty()) { ++ // Only convert if the root component is a single comp with legacy in it, don't convert already normal components + component = org.bukkit.craftbukkit.util.CraftChatMessage.fromString(component.getText())[0]; + } + return NBTTagString.create(org.bukkit.craftbukkit.util.CraftChatMessage.toJSON(component));