fix #5279 - clickable links again
This commit is contained in:
@@ -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;
|
||||
+ }
|
||||
|
||||
Reference in New Issue
Block a user