mirror of
https://github.com/FabricMC/fabric.git
synced 2024-11-14 19:25:23 -05:00
Fix incorrect behavior with ClientMessageEvents and CommandApi (#3182)
This commit is contained in:
parent
2e061fd481
commit
32651619ee
2 changed files with 8 additions and 2 deletions
|
@ -40,7 +40,7 @@ public abstract class ClientPlayNetworkHandlerMixin {
|
|||
}
|
||||
}
|
||||
|
||||
@ModifyVariable(method = "sendChatMessage", at = @At(value = "LOAD", ordinal = 0), ordinal = 0, argsOnly = true)
|
||||
@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);
|
||||
|
@ -55,7 +55,7 @@ public abstract class ClientPlayNetworkHandlerMixin {
|
|||
}
|
||||
}
|
||||
|
||||
@ModifyVariable(method = "sendChatCommand", at = @At(value = "LOAD", ordinal = 0), ordinal = 0, argsOnly = true)
|
||||
@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);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
package net.fabricmc.fabric.test.message.client;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -36,6 +37,11 @@ public class ChatTestClient implements ClientModInitializer {
|
|||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(ClientCommandManager.literal("block").then(ClientCommandManager.literal("send").executes(context -> {
|
||||
throw new AssertionError("This client command should be blocked!");
|
||||
}))));
|
||||
//Register the modified result command from ClientSendMessageEvents#MODIFY_COMMAND to ensure that MODIFY_COMMAND executes before the client command api
|
||||
ClientCommandRegistrationCallback.EVENT.register((dispatcher, dedicated) -> dispatcher.register(ClientCommandManager.literal("sending").then(ClientCommandManager.literal("modified").then(ClientCommandManager.literal("command").then(ClientCommandManager.literal("message").executes(context -> {
|
||||
LOGGER.info("Command modified by ClientSendMessageEvents#MODIFY_COMMAND successfully processed by fabric client command api");
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}))))));
|
||||
//Test client send message events
|
||||
ClientSendMessageEvents.ALLOW_CHAT.register((message) -> {
|
||||
if (message.contains("block send")) {
|
||||
|
|
Loading…
Reference in a new issue