Jump to content

Canceling the sending of a chat message


goldenfire64

Recommended Posts

I was trying to make a mod that cancels any chat that starts with ",chatmod", but when I tried event.setCanceled(true), my client didn't show the message but the clients of other players did show the message.

Here's a snippet of my code:

    @SubscribeEvent
    public void onChat(ClientChatReceivedEvent event) {
        String message = event.getMessage().getUnformattedText();
        print(message+" (printed)");
        if (message.split(" ")[0].contentEquals(",chatmod")) {
        	
        	print("CHATMOD COMMAND");
        	print("TYPE: "+message.split(" ")[2]);
        	event.setCanceled(true);
        	
        }
    }
    

Also, here's the print function I made:

void print(String toP) {
		
	Minecraft.getMinecraft().player.sendMessage(new TextComponentString(toP));
		
};

 

What event could be canceled so that the message wouldn't be sent in the first place?

Edited by goldenfire64
Spelling error
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.