Fix default ChatRenderer when no plugins are installed (#5702)

This commit is contained in:
Jason 2021-05-21 18:08:18 -07:00 committed by GitHub
parent ecb0d32cae
commit 1f28e6eeb2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View file

@ -174,10 +174,10 @@ index 0000000000000000000000000000000000000000..ba784ab037adfd37b01b222ea33abea0
+}
diff --git a/src/main/java/io/papermc/paper/chat/ChatRenderer.java b/src/main/java/io/papermc/paper/chat/ChatRenderer.java
new file mode 100644
index 0000000000000000000000000000000000000000..ec50931f02d8be3e32aa6bc8a2204a4f2e4cabb4
index 0000000000000000000000000000000000000000..85fd5d6777b53bab09cc54c360bb75141635bdd3
--- /dev/null
+++ b/src/main/java/io/papermc/paper/chat/ChatRenderer.java
@@ -0,0 +1,67 @@
@@ -0,0 +1,75 @@
+package io.papermc.paper.chat;
+
+import net.kyori.adventure.audience.Audience;
@ -191,8 +191,6 @@ index 0000000000000000000000000000000000000000..ec50931f02d8be3e32aa6bc8a2204a4f
+ */
+@FunctionalInterface
+public interface ChatRenderer {
+ ChatRenderer DEFAULT = viewerUnaware((source, sourceDisplayName, message) -> Component.translatable("chat.type.text", sourceDisplayName, message));
+
+ /**
+ * Renders a chat message. This will be called once for each receiving {@link Audience}.
+ *
@ -206,6 +204,16 @@ index 0000000000000000000000000000000000000000..ec50931f02d8be3e32aa6bc8a2204a4f
+ Component render(@NotNull Player source, @NotNull Component sourceDisplayName, @NotNull Component message, @NotNull Audience viewer);
+
+ /**
+ * Create a new instance of the default {@link ChatRenderer}.
+ *
+ * @return a new {@link ChatRenderer}
+ */
+ @NotNull
+ static ChatRenderer defaultRenderer() {
+ return viewerUnaware((source, sourceDisplayName, message) -> Component.translatable("chat.type.text", sourceDisplayName, message));
+ }
+
+ /**
+ * Creates a new viewer-unaware {@link ChatRenderer}, which will render the chat message a single time,
+ * displaying the same rendered message to every viewing {@link Audience}.
+ *

View file

@ -105,7 +105,7 @@ index 0000000000000000000000000000000000000000..89597b4a3064c3c6001c7e927a848ee7
+}
diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
new file mode 100644
index 0000000000000000000000000000000000000000..bab8156acf87731ccdc841de5b341176ddedaae6
index 0000000000000000000000000000000000000000..e7ca0a44919ad052fa2ef279b4cd8989f8969a20
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
@@ -0,0 +1,213 @@
@ -189,7 +189,7 @@ index 0000000000000000000000000000000000000000..bab8156acf87731ccdc841de5b341176
+ // no legacy events called, all nice and fresh!
+ () -> {
+ this.processModern(
+ ChatRenderer.DEFAULT,
+ ChatRenderer.defaultRenderer(),
+ new LazyPlayerSet(this.server),
+ Component.text(this.message).replaceText(URL_REPLACEMENT_CONFIG),
+ false