From d4f6c29fff3bfacacfc7187835d2c826ab37f6b0 Mon Sep 17 00:00:00 2001 From: FlorianMichael Date: Tue, 9 Jul 2024 23:40:37 +0200 Subject: [PATCH] Don't cancel chat commands without arguments Fixes https://github.com/ViaVersion/ViaFabricPlus/issues/474 --- .../network/MixinClientPlayNetworkHandler.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java index 667d416c..91c6142d 100644 --- a/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java +++ b/src/main/java/de/florianmichael/viafabricplus/injection/mixin/fixes/minecraft/network/MixinClientPlayNetworkHandler.java @@ -42,6 +42,10 @@ import net.minecraft.entity.vehicle.BoatEntity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.network.ClientConnection; +import net.minecraft.network.message.ArgumentSignatureDataMap; +import net.minecraft.network.message.LastSeenMessagesCollector; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.c2s.play.ChatCommandSignedC2SPacket; import net.minecraft.network.packet.c2s.play.ClientStatusC2SPacket; import net.minecraft.network.packet.s2c.play.*; import net.minecraft.recipe.RecipeEntry; @@ -58,6 +62,7 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.time.Instant; import java.util.ArrayList; import java.util.LinkedHashSet; import java.util.List; @@ -83,6 +88,8 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH @Shadow protected abstract boolean isSecureChatEnforced(); + @Shadow private LastSeenMessagesCollector lastSeenMessagesCollector; + protected MixinClientPlayNetworkHandler(MinecraftClient client, ClientConnection connection, ClientConnectionState connectionState) { super(client, connection, connectionState); } @@ -143,6 +150,15 @@ public abstract class MixinClientPlayNetworkHandler extends ClientCommonNetworkH } } + @Redirect(method = "sendCommand", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;sendPacket(Lnet/minecraft/network/packet/Packet;)V")) + private void alwaysSignCommands(ClientPlayNetworkHandler instance, Packet packet, @Local(argsOnly = true) String command) { + if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_20_3)) { + this.sendPacket(new ChatCommandSignedC2SPacket(command, Instant.now(), 0L, ArgumentSignatureDataMap.EMPTY, this.lastSeenMessagesCollector.collect().update())); + } else { + instance.sendPacket(packet); + } + } + @WrapWithCondition(method = "onPlayerRespawn", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ClientPlayNetworkHandler;startWorldLoading(Lnet/minecraft/client/network/ClientPlayerEntity;Lnet/minecraft/client/world/ClientWorld;Lnet/minecraft/client/gui/screen/DownloadingTerrainScreen$WorldEntryReason;)V")) private boolean checkDimensionChange(ClientPlayNetworkHandler instance, ClientPlayerEntity player, ClientWorld world, DownloadingTerrainScreen.WorldEntryReason worldEntryReason, @Local(ordinal = 0) RegistryKey registryKey) { return ProtocolTranslator.getTargetVersion().newerThanOrEqualTo(ProtocolVersion.v1_20_3) || registryKey != this.client.player.getWorld().getRegistryKey();