Fix chat signatures desyncing when cancelling __on_player_message (#1778)

This commit is contained in:
altrisi authored and GitHub committed 2023-08-01 12:43:47 +02:00
1 parent a29b84ec0d
commit 1a73edbf76
2 files changed
+14 -13

No files matched your search

@@ -2,6 +2,8 @@ package carpet.mixins;
import carpet.fakes.ServerPlayerInterface;
import carpet.script.external.Vanilla;
import net.minecraft.network.chat.ChatType;
import net.minecraft.network.chat.PlayerChatMessage;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.players.PlayerList;
@@ -13,6 +15,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import static carpet.script.CarpetEventServer.Event.PLAYER_MESSAGE;
import static carpet.script.CarpetEventServer.Event.PLAYER_RESPAWNS;
@Mixin(PlayerList.class)
@@ -26,6 +29,17 @@ public class PlayerList_scarpetEventsMixin
PLAYER_RESPAWNS.onPlayerEvent(player);
}
@Inject(method = "broadcastChatMessage(Lnet/minecraft/network/chat/PlayerChatMessage;Lnet/minecraft/server/level/ServerPlayer;Lnet/minecraft/network/chat/ChatType$Bound;)V",
at = @At("HEAD"),
cancellable = true)
private void cancellableChatMessageEvent(PlayerChatMessage message, ServerPlayer player, ChatType.Bound params, CallbackInfo ci) {
// having this earlier breaks signatures
if (PLAYER_MESSAGE.isNeeded())
{
if (PLAYER_MESSAGE.onPlayerMessage(player, message.signedContent())) ci.cancel();
}
}
@Inject(method = "respawn", at = @At(
value = "INVOKE",
target = "Lnet/minecraft/server/level/ServerPlayer;initInventoryMenu()V"
@@ -1,7 +1,6 @@
package carpet.mixins;
import net.minecraft.network.protocol.game.ServerboundChatCommandPacket;
import net.minecraft.network.protocol.game.ServerboundChatPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
@@ -26,7 +25,6 @@ import static carpet.script.CarpetEventServer.Event.PLAYER_STOPS_SPRINTING;
import static carpet.script.CarpetEventServer.Event.PLAYER_SWAPS_HANDS;
import static carpet.script.CarpetEventServer.Event.PLAYER_SWINGS_HAND;
import static carpet.script.CarpetEventServer.Event.PLAYER_SWITCHES_SLOT;
import static carpet.script.CarpetEventServer.Event.PLAYER_MESSAGE;
import static carpet.script.CarpetEventServer.Event.PLAYER_COMMAND;
import static carpet.script.CarpetEventServer.Event.PLAYER_USES_ITEM;
import static carpet.script.CarpetEventServer.Event.PLAYER_WAKES_UP;
@@ -274,17 +272,6 @@ public class ServerGamePacketListenerImpl_scarpetEventsMixin
}
}
@Inject(method = "handleChat(Lnet/minecraft/network/protocol/game/ServerboundChatPacket;)V",
at = @At(value = "HEAD"),
cancellable = true
)
private void onChatMessage(ServerboundChatPacket serverboundChatPacket, CallbackInfo ci) {
if (PLAYER_MESSAGE.isNeeded())
{
if(PLAYER_MESSAGE.onPlayerMessage(player, serverboundChatPacket.message())) ci.cancel();
}
}
@Inject(method = "handleChatCommand(Lnet/minecraft/network/protocol/game/ServerboundChatCommandPacket;)V",
at = @At(value = "HEAD")
)