Jump to content

[1.8] Custom action on clickable chat messages


VoidCatz

Recommended Posts

It is possible to have clickable chat messages. To achieve that you create a custom ChatStye and add a ClickEvent to it. After that this ChatStyle can be applied to an IChatComponent. The ClickEvent allows you to choose an Action from an predefined Enum. The available Actions are: OPEN_URL, OPEN_FILE, RUN_COMMAND, TWITCH_USER_INFO,  SUGGEST_COMMAND and CHANGE_PAGE. In my case I want to define custom click behavior. I tried overriding ClickEvent.getAction() but that doesn't seem to work... :(

 

Here is my code so far:

IChatComponent comp = new ChatComponentText("Text");
ChatStyle style = new ChatStyle().setChatClickEvent(new ClickEvent(Action.RUN_COMMAND, "") {
@Override
public Action getAction() {
	//custom behavior
	return Action.RUN_COMMAND;
}
});
comp.setChatStyle(style);

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.



×
×
  • Create New...

Important Information

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