13
0
geforkt von Mirrors/Paper

temporary fixes for adventure chat

Dieser Commit ist enthalten in:
Jake Potrebic 2022-06-07 16:49:14 -07:00
Ursprung 58133bdfdf
Commit 3a0b9487d4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: ECE0B3C133C016C5
3 geänderte Dateien mit 62 neuen und 34 gelöschten Zeilen

Datei anzeigen

@ -1167,10 +1167,10 @@ index d19b8ccc791c3f135603b950008136ae6d2f0bfb..bbfb98618a0b87406cc48465bdda15a0
if (!ichatbasecomponent.getStyle().isEmpty()) {
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerChatPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerChatPacket.java
index fc2d39d93f88d71af503c20c497be7385ec312eb..4a3279f9053a3baaa3dd61c53e1bfbbf72f2dadb 100644
index fc2d39d93f88d71af503c20c497be7385ec312eb..285c9197bd716febb158464a1c791337e1d43995 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerChatPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundPlayerChatPacket.java
@@ -14,9 +14,15 @@ import net.minecraft.network.chat.PlayerChatMessage;
@@ -14,9 +14,20 @@ import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.network.protocol.Packet;
import net.minecraft.util.Crypt;
@ -1182,12 +1182,17 @@ index fc2d39d93f88d71af503c20c497be7385ec312eb..4a3279f9053a3baaa3dd61c53e1bfbbf
+ public ClientboundPlayerChatPacket(Component signedContent, Optional<Component> unsignedContent, int typeId, ChatSender sender, Instant timeStamp, Crypt.SaltSignaturePair saltSignature) {
+ this(null, signedContent, unsignedContent, typeId, sender, timeStamp, saltSignature);
+ }
+
+ @Deprecated // doesn't support signed messages
+ public ClientboundPlayerChatPacket(net.kyori.adventure.text.Component adventure$message, int typeId, ChatSender sender, Instant timeStamp) {
+ this(adventure$message, Component.empty(), Optional.empty(), typeId, sender, timeStamp, net.minecraft.util.Crypt.SaltSignaturePair.EMPTY);
+ }
+ // Paper end
+
public ClientboundPlayerChatPacket(FriendlyByteBuf buf) {
this(buf.readComponent(), buf.readOptional(FriendlyByteBuf::readComponent), buf.readVarInt(), new ChatSender(buf), buf.readInstant(), new Crypt.SaltSignaturePair(buf));
}
@@ -24,7 +30,15 @@ public record ClientboundPlayerChatPacket(Component signedContent, Optional<Comp
@@ -24,7 +35,15 @@ public record ClientboundPlayerChatPacket(Component signedContent, Optional<Comp
@Override
public void write(FriendlyByteBuf buf) {
buf.writeComponent(this.signedContent);
@ -1276,46 +1281,49 @@ index 1fb62779527a228f748b49a4d2ddfc57ccb80cf8..bd808eb312ade7122973a47f4b965058
}
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
index 32b391d7c4c21813db204957286a11970267a3bd..75b5f37c54a4de7f4235e2e5246aeda8a605ef45 100644
index 32b391d7c4c21813db204957286a11970267a3bd..cfcdb21f48f74ea1638907e966f06c4aee072d34 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
@@ -8,17 +8,23 @@ import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.Component;
@@ -9,16 +9,25 @@ import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.Packet;
+// Paper start
// Spigot start
-public record ClientboundSystemChatPacket(String content, int typeId) implements Packet<ClientGamePacketListener> {
+public record ClientboundSystemChatPacket(@org.jetbrains.annotations.Nullable net.kyori.adventure.text.Component adventure$message, String content, int typeId) implements Packet<ClientGamePacketListener> {
+
+ public ClientboundSystemChatPacket(String content, int typeId) {
+ this(null, content, typeId);
+ }
+public record ClientboundSystemChatPacket(@javax.annotation.Nullable net.kyori.adventure.text.Component adventure$content, @javax.annotation.Nullable String content, int typeId) implements Packet<ClientGamePacketListener> { // Paper - Adventure
public ClientboundSystemChatPacket(Component content, int typeId) {
- this(Component.Serializer.toJson(content), typeId);
+ this(null, Component.Serializer.toJson(content), typeId);
+ this(null, Component.Serializer.toJson(content), typeId); // Paper - Adventure
}
public ClientboundSystemChatPacket(net.md_5.bungee.api.chat.BaseComponent[] content, int typeId) {
- this(net.md_5.bungee.chat.ComponentSerializer.toString(content), typeId);
+ this(null, net.md_5.bungee.chat.ComponentSerializer.toString(content), typeId);
+ this(null, net.md_5.bungee.chat.ComponentSerializer.toString(content), typeId); // Paper - Adventure
}
// Spigot end
+ // Paper start
+ public ClientboundSystemChatPacket {
+ com.google.common.base.Preconditions.checkArgument(!(adventure$content == null && content == null), "Component adventure$content and String (json) content cannot both be null");
+ }
+
+ public ClientboundSystemChatPacket(net.kyori.adventure.text.Component content, int typeId) {
+ this(content, null, typeId);
+ }
+ // Paper end
public ClientboundSystemChatPacket(FriendlyByteBuf buf) {
this(buf.readComponent(), buf.readVarInt());
@@ -26,7 +32,13 @@ public record ClientboundSystemChatPacket(String content, int typeId) implements
@@ -26,7 +35,15 @@ public record ClientboundSystemChatPacket(String content, int typeId) implements
@Override
public void write(FriendlyByteBuf buf) {
- buf.writeUtf(this.content, 262144); // Spigot
+ // Paper start
+ if (adventure$message != null) {
+ buf.writeComponent(this.adventure$message);
+ if (this.adventure$content != null) {
+ buf.writeComponent(this.adventure$content);
+ } else if (this.content != null) {
buf.writeUtf(this.content, 262144); // Spigot
+ } else {
+ buf.writeUtf(this.content, 262144); // Spigot
+ throw new IllegalArgumentException("Must supply either adventure component or string json content");
+ }
+ // Paper end
buf.writeVarInt(this.typeId);
@ -2472,7 +2480,7 @@ index 446fdca49a5a6999626a7ee3a1d5c168b15a09dd..f9863e138994f6c7a7975a852f106faa
public boolean isOp() {
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 765659b39d30e2e5c491c0808fe1808776ea767b..1b881118457da8f51fb579a4298927f41eb0bbe6 100644
index 765659b39d30e2e5c491c0808fe1808776ea767b..96011a24045b79ba5bab12aaa308426577d755a2 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -270,14 +270,39 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@ -2698,7 +2706,7 @@ index 765659b39d30e2e5c491c0808fe1808776ea767b..1b881118457da8f51fb579a4298927f4
@Override
public int getPing() {
return this.getHandle().latency;
@@ -1903,6 +1996,194 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -1903,6 +1996,207 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
return this.getHandle().allowsListing();
}
@ -2717,8 +2725,21 @@ index 765659b39d30e2e5c491c0808fe1808776ea767b..1b881118457da8f51fb579a4298927f4
+ @Override
+ public void sendMessage(final net.kyori.adventure.identity.Identity identity, final net.kyori.adventure.text.Component message, final net.kyori.adventure.audience.MessageType type) {
+ if (getHandle().connection == null) return;
+ final ClientboundChatPacket packet = new ClientboundChatPacket(null, type == net.kyori.adventure.audience.MessageType.CHAT ? net.minecraft.network.chat.ChatType.CHAT : net.minecraft.network.chat.ChatType.SYSTEM, identity.uuid());
+ packet.adventure$message = message;
+ // TODO this needs to be checked
+ final net.minecraft.core.Registry<ChatType> chatTypeRegistry = this.getHandle().level.registryAccess().registryOrThrow(net.minecraft.core.Registry.CHAT_TYPE_REGISTRY);
+ final net.minecraft.network.protocol.Packet<?> packet;
+ if (identity.equals(net.kyori.adventure.identity.Identity.nil()) || type == net.kyori.adventure.audience.MessageType.SYSTEM) {
+ packet = new net.minecraft.network.protocol.game.ClientboundSystemChatPacket(message, chatTypeRegistry.getId(chatTypeRegistry.get(ChatType.SYSTEM)));
+ } else {
+ final @Nullable Player source = this.getServer().getPlayer(identity.uuid());
+ final ChatSender sender;
+ if (source != null) {
+ sender = ((CraftPlayer) source).getHandle().asChatSender();
+ } else {
+ sender = new ChatSender(identity.uuid(), Component.empty(), null);
+ }
+ packet = new net.minecraft.network.protocol.game.ClientboundPlayerChatPacket(message, chatTypeRegistry.getId(chatTypeRegistry.get(ChatType.CHAT)), sender, java.time.Instant.now());
+ }
+ this.getHandle().connection.send(packet);
+ }
+

Datei anzeigen

@ -1672,7 +1672,7 @@ index 98ba88896c73651591b8ad8e070868fb443ae999..864e2e0355a5fb8c1d4a5b0896ba299f
};
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 5408ba255ee04b75e2f4977fc7aa73866945037c..b3061e6f6c2d645520cecc6cfd8f2a079a8f7f96 100644
index d3d8935bafb2e0773c96c5807ebd23f20de26592..d2267cd447a7666f4404500ccd6bde5f3b932a32 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
@@ -2344,12 +2344,31 @@ public final class CraftServer implements Server {
@ -1877,10 +1877,10 @@ index b0ffa23faf62629043dfd613315eaf9c5fcc2cfe..00000000000000000000000000000000
- }
-}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index d8d634ea96a03a643f6743da8af23480824ced98..485411ddc5ccbe17bc0ecd7caa9a8d5a15f042a7 100644
index 96011a24045b79ba5bab12aaa308426577d755a2..fba10ca35dc8b38dbab74de967c29c43dc9d62a9 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -2273,6 +2273,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@@ -2286,6 +2286,14 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
CraftPlayer.this.getHandle().connection.send(new net.minecraft.network.protocol.game.ClientboundSystemChatPacket(components, i));
}

Datei anzeigen

@ -6,23 +6,30 @@ Subject: [PATCH] Don't nest if we don't need to when cerealising text
diff --git a/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java b/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
index 75b5f37c54a4de7f4235e2e5246aeda8a605ef45..6ba9874037af30acaf585914990dc7988db7b2ea 100644
index cfcdb21f48f74ea1638907e966f06c4aee072d34..365cf8486d690029a48b771a6186118a28eba7d4 100644
--- a/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
+++ b/src/main/java/net/minecraft/network/protocol/game/ClientboundSystemChatPacket.java
@@ -21,7 +21,15 @@ public record ClientboundSystemChatPacket(@org.jetbrains.annotations.Nullable ne
@@ -16,7 +16,7 @@ public record ClientboundSystemChatPacket(@javax.annotation.Nullable net.kyori.a
}
public ClientboundSystemChatPacket(net.md_5.bungee.api.chat.BaseComponent[] content, int typeId) {
- this(null, net.md_5.bungee.chat.ComponentSerializer.toString(content), typeId);
+ this(null, garbageConversion(content), typeId); // Paper - don't nest if we don't need to so that we can preserve formatting
+ }
- this(null, net.md_5.bungee.chat.ComponentSerializer.toString(content), typeId); // Paper - Adventure
+ this(null, improveBungeeComponentSerialization(content), typeId); // Paper - Adventure & don't nest if we don't need to so that we can preserve formatting
}
// Spigot end
// Paper start
@@ -27,6 +27,14 @@ public record ClientboundSystemChatPacket(@javax.annotation.Nullable net.kyori.a
public ClientboundSystemChatPacket(net.kyori.adventure.text.Component content, int typeId) {
this(content, null, typeId);
}
+
+ private static String garbageConversion(net.md_5.bungee.api.chat.BaseComponent[] content) {
+ private static String improveBungeeComponentSerialization(net.md_5.bungee.api.chat.BaseComponent[] content) {
+ if (content.length == 1) {
+ return net.md_5.bungee.chat.ComponentSerializer.toString(content[0]);
+ } else {
+ return net.md_5.bungee.chat.ComponentSerializer.toString(content);
+ }
}
// Spigot end
+ }
// Paper end
public ClientboundSystemChatPacket(FriendlyByteBuf buf) {