From 7bb59f4a28c3eb50199bae01cd0689612567eb39 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/Adventure.patch | 20 ++++++++++++++++++- ...nilla-per-world-scoreboard-coloring-.patch | 14 ++++++------- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/Spigot-Server-Patches/Adventure.patch b/Spigot-Server-Patches/Adventure.patch index cc05c6834b..ff8d2a01ea 100644 --- a/Spigot-Server-Patches/Adventure.patch +++ b/Spigot-Server-Patches/Adventure.patch @@ -547,12 +547,30 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + +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..00000000000000000000000000000000 + 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/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch b/Spigot-Server-Patches/Option-to-use-vanilla-per-world-scoreboard-coloring-.patch index 5eabc826f7..99c5ba80f4 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 @@ -29,21 +29,21 @@ diff --git a/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.ja index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java +++ b/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java -@@ -0,0 +0,0 @@ import java.util.regex.MatchResult; - import net.kyori.adventure.text.Component; - import net.kyori.adventure.text.ComponentLike; +@@ -0,0 +0,0 @@ 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 { +@@ -0,0 +0,0 @@ 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(); }