fix #5292 with help from @JRoy

This commit is contained in:
Riley Park 2021-03-02 08:39:36 -08:00
parent 9907cedecb
commit 60e92c061b
No known key found for this signature in database
GPG Key ID: D831AF236C834E45
2 changed files with 14 additions and 11 deletions

View File

@ -106,16 +106,17 @@ index 0000000000000000000000000000000000000000..a2acd31dce4461338a8baa96e03df36a
+}
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..d7945e7340f406fbf21a1bd67f9c167a309d0fb7
index 0000000000000000000000000000000000000000..a8bc84d476093e6b39564450564f676adccde898
--- /dev/null
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
@@ -0,0 +1,209 @@
@@ -0,0 +1,212 @@
+package io.papermc.paper.adventure;
+
+import io.papermc.paper.chat.ChatFormatter;
+import io.papermc.paper.event.player.AbstractChatEvent;
+import io.papermc.paper.event.player.AsyncChatEvent;
+import io.papermc.paper.event.player.ChatEvent;
+import java.util.Set;
+import java.util.concurrent.ExecutionException;
+import java.util.function.Consumer;
+import java.util.regex.Pattern;
@ -171,6 +172,7 @@ index 0000000000000000000000000000000000000000..d7945e7340f406fbf21a1bd67f9c167a
+ event -> {
+ final AsyncChatEvent ae = this.createAsync(
+ legacyFormatter(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()),
+ event.getRecipients(),
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage())
+ );
+ ae.setCancelled(event.isCancelled()); // propagate cancelled state
@ -188,6 +190,7 @@ index 0000000000000000000000000000000000000000..d7945e7340f406fbf21a1bd67f9c167a
+ protected Void evaluate() {
+ final ChatEvent se = ChatProcessor.this.createSync(
+ legacyFormatter(event.getFormat(), event.getPlayer().getDisplayName(), event.getMessage()),
+ event.getRecipients(),
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage())
+ );
+ se.setCancelled(event.isCancelled()); // propagate cancelled state
@ -199,7 +202,7 @@ index 0000000000000000000000000000000000000000..d7945e7340f406fbf21a1bd67f9c167a
+ },
+ // no legacy events called, all nice and fresh!
+ () -> {
+ final AsyncChatEvent ae = this.createAsync(ChatFormatter.DEFAULT, Component.text(this.message).replaceText(URL_REPLACEMENT_CONFIG));
+ final AsyncChatEvent ae = this.createAsync(ChatFormatter.DEFAULT, new LazyPlayerSet(this.server), Component.text(this.message).replaceText(URL_REPLACEMENT_CONFIG));
+ post(ae);
+ if (listenersOnSyncEvent) {
+ this.continueWithSyncFromWhereAsyncLeftOff(ae);
@ -222,7 +225,7 @@ index 0000000000000000000000000000000000000000..d7945e7340f406fbf21a1bd67f9c167a
+ this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
+ @Override
+ protected Void evaluate() {
+ final ChatEvent se = ChatProcessor.this.createSync(ae.formatter(), ae.message());
+ final ChatEvent se = ChatProcessor.this.createSync(ae.formatter(), ae.recipients(), ae.message());
+ se.setCancelled(ae.isCancelled()); // propagate cancelled state
+ post(se);
+ ChatProcessor.this.complete(se);
@ -257,12 +260,12 @@ index 0000000000000000000000000000000000000000..d7945e7340f406fbf21a1bd67f9c167a
+ }
+ }
+
+ private AsyncChatEvent createAsync(final ChatFormatter formatter, final Component message) {
+ return new AsyncChatEvent(this.async, this.player.getBukkitEntity(), new LazyPlayerSet(this.server), formatter, message);
+ private AsyncChatEvent createAsync(final ChatFormatter formatter, final Set<Player> recipients, final Component message) {
+ return new AsyncChatEvent(this.async, this.player.getBukkitEntity(), recipients, formatter, message);
+ }
+
+ private ChatEvent createSync(final ChatFormatter formatter, final Component message) {
+ return new ChatEvent(this.player.getBukkitEntity(), new LazyPlayerSet(this.server), formatter, message);
+ private ChatEvent createSync(final ChatFormatter formatter, final Set<Player> recipients, final Component message) {
+ return new ChatEvent(this.player.getBukkitEntity(), recipients, formatter, message);
+ }
+
+ @SuppressWarnings("deprecation")

View File

@ -26,10 +26,10 @@ index db2dddd12f54e6d15916c4cee623676541de37fb..1942f5224aaebb18adb591d6f70a419c
+ }
}
diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
index d7945e7340f406fbf21a1bd67f9c167a309d0fb7..63085b09eb4d7dc5ebbad9f3d8d6309990473b45 100644
index a8bc84d476093e6b39564450564f676adccde898..4934b732a602e0c9aba4957459490455b4b368b2 100644
--- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
@@ -13,7 +13,9 @@ import net.kyori.adventure.text.event.ClickEvent;
@@ -14,7 +14,9 @@ import net.kyori.adventure.text.event.ClickEvent;
import net.minecraft.server.EntityPlayer;
import net.minecraft.server.IChatBaseComponent;
import net.minecraft.server.MinecraftServer;
@ -39,7 +39,7 @@ index d7945e7340f406fbf21a1bd67f9c167a309d0fb7..63085b09eb4d7dc5ebbad9f3d8d63099
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.bukkit.craftbukkit.util.LazyPlayerSet;
import org.bukkit.craftbukkit.util.Waitable;
@@ -99,6 +101,9 @@ public final class ChatProcessor {
@@ -102,6 +104,9 @@ public final class ChatProcessor {
}
private static Component displayName(final CraftPlayer player) {