ChatEvents
ChatEvents
ChatEvents is a very simple plugin, but that has infinite possibilities.
You can add hover and click events or insertion (shift + click will insert text in your chat bar).
This uses the tell-raw arguments to modify the chat: each time someone talks, it will replace the message by a raw message.
This message is configurable in the config under "format" (see config below). You can also create events in the config.
There even is a configurable permission to see the normal message, or the raw message (with events).
Each event has it's own unique (or not) permission, for exemple to limit a click event to moderators.
You can add events to the player name, the message, the hole line or create your own custom events on certain variables.
Here is the list of events:
- hover: Used for when the player puts his mouse over the word/sentence.
- show_text: Used to show text, can be whatever you want.
- show_item: Used to show an item.
- show_entity: Used to show an entity (e.g. {id:UUID,name:Blaze,type:BLAZE})
- show_achievement: Used to show an achievement (e.g. ?)
- click: Used for when the player clicks the word/sentence.
- suggest_command: Suggests a command in the chat bar.
- run_command: Runs a command as the player.
- open_url: Opens a URL (or the "Are you sure you want to open the following website?" prompt).
- change_page: Don't use this, it's for books, it is used to redirect to a specific page of the current book.
- insertion: Used to insert text in the chat bar when a player shift-clicks the word/sentence.
Configuration
After installing the plugin, a config.yml file will be generated like that:
format: '&7{PLAYER} &8ยป &f{MESSAGE}' priority: MONITOR permission: 'ChatEvents.sendJSON' events: username: hover: permission: 'ChatEvents.username.hover' action: show_text value: '&6Name: &e{USERNAME}\n&6Balance: &e{MONEY}\n&6Rank: &e{RANK}' click: permission: 'ChatEvents.username.click' action: suggest_command value: '/msg {USERNAME} Type your message here.' vars: - '{PLAYER}' - '{USERNAME}' - '{CUSTOM}' - '{TABNAME}' message: hover: permission: 'ChatEvents.message.hover' action: show_text value: '&6Click here to google this message.' disabled: true click: permission: 'ChatEvents.message.click' action: open_url value: 'http://www.google.com/?q={MESSAGE}' disabled: true vars: '{MESSAGE}' acustomevent: hover: permission: 'ChatEvents.other.hover' action: show_text value: '&6HelloWorld!' click: permission: 'ChatEvents.other.click' action: open_url value: 'http://www.google.com/?q=Hello World' vars: - '{VIEWER}' - '{VIEWERNAME}' - '{VIEWERCUSTOM}' - '{VIEWERTAB}' all: insertion: permission: 'ChatEvents.all.insertion' value: '{MESSAGE}' vars: '*'
(I removed the comments to make it easier to read)
Each time someone talks, the message will be in the format set in the "format" section.
For example, the default format will be the name of the player in gray, an arrow pointing right in dark gray and the message in white.
The "permission" part is used to determine if a player should see the events, or not.
You can also disable each event individually at any moment, just by adding "disabled: true" and reloading.
Permissions
The "permission" in the config, is the permission used to determine if a player should see the events, or not.
Then, for each individual event, you can set a permission.
For exemple, if you want normal players to be able to hover a player's name, but not click it, use something like this:
events: username: hover: permission: 'ChatEvents.username.hover' action: show_text value: '&6Name: &e{USERNAME}\n&6Balance: &e{MONEY}\n&6Rank: &e{RANK}' click: permission: 'ChatEvents.username.click' action: run_command value: '/mute {USERNAME} 15m' vars: - '{PLAYER}' - '{USERNAME}' - '{CUSTOM}' - '{TABNAME}'
And give the permission "ChatEvents.username.hover" to normal players, but not "ChatEvents.username.click".
You can use several variables, such as PLAYER, USERNAME, CUSTOM, TABNAME, WORLD or MESSAGE without any other plugin.
The variables VIEWER, VIEWERNAME, VIEWERCUSTOM and VIEWERTAB are also available and will change according to the receiver.
If you want other variables, install Vault and you will have access to MONEY, RANK, PREFIX or SUFFIX.
To insert a variable in a message, surround it with curly brackets ( {...} ) and use CAPITALS.
Developers
You have a plugin that is not supported by ChatEvents, and want to have the variables in the chat?
ChatEvents offers a VERY easy API to add your own variables!
For exemple, you have a plugin that adds tokens, and you want to show the player's tokens when you hover his name.
Then it is very easy, in your onEnable void, add this code:
Module tokensModule = new Module("tokens") { // The "tokens" part is what your variable name will be, this will give {TOKENS} @Override public String getValue (Player player, Player viewer) { String tokens = "0"; // Put the code to get the tokens of player here. return tokens; } }; Module relationModule = new Module("relation") { // This will give {RELATION} @Override public String getValue (Player player, Player viewer) { String relation = ChatColor.YELLOW + "Neutral"; // Put the code to get the relation between player and viewer here. return relation; } };
In the name of the module, you can put, or not the curly brackets ( {...} ) and put capitals or not.
But in the config, the curly brackets and the capitals are mandatory.
If you don't save this to a variable, it still works, but you won't have it saved.
Saving it to a variable can be usefull to disable it at any moment.
(for exemple when a mini-game is stopped, and your getValues would provoque errors because some variables are unloaded)
You can also add an optional "setValue" void like that:
@Override public void setValue (Player player, String tokens) { // This checks if the string tokens has the format of an integer, to prevent exceptions below. if (tokenscount.matches("\\-?[0-9]+")) { int tokenscount = Integer.parseInt(tokens); // Put the code to set the tokens of player to tokenscount here. } }
This code will never be used by ChatEvents itself, but maybe by other plugins.
After you've done that, add the variable in your config, like that for exemple:
events: tokens: hover: permission: 'ChatEvents.showTokens' action: show_text value: '&6Tokens: &e{TOKENS}' vars: '{PLAYER}'
Voila! You just created your own module for ChatEvents, and you can now use it in ChatEvents' config.
This plugin uses MetricsLite by Hidendra, collecting information which are available on mcstats.org.