Menu

Custom Player Commands

Zathrus Writer

Custom Player Commands

This is an event handling function that monitors players commands and changes them based on settings from a config file.

This function loads command replacements from file called playercmd.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_replaceplayercommand.class


Configuration file syntax

CommandsEX uses regular expressions to match commands 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:

  • /player command/ ==> replacement command
  • /{ci}player command, case insensitive/ ==> replacement command
  • /{cc}player command, keeping letter case/ ==> replacement uppercased command

For scripting (e.g. to replace 1 command with multiple others), use the following syntax:

/player command/ =={
    1st command to execute
    2nd command to execute
    ....
}

Please note that the closing bracket -> } <- must always be at the beginning of a line.

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 command given ignoring letter case. This way, you can easily catch typos like "/helP", "/Help" etc.

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


Executing commands as console

If required, CommandsEX provides you with a way to execute commands 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/ ==> sudo op $p

This example will make a player that types "/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:

  • /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