Events - Yannici/ChatBuilderLib GitHub Wiki

Events

In the new minecraft chat protocol it is possible to add events. There are two types of events at the moment:

Click Event

The click event allows to add clickable links in the chat. At clicking there are several options to choose what does the click should do. This can easily combined with the hover event

Actions

  • OPEN_URL
    With the OPEN_URL action you can specify an url as value which will open on click.
  • OPEN_FILE
    The OPEN_FILE action allows to open a file. For this you have to specify the file path as value.
  • RUN_COMMAND
    With the RUN_COMMAND action you can force the user to run a command on click. The command you can set in the value of the click event.
  • SUGGEST_COMMAND
    The SUGGEST_COMMAND action allows to write a specific text/command (set as event value) in the user's chat, but doesn't send it.

Example usage

ChatBuilder builder = new ChatBuilder();

/* opens a url on click */
ChatElement link = builder.appendText("ChatBuilderLib-Plugin");
link.setClickEvent(ChatClickEventAction.OPEN_URL, "https://github.com/Yannici/ChatBuilderLib");

/* runs a command on click */
ChatElement runCommand = builder.appendText("Go to the hub!");
runCommand.setClickEvent(ChatClickEventAction.RUN_COMMAND, "/hub");

/* opens a file */
ChatElement openFile = builder.appendText("Open that file");
openFile.setClickEvent(ChatClickEventAction.OPEN_FILE, "filepath/filename.txt");

/* write text to chat on click */
ChatElement suggestCommand = builder.appendText("Send to quit");
suggestCommand.setClickEvent(ChatClickEventAction.SUGGEST_COMMAND, "/quit");

Hover Event

The hover event allows you to specify a text, item or achievement which will show in a tooltip when hovering the specific text. This can easily combined with the click event.

Actions

  • SHOW_TEXT
    Will show a text in a tooltip on hover. This text can be formatted with ChatColor or minecraft color codes.
  • SHOW_ACHIEVEMENT
    You can specify a achievement which will be displayed when hovering the text.
  • SHOW_ITEM
    You can set a item, formatted as json, which will be displayed in a tooltip when hovering the text.

Example usage

ChatBuilder builder = new ChatBuilder();

/* shows a text on hover */
ChatElement textHover = builder.appendText("ChatBuilderLib-Plugin");
textHover.setClickEvent(ChatHoverEventAction.SHOW_TEXT, ChatColor.GREEN + "My beautiful §bplugin§f");

/* shows a achievement on hover */
ChatElement runCommand = builder.appendText("I just recieved a achievement!");
runCommand.setClickEvent(ChatHoverEventAction.SHOW_ACHIEVEMENT, "achievement.openInventory");

/* display an item on hover */
ChatElement openFile = builder.appendText("Look my new item!");
openFile.setClickEvent(ChatHoverEventAction.SHOW_ITEM, "{id:35,Damage:5,Count:2,tag:{display:{Name:OP-Item}}}");