mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-25 12:05:53 +01:00
Remove chat event APIs marked as deprecated for removal with 1.17
This commit is contained in:
parent
ad7644ce82
commit
3c5bfaddbe
@ -53,76 +53,6 @@ index ef58a6c00f444bd498a2d8fc4e457236f393954f..ecd149157d4fb80444f34bf5633d74bc
|
||||
+ }
|
||||
+ // 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..7d2fb50210246bb42d166f7e6d1c0cdfad0bdb3d
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/chat/ChatComposer.java
|
||||
@@ -0,0 +1,29 @@
|
||||
+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..ba784ab037adfd37b01b222ea33abea00161ecae
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/chat/ChatFormatter.java
|
||||
@@ -0,0 +1,29 @@
|
||||
+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..85fd5d6777b53bab09cc54c360bb75141635bdd3
|
||||
@ -206,26 +136,19 @@ index 0000000000000000000000000000000000000000..85fd5d6777b53bab09cc54c360bb7514
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/event/player/AbstractChatEvent.java b/src/main/java/io/papermc/paper/event/player/AbstractChatEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..718b860ace4077affad715a4e43961e10a83e9d9
|
||||
index 0000000000000000000000000000000000000000..fa03a5cb2d3e3e0a60d84bacc911d96c454f81da
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/event/player/AbstractChatEvent.java
|
||||
@@ -0,0 +1,299 @@
|
||||
@@ -0,0 +1,112 @@
|
||||
+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..718b860ace4077affad715a4e43961e1
|
||||
+ */
|
||||
+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..718b860ace4077affad715a4e43961e1
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * 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..718b860ace4077affad715a4e43961e1
|
||||
+ */
|
||||
+ 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..718b860ace4077affad715a4e43961e1
|
||||
+ */
|
||||
+ @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,26 +251,15 @@ index 0000000000000000000000000000000000000000..718b860ace4077affad715a4e43961e1
|
||||
+ 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
|
||||
index 0000000000000000000000000000000000000000..ee7ec316a2f814ec759e0a3e5dfe5efbee782b22
|
||||
index 0000000000000000000000000000000000000000..0d9e3c23027e3af90cb70e4bb6fb0ac1da35fc4d
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/event/player/AsyncChatEvent.java
|
||||
@@ -0,0 +1,73 @@
|
||||
@@ -0,0 +1,31 @@
|
||||
+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..ee7ec316a2f814ec759e0a3e5dfe5efb
|
||||
+ 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() {
|
||||
@ -590,14 +291,12 @@ index 0000000000000000000000000000000000000000..ee7ec316a2f814ec759e0a3e5dfe5efb
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/event/player/ChatEvent.java b/src/main/java/io/papermc/paper/event/player/ChatEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..c6bcf0dc3f77c631aa7eeb9b1e88b5bbfe445fc6
|
||||
index 0000000000000000000000000000000000000000..eb179aae1e1d2ce842442e49fe275827a430ccd0
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/event/player/ChatEvent.java
|
||||
@@ -0,0 +1,70 @@
|
||||
@@ -0,0 +1,36 @@
|
||||
+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..c6bcf0dc3f77c631aa7eeb9b1e88b5bb
|
||||
+ 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() {
|
||||
|
@ -110,16 +110,17 @@ index 0000000000000000000000000000000000000000..e597a90def72c5903382d7169fb7a2fb
|
||||
+}
|
||||
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..a29b6aaafd529e56a83dd96c32211f21e4aad348
|
||||
index 0000000000000000000000000000000000000000..4e9e0a39b876c900fdee1343d04a7046f5b3f80e
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
@@ -0,0 +1,214 @@
|
||||
@@ -0,0 +1,224 @@
|
||||
+package io.papermc.paper.adventure;
|
||||
+
|
||||
+import io.papermc.paper.chat.ChatRenderer;
|
||||
+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..a29b6aaafd529e56a83dd96c32211f21
|
||||
+ 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..a29b6aaafd529e56a83dd96c32211f21
|
||||
+ 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..a29b6aaafd529e56a83dd96c32211f21
|
||||
+ () -> {
|
||||
+ 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..a29b6aaafd529e56a83dd96c32211f21
|
||||
+ );
|
||||
+ }
|
||||
+
|
||||
+ 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..a29b6aaafd529e56a83dd96c32211f21
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ 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..a29b6aaafd529e56a83dd96c32211f21
|
||||
+ 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..a29b6aaafd529e56a83dd96c32211f21
|
||||
+ 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())) {
|
||||
+ for (final Audience viewer : viewers) {
|
||||
+ viewer.sendMessage(player, renderer.render(player, displayName, message, viewer), MessageType.CHAT);
|
||||
+
|
||||
+ 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 {
|
||||
+ 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);
|
||||
+ for (final Audience viewer : viewers) {
|
||||
+ viewer.sendMessage(player, renderer.render(player, displayName, message, viewer), 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) {
|
||||
@ -358,12 +368,14 @@ index 0000000000000000000000000000000000000000..bfaf5d3c5aae8a587c2b11d90089c588
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/adventure/LazyChatAudienceSet.java b/src/main/java/io/papermc/paper/adventure/LazyChatAudienceSet.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..10f08e2b73610ab06928d1f63348920fef8e91fa
|
||||
index 0000000000000000000000000000000000000000..2fd6c3e65354071af71c7d8ebb97b559b6e105ce
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/LazyChatAudienceSet.java
|
||||
@@ -0,0 +1,21 @@
|
||||
@@ -0,0 +1,26 @@
|
||||
+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..10f08e2b73610ab06928d1f63348920f
|
||||
+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;
|
||||
@ -1374,7 +1389,7 @@ index 8a77e28c9b12a110c721943aca545270ef8bbaef..8b082713c1bd41ff9d26ce45c949514a
|
||||
}
|
||||
// CraftBukkit end
|
||||
diff --git a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
index 3d1f20a5caf8b4665ea0208af755911c34081323..0df683b7503d4c34fc8af33b82a4440383702043 100644
|
||||
index e61752f3d00c6e2324745b92c880ee494f366765..75118458840caadfa82aa0fa2efd8a753b585ef2 100644
|
||||
--- a/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
+++ b/src/main/java/net/minecraft/server/network/ServerLoginPacketListenerImpl.java
|
||||
@@ -36,6 +36,7 @@ import net.minecraft.world.entity.player.Player;
|
||||
|
@ -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 a29b6aaafd529e56a83dd96c32211f21e4aad348..2039f83a718427d0969a1a2e2200f7922097449e 100644
|
||||
index 4e9e0a39b876c900fdee1343d04a7046f5b3f80e..eb0053850f53ceb60eb1ae3ac0e34034648fe1eb 100644
|
||||
--- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
@@ -16,7 +16,11 @@ import net.kyori.adventure.text.TextReplacementConfig;
|
||||
@@ -17,7 +17,11 @@ import net.kyori.adventure.text.TextReplacementConfig;
|
||||
import net.kyori.adventure.text.event.ClickEvent;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@ -41,7 +41,7 @@ index a29b6aaafd529e56a83dd96c32211f21e4aad348..2039f83a718427d0969a1a2e2200f792
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.util.LazyPlayerSet;
|
||||
import org.bukkit.craftbukkit.util.Waitable;
|
||||
@@ -178,10 +182,22 @@ public final class ChatProcessor {
|
||||
@@ -188,10 +192,22 @@ public final class ChatProcessor {
|
||||
}
|
||||
|
||||
private static String legacyDisplayName(final CraftPlayer player) {
|
||||
|
Loading…
Reference in New Issue
Block a user