Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-15 02:50:09 +01:00
Deprecate isPreview method in decorate events (#8645)
Dieser Commit ist enthalten in:
Ursprung
0bdbcd9d56
Commit
d8cf30dfd1
@ -316,10 +316,10 @@ index 0000000000000000000000000000000000000000..fa03a5cb2d3e3e0a60d84bacc911d96c
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/io/papermc/paper/event/player/AsyncChatCommandDecorateEvent.java b/src/main/java/io/papermc/paper/event/player/AsyncChatCommandDecorateEvent.java
|
diff --git a/src/main/java/io/papermc/paper/event/player/AsyncChatCommandDecorateEvent.java b/src/main/java/io/papermc/paper/event/player/AsyncChatCommandDecorateEvent.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..bd216f7333795fc6bc5bec593f9cc0e3c2c1a27e
|
index 0000000000000000000000000000000000000000..feece00981ebf932e64760e7a10a04ad080d0228
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/io/papermc/paper/event/player/AsyncChatCommandDecorateEvent.java
|
+++ b/src/main/java/io/papermc/paper/event/player/AsyncChatCommandDecorateEvent.java
|
||||||
@@ -0,0 +1,27 @@
|
@@ -0,0 +1,28 @@
|
||||||
+package io.papermc.paper.event.player;
|
+package io.papermc.paper.event.player;
|
||||||
+
|
+
|
||||||
+import net.kyori.adventure.text.Component;
|
+import net.kyori.adventure.text.Component;
|
||||||
@ -334,8 +334,9 @@ index 0000000000000000000000000000000000000000..bd216f7333795fc6bc5bec593f9cc0e3
|
|||||||
+
|
+
|
||||||
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||||
+
|
+
|
||||||
+ public AsyncChatCommandDecorateEvent(boolean async, @Nullable Player player, @NotNull Component originalMessage, boolean isPreview, @NotNull Component result) {
|
+ @ApiStatus.Internal
|
||||||
+ super(async, player, originalMessage, isPreview, result);
|
+ public AsyncChatCommandDecorateEvent(boolean async, @Nullable Player player, @NotNull Component originalMessage, @NotNull Component result) {
|
||||||
|
+ super(async, player, originalMessage, result);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
@ -349,10 +350,10 @@ index 0000000000000000000000000000000000000000..bd216f7333795fc6bc5bec593f9cc0e3
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/io/papermc/paper/event/player/AsyncChatDecorateEvent.java b/src/main/java/io/papermc/paper/event/player/AsyncChatDecorateEvent.java
|
diff --git a/src/main/java/io/papermc/paper/event/player/AsyncChatDecorateEvent.java b/src/main/java/io/papermc/paper/event/player/AsyncChatDecorateEvent.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..347122b12ad98115133ef98db69b271ee0cec194
|
index 0000000000000000000000000000000000000000..092b5b12053315d355607ccf72e2d6b9e6befcf8
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/io/papermc/paper/event/player/AsyncChatDecorateEvent.java
|
+++ b/src/main/java/io/papermc/paper/event/player/AsyncChatDecorateEvent.java
|
||||||
@@ -0,0 +1,119 @@
|
@@ -0,0 +1,116 @@
|
||||||
+package io.papermc.paper.event.player;
|
+package io.papermc.paper.event.player;
|
||||||
+
|
+
|
||||||
+import net.kyori.adventure.text.Component;
|
+import net.kyori.adventure.text.Component;
|
||||||
@ -361,20 +362,16 @@ index 0000000000000000000000000000000000000000..347122b12ad98115133ef98db69b271e
|
|||||||
+import org.bukkit.event.HandlerList;
|
+import org.bukkit.event.HandlerList;
|
||||||
+import org.bukkit.event.server.ServerEvent;
|
+import org.bukkit.event.server.ServerEvent;
|
||||||
+import org.jetbrains.annotations.ApiStatus;
|
+import org.jetbrains.annotations.ApiStatus;
|
||||||
|
+import org.jetbrains.annotations.Contract;
|
||||||
+import org.jetbrains.annotations.NotNull;
|
+import org.jetbrains.annotations.NotNull;
|
||||||
+import org.jetbrains.annotations.Nullable;
|
+import org.jetbrains.annotations.Nullable;
|
||||||
+
|
+
|
||||||
+/**
|
+/**
|
||||||
+ * This event is fired when the server decorates a component for chat purposes. It can be called
|
+ * This event is fired when the server decorates a component for chat purposes. This is called
|
||||||
+ * under the following circumstances:
|
+ * before {@link AsyncChatEvent} and the other chat events. It is recommended that you modify the
|
||||||
+ * <ul>
|
+ * message here, and use the chat events for modifying receivers and later the chat type. If you
|
||||||
+ * <li><b>Previewing:</b> If the client requests a preview response, this event is fired to decorate the component
|
+ * want to keep the message as "signed" for the clients who get it, be sure to include the entire
|
||||||
+ * before it is sent back to the client for signing.</li>
|
+ * original message somewhere in the final message.
|
||||||
+ * <li><b>Chat:</b> If the client sends a chat packet without having signed a preview (the client could have previews
|
|
||||||
+ * disabled or they sent the message too quickly) this event is fired to generated the decorated component. Note
|
|
||||||
+ * that when this is the case, the message will show up as modified as the decorated component wasn't signed
|
|
||||||
+ * by the client.</li>
|
|
||||||
+ * </ul>
|
|
||||||
+ * @see AsyncChatCommandDecorateEvent for the decoration of messages sent via commands
|
+ * @see AsyncChatCommandDecorateEvent for the decoration of messages sent via commands
|
||||||
+ */
|
+ */
|
||||||
+@ApiStatus.Experimental
|
+@ApiStatus.Experimental
|
||||||
@ -384,16 +381,14 @@ index 0000000000000000000000000000000000000000..347122b12ad98115133ef98db69b271e
|
|||||||
+
|
+
|
||||||
+ private final Player player;
|
+ private final Player player;
|
||||||
+ private final Component originalMessage;
|
+ private final Component originalMessage;
|
||||||
+ private final boolean isPreview;
|
|
||||||
+ private Component result;
|
+ private Component result;
|
||||||
+ private boolean cancelled;
|
+ private boolean cancelled;
|
||||||
+
|
+
|
||||||
+ @ApiStatus.Internal
|
+ @ApiStatus.Internal
|
||||||
+ public AsyncChatDecorateEvent(final boolean async, final @Nullable Player player, final @NotNull Component originalMessage, final boolean isPreview, final @NotNull Component result) {
|
+ public AsyncChatDecorateEvent(final boolean async, final @Nullable Player player, final @NotNull Component originalMessage, final @NotNull Component result) {
|
||||||
+ super(async);
|
+ super(async);
|
||||||
+ this.player = player;
|
+ this.player = player;
|
||||||
+ this.originalMessage = originalMessage;
|
+ this.originalMessage = originalMessage;
|
||||||
+ this.isPreview = isPreview;
|
|
||||||
+ this.result = result;
|
+ this.result = result;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
@ -443,9 +438,12 @@ index 0000000000000000000000000000000000000000..347122b12ad98115133ef98db69b271e
|
|||||||
+ * If this decorating is part of a preview request/response.
|
+ * If this decorating is part of a preview request/response.
|
||||||
+ *
|
+ *
|
||||||
+ * @return true if part of previewing
|
+ * @return true if part of previewing
|
||||||
|
+ * @deprecated chat preview was removed in 1.19.2
|
||||||
+ */
|
+ */
|
||||||
|
+ @Deprecated(forRemoval = true)
|
||||||
|
+ @Contract(value = "-> false", pure = true)
|
||||||
+ public boolean isPreview() {
|
+ public boolean isPreview() {
|
||||||
+ return this.isPreview;
|
+ return false;
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
+ @Override
|
+ @Override
|
||||||
|
@ -100,10 +100,10 @@ index 0000000000000000000000000000000000000000..07cd02c6f9df00844b808218be2afd79
|
|||||||
+}
|
+}
|
||||||
diff --git a/src/main/java/io/papermc/paper/adventure/ChatDecorationProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatDecorationProcessor.java
|
diff --git a/src/main/java/io/papermc/paper/adventure/ChatDecorationProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatDecorationProcessor.java
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000000000000000000000000000000000000..a9c2b67cab07b3a4e996159176919c7695f62951
|
index 0000000000000000000000000000000000000000..e7671b9e2fc5ed01461e4ae1557dfc14075e61bd
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/src/main/java/io/papermc/paper/adventure/ChatDecorationProcessor.java
|
+++ b/src/main/java/io/papermc/paper/adventure/ChatDecorationProcessor.java
|
||||||
@@ -0,0 +1,140 @@
|
@@ -0,0 +1,145 @@
|
||||||
+package io.papermc.paper.adventure;
|
+package io.papermc.paper.adventure;
|
||||||
+
|
+
|
||||||
+import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
+import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||||
@ -157,13 +157,19 @@ index 0000000000000000000000000000000000000000..a9c2b67cab07b3a4e996159176919c76
|
|||||||
+ public CompletableFuture<ChatDecorator.Result> process() {
|
+ public CompletableFuture<ChatDecorator.Result> process() {
|
||||||
+ return CompletableFuture.supplyAsync(() -> {
|
+ return CompletableFuture.supplyAsync(() -> {
|
||||||
+ ChatDecorator.Result result = new ChatDecorator.ModernResult(this.originalMessage, true, false);
|
+ ChatDecorator.Result result = new ChatDecorator.ModernResult(this.originalMessage, true, false);
|
||||||
+ if (canYouHearMe(AsyncPlayerChatPreviewEvent.getHandlerList())) {
|
+ if (listenToLegacy()) {
|
||||||
+ result = this.processLegacy(result);
|
+ result = this.processLegacy(result);
|
||||||
+ }
|
+ }
|
||||||
+ return this.processModern(result);
|
+ return this.processModern(result);
|
||||||
+ }, this.server.chatExecutor);
|
+ }, this.server.chatExecutor);
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
|
+ @SuppressWarnings("deprecation")
|
||||||
|
+ private static boolean listenToLegacy() {
|
||||||
|
+ return canYouHearMe(AsyncPlayerChatPreviewEvent.getHandlerList());
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @SuppressWarnings("deprecation")
|
||||||
+ private ChatDecorator.Result processLegacy(final ChatDecorator.Result input) {
|
+ private ChatDecorator.Result processLegacy(final ChatDecorator.Result input) {
|
||||||
+ if (this.player != null) {
|
+ if (this.player != null) {
|
||||||
+ final CraftPlayer player = this.player.getBukkitEntity();
|
+ final CraftPlayer player = this.player.getBukkitEntity();
|
||||||
@ -188,12 +194,11 @@ index 0000000000000000000000000000000000000000..a9c2b67cab07b3a4e996159176919c76
|
|||||||
+
|
+
|
||||||
+ final Component initialResult = input.message().component();
|
+ final Component initialResult = input.message().component();
|
||||||
+ final AsyncChatDecorateEvent event;
|
+ final AsyncChatDecorateEvent event;
|
||||||
+ //TODO
|
|
||||||
+ if (this.commandSourceStack != null) {
|
+ if (this.commandSourceStack != null) {
|
||||||
+ // TODO more command decorate context
|
+ // TODO more command decorate context
|
||||||
+ event = new AsyncChatCommandDecorateEvent(true, player, this.originalMessage, false, initialResult);
|
+ event = new AsyncChatCommandDecorateEvent(true, player, this.originalMessage, initialResult);
|
||||||
+ } else {
|
+ } else {
|
||||||
+ event = new AsyncChatDecorateEvent(true, player, this.originalMessage, false, initialResult);
|
+ event = new AsyncChatDecorateEvent(true, player, this.originalMessage, initialResult);
|
||||||
+ }
|
+ }
|
||||||
+ this.post(event);
|
+ this.post(event);
|
||||||
+ if (!event.isCancelled() && !event.result().equals(initialResult)) {
|
+ if (!event.isCancelled() && !event.result().equals(initialResult)) {
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren