Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ClientMessageEvents Injection Points #3778

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

package net.fabricmc.fabric.mixin.client.message;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

import net.minecraft.client.network.ClientPlayNetworkHandler;
Expand All @@ -33,32 +34,24 @@
@Mixin(value = ClientPlayNetworkHandler.class, priority = 800)
public abstract class ClientPlayNetworkHandlerMixin {
@Inject(method = "sendChatMessage", at = @At("HEAD"), cancellable = true)
private void fabric_allowSendChatMessage(String content, CallbackInfo ci) {
if (!ClientSendMessageEvents.ALLOW_CHAT.invoker().allowSendChatMessage(content)) {
ClientSendMessageEvents.CHAT_CANCELED.invoker().onSendChatMessageCanceled(content);
private void fabric_allowSendChatMessage(String _content, CallbackInfo ci, @Local(argsOnly = true) LocalRef<String> content) {
if (ClientSendMessageEvents.ALLOW_CHAT.invoker().allowSendChatMessage(content.get())) {
content.set(ClientSendMessageEvents.MODIFY_CHAT.invoker().modifySendChatMessage(content.get()));
ClientSendMessageEvents.CHAT.invoker().onSendChatMessage(content.get());
} else {
ClientSendMessageEvents.CHAT_CANCELED.invoker().onSendChatMessageCanceled(content.get());
ci.cancel();
}
}

@ModifyVariable(method = "sendChatMessage", at = @At("HEAD"), ordinal = 0, argsOnly = true)
private String fabric_modifySendChatMessage(String content) {
content = ClientSendMessageEvents.MODIFY_CHAT.invoker().modifySendChatMessage(content);
ClientSendMessageEvents.CHAT.invoker().onSendChatMessage(content);
return content;
}

@Inject(method = "sendChatCommand", at = @At("HEAD"), cancellable = true)
private void fabric_allowSendCommandMessage(String command, CallbackInfo ci) {
if (!ClientSendMessageEvents.ALLOW_COMMAND.invoker().allowSendCommandMessage(command)) {
ClientSendMessageEvents.COMMAND_CANCELED.invoker().onSendCommandMessageCanceled(command);
private void fabric_allowSendCommandMessage(String _command, CallbackInfo ci, @Local(argsOnly = true) LocalRef<String> command) {
if (ClientSendMessageEvents.ALLOW_COMMAND.invoker().allowSendCommandMessage(command.get())) {
command.set(ClientSendMessageEvents.MODIFY_COMMAND.invoker().modifySendCommandMessage(command.get()));
ClientSendMessageEvents.COMMAND.invoker().onSendCommandMessage(command.get());
} else {
ClientSendMessageEvents.COMMAND_CANCELED.invoker().onSendCommandMessageCanceled(command.get());
ci.cancel();
}
}

@ModifyVariable(method = "sendChatCommand", at = @At("HEAD"), ordinal = 0, argsOnly = true)
private String fabric_modifySendCommandMessage(String command) {
command = ClientSendMessageEvents.MODIFY_COMMAND.invoker().modifySendCommandMessage(command);
ClientSendMessageEvents.COMMAND.invoker().onSendCommandMessage(command);
return command;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@

import java.time.Instant;

import com.llamalad7.mixinextras.sugar.Local;
import com.llamalad7.mixinextras.sugar.ref.LocalRef;
import com.mojang.authlib.GameProfile;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

Expand Down Expand Up @@ -67,17 +68,13 @@ private void fabric_onChatMessage(Text message, @Nullable SignedMessage signedMe
}

@Inject(method = "onGameMessage", at = @At("HEAD"), cancellable = true)
private void fabric_allowGameMessage(Text message, boolean overlay, CallbackInfo ci) {
if (!ClientReceiveMessageEvents.ALLOW_GAME.invoker().allowReceiveGameMessage(message, overlay)) {
ClientReceiveMessageEvents.GAME_CANCELED.invoker().onReceiveGameMessageCanceled(message, overlay);
private void fabric_allowGameMessage(Text _message, boolean overlay, CallbackInfo ci, @Local(argsOnly = true) LocalRef<Text> message) {
if (ClientReceiveMessageEvents.ALLOW_GAME.invoker().allowReceiveGameMessage(message.get(), overlay)) {
message.set(ClientReceiveMessageEvents.MODIFY_GAME.invoker().modifyReceivedGameMessage(message.get(), overlay));
ClientReceiveMessageEvents.GAME.invoker().onReceiveGameMessage(message.get(), overlay);
} else {
ClientReceiveMessageEvents.GAME_CANCELED.invoker().onReceiveGameMessageCanceled(message.get(), overlay);
ci.cancel();
}
}

@ModifyVariable(method = "onGameMessage", at = @At(value = "LOAD", ordinal = 0), ordinal = 0, argsOnly = true)
private Text fabric_modifyGameMessage(Text message, Text message1, boolean overlay) {
message = ClientReceiveMessageEvents.MODIFY_GAME.invoker().modifyReceivedGameMessage(message, overlay);
ClientReceiveMessageEvents.GAME.invoker().onReceiveGameMessage(message, overlay);
return message;
}
}
Loading