So, i want a way to intercept sent chat messages without the server receiving them. Normally i could use a coremod, but i think since this could be useful to other people too, it might be better to be added into forge. The easiest way would probably to make a (cancallable) ClientChatSentEvent. To archieve the actual call, func_146403_a() in GuiChat should be changed to:
this.mc.ingameGUI.getChatGUI().addToSentMessages(p_146403_1_);
ClientChatSentEvent event = new ClientChatSentEvent(p_146403_1_);
if (!MinecraftForge.EVENT_BUS.post(event) && event.message != null) {
if (net.minecraftforge.client.ClientCommandHandler.instance.executeCommand(mc.thePlayer, p_146403_1_) == 1) return;
this.mc.thePlayer.sendChatMessage(p_146403_1_);
}
Edit: While at it, it might be wise to also provide a way to intercept tab-completion. I haven't looked at the code for that yet though
Why do you want to do this?
The existing "client only" commands can already be canceled, resulting in them being sent to the server. If you register a command as a client and server command you can somewhat easily control whether it should be sent to the server or not simply by listening to CommandEvent. Canceling that on a client command will forward it to the server.
Be careful with WrongUsageException, throwing it has the same effect as canceling the CommandEvent, until #1219 is pulled.
I do not want commands. I want an ability to intercept and change regular chat lines. Example usage would be on a server which have a kind of "team chat" which would be accessed like "/teamchat
Ah, missed the message part.
Couldn't you add a team chat key binding that filled in "/teamchat"? Vanilla already has the GameSettings#keyBindCommand key binding.
if (this.currentScreen == null && this.gameSettings.keyBindCommand.isPressed() && flag) {
this.displayGuiScreen(new GuiChat("/"));
}
Thats true, yet this feature would give more flexibility, like adding special commands (kinda like The terminal glasses from one of the OpenMods which use $$ as prefix) client side.
Why use special prefixes for commands, just use /.
As for the team chat it's rather simple, you have the ability to render your own chat frame.
Like any other game, you should probably have the chats as separate tabs and as such separate input boxes.
Since you control the input box you control where and how it goes.
We already have all the nessasary hooks for this.
Oh cool, didn't know that, can someone give me a pointer to the right classes?
We have ClientChatReceivedEvent that allows us to manipulate and monitor the chat that the client receives, ServerChatEvent to monitor the chat that the server receives, but we have no way to handle the chat that the player is about to send if we are considering a client-only mod. I need this for my chat translating mod, and the only way I can think of to manipulate the sent chat messages is to modify the built-in vanilla chat and make my own just for storing the user's chat input and manipulating it, which i find impractical.
Is it now included into Forge 1.8?
This event seems to have a reasonable case for it.
To take this to the next stage, someone should write a PR.
Most helpful comment
This event seems to have a reasonable case for it.
To take this to the next stage, someone should write a PR.