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)
@tustin2121
at least we know what's wrong now :) don't worry, these things happen... it's great you're working on such an excellent plugin itself, everyone seems to be happy about the work you do (including me!)
keep it up and good luck :)
@zathrus_writer
Checking it out, I think I put the option in the config but forgot to actually set it on the EchoControl... the problem is I SWEAR I tested this! :/
EDIT: I've put in a fix for this, though it is untested. I think I'm gonna double-point release this now. My other option is to roll out the first changes to the advanced scripting with only the echo control directive enabled, but that could be disastrous as there's a lot more that could go wrong.
EDIT2: as for vanish, that always returns false except by the ReplacementCommand class which checks if the user specified [cutoff] for the replacement. As for that, I realized when writing the examples a few comments ago that someone might want to specify how much of the word is cut off (cutting off the word "fuck", at the f, vs cutting off the word "candlejack", after the j, for example), and I'll probably implement that in the next release.
@tustin2121
hmm, I've checked out the code from your repository and I guess the echo supression and one more (vanish?) function was always returning false (and setting echo to false as well)
I'll double-check today but I think I was wondering whether you implemented this yet or not myself :)
@LihPeu
If you are getting echo suppression with both "true" and "false" values, that is a bug. Could you answer a couple questions/try a few things about this bug then?
The option that should affect this is options.default-echo (defaults to true). (The options.commands.echo option enables the echo command itself, which plays no part in this bug). The default should ensure that echo suppression is off. What are your specific results when playing with this value?
Secondly, I would like you to change one of those commands to use a single line script. Is echo suppression still happening in this case? ie:
Thanks, and I apologize for the bug.
This plugin provides great flexibility, and is a great way to create user friendly commands.. To share info with users I use the essentials plugin and target the info.txt with my custom commands.
/faq/ ==> news faq
/chat/ ==> news chat
/portals/ ==> news portals
/worlds/ ==> news worlds
I have avoided upgrading to the latest version of the plugin as in my tests when a user triggers one of the above commands they no longer get the information due to the new echo suppression, I noticed the echo options in the config, but with true or false i get the same results. Could you give me an example how to solve this please.
@zathrus_writer
No harm! It just means that it's probably confusing for the end user. Which is not good, generally. :j
@MelonCraftServer
I will point you to a very hand tool I use when making regexes (regular expressions): http://regexpal.com/ This makes testing them very easy. It may not work on the more advanced stuff (like look-back and look-ahead), but for the basic stuff it works perfectly fine.
Directly responding to the question, I personally try to be very conservative and specific about what capture groups capture. Usually I'd make those capture groups ([^\b]+) which means capture all characters that are not word breaking characters (or use \w for whitespace characters like space and tab).
The plus means there must be at least one of character to match. Note that the command
/regionset
(note two spaces at the end) matches the regex you supplied and replaces the back references with nothing. Obviously if only you are using this command, that won't be a problem, but just be warned that regexes can match in ways you don't always foresee.Generally I only use (.*) if I'm capturing the rest of the line for insert into, for example, a say command. As for the back references themselves, what you said should all work like you want. ($0 would be replaced with the whole inputted command, $1 and up are replaced with the capture groups.) :)
@zathrus_writer
Thank you so much. I have one more question: for multiple strings, would i use: /regionset (.*) (.*)/ =={ /expand vert region d $1 region addowner $2 }
Would that reference the correct strings? Do i need to add modifiers to the greedy quantifyer to connect them to $1 and $2 respectively?
@tustin2121
you're right of course, I'm probably a bit overworked... sry to confuse :)
@zathrus_writer
Actually, that's not all correct:
There are three contexts when using Commander: when dealing with player chat, when dealing with player commands, and when dealing with server commands. By default (ie when using the regular ==>) when dealing with chat, Commander will replace the matched text with the replacement text, not executing a command. By default (==>) when working with commands (player or server), Commander will match the whole command and completely replace it with another command (or a script).
@MelonCraftServer
So, examples:
A player types into the chat
Hey asses, how are you doing?
. The following rule will apply:and the player will actually say to the server
Hey dudees, how are you doing?
. (Obviously this isn't the ideal rule, so tweaking will have to be done, but this is how it would print).A player types into the chat
Welcome to Hell, bitch and you sonofabitch
. The following rule will apply:and the player will actually say to the server (for example)
Welcome to Hell, honey and you sonofabitch
(the "honey" is randomly chosen from the list)(also note the "\b" at the start indicates that there should be a word break at the start, as per the rules of regular expressions. Hence why the latter instance isn't replaced.)A player types into the chat
Hey, have any of you seen candlejack around anywhere?
. The following rule is matched:and the player will say
Hey, have any of you seen can
and will be immediately kicked (the ordering of that is a bit bugged still, I think, but it should work) (also, you can adjust how much of the original word gets cut in the config file). (Final chat note: many rules can be matched on one chat. They will be replaced in the order in the file. HOWEVER, if a rule like the one above, that executes a command and cuts off the player, if matched, only that rule will execute.)*A player named Notch3 types a command
/smite me
. The following rule will apply:(This assumes you have a plugin that can execute /smite [playername] and that Notch3 has permission to use it). The player will execute the command
/smite Notch3
and will be struck by lightning.Finally, the console user types the command
tell story
. The following rule will apply:The server will then broadcast all three of those messages to the server, in order, all at once.
works for both - console and chat replacements:
player chat replacement only, executes "say" with console privileges:
will self-kill any player that says "avadakedavra" in chat:
replaces the word asshole randomly with one word from the semicolon-separated list:
checks when a player types /tellstory and executes the 2 /say commands in a sequence:
After reading the info on regexes, i still don't completely inderstand them. What i have been able to do is modify examples and make them work for my commands. Can somone post some examples? I should be able to unscramble them for them to function. Also, it would be beneficial to create a "templates" section, or more examples so nonprogrammers like myself can easily pick up. Thanks. Love the plugin. Hardest laughsin a long time!
@tustin2121
well, I have no idea what the switch/case is about (not the idea - I know that from programming - but the idea to put it to Commander :) ... if you'd like to explain it a bit, maybe I can help
another thing I discovered is that when you use scripting ( =={ ... } ) in player chat replacements, it just outputs an empty string. I guess it could perhaps take each line of text as a new message and output those messages separately in such case?
@zathrus_writer
But of course. I always found the way CB did that execute order thing really weird... I'll have to change it in the next update.
Also, thanks. :) I'm not sure how I'm gonna do half the planned stuff yet. Like Switch/Case? No idea. I just threw it in there because I was using switch-cases somewhere else while coding. I'm not sure if it's possible to get an integer from minecraft which can be switched on... -_-
@tustin2121
that's some interesting scripting work in progress... I like it a lot and also I'm trying to implement it into CommandsEX at this very moment :)
... also, I've found out that CB has its priorities mismatched with what most people would normally expect. Lowest priority gets executed first, highest last and monitor after that all. You might need to update your event priorities, too. See here for more info.
Version 1.2 has been uploaded and will be avaiable whenever it gets "approved", whatever that means. (I didn't realize that Bukkit has become Apple now). Version 1.2 has scripting! And it's kinda sorta tested, so if there are any errors, feel free to file a ticket (as always)! :)
1.2 has minimal scripting. I've got more planned, including variables and conditionals. :P
@Pr0d1gyR
this could be what you're looking for: http://dev.bukkit.org/server-mods/simplecommandsigns/
@tustin2121
thanks, good luck with your job :-)
@carlosjj
Duly noted: that'll be the first thing I do when I get the chance.
Love this command, need Scripting (one command calls a list of commands)!
@Pr0d1gyR
I'm not entirely sure what you're attempting to do, so I'll answer as best I can. Commander allows command shortening. That is all. It does not do permission checking or anything. The long-form commands still get tested for permissions by their plugin once the command is expanded.
In order to do what (I think) you're trying to do means you have to open up a permission in PEX. The short command will just expand to the long-form PEX command. In terms of the one-time thing, you should try giving the permission for the once-off command to the default group, and not any of the resulting groups. But, seeing as I don't own or run PEX, I can only give you limited advice there.
In other words, this is not a Commander question, this is a PEX question. Commander is simply the arbiter of making the command easier. I highly suggest you work out the details using the long-form commands first, and then shorten them when all is right. :)
Aside: Continued thanks to zathrus_writer for fielding questions about a plugin he didn't make. ^_^; I haven't played Minecraft in a while, as I am particularly busy with work stuff. When the product finally gets kicked out the door, I shall return to this plugin first and update stuff. Unfortunately the timeframe for that is not set, but rough guesstimates place it in the summer months. :/
Ok sorry if this answer is right infront of my face but, I want to know, now a player that just joins my server needs to pick a race, the races are made by permission groups (pex) so i want them to be able add there self to the race they want with the short command i have givin, is it not possible to make it so they can use the short version but not the long version? Because the long version gives them the ability to change others groups which can cause lots of problems, i just want them to be able to use one command of changing to a race as Guest rank and never change again.