fix #5279 - clickable links again

This commit is contained in:
Riley Park 2021-02-28 18:40:19 -08:00
parent ff5ff3af40
commit df4c68b669
No known key found for this signature in database
GPG Key ID: D831AF236C834E45
2 changed files with 29 additions and 11 deletions

View File

@ -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 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 new file mode 100644
index 0000000000000000000000000000000000000000..af7388719d06cd4672f8b18f8929b1076ca0ce42 index 0000000000000000000000000000000000000000..5f1f839da11058cffae8b29ad2820dc4cc1b1e10
--- /dev/null --- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java +++ b/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java
@@ -0,0 +1,43 @@ @@ -0,0 +1,61 @@
+package io.papermc.paper.adventure; +package io.papermc.paper.adventure;
+ +
+import java.util.function.BiFunction; +import java.util.function.BiFunction;
+import java.util.regex.MatchResult; +import java.util.regex.MatchResult;
+import java.util.regex.Pattern;
+import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.ComponentLike; +import net.kyori.adventure.text.ComponentLike;
+import net.kyori.adventure.text.TextComponent; +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; +import org.bukkit.craftbukkit.entity.CraftPlayer;
+ +
+public class VanillaChatMessageLogic { +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) { + public static Component displayNameForChat(final CraftPlayer player) {
+ return player.displayName(); + return player.displayName();
+ } + }
@ -568,7 +586,7 @@ index 0000000000000000000000000000000000000000..af7388719d06cd4672f8b18f8929b107
+ return displayName; + return displayName;
+ } else if (this.index == 1) { + } else if (this.index == 1) {
+ this.index++; + 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 { + } else {
+ return builder; + return builder;
+ } + }

View File

@ -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 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 --- a/src/main/java/io/papermc/paper/adventure/VanillaChatMessageLogic.java
+++ b/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; @@ -8,6 +8,8 @@ import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.TextComponent; 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 net.minecraft.server.ScoreboardTeam;
+import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftPlayer; import org.bukkit.craftbukkit.entity.CraftPlayer;
public class VanillaChatMessageLogic { public class VanillaChatMessageLogic {
@@ -27,6 +29,9 @@ public class VanillaChatMessageLogic {
// copied from adventure-text-serializer-legacy -->
public static Component displayNameForChat(final CraftPlayer player) { public static Component displayNameForChat(final CraftPlayer player) {
+ if (((CraftWorld) player.getWorld()).getHandle().paperConfig.useVanillaScoreboardColoring) { + if (((CraftWorld) player.getWorld()).getHandle().paperConfig.useVanillaScoreboardColoring) {
+ IChatBaseComponent nameFromTeam = ScoreboardTeam.a(player.getHandle().getScoreboardTeam(), player.getHandle().getDisplayName()); + return PaperAdventure.asAdventure(ScoreboardTeam.a(player.getHandle().getScoreboardTeam(), player.getHandle().getDisplayName()));
+ // Explicitly add a RESET here, vanilla uses components for this now...
+ return PaperAdventure.asAdventure(nameFromTeam);
+ } + }
return player.displayName(); return player.displayName();
} }