mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Expose signed message in chat events (#8694)
This commit is contained in:
parent
424df4f743
commit
c2bee2c705
2 changed files with 27 additions and 8 deletions
|
@ -204,15 +204,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.event.player;
|
||||
+
|
||||
+import java.util.Set;
|
||||
+import io.papermc.paper.chat.ChatRenderer;
|
||||
+import net.kyori.adventure.audience.Audience;
|
||||
+import net.kyori.adventure.chat.SignedMessage;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
+import org.bukkit.event.player.PlayerEvent;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+import java.util.Set;
|
||||
+
|
||||
+import static java.util.Objects.requireNonNull;
|
||||
+
|
||||
+/**
|
||||
|
@ -221,16 +223,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+public abstract class AbstractChatEvent extends PlayerEvent implements Cancellable {
|
||||
+ private final Set<Audience> viewers;
|
||||
+ private final Component originalMessage;
|
||||
+ private final SignedMessage signedMessage;
|
||||
+ private ChatRenderer renderer;
|
||||
+ private Component message;
|
||||
+ private boolean cancelled = false;
|
||||
+
|
||||
+ AbstractChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage) {
|
||||
+ AbstractChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage, final @NotNull SignedMessage signedMessage) {
|
||||
+ super(player, async);
|
||||
+ this.viewers = viewers;
|
||||
+ this.renderer = renderer;
|
||||
+ this.message = message;
|
||||
+ this.originalMessage = originalMessage;
|
||||
+ this.signedMessage = signedMessage;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -304,6 +308,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ return this.originalMessage;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the signed message.
|
||||
+ * Changes made in this event will <b>not</b> update
|
||||
+ * the signed message.
|
||||
+ *
|
||||
+ * @return the signed message
|
||||
+ */
|
||||
+ @NotNull
|
||||
+ public final SignedMessage signedMessage() {
|
||||
+ return this.signedMessage;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public final boolean isCancelled() {
|
||||
+ return this.cancelled;
|
||||
|
@ -481,6 +497,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+import java.util.Set;
|
||||
+import io.papermc.paper.chat.ChatRenderer;
|
||||
+import net.kyori.adventure.audience.Audience;
|
||||
+import net.kyori.adventure.chat.SignedMessage;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
|
@ -492,8 +509,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+public final class AsyncChatEvent extends AbstractChatEvent {
|
||||
+ private static final HandlerList HANDLERS = new HandlerList();
|
||||
+
|
||||
+ public AsyncChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage) {
|
||||
+ super(async, player, viewers, renderer, message, originalMessage);
|
||||
+ public AsyncChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage, final @NotNull SignedMessage signedMessage) {
|
||||
+ super(async, player, viewers, renderer, message, originalMessage, signedMessage);
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
|
@ -518,6 +535,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+import java.util.Set;
|
||||
+import io.papermc.paper.chat.ChatRenderer;
|
||||
+import net.kyori.adventure.audience.Audience;
|
||||
+import net.kyori.adventure.chat.SignedMessage;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import org.bukkit.Warning;
|
||||
+import org.bukkit.entity.Player;
|
||||
|
@ -534,8 +552,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+public final class ChatEvent extends AbstractChatEvent {
|
||||
+ private static final HandlerList HANDLERS = new HandlerList();
|
||||
+
|
||||
+ public ChatEvent(final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage) {
|
||||
+ super(false, player, viewers, renderer, message, originalMessage);
|
||||
+ public ChatEvent(final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage, final @NotNull SignedMessage signedMessage) {
|
||||
+ super(false, player, viewers, renderer, message, originalMessage, signedMessage);
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
|
|
|
@ -427,7 +427,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ }
|
||||
+
|
||||
+ private void processModern(final ChatRenderer renderer, final Set<Audience> viewers, final Component message, final Player player, final boolean cancelled) {
|
||||
+ final AsyncChatEvent ae = new AsyncChatEvent(this.async, player, viewers, renderer, message, this.paper$originalMessage);
|
||||
+ final PlayerChatMessage.AdventureView signedMessage = this.message.adventureView();
|
||||
+ final AsyncChatEvent ae = new AsyncChatEvent(this.async, player, viewers, renderer, message, this.paper$originalMessage, signedMessage);
|
||||
+ ae.setCancelled(cancelled); // propagate cancelled state
|
||||
+ this.post(ae);
|
||||
+ final boolean listenersOnSyncEvent = canYouHearMe(ChatEvent.getHandlerList());
|
||||
|
@ -435,7 +436,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
|
||||
+ @Override
|
||||
+ protected Void evaluate() {
|
||||
+ final ChatEvent se = new ChatEvent(player, ae.viewers(), ae.renderer(), ae.message(), ChatProcessor.this.paper$originalMessage/*, ae.usePreviewComponent()*/);
|
||||
+ final ChatEvent se = new ChatEvent(player, ae.viewers(), ae.renderer(), ae.message(), ChatProcessor.this.paper$originalMessage/*, ae.usePreviewComponent()*/, signedMessage);
|
||||
+ se.setCancelled(ae.isCancelled()); // propagate cancelled state
|
||||
+ ChatProcessor.this.post(se);
|
||||
+ ChatProcessor.this.readModernModifications(se, renderer);
|
||||
|
|
Loading…
Reference in a new issue