Jump to content

Checking for specific server message


logan121

Recommended Posts


Hello, im trying to make it so if the message that is sent in chat is == `hi` it will send hi! back. 

This is what I have managed so far, although im unsure how i can make it only send if the message is == `hi` Originally I tried if(e.message.equals("hi");

However, it is false no matter what I do!

The type is IChatComponent

I then found out that I can do the following:
However, im unsure how i can filter the message so its only true if the message is == `hi`
 

@SubscribeEvent
public void onChat(ChatReceivedEvent e) {
    if(e.message.equals(e.message)) {
        System.out.println(e.message);
        mc.Player.sendChatMessage("hi!");
    }else {
        System.out.println(e.type);
        System.out.println("1");
    }
}

If anyone could help me it would be great as I have been trying to get this to work for around 2 hours.

Thanks,
Logan

Link to comment
Share on other sites

@SubscribeEvent
public void onChat(ChatReceivedEvent e) {
    String raw = e.message.getUnformattedText();
    if (raw.contains("!help")) {
        mc.Player.sendChatMessage("hi");
    }
}

 

I've finally figured it out, 

next step: How can I make it so if the player sends this message, it will only send it client side?

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.