Commander
Ever wanted to make an alias for those really long commands you have to type out constantly? Want to give players a simple one word command to warp somewhere? Want to create advanced scripts that run when you type a command? Want to clean up the server chat a bit?
Commander can do all that for you!
Commander is a find-replace plugin for commands and chat. It uses regular expressions to search player commands, player chat, or even console commands and replaces any matches with specified replacements! It even supports back references!
Commander is also a scripting language (Coming Soon!) which allows a single command to fire off a set of commands, with if statements and while loops and function calls! Oh my!
How it works
Commander examines player commands and server commands before proper processing of the commands even begins. It will use a list of regular expressions provided in the configuration folder and attempt to match the regex to the whole command. If it matches, it will replace the command with the specified replacement, be it a single command or a script!
For chat, it will attempt to find the regex in the chat somewhere, and replace the matched words with the specified replacement. Commander will even check if the word it found is in all caps, and, if it is, make the replacement in all caps as well! It also supports Command Words, which will fire off a command or script when the regex matches a word in the chat!
A Note about Permissions
Commander does not use permissions when matching, and there are no plans to make it use permissions. Commander simply finds and replaces the command regardless of permission status. There are also no permissions to bypass replacement - it will replace for all players regardless of permission status. If you wish to deny access to a command, you must deny access to the replacement. Note also: Players will not see the replacement command, they will only know what they entered worked or did not work.
Commander, however, does have support for Bukkit's built-in permissions in script (Coming Soon!). If you want to deny your players access to a command which fires off a script, you can put an if statement that checks if the current player has the proper permission!
Example Configuration
When you start up the plugin for the first time, Commander will place 3 text files in its data folder along with the config.yml. There is one file for each replacement context: player commands, player chat, and console commands. The following is the default player command file:
/cmode/ ==> gamemode $p 1 /smode/ ==> gamemode $p 0 /promote (.*)/ ==> pex promote $1 /demote (.*)/ ==> pex demote $1
The format is as follows: /find regex/ ==> replacement
The find regex is denoted by forward slashes (/). The replacement comes after the double equals arrow (==>).
Java regular expressions are fully supported (minus the escaping the backslash malarkey) and a guide to java regexes can be found here.
In the replacement string, the dollar sign ($) signifies a back reference to a capture group in the regex. Special back references can also be used relating to the player issuing them. The list of back references is as follows:
- $0 - $9 = back reference to a capture group in the regex (following java's model)
- $p = player name (not display name, but normal name)
- ....more to come....
Version 2.0 BETA
Version 2.0 is the advanced scripting overhaul. It is currently in alpha and may be unstable. However, while developing the scripting, I made sure all unit tests pass every time I change something, so there is the distinct possibility that all will work perfectly fine for your needs!
A comprehensive scripting reference guide can be found in the Pages tab!
Version 2.0 also adds an API for those who wish to use Commander's scripting language in their own plugin!
Version 1.2
(Yes, I realize now that I skipped version 1.1, because I thought zathrus's update was 1.1, when it was 1.0.1) Version 1.2 adds scripting!! Yay! To script, do this:
/regex/ =={ commands }
Version 1.2 also adds a helpful Reference.txt that gets copied to your data folder. There, it will explain in detail all the new changes that have taken place!
Known Bugs
- 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...
- The [cutoff] parameter does not work properly due to the way it executes the command given to it. Due to this, cutoff will only work properly if the replacement word or phrase is the first or only thing said in the chat.+
- When parsing a script, the plugin will not detect uneven braces when there are too many open braces. This leads to commands after the orphaned open bracket not executing, as well as causing far more than just that script to be parsed as a script.+
- Backslashes, which are supposed to escape special characters, in fact remove the character they are supposed to escape.+
+ This has been fixed in the advancedScripting branch of development.
Planned Features
- More special replacement back references
- Advanced Scripting (in progress)
- Player persistent variables (session only). (for Version 2.0)
This plugin saves me in so many ways but I have countered some problems on the last things I added:
/regex/ =c=> [cutoff] quit - Quits the player but the cutoff does not happen.
/regex/ =c=> [cutoff] sudo kick $p - Royalcommands spits out an error here cause of the sudo command.
@crfptb0808
From the console, type the command "commander debug" and it will toggle on debugging: every command that commander processes will be printed to the console. With that, you can see if the command is processing the way you want.
Remember to make sure that the rule is in the right config file and that the plugin the final command is referencing is actually installed properly and you are writing the final command properly. Commander does not print anything to the player itself - it simply rearranges what the player types and passes it off to normal command processing. It is normal command processing that returns the message "unknown command". Make sure you try the final command without commander processing it to see if it works.
@tustin2121
Hey thanks for the tip, but that doesnt seem to work! I paste the /rank (\W+) (.+)/ ==> permissions player setgroup $1 $2 in my config, but when i do /rank crfptb0808 admin (just to test) it says "Unknown command" :/ Is there a way to fix it?
@crfptb0808
Of course! That is what the plugin is designed to do. In this case, you put into either the player commands file, if you plan to use it while logged in, the server commands file, if you plan to use it only from the console, or both the following rule:
That's an untested, thrown together regex as an example. You can play with the regex to suit your needs. The \W means non-white space characters - so one or more non-spaces. See if that works! :)
Hi there! Great plugin, but I had one question. I use the plugin for shortening commands and censoring. But the shortening commands part i needed help with. I use permissions bukkit and to rank someone up i have to type /permissions player setgroup <player> <Rank>. Is there a way to set it up to where i can do /rank <player> <rank>, so essentially removing the /permissions player setgroup??
Sorry if this was confusing in any way
Awsome plugin, one little request to make the echo more genuine is to be able to add colors to the text.
@tustin2121
The command was executed in the chat of the MC client.
The replacement command works.
I did not reload from console. I'll try that... yep, that works. Thx for helping.
@Gretter
Where were you doing the command from? Please note that commands in playercmd.txt only get applied to commands the players make, servercmd.txt only gets applied to commands from the console.
Also remember that commander only replaces commands being processed and the plugin still has to be properly installed. Please ensure you can run the command without the commander shortcut.
Finally, the /commander reload command can only be run from the console (as Commander does not have permissions) and on the console it has text that confirm the reload. :)
hey Zath.
I'm happy to say we've installed commander.
/gc/ ==> ch qm global test
With this in playercmd.txt I expected /gc in chat to result in the same as: /ch gm global test
The result is: Unknown command.
The server was was restarted. Perhaps /commander reload would have been enough, but /commander reload does not confirm reload. It displays the command syntax: /commander [reload|debug]
Best regards Gretter
P.S. Hope you're having a better weather then we are.... all this rain makes me play to much MC.
@vlaster
you most probably need to type this into your playercmd.txt file:
/a (.*)/ ==> track $1
... please note, there are no spaces at the beginning or the end of the first part. In your example you had / a /, above you can see it must be written like /a/
Also, /testcommand == [cmd] ==> null has completely wrong syntax, so it cannot work. It's missing a closing / character and there is no such syntax as == [cmd] ==> null
@zathrus_writer
I wrote this command in cmd to test if it works but still says in cmd: /testcommand == [cmd] ==> null Some commands work, as time set and op
hello, what I have to write to run this command / track <player> when i write / a <player>, I write in playercmd this: / a / ==> track, and does not work
thanks good plugin ;)
Love this!!! work! :D
I not set any handle.. I use defaults.
@Koiraman
how did you set up Commander to handle /echo command?
On i type /echo something text here..
Then i got message: An internal error has occurred while attempting to perform this command.
Please fix that. Thanks.
- kuchiyo
Love this!!!
I have a plugin idea..
on someone type: /healme then it plays rickroll :D:D
@turtledude01
you can use keyword sudo in front of a command to execute it as console instead of the Player:
/testcommand/ ==> sudo pex user $p group set myGroup
I got this plugin hoping that i could use it to make players type in a command that is a code that allows then to auto set themself in the group Member. But a player must be OP to use any commands this plugin brings. How can i allow the players to type in a code to be set in the group? Thanks
@tustin2121
Hey, thanks for looking into this, my results when playing with the echo values in the config remain the same when both set to true or false. I just tried your suggestion of the script, and the same results, no echo. Its not problem for me, the previous version is working perfectly, I am keen to use the new multi-line script options, when the next version is out. Thanks again, great work on this plugin :D