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)
How would I go about displaying a message? When a user preforms /survival, I would like to preform /mvtp survival, along with some code that says "&aTeleported to Survival. Any help would be appreciated!
I'm back from my coding hiatus (after reading up on who Eloraam is).
@jaggy80
Sorry it's taken so long, but the first thing that's being fixed (and actually is right now, but hasn't been checked in yet) is your bug with the hash symbols. Sorry it's taken so damn long about it. -_- You'll be able to escape the hash with a backslash.
Other things include fixing some error reporting. If anyone else want to ask for a bug fix, be my guest. I'm probably going to release little incremental builds for a while.
@Corsicaman
I haven't officially tested it for 1.5.1 yet, and I'm doing a little bit of development on it to address some long-overdue bugs.
@CaptainJohnnyBlu
If it works on 1.5.1 you should write it in the plugin's description, just to let people know. ;)
@MelonCraftServer
Sweet. :) Wanna give any specific examples?
@CaptainJohnnyBlu
The source is no secret. Does no one know about the tabs at the top of each and every mod? One's called "Pages" where I put all the documentation, and there's one called "Repository" which has a link to the Git project.
While the source is no secret, the project and code is under Creative Commons License.
...which upon checking is not noted on the project. It's certainly on my other project, MCSignOnDoor. Huh. Edit: fixed that.
@omgitsmit
Yes.
May I see the source, or is it secret? ;)
@MelonCraftServer
Oh, you.
Does this work in 1.5.1?
This is possibly my favorite plugin which I use to censor, abridge and everything else. Thank you so much for possibly the most flexible and useful plugin on bukkit
I've been using this plugin for quite a while. Thank you =D
This plugin is amazing. Don't let it go away!
Question: can I map command aliases onto commands that aren't in the right channel? (I don't know if that's the right word) For example, BungeeCord makes commands like /glist, but when I use another plugin to "run" them (ex: CommandSigns, Commander), it shows up as an unknown command.
@omgitsmit
I haven't even updated my client to 1.5 yet (I like IC2/Buildcraft/Railcraft too much to try right now), and I still need to test MCSignOnDoor's new code against it, let alone this thing.
I don't even know if anything significant changed in the move to 1.5 (that is, significant to my plugin here). When bukkit releases something, try it out and see. It won't hurt anything if it crashes and burns on startup; it will only tell you (and me) what pieces of code are broken, if any at all. (as always, do try out new versions on new worlds rather than risk the current one - and back up!!).
(Well, at least I know its still being used. :P )
@mcbuild
I too would like to use this with 1.5, but i understand some authors want to wait for at least a beta from the bukkit team.
Does it work with 1.5?
@ThedarkdudeZ
I have no idea what you're talking about...
Could you add a config for the messages in chat, like the "Powertool cleared etc."? thanks.
@tustin2121
Yeah, I recommend putting a link to the help pages. For some reason, the link to the "pages" tab at the top is very hidden above the page and is so small I can barely click it. Took a while to find.
@ohaitran
Yes! This is what scripting is! Go to the Pages tab at the top and find the Reference Sheet for the version you are using. Or just browse. :D
Clearly I need to make a link in the main description to the help pages directly...
Is it possible to make one command cause multiple commands? For example making "/fly" do the command "fly" and "speed 5". Or can you only make it one command?