mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-30 16:19:03 +01:00
Remove chat event APIs marked as deprecated for removal with 1.17
This commit is contained in:
parent
ba7094caa9
commit
166760a713
2 changed files with 39 additions and 357 deletions
|
@ -53,76 +53,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ }
|
||||
+ // Paper end
|
||||
}
|
||||
diff --git a/src/main/java/io/papermc/paper/chat/ChatComposer.java b/src/main/java/io/papermc/paper/chat/ChatComposer.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/chat/ChatComposer.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.chat;
|
||||
+
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+/**
|
||||
+ * A chat composer is responsible for composing chat messages sent by {@link Player}s to the server.
|
||||
+ *
|
||||
+ * @deprecated for removal with 1.17, in favor of {@link ChatRenderer}
|
||||
+ */
|
||||
+@Deprecated
|
||||
+@FunctionalInterface
|
||||
+public interface ChatComposer {
|
||||
+ ChatComposer DEFAULT = (player, displayName, message) -> Component.translatable("chat.type.text", displayName, message);
|
||||
+
|
||||
+ /**
|
||||
+ * Composes a chat message.
|
||||
+ *
|
||||
+ * @param source the message source
|
||||
+ * @param displayName the display name of the {@link Player} sending the message
|
||||
+ * @param message the chat message
|
||||
+ * @return a composed chat message
|
||||
+ * @deprecated for removal with 1.17
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ @NotNull
|
||||
+ Component composeChat(final @NotNull Player source, final @NotNull Component displayName, final @NotNull Component message);
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/chat/ChatFormatter.java b/src/main/java/io/papermc/paper/chat/ChatFormatter.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/chat/ChatFormatter.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.chat;
|
||||
+
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+/**
|
||||
+ * A chat formatter is responsible for the formatting of chat messages sent by {@link Player}s to the server.
|
||||
+ *
|
||||
+ * @deprecated for removal with 1.17, in favour of {@link ChatRenderer}
|
||||
+ */
|
||||
+@Deprecated
|
||||
+@FunctionalInterface
|
||||
+public interface ChatFormatter {
|
||||
+ @Deprecated
|
||||
+ ChatFormatter DEFAULT = (displayName, message) -> Component.translatable("chat.type.text", displayName, message);
|
||||
+
|
||||
+ /**
|
||||
+ * Formats a chat message.
|
||||
+ *
|
||||
+ * @param displayName the display name of the {@link Player} sending the message
|
||||
+ * @param message the chat message
|
||||
+ * @return a formatted chat message
|
||||
+ * @deprecated for removal with 1.17
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ @NotNull
|
||||
+ Component chat(final @NotNull Component displayName, final @NotNull Component message);
|
||||
+}
|
||||
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..0000000000000000000000000000000000000000
|
||||
|
@ -212,20 +142,13 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.event.player;
|
||||
+
|
||||
+import io.papermc.paper.chat.ChatComposer;
|
||||
+import io.papermc.paper.chat.ChatFormatter;
|
||||
+import java.util.HashSet;
|
||||
+import java.util.Set;
|
||||
+import io.papermc.paper.chat.ChatRenderer;
|
||||
+import net.kyori.adventure.audience.Audience;
|
||||
+import net.kyori.adventure.audience.ForwardingAudience;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import org.bukkit.Bukkit;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
+import org.bukkit.event.player.PlayerEvent;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+
|
||||
+import static java.util.Objects.requireNonNull;
|
||||
|
@ -235,93 +158,20 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ */
|
||||
+public abstract class AbstractChatEvent extends PlayerEvent implements Cancellable {
|
||||
+ private final Set<Audience> viewers;
|
||||
+ @Deprecated private final Set<Player> recipients;
|
||||
+ private boolean cancelled = false;
|
||||
+ private ChatRenderer renderer;
|
||||
+ @Deprecated private @Nullable ChatComposer composer;
|
||||
+ @Deprecated private @Nullable ChatFormatter formatter;
|
||||
+ private final Component originalMessage;
|
||||
+ 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) {
|
||||
+ super(player, async);
|
||||
+ this.viewers = viewers;
|
||||
+ this.recipients = new HashSet<>(Bukkit.getOnlinePlayers());
|
||||
+ this.renderer = renderer;
|
||||
+ this.message = message;
|
||||
+ this.originalMessage = originalMessage;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ AbstractChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message) {
|
||||
+ super(player, async);
|
||||
+ this.viewers = viewers;
|
||||
+ this.recipients = new HashSet<>(Bukkit.getOnlinePlayers());
|
||||
+ this.renderer = renderer;
|
||||
+ this.message = message;
|
||||
+ this.originalMessage = message;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ AbstractChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Player> recipients, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage) {
|
||||
+ super(player, async);
|
||||
+ this.recipients = recipients;
|
||||
+ this.viewers = viewers;
|
||||
+ this.renderer = renderer;
|
||||
+ this.message = message;
|
||||
+ this.originalMessage = originalMessage;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ AbstractChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Player> recipients, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message) {
|
||||
+ super(player, async);
|
||||
+ this.recipients = recipients;
|
||||
+ this.viewers = viewers;
|
||||
+ this.renderer = renderer;
|
||||
+ this.message = message;
|
||||
+ this.originalMessage = message;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ AbstractChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Player> recipients, final @NotNull ChatComposer composer, final @NotNull Component message) {
|
||||
+ super(player, async);
|
||||
+ this.recipients = recipients;
|
||||
+ final Set<Audience> audiences = new HashSet<>(recipients);
|
||||
+ audiences.add(Bukkit.getConsoleSender());
|
||||
+ this.viewers = audiences;
|
||||
+ this.composer = composer;
|
||||
+ this.message = message;
|
||||
+ this.originalMessage = message;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ AbstractChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Player> recipients, final @NotNull ChatFormatter formatter, final @NotNull Component message) {
|
||||
+ super(player, async);
|
||||
+ this.recipients = recipients;
|
||||
+ final Set<Audience> audiences = new HashSet<>(recipients);
|
||||
+ audiences.add(Bukkit.getConsoleSender());
|
||||
+ this.viewers = audiences;
|
||||
+ this.formatter = formatter;
|
||||
+ this.message = message;
|
||||
+ this.originalMessage = message;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets a set of {@link Audience audiences} that this chat message will be displayed to.
|
||||
+ *
|
||||
+ * <p>The set returned is not guaranteed to be mutable and may auto-populate
|
||||
|
@ -340,26 +190,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets a set of recipients that this chat message will be displayed to.
|
||||
+ *
|
||||
+ * <p>The set returned is not guaranteed to be mutable and may auto-populate
|
||||
+ * on access. Any listener accessing the returned set should be aware that
|
||||
+ * it may reduce performance for a lazy set implementation.</p>
|
||||
+ *
|
||||
+ * <p>Listeners should be aware that modifying the list may throw {@link
|
||||
+ * UnsupportedOperationException} if the event caller provides an
|
||||
+ * unmodifiable set.</p>
|
||||
+ *
|
||||
+ * @return a set of players who will receive the chat message
|
||||
+ * @deprecated for removal with 1.17, in favor of {@link #viewers()}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ @NotNull
|
||||
+ public final Set<Player> recipients() {
|
||||
+ return this.recipients;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the chat renderer.
|
||||
+ *
|
||||
+ * @param renderer the chat renderer
|
||||
|
@ -367,8 +197,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ */
|
||||
+ public final void renderer(final @NotNull ChatRenderer renderer) {
|
||||
+ this.renderer = requireNonNull(renderer, "renderer");
|
||||
+ this.formatter = null;
|
||||
+ this.composer = null;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
@ -378,86 +206,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ */
|
||||
+ @NotNull
|
||||
+ public final ChatRenderer renderer() {
|
||||
+ if(this.renderer == null) {
|
||||
+ if(this.composer != null) {
|
||||
+ this.renderer = ChatRenderer.viewerUnaware((source, displayName, message) -> this.composer.composeChat(source, source.displayName(), message));
|
||||
+ } else {
|
||||
+ requireNonNull(this.formatter, "renderer, composer, and formatter");
|
||||
+ this.renderer = ChatRenderer.viewerUnaware((source, displayName, message) -> this.formatter.chat(source.displayName(), message));
|
||||
+ }
|
||||
+ }
|
||||
+ return this.renderer;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the chat composer.
|
||||
+ *
|
||||
+ * @return the chat composer
|
||||
+ * @deprecated for removal with 1.17, in favour of {@link #renderer()}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ @NotNull
|
||||
+ public final ChatComposer composer() {
|
||||
+ if(this.composer == null) {
|
||||
+ if(this.renderer != null) {
|
||||
+ this.composer = (source, displayName, message) -> this.renderer.render(source, displayName, message, this.legacyForwardingAudience());
|
||||
+ } else {
|
||||
+ requireNonNull(this.formatter, "renderer, composer, and formatter");
|
||||
+ this.composer = (source, displayName, message) -> this.formatter.chat(displayName, message);
|
||||
+ }
|
||||
+ }
|
||||
+ return this.composer;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the chat composer.
|
||||
+ *
|
||||
+ * @param composer the chat composer
|
||||
+ * @throws NullPointerException if {@code composer} is {@code null}
|
||||
+ * @deprecated for removal with 1.17, in favour of {@link #renderer(ChatRenderer)}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ public final void composer(final @NotNull ChatComposer composer) {
|
||||
+ this.composer = requireNonNull(composer, "composer");
|
||||
+ this.formatter = null;
|
||||
+ this.renderer = null;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the chat formatter.
|
||||
+ *
|
||||
+ * @return the chat formatter
|
||||
+ * @deprecated for removal with 1.17, in favour of {@link #renderer()}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ @NotNull
|
||||
+ public final ChatFormatter formatter() {
|
||||
+ if(this.formatter == null) {
|
||||
+ if(this.renderer != null) {
|
||||
+ this.formatter = (displayName, message) -> this.renderer.render(this.player, displayName, message, this.legacyForwardingAudience());
|
||||
+ } else {
|
||||
+ requireNonNull(this.composer, "renderer, composer, and formatter");
|
||||
+ this.formatter = (displayName, message) -> this.composer.composeChat(this.player, displayName, message);
|
||||
+ }
|
||||
+ }
|
||||
+ return this.formatter;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Sets the chat formatter.
|
||||
+ *
|
||||
+ * @param formatter the chat formatter
|
||||
+ * @throws NullPointerException if {@code formatter} is {@code null}
|
||||
+ * @deprecated for removal with 1.17, in favour of {@link #renderer(ChatRenderer)}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ public final void formatter(final @NotNull ChatFormatter formatter) {
|
||||
+ this.formatter = requireNonNull(formatter, "formatter");
|
||||
+ this.composer = null;
|
||||
+ this.renderer = null;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the user-supplied message.
|
||||
+ * The return value will reflect changes made using {@link #message(Component)}.
|
||||
+ *
|
||||
|
@ -499,15 +251,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ public final void setCancelled(final boolean cancelled) {
|
||||
+ this.cancelled = cancelled;
|
||||
+ }
|
||||
+
|
||||
+ private @NotNull Audience legacyForwardingAudience() {
|
||||
+ return new ForwardingAudience() {
|
||||
+ @Override
|
||||
+ public @NonNull Iterable<? extends Audience> audiences() {
|
||||
+ return AbstractChatEvent.this.viewers;
|
||||
+ }
|
||||
+ };
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/event/player/AsyncChatEvent.java b/src/main/java/io/papermc/paper/event/player/AsyncChatEvent.java
|
||||
new file mode 100644
|
||||
|
@ -517,8 +260,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.event.player;
|
||||
+
|
||||
+import io.papermc.paper.chat.ChatComposer;
|
||||
+import io.papermc.paper.chat.ChatFormatter;
|
||||
+import java.util.Set;
|
||||
+import io.papermc.paper.chat.ChatRenderer;
|
||||
+import net.kyori.adventure.audience.Audience;
|
||||
|
@ -537,46 +278,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ super(async, player, viewers, renderer, message, originalMessage);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17, use {@link #AsyncChatEvent(boolean, Player, Set, ChatRenderer, Component, Component)}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ public AsyncChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message) {
|
||||
+ super(async, player, viewers, renderer, message);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17, use {@link #AsyncChatEvent(boolean, Player, Set, ChatRenderer, Component, Component)}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ public AsyncChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Player> recipients, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage) {
|
||||
+ super(async, player, recipients, viewers, renderer, message, originalMessage);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17, use {@link #AsyncChatEvent(boolean, Player, Set, ChatRenderer, Component, Component)}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ public AsyncChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Player> recipients, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message) {
|
||||
+ super(async, player, recipients, viewers, renderer, message);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17, use {@link #AsyncChatEvent(boolean, Player, Set, ChatRenderer, Component, Component)}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ public AsyncChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Player> recipients, final @NotNull ChatComposer composer, final @NotNull Component message) {
|
||||
+ super(async, player, recipients, composer, message);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17, use {@link #AsyncChatEvent(boolean, Player, Set, ChatRenderer, Component, Component)}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ public AsyncChatEvent(final boolean async, final @NotNull Player player, final @NotNull Set<Player> recipients, final @NotNull ChatFormatter formatter, final @NotNull Component message) {
|
||||
+ super(async, player, recipients, formatter, message);
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ @Override
|
||||
+ public HandlerList getHandlers() {
|
||||
|
@ -596,8 +297,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.event.player;
|
||||
+
|
||||
+import io.papermc.paper.chat.ChatComposer;
|
||||
+import io.papermc.paper.chat.ChatFormatter;
|
||||
+import java.util.Set;
|
||||
+import io.papermc.paper.chat.ChatRenderer;
|
||||
+import net.kyori.adventure.audience.Audience;
|
||||
|
@ -621,38 +320,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ super(false, player, viewers, renderer, message, originalMessage);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17, use {@link #ChatEvent(Player, Set, ChatRenderer, Component, Component)}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ public ChatEvent(final @NotNull Player player, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message) {
|
||||
+ super(false, player, viewers, renderer, message);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17, use {@link #ChatEvent(Player, Set, ChatRenderer, Component, Component)}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ public ChatEvent(final @NotNull Player player, final @NotNull Set<Player> recipients, final @NotNull Set<Audience> viewers, final @NotNull ChatRenderer renderer, final @NotNull Component message, final @NotNull Component originalMessage) {
|
||||
+ super(false, player, recipients, viewers, renderer, message, originalMessage);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17, use {@link #ChatEvent(Player, Set, ChatRenderer, Component, Component)}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ public ChatEvent(final @NotNull Player player, final @NotNull Set<Player> recipients, final @NotNull ChatComposer composer, final @NotNull Component message) {
|
||||
+ super(false, player, recipients, composer, message);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * @deprecated for removal with 1.17, use {@link #ChatEvent(Player, Set, ChatRenderer, Component, Component)}
|
||||
+ */
|
||||
+ @Deprecated
|
||||
+ public ChatEvent(final @NotNull Player player, final @NotNull Set<Player> recipients, final @NotNull ChatFormatter formatter, final @NotNull Component message) {
|
||||
+ super(false, player, recipients, formatter, message);
|
||||
+ }
|
||||
+
|
||||
+ @NotNull
|
||||
+ @Override
|
||||
+ public HandlerList getHandlers() {
|
||||
|
|
|
@ -120,6 +120,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+import io.papermc.paper.event.player.AbstractChatEvent;
|
||||
+import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
+import io.papermc.paper.event.player.ChatEvent;
|
||||
+import java.util.HashSet;
|
||||
+import java.util.Set;
|
||||
+import java.util.concurrent.ExecutionException;
|
||||
+import java.util.function.Consumer;
|
||||
|
@ -178,7 +179,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ event -> {
|
||||
+ this.processModern(
|
||||
+ legacyRenderer(event.getFormat()),
|
||||
+ event.getRecipients(),
|
||||
+ this.viewersFromLegacy(event.getRecipients()),
|
||||
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage()),
|
||||
+ event.isCancelled()
|
||||
+ );
|
||||
|
@ -187,7 +188,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ event -> {
|
||||
+ this.processModern(
|
||||
+ legacyRenderer(event.getFormat()),
|
||||
+ event.getRecipients(),
|
||||
+ this.viewersFromLegacy(event.getRecipients()),
|
||||
+ PaperAdventure.LEGACY_SECTION_UXRC.deserialize(event.getMessage()),
|
||||
+ event.isCancelled()
|
||||
+ );
|
||||
|
@ -196,7 +197,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ () -> {
|
||||
+ this.processModern(
|
||||
+ ChatRenderer.defaultRenderer(),
|
||||
+ new LazyPlayerSet(this.server),
|
||||
+ new LazyChatAudienceSet(this.server),
|
||||
+ Component.text(this.message).replaceText(URL_REPLACEMENT_CONFIG),
|
||||
+ false
|
||||
+ );
|
||||
|
@ -204,6 +205,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ );
|
||||
+ }
|
||||
+
|
||||
+ private Set<Audience> viewersFromLegacy(final Set<Player> recipients) {
|
||||
+ if (recipients instanceof LazyPlayerSet lazyPlayerSet && lazyPlayerSet.isLazy()) {
|
||||
+ return new LazyChatAudienceSet(this.server);
|
||||
+ }
|
||||
+ final HashSet<Audience> viewers = new HashSet<>(recipients);
|
||||
+ viewers.add(this.server.console);
|
||||
+ return viewers;
|
||||
+ }
|
||||
+
|
||||
+ @SuppressWarnings("deprecation")
|
||||
+ private void processingLegacyFirst(
|
||||
+ final Consumer<AsyncPlayerChatEvent> continueAfterAsync,
|
||||
|
@ -235,8 +245,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private void processModern(final ChatRenderer renderer, final Set<Player> recipients, final Component message, final boolean cancelled) {
|
||||
+ final AsyncChatEvent ae = this.createAsync(renderer, recipients, new LazyChatAudienceSet(), message);
|
||||
+ private void processModern(final ChatRenderer renderer, final Set<Audience> viewers, final Component message, final boolean cancelled) {
|
||||
+ final AsyncChatEvent ae = this.createAsync(renderer, viewers, message);
|
||||
+ ae.setCancelled(cancelled); // propagate cancelled state
|
||||
+ post(ae);
|
||||
+ final boolean listenersOnSyncEvent = anyListeners(ChatEvent.getHandlerList());
|
||||
|
@ -251,7 +261,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ this.queueIfAsyncOrRunImmediately(new Waitable<Void>() {
|
||||
+ @Override
|
||||
+ protected Void evaluate() {
|
||||
+ final ChatEvent se = ChatProcessor.this.createSync(ae.renderer(), ae.recipients(), ae.viewers(), ae.message());
|
||||
+ final ChatEvent se = ChatProcessor.this.createSync(ae.renderer(), ae.viewers(), ae.message());
|
||||
+ se.setCancelled(ae.isCancelled()); // propagate cancelled state
|
||||
+ post(se);
|
||||
+ ChatProcessor.this.complete(se);
|
||||
|
@ -271,26 +281,26 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ final ChatRenderer renderer = event.renderer();
|
||||
+
|
||||
+ final Set<Audience> viewers = event.viewers();
|
||||
+ final Set<Player> recipients = event.recipients();
|
||||
+ if (viewers instanceof LazyChatAudienceSet && recipients instanceof LazyPlayerSet &&
|
||||
+ (!((LazyChatAudienceSet) viewers).isLazy() || ((LazyPlayerSet) recipients).isLazy())) {
|
||||
+
|
||||
+ if (viewers instanceof LazyChatAudienceSet lazyAudienceSet && lazyAudienceSet.isLazy()) {
|
||||
+ this.server.console.sendMessage(player, renderer.render(player, displayName, message, this.server.console), MessageType.CHAT);
|
||||
+ for (final ServerPlayer viewer : this.server.getPlayerList().getPlayers()) {
|
||||
+ final Player bukkit = viewer.getBukkitEntity();
|
||||
+ bukkit.sendMessage(player, renderer.render(player, displayName, message, bukkit), MessageType.CHAT);
|
||||
+ }
|
||||
+ } else {
|
||||
+ for (final Audience viewer : viewers) {
|
||||
+ viewer.sendMessage(player, renderer.render(player, displayName, message, viewer), MessageType.CHAT);
|
||||
+ }
|
||||
+ } else {
|
||||
+ this.server.console.sendMessage(player, renderer.render(player, displayName, message, this.server.console), MessageType.CHAT);
|
||||
+ for (final Player recipient : recipients) {
|
||||
+ recipient.sendMessage(player, renderer.render(player, displayName, message, recipient), MessageType.CHAT);
|
||||
+ }
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private AsyncChatEvent createAsync(final ChatRenderer renderer, final Set<Player> recipients, final Set<Audience> viewers, final Component message) {
|
||||
+ return new AsyncChatEvent(this.async, this.player.getBukkitEntity(), recipients, viewers, renderer, message, this.originalMessage);
|
||||
+ private AsyncChatEvent createAsync(final ChatRenderer renderer, final Set<Audience> viewers, final Component message) {
|
||||
+ return new AsyncChatEvent(this.async, this.player.getBukkitEntity(), viewers, renderer, message, this.originalMessage);
|
||||
+ }
|
||||
+
|
||||
+ private ChatEvent createSync(final ChatRenderer renderer, final Set<Player> recipients, final Set<Audience> viewers, final Component message) {
|
||||
+ return new ChatEvent(this.player.getBukkitEntity(), recipients, viewers, renderer, message, this.originalMessage);
|
||||
+ private ChatEvent createSync(final ChatRenderer renderer, final Set<Audience> viewers, final Component message) {
|
||||
+ return new ChatEvent(this.player.getBukkitEntity(), viewers, renderer, message, this.originalMessage);
|
||||
+ }
|
||||
+
|
||||
+ private static String legacyDisplayName(final CraftPlayer player) {
|
||||
|
@ -364,6 +374,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
@@ -0,0 +0,0 @@
|
||||
+package io.papermc.paper.adventure;
|
||||
+
|
||||
+import java.util.HashSet;
|
||||
+import java.util.Set;
|
||||
+import net.kyori.adventure.audience.Audience;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
+import org.bukkit.Bukkit;
|
||||
|
@ -371,13 +383,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
|
||||
+import org.bukkit.entity.Player;
|
||||
+
|
||||
+import java.util.HashSet;
|
||||
+import java.util.Set;
|
||||
+
|
||||
+final class LazyChatAudienceSet extends LazyHashSet<Audience> {
|
||||
+ private final MinecraftServer server;
|
||||
+
|
||||
+ public LazyChatAudienceSet(final MinecraftServer server) {
|
||||
+ this.server = server;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ protected Set<Audience> makeReference() {
|
||||
+ final Set<Player> playerSet = LazyPlayerSet.makePlayerSet(MinecraftServer.getServer());
|
||||
+ final Set<Player> playerSet = LazyPlayerSet.makePlayerSet(this.server);
|
||||
+ final HashSet<Audience> audiences = new HashSet<>(playerSet);
|
||||
+ audiences.add(Bukkit.getConsoleSender());
|
||||
+ return audiences;
|
||||
|
|
Loading…
Reference in a new issue