mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 02:25:28 +01:00
fix ChatProcessor
This commit is contained in:
parent
12fee1cf81
commit
5256716ffb
@ -79,6 +79,19 @@ index 2df8fa1ae2dc58291add80fae0599ee4ff5066ee..ed7e1a6fc745df745d5bc79623948bb1
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/resources/RegistryDataLoader.java b/src/main/java/net/minecraft/resources/RegistryDataLoader.java
|
||||
index cdb467969a4a4b83653d02e7540e1dc59ecdf62a..069164e9ff55c12ab7d71366242661250d432953 100644
|
||||
--- a/src/main/java/net/minecraft/resources/RegistryDataLoader.java
|
||||
+++ b/src/main/java/net/minecraft/resources/RegistryDataLoader.java
|
||||
@@ -87,7 +87,7 @@ public class RegistryDataLoader {
|
||||
return new RegistryOps.RegistryInfoLookup() {
|
||||
@Override
|
||||
public <T> Optional<RegistryOps.RegistryInfo<T>> lookup(ResourceKey<? extends Registry<? extends T>> registryRef) {
|
||||
- return Optional.ofNullable(map.get(registryRef));
|
||||
+ return Optional.ofNullable((RegistryOps.RegistryInfo<T>) map.get(registryRef)); // Paper - decompile fix
|
||||
}
|
||||
};
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 870db0028becd6b76af76190fae908d0031ed94d..06b1da8b559f9d545f1593d81de7b25e0a12f176 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
|
@ -246,10 +246,10 @@ index 0000000000000000000000000000000000000000..a9c2b67cab07b3a4e996159176919c76
|
||||
+}
|
||||
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..12ea885e815b6814a74ac3aa9d9c325e53721ecd
|
||||
index 0000000000000000000000000000000000000000..8b7b140ac0326ffccd51684e283647148de30647
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
@@ -0,0 +1,379 @@
|
||||
@@ -0,0 +1,373 @@
|
||||
+package io.papermc.paper.adventure;
|
||||
+
|
||||
+import com.google.common.base.Suppliers;
|
||||
@ -269,9 +269,8 @@ index 0000000000000000000000000000000000000000..12ea885e815b6814a74ac3aa9d9c325e
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import net.minecraft.Util;
|
||||
+import net.minecraft.network.chat.ChatDecorator;
|
||||
+import net.minecraft.network.chat.ChatMessageContent;
|
||||
+import net.minecraft.network.chat.ChatType;
|
||||
+import net.minecraft.network.chat.OutgoingPlayerChatMessage;
|
||||
+import net.minecraft.network.chat.OutgoingChatMessage;
|
||||
+import net.minecraft.network.chat.PlayerChatMessage;
|
||||
+import net.minecraft.resources.ResourceKey;
|
||||
+import net.minecraft.server.MinecraftServer;
|
||||
@ -301,7 +300,7 @@ index 0000000000000000000000000000000000000000..12ea885e815b6814a74ac3aa9d9c325e
|
||||
+ final boolean async;
|
||||
+ final String craftbukkit$originalMessage;
|
||||
+ final Component paper$originalMessage;
|
||||
+ final OutgoingPlayerChatMessage outgoing;
|
||||
+ final OutgoingChatMessage outgoing;
|
||||
+
|
||||
+ static final int MESSAGE_CHANGED = 1;
|
||||
+ static final int FORMAT_CHANGED = 2;
|
||||
@ -322,18 +321,18 @@ index 0000000000000000000000000000000000000000..12ea885e815b6814a74ac3aa9d9c325e
|
||||
+ */
|
||||
+ this.message = message;
|
||||
+ this.async = async;
|
||||
+ if (this.message.signedContent().decorationResult().modernized()) {
|
||||
+ this.craftbukkit$originalMessage = this.message.signedContent().decorationResult().message().legacyMessage();
|
||||
+ if (this.message.requireResult().modernized()) {
|
||||
+ this.craftbukkit$originalMessage = this.message.requireResult().message().legacyMessage();
|
||||
+ } else {
|
||||
+ this.craftbukkit$originalMessage = message.signedContent().plain();
|
||||
+ 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.signedContent().decorationResult().message().component();
|
||||
+ this.outgoing = OutgoingPlayerChatMessage.create(this.message);
|
||||
+ this.paper$originalMessage = this.message.requireResult().message().component();
|
||||
+ this.outgoing = OutgoingChatMessage.create(this.message);
|
||||
+ }
|
||||
+
|
||||
+ @SuppressWarnings("deprecated")
|
||||
@ -386,7 +385,7 @@ index 0000000000000000000000000000000000000000..12ea885e815b6814a74ac3aa9d9c325e
|
||||
+ private ChatRenderer modernRenderer(final String format) {
|
||||
+ if (this.flags.get(FORMAT_CHANGED)) {
|
||||
+ return legacyRenderer(format);
|
||||
+ } else if (this.message.signedContent().decorationResult() instanceof ChatDecorator.LegacyResult legacyResult) {
|
||||
+ } else if (this.message.requireResult() instanceof ChatDecorator.LegacyResult legacyResult) {
|
||||
+ return legacyRenderer(legacyResult.format());
|
||||
+ } else {
|
||||
+ return defaultRenderer();
|
||||
@ -396,7 +395,7 @@ index 0000000000000000000000000000000000000000..12ea885e815b6814a74ac3aa9d9c325e
|
||||
+ private Component modernMessage(final String legacyMessage) {
|
||||
+ if (this.flags.get(MESSAGE_CHANGED)) {
|
||||
+ return legacySection().deserialize(legacyMessage);
|
||||
+ } else if (this.message.unsignedContent().isEmpty() && this.message.signedContent().decorationResult() instanceof ChatDecorator.LegacyResult legacyResult) {
|
||||
+ } else if (this.message.unsignedContent() == null && this.message.requireResult() instanceof ChatDecorator.LegacyResult legacyResult) {
|
||||
+ return legacyResult.message().component();
|
||||
+ } else {
|
||||
+ return this.paper$originalMessage;
|
||||
@ -404,9 +403,8 @@ index 0000000000000000000000000000000000000000..12ea885e815b6814a74ac3aa9d9c325e
|
||||
+ }
|
||||
+
|
||||
+ private void readLegacyModifications(final String message, final String format, final Player playerSender) {
|
||||
+ final ChatMessageContent content = this.message.signedContent();
|
||||
+ if (content.decorationResult() instanceof ChatDecorator.LegacyResult result) {
|
||||
+ if ((content.isDecorated() || this.message.unsignedContent().isPresent()) && !result.modernized()) {
|
||||
+ 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));
|
||||
@ -443,8 +441,8 @@ index 0000000000000000000000000000000000000000..12ea885e815b6814a74ac3aa9d9c325e
|
||||
+ }
|
||||
+
|
||||
+ private void readModernModifications(final AbstractChatEvent chatEvent, final ChatRenderer originalRenderer) {
|
||||
+ if (this.message.signedContent().isDecorated()) {
|
||||
+ this.flags.set(MESSAGE_CHANGED, !chatEvent.message().equals(this.message.signedContent().decorationResult().message().component()));
|
||||
+ 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));
|
||||
+ }
|
||||
@ -456,7 +454,6 @@ index 0000000000000000000000000000000000000000..12ea885e815b6814a74ac3aa9d9c325e
|
||||
+
|
||||
+ private void complete(final AbstractChatEvent event) {
|
||||
+ if (event.isCancelled()) {
|
||||
+ this.outgoing.sendHeadersToRemainingPlayers(this.server.getPlayerList());
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
@ -536,7 +533,7 @@ index 0000000000000000000000000000000000000000..12ea885e815b6814a74ac3aa9d9c325e
|
||||
+ }
|
||||
+
|
||||
+ private void broadcastToViewers(Collection<Audience> viewers, final Player source, final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> msgFunction) {
|
||||
+ final Supplier<Component> fallbackSupplier = Suppliers.memoize(() -> PaperAdventure.asAdventure(msgFunction instanceof ConstantFunction constantFunction ? constantFunction.component : ChatProcessor.this.message.serverContent()));
|
||||
+ final Supplier<Component> fallbackSupplier = Suppliers.memoize(() -> PaperAdventure.asAdventure(msgFunction instanceof ConstantFunction constantFunction ? constantFunction.component : ChatProcessor.this.message.decoratedContent()));
|
||||
+ final Function<Audience, Component> audienceMsgFunction = !(msgFunction instanceof ConstantFunction || msgFunction == null) ? msgFunction.andThen(PaperAdventure::asAdventure) : viewer -> fallbackSupplier.get();
|
||||
+ for (Audience viewer : viewers) {
|
||||
+ if (viewer instanceof Player || viewer instanceof ConsoleCommandSender) {
|
||||
@ -546,9 +543,6 @@ index 0000000000000000000000000000000000000000..12ea885e815b6814a74ac3aa9d9c325e
|
||||
+ viewer.sendMessage(source, audienceMsgFunction.apply(viewer), MessageType.CHAT);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // Make sure to send remaining headers
|
||||
+ ChatProcessor.this.outgoing.sendHeadersToRemainingPlayers(ChatProcessor.this.server.getPlayerList());
|
||||
+ }
|
||||
+
|
||||
+ private void sendToViewer(final CommandSender viewer, final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> msgFunction) {
|
||||
@ -563,7 +557,7 @@ index 0000000000000000000000000000000000000000..12ea885e815b6814a74ac3aa9d9c325e
|
||||
+
|
||||
+ private void sendToServer(final ChatType.Bound chatType, final @Nullable Function<Audience, net.minecraft.network.chat.Component> msgFunction) {
|
||||
+ final PlayerChatMessage toConsoleMessage = msgFunction == null ? ChatProcessor.this.message : ChatProcessor.this.message.withUnsignedContent(msgFunction.apply(ChatProcessor.this.server.console));
|
||||
+ ChatProcessor.this.server.logChatMessage(toConsoleMessage.serverContent(), chatType, ChatProcessor.this.server.getPlayerList().verifyChatTrusted(toConsoleMessage, ChatProcessor.this.player.asChatSender()) ? null : "Not Secure");
|
||||
+ ChatProcessor.this.server.logChatMessage(toConsoleMessage.decoratedContent(), chatType, ChatProcessor.this.server.getPlayerList().verifyChatTrusted(toConsoleMessage) ? null : "Not Secure");
|
||||
+ }
|
||||
+
|
||||
+ record ConstantFunction(net.minecraft.network.chat.Component component) implements Function<Audience, net.minecraft.network.chat.Component> {
|
||||
@ -1693,6 +1687,31 @@ index f8773f2982e6cd40661d138a7c32f219cda9225c..74cf1c043beef03cfd5adf481414a5ee
|
||||
if (!playerChatMessage.isFullyFiltered()) {
|
||||
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 b3a44ed8f365daf1031d46d879c84d2ea15cd951..acbcb582680c0e3215c4e083a2b01b81e1fcfa25 100644
|
||||
--- a/src/main/java/net/minecraft/network/chat/PlayerChatMessage.java
|
||||
+++ b/src/main/java/net/minecraft/network/chat/PlayerChatMessage.java
|
||||
@@ -15,7 +15,19 @@ import net.minecraft.util.ExtraCodecs;
|
||||
import net.minecraft.util.SignatureUpdater;
|
||||
import net.minecraft.util.SignatureValidator;
|
||||
|
||||
-public record PlayerChatMessage(SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask) {
|
||||
+// Paper start
|
||||
+public record PlayerChatMessage(SignedMessageLink link, @Nullable MessageSignature signature, SignedMessageBody signedBody, @Nullable Component unsignedContent, FilterMask filterMask, @Nullable net.minecraft.network.chat.ChatDecorator.Result result) {
|
||||
+ 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");
|
||||
+ }
|
||||
+ // Paper end
|
||||
public static final MapCodec<PlayerChatMessage> MAP_CODEC = RecordCodecBuilder.mapCodec((instance) -> {
|
||||
return instance.group(SignedMessageLink.CODEC.fieldOf("link").forGetter(PlayerChatMessage::link), MessageSignature.CODEC.optionalFieldOf("signature").forGetter((message) -> {
|
||||
return Optional.ofNullable(message.signature);
|
||||
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java
|
||||
index 02183c810f9968621b9b20c1f7b54258b620c507..32ef3edebe94a2014168b7e438752a80b2687e5f 100644
|
||||
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSetActionBarTextPacket.java
|
||||
@ -1843,6 +1862,22 @@ index 762a9392ffac3042356709dddd15bb3516048bed..3544e2dc2522e9d6305d727d56e73490
|
||||
buf.writeComponent(this.header);
|
||||
buf.writeComponent(this.footer);
|
||||
}
|
||||
diff --git a/src/main/java/net/minecraft/resources/RegistryDataLoader.java b/src/main/java/net/minecraft/resources/RegistryDataLoader.java
|
||||
index 069164e9ff55c12ab7d71366242661250d432953..38b3460acfb8f50be8f34a6b2bd04e9686472ea1 100644
|
||||
--- a/src/main/java/net/minecraft/resources/RegistryDataLoader.java
|
||||
+++ b/src/main/java/net/minecraft/resources/RegistryDataLoader.java
|
||||
@@ -57,6 +57,11 @@ public class RegistryDataLoader {
|
||||
RegistryOps.RegistryInfoLookup registryInfoLookup = createContext(baseRegistryManager, list);
|
||||
list.forEach((loader) -> {
|
||||
loader.getSecond().load(resourceManager, registryInfoLookup);
|
||||
+ // Paper start
|
||||
+ if (loader.getFirst().key() == Registries.CHAT_TYPE) {
|
||||
+ Registry.register((Registry<ChatType>) loader.getFirst(), ChatType.RAW, new ChatType(new net.minecraft.network.chat.ChatTypeDecoration("%s", List.of(net.minecraft.network.chat.ChatTypeDecoration.Parameter.CONTENT), net.minecraft.network.chat.Style.EMPTY), new net.minecraft.network.chat.ChatTypeDecoration("%s", List.of(net.minecraft.network.chat.ChatTypeDecoration.Parameter.CONTENT), net.minecraft.network.chat.Style.EMPTY))); // CraftBukkit
|
||||
+ }
|
||||
+ // Paper end
|
||||
});
|
||||
list.forEach((loader) -> {
|
||||
Registry<?> registry = loader.getFirst();
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index 0f7dd33d51281b383be0fb47d4e6b133f123ce1f..011c3d2dbd34dd0c2afba477202c937c654d42a4 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@ -1999,7 +2034,7 @@ index 48972d64710fb0d3821e7c1a0722a1d203c47e07..6a8c67dc668c775809227b455b2dd522
|
||||
// CraftBukkit end
|
||||
this.chatVisibility = packet.chatVisibility();
|
||||
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
index 3e37ce53e31b0c4e362ff7eefb3662d7d1aabea4..340e7da85506b79be154bfea1445c6d2b4feefcc 100644
|
||||
index 3e37ce53e31b0c4e362ff7eefb3662d7d1aabea4..91a0b7923b5a39a7de5d7899002ec4cd4a987a47 100644
|
||||
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
|
||||
@@ -185,6 +185,8 @@ import net.minecraft.world.phys.shapes.VoxelShape;
|
||||
@ -2090,7 +2125,7 @@ index 3e37ce53e31b0c4e362ff7eefb3662d7d1aabea4..340e7da85506b79be154bfea1445c6d2
|
||||
this.chatMessageChain.append((executor) -> {
|
||||
return CompletableFuture.allOf(completablefuture, completablefuture1).thenAcceptAsync((ovoid) -> {
|
||||
- PlayerChatMessage playerchatmessage1 = playerchatmessage.withUnsignedContent((Component) completablefuture1.join()).filter(((FilteredText) completablefuture.join()).mask());
|
||||
+ PlayerChatMessage playerchatmessage1 = playerchatmessage.withUnsignedContent(completablefuture1.join().component()).filter(((FilteredText) completablefuture.join()).mask()); // Paper
|
||||
+ PlayerChatMessage playerchatmessage1 = playerchatmessage.filter(((FilteredText) completablefuture.join()).mask()).withResult(completablefuture1.join()); // Paper
|
||||
|
||||
this.broadcastChatMessage(playerchatmessage1);
|
||||
}, this.server.chatExecutor); // CraftBukkit - async chat
|
||||
|
@ -12,10 +12,10 @@ 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 12ea885e815b6814a74ac3aa9d9c325e53721ecd..28ddab1121e314e82bf764fd89f36714bd7445f8 100644
|
||||
index 8b7b140ac0326ffccd51684e283647148de30647..fd5cbb45e9894b7895ea488e2b9876c0391f6f11 100644
|
||||
--- a/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
+++ b/src/main/java/io/papermc/paper/adventure/ChatProcessor.java
|
||||
@@ -24,8 +24,10 @@ import net.minecraft.network.chat.PlayerChatMessage;
|
||||
@@ -23,8 +23,10 @@ import net.minecraft.network.chat.PlayerChatMessage;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
@ -26,7 +26,7 @@ index 12ea885e815b6814a74ac3aa9d9c325e53721ecd..28ddab1121e314e82bf764fd89f36714
|
||||
import org.bukkit.craftbukkit.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.util.LazyPlayerSet;
|
||||
import org.bukkit.craftbukkit.util.Waitable;
|
||||
@@ -332,10 +334,16 @@ public final class ChatProcessor {
|
||||
@@ -326,10 +328,16 @@ public final class ChatProcessor {
|
||||
}
|
||||
|
||||
static String legacyDisplayName(final CraftPlayer player) {
|
||||
|
Loading…
Reference in New Issue
Block a user