mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-08 21:14:41 -04:00
Fix ClientMessageEvents Injection Points (#3778)
(cherry picked from commit a7dc0e41c4
)
This commit is contained in:
parent
5b61bd2784
commit
fc3f06ac9e
2 changed files with 22 additions and 32 deletions
fabric-message-api-v1/src/client/java/net/fabricmc/fabric/mixin/client/message
|
@ -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;
|
||||
|
@ -33,32 +34,24 @@ import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents;
|
|||
@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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,13 +18,14 @@ package net.fabricmc.fabric.mixin.client.message;
|
|||
|
||||
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;
|
||||
|
||||
|
@ -67,17 +68,13 @@ public abstract class MessageHandlerMixin {
|
|||
}
|
||||
|
||||
@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…
Add table
Reference in a new issue