mirror of
https://github.com/PaperMC/Paper.git
synced 2024-10-31 16:00:18 +01:00
Remove dead code (LegacyResult) (#10411)
* Stop firing AsyncPlayerChatPreviewEvent as chat preview was removed in 1.19.3. This is in parity with upstream * formatting and small tweaks * correctly set MESSAGE_CHANGED flag for modern modifications --------- Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
This commit is contained in:
parent
862299b6a6
commit
9e886c4310
@ -340,7 +340,7 @@ index 0000000000000000000000000000000000000000..a0fd845bc9b2540c398fe1dbbf821803
|
||||
+}
|
||||
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
|
||||
index 0000000000000000000000000000000000000000..feece00981ebf932e64760e7a10a04ad080d0228
|
||||
index 0000000000000000000000000000000000000000..01cf89d3558132912c4d0eb48c98cd8c06e46a67
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/event/player/AsyncChatCommandDecorateEvent.java
|
||||
@@ -0,0 +1,28 @@
|
||||
@ -359,8 +359,8 @@ index 0000000000000000000000000000000000000000..feece00981ebf932e64760e7a10a04ad
|
||||
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
+
|
||||
+ @ApiStatus.Internal
|
||||
+ public AsyncChatCommandDecorateEvent(boolean async, @Nullable Player player, @NotNull Component originalMessage, @NotNull Component result) {
|
||||
+ super(async, player, originalMessage, result);
|
||||
+ public AsyncChatCommandDecorateEvent(@Nullable Player player, @NotNull Component originalMessage) {
|
||||
+ super(player, originalMessage);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
@ -374,17 +374,16 @@ index 0000000000000000000000000000000000000000..feece00981ebf932e64760e7a10a04ad
|
||||
+}
|
||||
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
|
||||
index 0000000000000000000000000000000000000000..9e1eb774d841e2c7ffa8bef688d832bdffaa0944
|
||||
index 0000000000000000000000000000000000000000..d4c01e4d332b46f0b129dd5f9e9737ba19923562
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/event/player/AsyncChatDecorateEvent.java
|
||||
@@ -0,0 +1,120 @@
|
||||
@@ -0,0 +1,118 @@
|
||||
+package io.papermc.paper.event.player;
|
||||
+
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.Cancellable;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.player.AsyncPlayerChatPreviewEvent;
|
||||
+import org.bukkit.event.server.ServerEvent;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.Contract;
|
||||
@ -412,11 +411,11 @@ index 0000000000000000000000000000000000000000..9e1eb774d841e2c7ffa8bef688d832bd
|
||||
+ private boolean cancelled;
|
||||
+
|
||||
+ @ApiStatus.Internal
|
||||
+ public AsyncChatDecorateEvent(final boolean async, final @Nullable Player player, final @NotNull Component originalMessage, final @NotNull Component result) {
|
||||
+ super(async);
|
||||
+ public AsyncChatDecorateEvent(final @Nullable Player player, final @NotNull Component originalMessage) {
|
||||
+ super(true);
|
||||
+ this.player = player;
|
||||
+ this.originalMessage = originalMessage;
|
||||
+ this.result = result;
|
||||
+ this.result = originalMessage;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
@ -443,7 +442,6 @@ index 0000000000000000000000000000000000000000..9e1eb774d841e2c7ffa8bef688d832bd
|
||||
+ /**
|
||||
+ * Gets the decoration result. This may already be different from
|
||||
+ * {@link #originalMessage()} if some other listener to this event
|
||||
+ * <b>OR</b> the legacy preview event ({@link AsyncPlayerChatPreviewEvent})
|
||||
+ * changed the result.
|
||||
+ *
|
||||
+ * @return the result
|
||||
|
@ -14,7 +14,7 @@ Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/adventure/AdventureCodecs.java b/src/main/java/io/papermc/paper/adventure/AdventureCodecs.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..215ccf169d4e8522da5495768d33cf3e5cd92690
|
||||
index 0000000000000000000000000000000000000000..9090b0ebcd3ceecb14f83b274ad364d6ea17d1f4
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/AdventureCodecs.java
|
||||
@@ -0,0 +1,418 @@
|
||||
@ -416,7 +416,7 @@ index 0000000000000000000000000000000000000000..215ccf169d4e8522da5495768d33cf3e
|
||||
+ });
|
||||
+ }
|
||||
+
|
||||
+ static @Nullable String tryCollapseToString(final Component component) {
|
||||
+ public static @Nullable String tryCollapseToString(final Component component) {
|
||||
+ if (component instanceof final TextComponent textComponent) {
|
||||
+ if (component.children().isEmpty() && component.style().isEmpty()) {
|
||||
+ return textComponent.content();
|
||||
@ -611,163 +611,12 @@ index 0000000000000000000000000000000000000000..23bd6d2d8fed5a3491e856f8b875456d
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
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
|
||||
index 0000000000000000000000000000000000000000..3b53d87a52cafb2503419f21ddd87d42a5ec0330
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/ChatDecorationProcessor.java
|
||||
@@ -0,0 +1,145 @@
|
||||
+package io.papermc.paper.adventure;
|
||||
+
|
||||
+import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||
+import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||
+import java.util.ArrayList;
|
||||
+import java.util.List;
|
||||
+import java.util.concurrent.CompletableFuture;
|
||||
+import java.util.regex.Pattern;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
+import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
+import net.minecraft.Optionull;
|
||||
+import net.minecraft.commands.CommandSourceStack;
|
||||
+import net.minecraft.network.chat.ChatDecorator;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
+import net.minecraft.server.level.ServerPlayer;
|
||||
+import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
+import org.bukkit.craftbukkit.util.LazyPlayerSet;
|
||||
+import org.bukkit.event.Event;
|
||||
+import org.bukkit.event.player.AsyncPlayerChatPreviewEvent;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+
|
||||
+import static io.papermc.paper.adventure.ChatProcessor.DEFAULT_LEGACY_FORMAT;
|
||||
+import static io.papermc.paper.adventure.ChatProcessor.canYouHearMe;
|
||||
+import static io.papermc.paper.adventure.ChatProcessor.displayName;
|
||||
+import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+public final class ChatDecorationProcessor {
|
||||
+
|
||||
+ private static final String DISPLAY_NAME_TAG = "---paper_dn---";
|
||||
+ private static final Pattern DISPLAY_NAME_PATTERN = Pattern.compile("%(1\\$)?s");
|
||||
+ private static final String CONTENT_TAG = "---paper_content---";
|
||||
+ private static final Pattern CONTENT_PATTERN = Pattern.compile("%(2\\$)?s");
|
||||
+
|
||||
+ final MinecraftServer server;
|
||||
+ final @Nullable ServerPlayer player;
|
||||
+ final @Nullable CommandSourceStack commandSourceStack;
|
||||
+ final Component originalMessage;
|
||||
+
|
||||
+ public ChatDecorationProcessor(final MinecraftServer server, final @Nullable ServerPlayer player, final @Nullable CommandSourceStack commandSourceStack, final net.minecraft.network.chat.Component originalMessage) {
|
||||
+ this.server = server;
|
||||
+ this.player = player;
|
||||
+ this.commandSourceStack = commandSourceStack;
|
||||
+ this.originalMessage = PaperAdventure.asAdventure(originalMessage);
|
||||
+ }
|
||||
+
|
||||
+ public CompletableFuture<ChatDecorator.Result> process() {
|
||||
+ return CompletableFuture.supplyAsync(() -> {
|
||||
+ ChatDecorator.Result result = new ChatDecorator.ModernResult(this.originalMessage, true, false);
|
||||
+ if (listenToLegacy()) {
|
||||
+ result = this.processLegacy(result);
|
||||
+ }
|
||||
+ return this.processModern(result);
|
||||
+ }, this.server.chatExecutor);
|
||||
+ }
|
||||
+
|
||||
+ @SuppressWarnings("deprecation")
|
||||
+ private static boolean listenToLegacy() {
|
||||
+ return canYouHearMe(AsyncPlayerChatPreviewEvent.getHandlerList());
|
||||
+ }
|
||||
+
|
||||
+ @SuppressWarnings("deprecation")
|
||||
+ private ChatDecorator.Result processLegacy(final ChatDecorator.Result input) {
|
||||
+ if (this.player != null) {
|
||||
+ final CraftPlayer player = this.player.getBukkitEntity();
|
||||
+ final String originalMessage = legacySection().serialize(this.originalMessage);
|
||||
+ final AsyncPlayerChatPreviewEvent event = new AsyncPlayerChatPreviewEvent(true, player, originalMessage, new LazyPlayerSet(this.server));
|
||||
+ this.post(event);
|
||||
+
|
||||
+ final boolean isDefaultFormat = DEFAULT_LEGACY_FORMAT.equals(event.getFormat());
|
||||
+ if (event.isCancelled() || (isDefaultFormat && originalMessage.equals(event.getMessage()))) {
|
||||
+ return input;
|
||||
+ } else {
|
||||
+ final Component message = legacySection().deserialize(event.getMessage());
|
||||
+ final Component component = isDefaultFormat ? message : legacyFormat(event.getFormat(), ((CraftPlayer) event.getPlayer()), legacySection().deserialize(event.getMessage()));
|
||||
+ return legacy(component, event.getFormat(), new ChatDecorator.MessagePair(message, event.getMessage()), isDefaultFormat);
|
||||
+ }
|
||||
+ }
|
||||
+ return input;
|
||||
+ }
|
||||
+
|
||||
+ private ChatDecorator.Result processModern(final ChatDecorator.Result input) {
|
||||
+ final @Nullable CraftPlayer player = Optionull.map(this.player, ServerPlayer::getBukkitEntity);
|
||||
+
|
||||
+ final Component initialResult = input.message().component();
|
||||
+ final AsyncChatDecorateEvent event;
|
||||
+ if (this.commandSourceStack != null) {
|
||||
+ // TODO more command decorate context
|
||||
+ event = new AsyncChatCommandDecorateEvent(true, player, this.originalMessage, initialResult);
|
||||
+ } else {
|
||||
+ event = new AsyncChatDecorateEvent(true, player, this.originalMessage, initialResult);
|
||||
+ }
|
||||
+ this.post(event);
|
||||
+ if (!event.isCancelled() && !event.result().equals(initialResult)) {
|
||||
+ if (input instanceof ChatDecorator.LegacyResult legacyResult) {
|
||||
+ if (legacyResult.hasNoFormatting()) {
|
||||
+ /*
|
||||
+ The MessagePair in the decoration result may be different at this point. This is because the legacy
|
||||
+ decoration system requires the same modifications be made to the message, so we can't have the initial
|
||||
+ message value for the legacy chat events be changed by the modern decorate event.
|
||||
+ */
|
||||
+ return noFormatting(event.result(), legacyResult.format(), legacyResult.message().legacyMessage());
|
||||
+ } else {
|
||||
+ final Component formatted = legacyFormat(legacyResult.format(), player, event.result());
|
||||
+ return withFormatting(formatted, legacyResult.format(), event.result(), legacyResult.message().legacyMessage());
|
||||
+ }
|
||||
+ } else {
|
||||
+ return new ChatDecorator.ModernResult(event.result(), true, false);
|
||||
+ }
|
||||
+ }
|
||||
+ return input;
|
||||
+ }
|
||||
+
|
||||
+ private void post(final Event event) {
|
||||
+ this.server.server.getPluginManager().callEvent(event);
|
||||
+ }
|
||||
+
|
||||
+ private static Component legacyFormat(final String format, final @Nullable CraftPlayer player, final Component message) {
|
||||
+ final List<TagResolver.Single> args = new ArrayList<>(player != null ? 2 : 1);
|
||||
+ if (player != null) {
|
||||
+ args.add(Placeholder.component(DISPLAY_NAME_TAG, displayName(player)));
|
||||
+ }
|
||||
+ args.add(Placeholder.component(CONTENT_TAG, message));
|
||||
+ String miniMsg = MiniMessage.miniMessage().serialize(legacySection().deserialize(format));
|
||||
+ miniMsg = DISPLAY_NAME_PATTERN.matcher(miniMsg).replaceFirst("<" + DISPLAY_NAME_TAG + ">");
|
||||
+ miniMsg = CONTENT_PATTERN.matcher(miniMsg).replaceFirst("<" + CONTENT_TAG + ">");
|
||||
+ return MiniMessage.miniMessage().deserialize(miniMsg, TagResolver.resolver(args));
|
||||
+ }
|
||||
+
|
||||
+ public static ChatDecorator.LegacyResult legacy(final Component maybeFormatted, final String format, final ChatDecorator.MessagePair message, final boolean hasNoFormatting) {
|
||||
+ return new ChatDecorator.LegacyResult(maybeFormatted, format, message, hasNoFormatting, false);
|
||||
+ }
|
||||
+
|
||||
+ public static ChatDecorator.LegacyResult noFormatting(final Component component, final String format, final String legacyMessage) {
|
||||
+ return new ChatDecorator.LegacyResult(component, format, new ChatDecorator.MessagePair(component, legacyMessage), true, true);
|
||||
+ }
|
||||
+
|
||||
+ public static ChatDecorator.LegacyResult withFormatting(final Component formatted, final String format, final Component message, final String legacyMessage) {
|
||||
+ return new ChatDecorator.LegacyResult(formatted, format, new ChatDecorator.MessagePair(message, legacyMessage), false, true);
|
||||
+ }
|
||||
+}
|
||||
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..57081e84d50f7eca7ea11540b550da8269378e9e
|
||||
index 0000000000000000000000000000000000000000..bfb1904be53112cdff62001c3307c7d5ef89704c
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
@@ -0,0 +1,414 @@
|
||||
@@ -0,0 +1,376 @@
|
||||
+package io.papermc.paper.adventure;
|
||||
+
|
||||
+import io.papermc.paper.chat.ChatRenderer;
|
||||
@ -789,10 +638,10 @@ index 0000000000000000000000000000000000000000..57081e84d50f7eca7ea11540b550da82
|
||||
+import net.kyori.adventure.audience.ForwardingAudience;
|
||||
+import net.kyori.adventure.key.Key;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
+import net.minecraft.Optionull;
|
||||
+import net.minecraft.Util;
|
||||
+import net.minecraft.core.registries.Registries;
|
||||
+import net.minecraft.network.chat.ChatDecorator;
|
||||
+import net.minecraft.network.chat.ChatType;
|
||||
+import net.minecraft.network.chat.OutgoingChatMessage;
|
||||
+import net.minecraft.network.chat.PlayerChatMessage;
|
||||
@ -812,6 +661,7 @@ index 0000000000000000000000000000000000000000..57081e84d50f7eca7ea11540b550da82
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+import org.intellij.lang.annotations.Subst;
|
||||
+
|
||||
+import static net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection;
|
||||
+
|
||||
@ -830,33 +680,15 @@ index 0000000000000000000000000000000000000000..57081e84d50f7eca7ea11540b550da82
|
||||
+ static final int MESSAGE_CHANGED = 1;
|
||||
+ static final int FORMAT_CHANGED = 2;
|
||||
+ static final int SENDER_CHANGED = 3; // Not used
|
||||
+ // static final int FORCE_PREVIEW_USE = 4; // TODO (future, maybe?)
|
||||
+ private final BitSet flags = new BitSet(3);
|
||||
+
|
||||
+ public ChatProcessor(final MinecraftServer server, final ServerPlayer player, final PlayerChatMessage message, final boolean async) {
|
||||
+ this.server = server;
|
||||
+ this.player = player;
|
||||
+ /*
|
||||
+ CraftBukkit's preview/decoration system relies on both the "decorate" and chat event making the same modifications. If
|
||||
+ there is unsigned content in the legacyMessage, that is because the player sent the legacyMessage without it being
|
||||
+ previewed (probably by sending it too quickly). We can just ignore that because the same changes will
|
||||
+ happen in the chat event.
|
||||
+
|
||||
+ If unsigned content is present, it will be the same as `this.legacyMessage.signedContent().previewResult().component()`.
|
||||
+ */
|
||||
+ this.message = message;
|
||||
+ this.async = async;
|
||||
+ if (this.message.requireResult().modernized()) {
|
||||
+ this.craftbukkit$originalMessage = this.message.requireResult().message().legacyMessage();
|
||||
+ } else {
|
||||
+ this.craftbukkit$originalMessage = message.signedContent();
|
||||
+ }
|
||||
+ /*
|
||||
+ this.paper$originalMessage is the input to paper's chat events. This should be the decorated message component.
|
||||
+ Even if the legacy preview event modified the format, and the client signed the formatted message, this should
|
||||
+ still just be the message component.
|
||||
+ */
|
||||
+ this.paper$originalMessage = this.message.requireResult().message().component();
|
||||
+ this.craftbukkit$originalMessage = message.unsignedContent() != null ? LegacyComponentSerializer.legacySection().serialize(PaperAdventure.asAdventure(message.unsignedContent())) : message.signedContent();
|
||||
+ this.paper$originalMessage = PaperAdventure.asAdventure(this.message.decoratedContent());
|
||||
+ this.outgoing = OutgoingChatMessage.create(this.message);
|
||||
+ }
|
||||
+
|
||||
@ -910,8 +742,6 @@ index 0000000000000000000000000000000000000000..57081e84d50f7eca7ea11540b550da82
|
||||
+ private ChatRenderer modernRenderer(final String format) {
|
||||
+ if (this.flags.get(FORMAT_CHANGED)) {
|
||||
+ return legacyRenderer(format);
|
||||
+ } else if (this.message.requireResult() instanceof ChatDecorator.LegacyResult legacyResult) {
|
||||
+ return legacyRenderer(legacyResult.format());
|
||||
+ } else {
|
||||
+ return defaultRenderer();
|
||||
+ }
|
||||
@ -920,25 +750,14 @@ index 0000000000000000000000000000000000000000..57081e84d50f7eca7ea11540b550da82
|
||||
+ private Component modernMessage(final String legacyMessage) {
|
||||
+ if (this.flags.get(MESSAGE_CHANGED)) {
|
||||
+ return legacySection().deserialize(legacyMessage);
|
||||
+ } else if (this.message.unsignedContent() == null && this.message.requireResult() instanceof ChatDecorator.LegacyResult legacyResult) {
|
||||
+ return legacyResult.message().component();
|
||||
+ } else {
|
||||
+ return this.paper$originalMessage;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private void readLegacyModifications(final String message, final String format, final Player playerSender) {
|
||||
+ if (this.message.requireResult() instanceof ChatDecorator.LegacyResult result) {
|
||||
+ if (this.message.unsignedContent() != null && !result.modernized()) {
|
||||
+ this.flags.set(MESSAGE_CHANGED, !message.equals(result.message().legacyMessage()));
|
||||
+ } else {
|
||||
+ this.flags.set(MESSAGE_CHANGED, !message.equals(this.craftbukkit$originalMessage));
|
||||
+ }
|
||||
+ this.flags.set(FORMAT_CHANGED, !format.equals(result.format()));
|
||||
+ } else {
|
||||
+ this.flags.set(MESSAGE_CHANGED, !message.equals(this.craftbukkit$originalMessage));
|
||||
+ this.flags.set(FORMAT_CHANGED, !format.equals(DEFAULT_LEGACY_FORMAT));
|
||||
+ }
|
||||
+ this.flags.set(SENDER_CHANGED, playerSender != this.player.getBukkitEntity());
|
||||
+ }
|
||||
+
|
||||
@ -967,15 +786,10 @@ index 0000000000000000000000000000000000000000..57081e84d50f7eca7ea11540b550da82
|
||||
+ }
|
||||
+
|
||||
+ private void readModernModifications(final AbstractChatEvent chatEvent, final ChatRenderer originalRenderer) {
|
||||
+ if (this.message.unsignedContent() != null) {
|
||||
+ this.flags.set(MESSAGE_CHANGED, !chatEvent.message().equals(this.message.requireResult().message().component()));
|
||||
+ } else {
|
||||
+ this.flags.set(MESSAGE_CHANGED, !chatEvent.message().equals(this.paper$originalMessage));
|
||||
+ }
|
||||
+ if (originalRenderer != chatEvent.renderer()) { // don't set to false if it hasn't changed
|
||||
+ this.flags.set(FORMAT_CHANGED, true);
|
||||
+ }
|
||||
+ // this.flags.set(FORCE_PREVIEW_USE, chatEvent.usePreviewComponent()); // TODO (future, maybe?)
|
||||
+ }
|
||||
+
|
||||
+ private void complete(final AbstractChatEvent event) {
|
||||
@ -993,9 +807,6 @@ index 0000000000000000000000000000000000000000..57081e84d50f7eca7ea11540b550da82
|
||||
+ final ChatType.Bound chatType = ChatType.bind(chatTypeKey, this.player.level().registryAccess(), PaperAdventure.asVanilla(displayName(player)));
|
||||
+
|
||||
+ OutgoingChat outgoingChat = viewers instanceof LazyChatAudienceSet lazyAudienceSet && lazyAudienceSet.isLazy() ? new ServerOutgoingChat() : new ViewersOutgoingChat();
|
||||
+ /* if (this.flags.get(FORCE_PREVIEW_USE)) { // TODO (future, maybe?)
|
||||
+ outgoingChat.sendOriginal(player, viewers, chatType);
|
||||
+ } else */
|
||||
+ if (this.flags.get(FORMAT_CHANGED)) {
|
||||
+ if (renderer instanceof ChatRenderer.ViewerUnaware unaware) {
|
||||
+ outgoingChat.sendFormatChangedViewerUnaware(player, PaperAdventure.asVanilla(unaware.render(player, displayName, message)), viewers, chatType);
|
||||
@ -1004,7 +815,7 @@ index 0000000000000000000000000000000000000000..57081e84d50f7eca7ea11540b550da82
|
||||
+ }
|
||||
+ } else if (this.flags.get(MESSAGE_CHANGED)) {
|
||||
+ if (!(renderer instanceof ChatRenderer.ViewerUnaware unaware)) {
|
||||
+ throw new IllegalStateException("BUG: There should not be a non-legacy renderer at this point");
|
||||
+ throw new IllegalStateException("BUG: This should be a ViewerUnaware renderer at this point");
|
||||
+ }
|
||||
+ final Component renderedComponent = chatTypeKey == ChatType.CHAT ? message : unaware.render(player, displayName, message);
|
||||
+ outgoingChat.sendMessageChanged(player, PaperAdventure.asVanilla(renderedComponent), viewers, chatType);
|
||||
@ -1085,7 +896,7 @@ index 0000000000000000000000000000000000000000..57081e84d50f7eca7ea11540b550da82
|
||||
+ });
|
||||
+
|
||||
+ private net.kyori.adventure.chat.ChatType.Bound adventure(ChatType.Bound chatType) {
|
||||
+ final String stringKey = Objects.requireNonNull(
|
||||
+ @Subst("key:value") final String stringKey = Objects.requireNonNull(
|
||||
+ ChatProcessor.this.server.registryAccess().registryOrThrow(Registries.CHAT_TYPE).getKey(chatType.chatType()),
|
||||
+ () -> "No key for '%s' in CHAT_TYPE registry.".formatted(chatType)
|
||||
+ ).toString();
|
||||
@ -1213,6 +1024,67 @@ index 0000000000000000000000000000000000000000..d496a9a6ad229e42f1c44e31eafa6974
|
||||
+ return LegacyComponentSerializer.legacySection().serialize(player.adventure$displayName);
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/adventure/ImprovedChatDecorator.java b/src/main/java/io/papermc/paper/adventure/ImprovedChatDecorator.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..0848ad9c7a6d386f0219b75df1ae4d08ba23aa59
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/ImprovedChatDecorator.java
|
||||
@@ -0,0 +1,55 @@
|
||||
+package io.papermc.paper.adventure;
|
||||
+
|
||||
+import io.papermc.paper.event.player.AsyncChatCommandDecorateEvent;
|
||||
+import io.papermc.paper.event.player.AsyncChatDecorateEvent;
|
||||
+import java.util.concurrent.CompletableFuture;
|
||||
+import net.minecraft.commands.CommandSourceStack;
|
||||
+import net.minecraft.network.chat.ChatDecorator;
|
||||
+import net.minecraft.network.chat.Component;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
+import net.minecraft.server.level.ServerPlayer;
|
||||
+import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
+import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
+import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
+import org.checkerframework.framework.qual.DefaultQualifier;
|
||||
+
|
||||
+@DefaultQualifier(NonNull.class)
|
||||
+public final class ImprovedChatDecorator implements ChatDecorator {
|
||||
+ private final MinecraftServer server;
|
||||
+
|
||||
+ public ImprovedChatDecorator(final MinecraftServer server) {
|
||||
+ this.server = server;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public CompletableFuture<Component> decorate(final @Nullable ServerPlayer sender, final Component message) {
|
||||
+ return decorate(this.server, sender, null, message);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public CompletableFuture<Component> decorate(final @Nullable ServerPlayer sender, final @Nullable CommandSourceStack commandSourceStack, final Component message) {
|
||||
+ return decorate(this.server, sender, commandSourceStack, message);
|
||||
+ }
|
||||
+
|
||||
+ private static CompletableFuture<Component> decorate(final MinecraftServer server, final @Nullable ServerPlayer player, final @Nullable CommandSourceStack commandSourceStack, final Component originalMessage) {
|
||||
+ return CompletableFuture.supplyAsync(() -> {
|
||||
+ final net.kyori.adventure.text.Component initialResult = PaperAdventure.asAdventure(originalMessage);
|
||||
+
|
||||
+ final @Nullable CraftPlayer craftPlayer = player == null ? null : player.getBukkitEntity();
|
||||
+
|
||||
+ final AsyncChatDecorateEvent event;
|
||||
+ if (commandSourceStack != null) {
|
||||
+ // TODO more command decorate context
|
||||
+ event = new AsyncChatCommandDecorateEvent(craftPlayer, initialResult);
|
||||
+ } else {
|
||||
+ event = new AsyncChatDecorateEvent(craftPlayer, initialResult);
|
||||
+ }
|
||||
+
|
||||
+ if (event.callEvent()) {
|
||||
+ return PaperAdventure.asVanilla(event.result());
|
||||
+ }
|
||||
+
|
||||
+ return originalMessage;
|
||||
+ }, server.chatExecutor);
|
||||
+ }
|
||||
+}
|
||||
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..2fd6c3e65354071af71c7d8ebb97b559b6e105ce
|
||||
@ -1247,7 +1119,7 @@ index 0000000000000000000000000000000000000000..2fd6c3e65354071af71c7d8ebb97b559
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..032d23ecda574ed1a3c740c16d13055f399bd6c4
|
||||
index 0000000000000000000000000000000000000000..5bacfadf01777171e51858d450a68135d422bf0f
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
||||
@@ -0,0 +1,421 @@
|
||||
@ -1401,7 +1273,7 @@ index 0000000000000000000000000000000000000000..032d23ecda574ed1a3c740c16d13055f
|
||||
+
|
||||
+ // Component
|
||||
+
|
||||
+ public static Component asAdventure(final net.minecraft.network.chat.Component component) {
|
||||
+ public static @NotNull Component asAdventure(@Nullable final net.minecraft.network.chat.Component component) {
|
||||
+ return component == null ? Component.empty() : WRAPPER_AWARE_SERIALIZER.deserialize(component);
|
||||
+ }
|
||||
+
|
||||
@ -1429,7 +1301,7 @@ index 0000000000000000000000000000000000000000..032d23ecda574ed1a3c740c16d13055f
|
||||
+ return jsons;
|
||||
+ }
|
||||
+
|
||||
+ public static net.minecraft.network.chat.Component asVanilla(final Component component) {
|
||||
+ public static net.minecraft.network.chat.Component asVanilla(@Nullable final Component component) {
|
||||
+ if (component == null) return null;
|
||||
+ if (true) return new AdventureComponent(component);
|
||||
+ return WRAPPER_AWARE_SERIALIZER.serialize(component);
|
||||
@ -2131,7 +2003,7 @@ index db93483cfee13ca4303d7452ecbb47507dc5f89e..f6938c35ac6f6116084d3e7ec9cdc918
|
||||
public CommandSourceStack(CommandSource output, Vec3 pos, Vec2 rot, ServerLevel world, int level, String name, Component displayName, MinecraftServer server, @Nullable Entity entity) {
|
||||
this(output, pos, rot, world, level, name, displayName, server, entity, false, CommandResultCallback.EMPTY, EntityAnchorArgument.Anchor.FEET, CommandSigningContext.ANONYMOUS, TaskChainer.immediate(server));
|
||||
diff --git a/src/main/java/net/minecraft/commands/arguments/MessageArgument.java b/src/main/java/net/minecraft/commands/arguments/MessageArgument.java
|
||||
index 7511445f48d9f13106b5d45b5d5bae9172fccfe4..43a47a6d8e5043ef743c5c2d8fb802d8ba3cb8ec 100644
|
||||
index 7511445f48d9f13106b5d45b5d5bae9172fccfe4..23f6b833e71002c648e20744ed0beb344efbe8b9 100644
|
||||
--- a/src/main/java/net/minecraft/commands/arguments/MessageArgument.java
|
||||
+++ b/src/main/java/net/minecraft/commands/arguments/MessageArgument.java
|
||||
@@ -50,17 +50,21 @@ public class MessageArgument implements SignedArgument<MessageArgument.Message>
|
||||
@ -2142,9 +2014,9 @@ index 7511445f48d9f13106b5d45b5d5bae9172fccfe4..43a47a6d8e5043ef743c5c2d8fb802d8
|
||||
- source.getChatMessageChainer().append(completableFuture, filtered -> {
|
||||
- PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(component).filter(filtered.mask());
|
||||
+ // Paper start - support asynchronous chat decoration
|
||||
+ CompletableFuture<ChatDecorator.Result> componentFuture = minecraftServer.getChatDecorator().decorate(source.getPlayer(), source, message.decoratedContent());
|
||||
+ CompletableFuture<Component> componentFuture = minecraftServer.getChatDecorator().decorate(source.getPlayer(), source, message.decoratedContent());
|
||||
+ source.getChatMessageChainer().append(CompletableFuture.allOf(completableFuture, componentFuture), filtered -> {
|
||||
+ PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(componentFuture.join().component()).filter(completableFuture.join().mask());
|
||||
+ PlayerChatMessage playerChatMessage2 = message.withUnsignedContent(componentFuture.join()).filter(completableFuture.join().mask());
|
||||
+ // Paper end - support asynchronous chat decoration
|
||||
callback.accept(playerChatMessage2);
|
||||
});
|
||||
@ -2155,8 +2027,8 @@ index 7511445f48d9f13106b5d45b5d5bae9172fccfe4..43a47a6d8e5043ef743c5c2d8fb802d8
|
||||
- Component component = chatDecorator.decorate(source.getPlayer(), message.decoratedContent());
|
||||
- callback.accept(message.withUnsignedContent(component));
|
||||
+ // Paper start - support asynchronous chat decoration
|
||||
+ CompletableFuture<ChatDecorator.Result> componentFuture = chatDecorator.decorate(source.getPlayer(), source, message.decoratedContent());
|
||||
+ source.getChatMessageChainer().append(componentFuture, (result) -> callback.accept(message.withUnsignedContent(result.component())));
|
||||
+ CompletableFuture<Component> componentFuture = chatDecorator.decorate(source.getPlayer(), source, message.decoratedContent());
|
||||
+ source.getChatMessageChainer().append(componentFuture, (result) -> callback.accept(message.withUnsignedContent(result)));
|
||||
+ // Paper end - support asynchronous chat decoration
|
||||
}
|
||||
|
||||
@ -2237,10 +2109,10 @@ index d0e159f54da70bf0bd834738ced5d4b414a36142..0d80fcee1831af59b06c4d00dc713bd4
|
||||
try {
|
||||
int j = friendlyByteBuf.writerIndex();
|
||||
diff --git a/src/main/java/net/minecraft/network/chat/ChatDecorator.java b/src/main/java/net/minecraft/network/chat/ChatDecorator.java
|
||||
index e4624d696dcf0ddb6d42a80701dfc47ec6877540..8885e405b626daa0af1485ad734863af73b3c1f3 100644
|
||||
index e4624d696dcf0ddb6d42a80701dfc47ec6877540..6b8dc1eb490098cc14673c9ab0aa16fe3471325b 100644
|
||||
--- a/src/main/java/net/minecraft/network/chat/ChatDecorator.java
|
||||
+++ b/src/main/java/net/minecraft/network/chat/ChatDecorator.java
|
||||
@@ -2,10 +2,70 @@ package net.minecraft.network.chat;
|
||||
@@ -2,10 +2,18 @@ package net.minecraft.network.chat;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@ -2249,68 +2121,16 @@ index e4624d696dcf0ddb6d42a80701dfc47ec6877540..8885e405b626daa0af1485ad734863af
|
||||
@FunctionalInterface
|
||||
public interface ChatDecorator {
|
||||
- ChatDecorator PLAIN = (sender, message) -> message;
|
||||
+ ChatDecorator PLAIN = (sender, message) -> CompletableFuture.completedFuture(message); // Paper - adventure; support async chat decoration events;
|
||||
+ ChatDecorator PLAIN = (sender, message) -> CompletableFuture.completedFuture(message); // Paper - adventure; support async chat decoration events
|
||||
|
||||
- Component decorate(@Nullable ServerPlayer sender, Component message);
|
||||
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper - adventure; support chat decoration events
|
||||
+ @io.papermc.paper.annotation.DoNotUse @Deprecated // Paper - adventure; support chat decoration events (callers should use the overload with CommandSourceStack)
|
||||
+ CompletableFuture<Component> decorate(@Nullable ServerPlayer sender, Component message); // Paper - adventure; support async chat decoration events
|
||||
+
|
||||
+ // Paper start - adventure; support async chat decoration events
|
||||
+ default CompletableFuture<Result> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message) {
|
||||
+ default CompletableFuture<Component> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message) {
|
||||
+ throw new UnsupportedOperationException("Must override this implementation");
|
||||
+ }
|
||||
+
|
||||
+ static ChatDecorator create(ImprovedChatDecorator delegate) {
|
||||
+ return new ChatDecorator() {
|
||||
+ @Override
|
||||
+ public CompletableFuture<Component> decorate(@Nullable ServerPlayer sender, Component message) {
|
||||
+ return this.decorate(sender, null, message).thenApply(Result::component);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public CompletableFuture<Result> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message) {
|
||||
+ return delegate.decorate(sender, commandSourceStack, message);
|
||||
+ }
|
||||
+ };
|
||||
+ }
|
||||
+
|
||||
+ @FunctionalInterface
|
||||
+ interface ImprovedChatDecorator {
|
||||
+ CompletableFuture<Result> decorate(@Nullable ServerPlayer sender, @Nullable net.minecraft.commands.CommandSourceStack commandSourceStack, Component message);
|
||||
+ }
|
||||
+
|
||||
+ interface Result {
|
||||
+ boolean hasNoFormatting();
|
||||
+
|
||||
+ Component component();
|
||||
+
|
||||
+ MessagePair message();
|
||||
+
|
||||
+ boolean modernized();
|
||||
+ }
|
||||
+
|
||||
+ record MessagePair(net.kyori.adventure.text.Component component, String legacyMessage) { }
|
||||
+
|
||||
+ record LegacyResult(Component component, String format, MessagePair message, boolean hasNoFormatting, boolean modernized) implements Result {
|
||||
+ public LegacyResult(net.kyori.adventure.text.Component component, String format, MessagePair message, boolean hasNoFormatting, boolean modernified) {
|
||||
+ this(io.papermc.paper.adventure.PaperAdventure.asVanilla(component), format, message, hasNoFormatting, modernified);
|
||||
+ }
|
||||
+ public LegacyResult {
|
||||
+ component = component instanceof io.papermc.paper.adventure.AdventureComponent adventureComponent ? adventureComponent.deepConverted() : component;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ record ModernResult(Component component, boolean hasNoFormatting, boolean modernized) implements Result {
|
||||
+ public ModernResult(net.kyori.adventure.text.Component component, boolean hasNoFormatting, boolean modernized) {
|
||||
+ this(io.papermc.paper.adventure.PaperAdventure.asVanilla(component), hasNoFormatting, modernized);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public MessagePair message() {
|
||||
+ final net.kyori.adventure.text.Component adventureComponent = io.papermc.paper.adventure.PaperAdventure.WRAPPER_AWARE_SERIALIZER.deserialize(this.component);
|
||||
+ return new MessagePair(adventureComponent, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().serialize(adventureComponent));
|
||||
+ }
|
||||
+ }
|
||||
+ // Paper end - adventure; support async chat decoration events
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/network/chat/ComponentSerialization.java b/src/main/java/net/minecraft/network/chat/ComponentSerialization.java
|
||||
@ -2452,27 +2272,14 @@ index e2def0ca552343143e495736d533b3334686fd62..c87b708c368713a23a10ad97704575ee
|
||||
sender.connection.sendPlayerChatMessage(playerChatMessage, params);
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/network/chat/PlayerChatMessage.java b/src/main/java/net/minecraft/network/chat/PlayerChatMessage.java
|
||||
index d89049328641faa889b7c567123ab3a2c63b8df0..81e904e78c9fec49ac244f0a62cef75e5824f2dd 100644
|
||||
index d89049328641faa889b7c567123ab3a2c63b8df0..76b304560c2b631a18f20e656a65ac75af7b4e63 100644
|
||||
--- a/src/main/java/net/minecraft/network/chat/PlayerChatMessage.java
|
||||
+++ b/src/main/java/net/minecraft/network/chat/PlayerChatMessage.java
|
||||
@@ -15,8 +15,54 @@ import net.minecraft.util.SignatureUpdater;
|
||||
import net.minecraft.util.SignatureValidator;
|
||||
|
||||
@@ -17,6 +17,42 @@ import net.minecraft.util.SignatureValidator;
|
||||
public record PlayerChatMessage(
|
||||
- SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask
|
||||
+ SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask, @Nullable net.minecraft.network.chat.ChatDecorator.Result result // Paper - adventure; support signed messages
|
||||
SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask
|
||||
) {
|
||||
+ // Paper start - adventure; support signed messages
|
||||
+ public PlayerChatMessage(SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask) {
|
||||
+ this(link, signature, signedBody, unsignedContent, filterMask, null);
|
||||
+ }
|
||||
+ public PlayerChatMessage withResult(net.minecraft.network.chat.ChatDecorator.Result result) {
|
||||
+ final PlayerChatMessage msg = this.withUnsignedContent(result.component());
|
||||
+ return new PlayerChatMessage(msg.link, msg.signature, msg.signedBody, msg.unsignedContent, msg.filterMask, result);
|
||||
+ }
|
||||
+ public net.minecraft.network.chat.ChatDecorator.Result requireResult() {
|
||||
+ return Objects.requireNonNull(this.result, "Requires a decoration result to be set here");
|
||||
+ }
|
||||
+ public final class AdventureView implements net.kyori.adventure.chat.SignedMessage {
|
||||
+ private AdventureView() {
|
||||
+ }
|
||||
@ -2511,12 +2318,19 @@ index d89049328641faa889b7c567123ab3a2c63b8df0..81e904e78c9fec49ac244f0a62cef75e
|
||||
public static final MapCodec<PlayerChatMessage> MAP_CODEC = RecordCodecBuilder.mapCodec(
|
||||
instance -> instance.group(
|
||||
SignedMessageLink.CODEC.fieldOf("link").forGetter(PlayerChatMessage::link),
|
||||
@@ -47,7 +93,7 @@ public record PlayerChatMessage(
|
||||
@@ -47,7 +83,14 @@ public record PlayerChatMessage(
|
||||
}
|
||||
|
||||
public PlayerChatMessage withUnsignedContent(Component unsignedContent) {
|
||||
- Component component = !unsignedContent.equals(Component.literal(this.signedContent())) ? unsignedContent : null;
|
||||
+ Component component = !(unsignedContent instanceof io.papermc.paper.adventure.AdventureComponent advComponent ? advComponent.deepConverted() : unsignedContent).equals(Component.literal(this.signedContent())) ? unsignedContent : null; // Paper - adventure; convert adventure component wraps
|
||||
+ // Paper start - adventure
|
||||
+ final Component component;
|
||||
+ if (unsignedContent instanceof io.papermc.paper.adventure.AdventureComponent advComponent) {
|
||||
+ component = this.signedContent().equals(io.papermc.paper.adventure.AdventureCodecs.tryCollapseToString(advComponent.adventure$component())) ? null : unsignedContent;
|
||||
+ } else {
|
||||
+ component = !unsignedContent.equals(Component.literal(this.signedContent())) ? unsignedContent : null;
|
||||
+ }
|
||||
+ // Paper end - adventure
|
||||
return new PlayerChatMessage(this.link, this.signature, this.signedBody, component, this.filterMask);
|
||||
}
|
||||
|
||||
@ -2662,7 +2476,7 @@ index a5578cbce2d1d39ba3315e53425d5323e6823a65..7a036c08fa67504d06c8f72a32c22814
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 4035faedd9f5f72f262822a9f050178d99be06e4..4c18491a627e66297627abbded1af48b2026e610 100644
|
||||
index 4035faedd9f5f72f262822a9f050178d99be06e4..00a1806720e67eb747061e0a6c2ea334dd4453ce 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -191,6 +191,7 @@ import org.bukkit.craftbukkit.SpigotTimings; // Spigot
|
||||
@ -2722,7 +2536,7 @@ index 4035faedd9f5f72f262822a9f050178d99be06e4..4c18491a627e66297627abbded1af48b
|
||||
this.motd = motd;
|
||||
}
|
||||
|
||||
@@ -2434,23 +2445,28 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -2434,23 +2445,24 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
}
|
||||
|
||||
public void logChatMessage(Component message, ChatType.Bound params, @Nullable String prefix) {
|
||||
@ -2747,14 +2561,10 @@ index 4035faedd9f5f72f262822a9f050178d99be06e4..4c18491a627e66297627abbded1af48b
|
||||
- // CraftBukkit end
|
||||
+ new com.google.common.util.concurrent.ThreadFactoryBuilder().setDaemon(true).setNameFormat("Async Chat Thread - #%d").setUncaughtExceptionHandler(new net.minecraft.DefaultUncaughtExceptionHandlerWithName(net.minecraft.server.MinecraftServer.LOGGER)).build()); // Paper
|
||||
|
||||
+ public final ChatDecorator improvedChatDecorator = new io.papermc.paper.adventure.ImprovedChatDecorator(this); // Paper - adventure
|
||||
public ChatDecorator getChatDecorator() {
|
||||
- return ChatDecorator.PLAIN;
|
||||
+ // Paper start - moved to ChatPreviewProcessor
|
||||
+ return ChatDecorator.create((sender, commandSourceStack, message) -> {
|
||||
+ final io.papermc.paper.adventure.ChatDecorationProcessor processor = new io.papermc.paper.adventure.ChatDecorationProcessor(this, sender, commandSourceStack, message);
|
||||
+ return processor.process();
|
||||
+ });
|
||||
+ // Paper end
|
||||
+ return this.improvedChatDecorator; // Paper - support async chat decoration events
|
||||
}
|
||||
|
||||
public boolean logIPs() {
|
||||
@ -2947,7 +2757,7 @@ index a60fef571c94858998a91711b17d3670c28a81bd..04a728a16bb629adbae1cd8586764a6d
|
||||
|
||||
@Override
|
||||
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index 58872976048a1162602d5f11a85eaead837cd805..93ef520b8f047870f48e908ae55590547ad88729 100644
|
||||
index 58872976048a1162602d5f11a85eaead837cd805..c51e38bb683d239d6116075b5a613b5ef709056a 100644
|
||||
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -44,6 +44,7 @@ import net.minecraft.nbt.ListTag;
|
||||
@ -2987,12 +2797,12 @@ index 58872976048a1162602d5f11a85eaead837cd805..93ef520b8f047870f48e908ae5559054
|
||||
|
||||
CompletableFuture<FilteredText> completablefuture = this.filterTextPacket(playerchatmessage.signedContent()).thenApplyAsync(Function.identity(), this.server.chatExecutor); // CraftBukkit - async chat
|
||||
- Component ichatbasecomponent = this.server.getChatDecorator().decorate(this.player, playerchatmessage.decoratedContent());
|
||||
+ CompletableFuture<ChatDecorator.Result> componentFuture = this.server.getChatDecorator().decorate(this.player, null, playerchatmessage.decoratedContent()); // Paper
|
||||
+ CompletableFuture<Component> componentFuture = this.server.getChatDecorator().decorate(this.player, null, playerchatmessage.decoratedContent()); // Paper - Adventure
|
||||
|
||||
- this.chatMessageChain.append(completablefuture, (filteredtext) -> {
|
||||
- PlayerChatMessage playerchatmessage1 = playerchatmessage.withUnsignedContent(ichatbasecomponent).filter(filteredtext.mask());
|
||||
+ this.chatMessageChain.append(CompletableFuture.allOf(completablefuture, componentFuture), (filteredtext) -> {
|
||||
+ PlayerChatMessage playerchatmessage1 = playerchatmessage.filter(completablefuture.join().mask()).withResult(componentFuture.join()); // Paper
|
||||
+ this.chatMessageChain.append(CompletableFuture.allOf(completablefuture, componentFuture), (filteredtext) -> { // Paper - Adventure
|
||||
+ PlayerChatMessage playerchatmessage1 = playerchatmessage.withUnsignedContent(componentFuture.join()).filter(completablefuture.join().mask()); // Paper - Adventure
|
||||
|
||||
this.broadcastChatMessage(playerchatmessage1);
|
||||
});
|
||||
|
@ -17,7 +17,7 @@ Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
Co-authored-by: SoSeDiK <mrsosedik@gmail.com>
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index 4be0935a36bd7b2e0d83e30b6edc43a6429dac22..37cba1e693490e42908f45dc68e60ac3afebbb49 100644
|
||||
index ee369964eb7f0ac0c24699b804214ce1a9632043..01d1759aefdb0a224f1e8764ec1114ef1baa6cf5 100644
|
||||
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -1930,7 +1930,7 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl
|
||||
@ -53,7 +53,7 @@ index 56a63adc3c0c919594c3f2646d4cf5b86b5c6f1e..5b22714d6f5eb8318275ca0bf01597be
|
||||
if (this.commandMap.dispatch(sender, commandLine)) {
|
||||
return true;
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
index 42b27e1b8bc317a4cd0fcc27a5d7ce2d69d33aeb..6f3c450cd03fa4848175cada63be2dcf5abe45ba 100644
|
||||
index 42b27e1b8bc317a4cd0fcc27a5d7ce2d69d33aeb..0391c8f663a52a006e3d7c447a529a958fb98e18 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
|
||||
@@ -462,7 +462,20 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
|
||||
@ -68,7 +68,7 @@ index 42b27e1b8bc317a4cd0fcc27a5d7ce2d69d33aeb..6f3c450cd03fa4848175cada63be2dcf
|
||||
+ if (msg.startsWith("/")) {
|
||||
+ this.getHandle().connection.handleCommand(msg);
|
||||
+ } else {
|
||||
+ final PlayerChatMessage playerChatMessage = PlayerChatMessage.system(msg).withResult(new net.minecraft.network.chat.ChatDecorator.ModernResult(Component.literal(msg), true, false));
|
||||
+ final PlayerChatMessage playerChatMessage = PlayerChatMessage.system(msg).withUnsignedContent(Component.literal(msg));
|
||||
+ // TODO chat decorating
|
||||
+ // TODO text filtering
|
||||
+ this.getHandle().connection.chat(msg, playerChatMessage, false);
|
||||
|
@ -12,13 +12,13 @@ for this on CB at one point but I can't find it. We may need to do this
|
||||
ourselves at some point in the future.
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
index 57081e84d50f7eca7ea11540b550da8269378e9e..e4fd372a1d585887287253a02531cd192929377b 100644
|
||||
index bfb1904be53112cdff62001c3307c7d5ef89704c..1d78e8beacbc93ef2cd6beb418edca843f8a5429 100644
|
||||
--- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
@@ -19,6 +19,7 @@ import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
@@ -20,6 +20,7 @@ import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
+import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.Optionull;
|
||||
import net.minecraft.Util;
|
||||
@ -31,7 +31,7 @@ index 57081e84d50f7eca7ea11540b550da8269378e9e..e4fd372a1d585887287253a02531cd19
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.util.LazyPlayerSet;
|
||||
import org.bukkit.craftbukkit.util.Waitable;
|
||||
@@ -367,10 +369,16 @@ public final class ChatProcessor {
|
||||
@@ -329,10 +331,16 @@ public final class ChatProcessor {
|
||||
}
|
||||
|
||||
static String legacyDisplayName(final CraftPlayer player) {
|
||||
|
@ -125,7 +125,7 @@ index 72f2e81b9905a0d57ed8e2a88578f62d5235c456..7b58b2d6297800c2dcdbf7539e5ab8e7
|
||||
|
||||
public static void registerCommands(final MinecraftServer server) {
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 46386befc7c76788bdd136f7d7b4eb8e1e5d19b9..1a7dffb3947dab0e334cd5873c69542f383aed61 100644
|
||||
index 6342b7a3c4ccad528f026384da64e973e630f030..746eeb22127d8633f1eeef1bb9c20edb7fd23e5a 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -252,6 +252,11 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@ -152,7 +152,7 @@ index 46386befc7c76788bdd136f7d7b4eb8e1e5d19b9..1a7dffb3947dab0e334cd5873c69542f
|
||||
this.logTickTime(l - i);
|
||||
this.profiler.pop();
|
||||
org.spigotmc.WatchdogThread.tick(); // Spigot
|
||||
@@ -2673,4 +2683,30 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
@@ -2669,4 +2679,30 @@ public abstract class MinecraftServer extends ReentrantBlockableEventLoop<TickTa
|
||||
public static record ServerResourcePackInfo(UUID id, String url, String hash, boolean isRequired, @Nullable Component prompt) {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user