Menu

Chat Text Replacements

Zathrus Writer

Chat Text Replacements

This is an event handling function that monitors players chat and replaces text based on settings from a config file.

This function loads text replacements from file called playerchat.txt (unless file name is changed in the plugin config file), located in the CommandsEX directory in your plugins folder. If the config file doesn't exist, it will be created automatically.


How to remove this feature

Should there be a need to manually remove this feature from the JAR file, the following file must be removed: com/github/zathrus_writer/commandsex/handlers/Handler_replacechat.class


Configuration file syntax

CommandsEX uses regular expressions to match chat text against texts provided in the config file. You can use any regular expression supported by Java and test them here (basic stuff) or here (advanced stuff).

The actual format of your config file must follow this principle:

  • /text to search for/ ==> replacement text
  • /{ci}search text, case insensitive/ ==> replacement text
  • /{cc}search text, keep letter case/ ==> replacement uppercased text
  • /chat message/ =c=> command_to_execute
  • /chat message/ =r=> semicolon;separated;values;to;randomly;replace;original;text

The {ci} and {cc} switches are special to CommandsEX. They must be listed at the beginning of the regular expression. As the example above states, if {ci} is used, CommandsEX will search for the text given ignoring letter case. This way, you can easily catch words like "idiot", "IDioT", "IDIOT" etc.

The {cc} switch will check if the text entered by a player is uppercase and if it is, CommandsEX will automatically make the text replacement uppercase as well.

The =c=> replacement type will react on a provided text in a chat message and execute command on the right-hand side. This is a chat to command bridge that can be used for instance to create passwords that will, when typed correctly, unlock locations or give rewards to players.

The =r=> replacement type will randomly replace given text in chat by one of the replacements provided. Replacement texts must be separated by semicolon.


Executing commands as console

If required, CommandsEX provides you with a way to execute commands when using =c=> replacement type as if the player was typing them into console.

To do so, you simply need to prefix the right-hand side replacement command with the word sudo, which stands for "Super-User Do" and comes from the Unix platform.

Example:

  • /makemeop/ =c=> sudo op $p

This example will make any player that types in "makemeop" into chat an Operator.


Back references support

CommandsEX supports back references following java's model (e.g. $1 - $9), adding reference $p for player's name (not display name, but the real user name).

These are some more examples of how back references work (these are applicable to player commands and are here only for reference):

  • /cmode/ ==> gamemode $p 1 (switches game mode of the player to creative)
  • /smode/ ==> gamemode $p 0 (switches game mode of the player to survival)
  • /promote (.*)/ ==> pex promote $1
  • /demote (.*)/ ==> pex demote $1

Known caveats:

Command words (regexes matching against the chat which execute commands) run the commands before the chat message is broadcast, instead of afterward. The commands are still run in response to what you say in chat, it just doesn't seem like it...


Credits:

This functionality has been merged from the former Commander plugin, developed by tustin2121


Related

Wiki: CommandsEX CraftBukkit plugin Wiki
Wiki: Configuration

MongoDB Logo MongoDB