From df4c68b669e1347e7f86718e8eb2d2f391a9dd8c Mon Sep 17 00:00:00 2001 From: Riley Park Date: Sun, 28 Feb 2021 18:40:19 -0800 Subject: [PATCH] fix #5279 - clickable links again --- Spigot-Server-Patches/0010-Adventure.patch | 24 ++++++++++++++++--- ...nilla-per-world-scoreboard-coloring-.patch | 16 ++++++------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Spigot-Server-Patches/0010-Adventure.patch b/Spigot-Server-Patches/0010-Adventure.patch index 3b5c1b2ca0..1dbcacc210 100644 --- a/Spigot-Server-Patches/0010-Adventure.patch +++ b/Spigot-Server-Patches/0010-Adventure.patch @@ -539,20 +539,38 @@ index 0000000000000000000000000000000000000000..59dd2a453dbfc538431a3414ab35d183 +} diff --git a/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java b/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java new file mode 100644 -index 0000000000000000000000000000000000000000..af7388719d06cd4672f8b18f8929b1076ca0ce42 +index 0000000000000000000000000000000000000000..5f1f839da11058cffae8b29ad2820dc4cc1b1e10 --- /dev/null +++ b/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java -@@ -0,0 +1,43 @@ +@@ -0,0 +1,61 @@ +package io.papermc.paper.adventure; + +import java.util.function.BiFunction; +import java.util.regex.MatchResult; ++import java.util.regex.Pattern; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.ComponentLike; +import net.kyori.adventure.text.TextComponent; ++import net.kyori.adventure.text.TextReplacementConfig; ++import net.kyori.adventure.text.event.ClickEvent; +import org.bukkit.craftbukkit.entity.CraftPlayer; + +public class VanillaChatMessageLogic { ++ // <-- copied from adventure-text-serializer-legacy ++ private static final Pattern DEFAULT_URL_PATTERN = Pattern.compile("(?:(https?)://)?([-\\w_.]+\\.\\w{2,})(/\\S*)?"); ++ private static final Pattern URL_SCHEME_PATTERN = Pattern.compile("^[a-z][a-z0-9+\\-.]*:"); ++ private static final TextReplacementConfig URL_REPLACEMENT_CONFIG = TextReplacementConfig.builder() ++ .match(DEFAULT_URL_PATTERN) ++ .replacement(url -> { ++ String clickUrl = url.content(); ++ if (!URL_SCHEME_PATTERN.matcher(clickUrl).find()) { ++ clickUrl = "http://" + clickUrl; ++ } ++ return url.clickEvent(ClickEvent.openUrl(clickUrl)); ++ }) ++ .build(); ++ // copied from adventure-text-serializer-legacy --> ++ + public static Component displayNameForChat(final CraftPlayer player) { + return player.displayName(); + } @@ -568,7 +586,7 @@ index 0000000000000000000000000000000000000000..af7388719d06cd4672f8b18f8929b107 + return displayName; + } else if (this.index == 1) { + this.index++; -+ return PaperAdventure.LEGACY_SECTION_UXRC.deserialize(message).mergeStyle(builder.asComponent()); ++ return PaperAdventure.LEGACY_SECTION_UXRC.deserialize(message).mergeStyle(builder.asComponent()).replaceText(URL_REPLACEMENT_CONFIG); + } else { + return builder; + } diff --git a/Spigot-Server-Patches/0083-Option-to-use-vanilla-per-world-scoreboard-coloring-.patch b/Spigot-Server-Patches/0083-Option-to-use-vanilla-per-world-scoreboard-coloring-.patch index b71d070484..95aff69a5f 100644 --- a/Spigot-Server-Patches/0083-Option-to-use-vanilla-per-world-scoreboard-coloring-.patch +++ b/Spigot-Server-Patches/0083-Option-to-use-vanilla-per-world-scoreboard-coloring-.patch @@ -26,24 +26,24 @@ index db2dddd12f54e6d15916c4cee623676541de37fb..1942f5224aaebb18adb591d6f70a419c + } } diff --git a/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java b/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java -index af7388719d06cd4672f8b18f8929b1076ca0ce42..c59fff15527ac6450e7992431ab22647df19ae95 100644 +index 5f1f839da11058cffae8b29ad2820dc4cc1b1e10..b62d573db85dcc59f9a2704c9142bde6bd5105c9 100644 --- a/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java +++ b/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java -@@ -5,10 +5,18 @@ import java.util.regex.MatchResult; - import net.kyori.adventure.text.Component; - import net.kyori.adventure.text.ComponentLike; +@@ -8,6 +8,8 @@ import net.kyori.adventure.text.ComponentLike; import net.kyori.adventure.text.TextComponent; -+import net.minecraft.server.IChatBaseComponent; + import net.kyori.adventure.text.TextReplacementConfig; + import net.kyori.adventure.text.event.ClickEvent; +import net.minecraft.server.ScoreboardTeam; +import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.entity.CraftPlayer; public class VanillaChatMessageLogic { +@@ -27,6 +29,9 @@ public class VanillaChatMessageLogic { + // copied from adventure-text-serializer-legacy --> + public static Component displayNameForChat(final CraftPlayer player) { + if (((CraftWorld) player.getWorld()).getHandle().paperConfig.useVanillaScoreboardColoring) { -+ IChatBaseComponent nameFromTeam = ScoreboardTeam.a(player.getHandle().getScoreboardTeam(), player.getHandle().getDisplayName()); -+ // Explicitly add a RESET here, vanilla uses components for this now... -+ return PaperAdventure.asAdventure(nameFromTeam); ++ return PaperAdventure.asAdventure(ScoreboardTeam.a(player.getHandle().getScoreboardTeam(), player.getHandle().getDisplayName())); + } return player.displayName(); }