13
0
geforkt von Mirrors/Paper

fix #5279 - clickable links again

Dieser Commit ist enthalten in:
Riley Park 2021-02-28 18:40:19 -08:00
Ursprung a26dc45546
Commit 7bb59f4a28
2 geänderte Dateien mit 26 neuen und 8 gelöschten Zeilen

Datei anzeigen

@ -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;
+ }

Datei anzeigen

@ -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();
}