Jump to content

Recommended Posts

Posted

Hello, everyone.

I'm new to Forge and modding. I decided to try to make a couple of mods.

 

My first mod is to send a message in the public chat when client sees a certain message in the chat. Some sort of a bot.

So, here is what I got:

@EventHandler
    public void onChatRecieved(ClientChatReceivedEvent e){
    	if (e.message.getUnformattedTextForChat().contains("Bot, hi")){
    		Minecraft.getMinecraft().thePlayer.sendChatMessage("Troll");
    	}
    }

Full .class

 

  Reveal hidden contents

 

 

For some reason, this code is not working and I don't know why. When I say "Bot, hi" in the chat, it doesn't send "Troll" in the chat.

 

Can anyone help me? Will be much appreciated. :)

Posted

Well, for starters, you would have to retrieve the player that sent the text "Bot, hi". Then, send a message to that player.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted

More accurately:

Minecraft.getMinecraft().thePlayer

is the bot, not the other person.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Thanks you guys for replying to this thread. I read the replies and got some questions.

 

  On 12/31/2015 at 4:45 AM, HappyKiller1O1 said:

Well, for starters, you would have to retrieve the player that sent the text "Bot, hi". Then, send a message to that player.

 

I believe you think this mod is going to be a server side. No. I'm trying to create this mod for a client, so the client is going to be on a vanilla server.

The reason I do this, is I do not own this server. If I did, I could have just created a plugin for it.

 


 

  Quote

More accurately:

Minecraft.getMinecraft().thePlayer

is the bot, not the other person.

 

Could you please explain what you mean by that?

Posted
  On 12/31/2015 at 5:16 AM, Artur_Gamez said:
  Quote

More accurately:

Minecraft.getMinecraft().thePlayer

is the bot, not the other person.

 

Could you please explain what you mean by that?

 

Minecraft.getMinecraft().thePlayer is the client side local player.  If the bot tries to access this it will simply access itself.

 

If the code is running on a server, it will simply crash.  That's it, server's 404.  Game over man, game over.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

You have to talk to the server to send something back to the player.

I am not a cat. I know my profile picture is sexy and amazing beyond anything you could imagine but my cat like features only persist in my fierce eyes. I might be a cat.

Posted
  On 12/31/2015 at 6:44 AM, HappyKiller1O1 said:

You have to talk to the server to send something back to the player.

 

I want to make it like Twitch Bot. Its going to do something if a player typed something in the chat. And I dont want to touch the server side.

Posted
  On 12/31/2015 at 1:52 PM, diesieben07 said:

ClientChatReceivedEvent is a forge event, not an FML lifecycle event like FMLPreInitializationEvent.

Read a tutorial on forge events.

 

Do you mean I registered the event wrong?

Posted

Ok, so. I think that I got the event part. But the question is, how to get client to send a message in the server chat?

 

  On 12/31/2015 at 10:18 PM, HappyKiller1O1 said:

He's probably a very "bold" person. :P

 

Ha ha. Ha. You are a very "funny" person. -.-

  • 2 months later...
Posted

Well after just testing this for a project i'm working on. Your issue is this line.

 

if (e.message.getUnformattedTextForChat().contains("Bot, hi")){

 

You need to change it to this

if (e.message.getUnformattedText().contains("Bot, hi")){

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.