mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-27 15:00:13 +01:00
bug #5373 - fix AsyncChatEvent not being posted when processing a legacy APCE continuation
This commit is contained in:
parent
797fc746d0
commit
8b1e661370
2 changed files with 67 additions and 79 deletions
|
@ -123,8 +123,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+import net.kyori.adventure.text.Component;
|
||||
+import net.kyori.adventure.text.TextReplacementConfig;
|
||||
+import net.kyori.adventure.text.event.ClickEvent;
|
||||
+import net.kyori.adventure.text.format.Style;
|
||||
+import net.kyori.adventure.text.format.TextDecoration;
|
||||
+import net.minecraft.server.EntityPlayer;
|
||||
+import net.minecraft.server.IChatBaseComponent;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
|
@ -165,66 +163,80 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ this.async = async;
|
||||
+ }
|
||||
+
|
||||
+ @SuppressWarnings("deprecation")
|
||||
+ @SuppressWarnings("CodeBlock2Expr")
|
||||
+ public void process() {
|
||||
+ final boolean listenersOnSyncEvent = anyListeners(ChatEvent.getHandlerList());
|
||||
+
|
||||
+ this.processLegacy(
|
||||
+ this.processingLegacyFirst(
|
||||
+ // continuing from AsyncPlayerChatEvent (without PlayerChatEvent)
|
||||
+ event -> {
|
||||
+ final AsyncChatEvent ae = this.createAsync(
|
||||
+ this.processModern(
|
||||
+ legacyFormatter(event.getFormat(), legacyDisplayName((CraftPlayer) event.getPlayer()), event.getMessage()),
|
||||
+ event.getRecipients(),
|
||||
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage())
|
||||
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage()),
|
||||
+ event.isCancelled()
|
||||
+ );
|
||||
+ ae.setCancelled(event.isCancelled()); // propagate cancelled state
|
||||
+ post(ae);
|
||||
+ if (listenersOnSyncEvent) {
|
||||
+ this.continueWithSyncFromWhereAsyncLeftOff(ae);
|
||||
+ } else {
|
||||
+ this.complete(ae);
|
||||
+ }
|
||||
+ },
|
||||
+ // continuing from AsyncPlayerChatEvent and PlayerChatEvent
|
||||
+ event -> {
|
||||
+ this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
|
||||
+ @Override
|
||||
+ protected Void evaluate() {
|
||||
+ final ChatEvent se = ChatProcessor.this.createSync(
|
||||
+ legacyFormatter(event.getFormat(), legacyDisplayName((CraftPlayer) event.getPlayer()), event.getMessage()),
|
||||
+ event.getRecipients(),
|
||||
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage())
|
||||
+ );
|
||||
+ se.setCancelled(event.isCancelled()); // propagate cancelled state
|
||||
+ post(se);
|
||||
+ ChatProcessor.this.complete(se);
|
||||
+ return null;
|
||||
+ }
|
||||
+ });
|
||||
+ this.processModern(
|
||||
+ legacyFormatter(event.getFormat(), legacyDisplayName((CraftPlayer) event.getPlayer()), event.getMessage()),
|
||||
+ event.getRecipients(),
|
||||
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage()),
|
||||
+ event.isCancelled()
|
||||
+ );
|
||||
+ },
|
||||
+ // no legacy events called, all nice and fresh!
|
||||
+ () -> {
|
||||
+ 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);
|
||||
+ } else {
|
||||
+ this.complete(ae);
|
||||
+ }
|
||||
+ this.processModern(
|
||||
+ ChatFormatter.DEFAULT,
|
||||
+ new LazyPlayerSet(this.server),
|
||||
+ Component.text(this.message).replaceText(URL_REPLACEMENT_CONFIG),
|
||||
+ false
|
||||
+ );
|
||||
+ }
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ private static String legacyDisplayName(final CraftPlayer player) {
|
||||
+ return player.getDisplayName();
|
||||
+ @SuppressWarnings("deprecation")
|
||||
+ private void processingLegacyFirst(
|
||||
+ final Consumer<AsyncPlayerChatEvent> continueAfterAsync,
|
||||
+ final Consumer<PlayerChatEvent> continueAfterAsyncAndSync,
|
||||
+ final Runnable modernOnly
|
||||
+ ) {
|
||||
+ final boolean listenersOnAsyncEvent = anyListeners(AsyncPlayerChatEvent.getHandlerList());
|
||||
+ final boolean listenersOnSyncEvent = anyListeners(PlayerChatEvent.getHandlerList());
|
||||
+ if (listenersOnAsyncEvent || listenersOnSyncEvent) {
|
||||
+ final CraftPlayer player = this.player.getBukkitEntity();
|
||||
+ final AsyncPlayerChatEvent ae = new AsyncPlayerChatEvent(this.async, player, this.message, new LazyPlayerSet(this.server));
|
||||
+ post(ae);
|
||||
+ if (listenersOnSyncEvent) {
|
||||
+ final PlayerChatEvent se = new PlayerChatEvent(player, ae.getMessage(), ae.getFormat(), ae.getRecipients());
|
||||
+ se.setCancelled(ae.isCancelled()); // propagate cancelled state
|
||||
+ this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
|
||||
+ @Override
|
||||
+ protected Void evaluate() {
|
||||
+ post(se);
|
||||
+ return null;
|
||||
+ }
|
||||
+ });
|
||||
+ continueAfterAsyncAndSync.accept(se);
|
||||
+ } else if (!ae.isCancelled()) {
|
||||
+ continueAfterAsync.accept(ae);
|
||||
+ }
|
||||
+ } else {
|
||||
+ modernOnly.run();
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private static Component displayName(final CraftPlayer player) {
|
||||
+ return player.displayName();
|
||||
+ }
|
||||
+
|
||||
+ private static ChatFormatter legacyFormatter(final String format, final String legacyDisplayName, final String legacyMessage) {
|
||||
+ return (displayName, message) -> PaperAdventure.LEGACY_SECTION_UXRC.deserialize(String.format(format, legacyDisplayName, legacyMessage)).replaceText(URL_REPLACEMENT_CONFIG);
|
||||
+ private void processModern(final ChatFormatter formatter, final Set<Player> recipients, final Component message, final boolean cancelled) {
|
||||
+ final AsyncChatEvent ae = this.createAsync(formatter, recipients, message);
|
||||
+ ae.setCancelled(cancelled); // propagate cancelled state
|
||||
+ post(ae);
|
||||
+ final boolean listenersOnSyncEvent = anyListeners(ChatEvent.getHandlerList());
|
||||
+ if (listenersOnSyncEvent) {
|
||||
+ this.continueWithSyncFromWhereAsyncLeftOff(ae);
|
||||
+ } else {
|
||||
+ this.complete(ae);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private void continueWithSyncFromWhereAsyncLeftOff(final AsyncChatEvent ae) {
|
||||
|
@ -274,35 +286,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ return new ChatEvent(this.player.getBukkitEntity(), recipients, formatter, message);
|
||||
+ }
|
||||
+
|
||||
+ @SuppressWarnings("deprecation")
|
||||
+ public void processLegacy(
|
||||
+ final Consumer<AsyncPlayerChatEvent> continueAfterAsync,
|
||||
+ final Consumer<PlayerChatEvent> continueAfterAsyncAndSync,
|
||||
+ final Runnable modernOnly
|
||||
+ ) {
|
||||
+ final boolean listenersOnAsyncEvent = anyListeners(AsyncPlayerChatEvent.getHandlerList());
|
||||
+ final boolean listenersOnSyncEvent = anyListeners(PlayerChatEvent.getHandlerList());
|
||||
+ if (listenersOnAsyncEvent || listenersOnSyncEvent) {
|
||||
+ final CraftPlayer player = this.player.getBukkitEntity();
|
||||
+ final AsyncPlayerChatEvent ae = new AsyncPlayerChatEvent(this.async, player, this.message, new LazyPlayerSet(this.server));
|
||||
+ post(ae);
|
||||
+ if (listenersOnSyncEvent) {
|
||||
+ final PlayerChatEvent se = new PlayerChatEvent(player, ae.getMessage(), ae.getFormat(), ae.getRecipients());
|
||||
+ se.setCancelled(ae.isCancelled()); // propagate cancelled state
|
||||
+ this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
|
||||
+ @Override
|
||||
+ protected Void evaluate() {
|
||||
+ post(se);
|
||||
+ return null;
|
||||
+ }
|
||||
+ });
|
||||
+ continueAfterAsyncAndSync.accept(se);
|
||||
+ } else if (!ae.isCancelled()) {
|
||||
+ continueAfterAsync.accept(ae);
|
||||
+ }
|
||||
+ } else {
|
||||
+ modernOnly.run();
|
||||
+ }
|
||||
+ private static String legacyDisplayName(final CraftPlayer player) {
|
||||
+ return player.getDisplayName();
|
||||
+ }
|
||||
+
|
||||
+ private static Component displayName(final CraftPlayer player) {
|
||||
+ return player.displayName();
|
||||
+ }
|
||||
+
|
||||
+ private static ChatFormatter legacyFormatter(final String format, final String legacyDisplayName, final String legacyMessage) {
|
||||
+ return (displayName, message) -> PaperAdventure.LEGACY_SECTION_UXRC.deserialize(String.format(format, legacyDisplayName, legacyMessage)).replaceText(URL_REPLACEMENT_CONFIG);
|
||||
+ }
|
||||
+
|
||||
+ private void queueIfAsyncOrRunImmediately(final Waitable<Void> waitable) {
|
||||
|
|
|
@ -29,12 +29,7 @@ diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/m
|
|||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
@@ -0,0 +0,0 @@ import java.util.regex.Pattern;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
-import net.kyori.adventure.text.format.Style;
|
||||
-import net.kyori.adventure.text.format.TextDecoration;
|
||||
@@ -0,0 +0,0 @@ import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.minecraft.server.EntityPlayer;
|
||||
import net.minecraft.server.IChatBaseComponent;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
|
Loading…
Reference in a new issue