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)
I have a suggestion, idk if I could set "/ranks" to a text file or yml, like I can set random commands and they loads a text file. You think its possible or its already implemented?
@Remi_Scarlet
Well, that error is on the myUltraWarps plugin. Commander caught that exception and did what it was supposed to: stop and report the error.
I guess that error message is a little misleading: Given the stacktrace, Commander properly processed the replacement and fired off the proper command. The command itself, however, threw an exception, which Commander could have caught earlier or differently to differentiate that it was the inner command that threw the exception.
Another double point release then! XD
EDIT: Best guess on the error in myUltraWarps: you used the "back" command when you hadn't warped anywhere that session yet, and the plugin developer hadn't thought to check that variable for null before using it.
EDIT2: Also, I have to thank you for supplying that stack trace, so now I know exactly how to properly report this exception. :)
Wow! That was an incredibly fast update! I've only done quick, basic testing of the new version but it's working flawlessly so far. Thank you! I'll report in any bugs if I find any.
edit: Well, here's one error I found.
http://pastie.org/4606317
@Remi_Scarlet
This is a bug on my part. I guess no one ever used a plugin that had a higher priority than Commander. Bukkit, despite canceling the event, still gives the event to all registered plugins. I do not ignore canceled events, so I still process canceled events. And if there is a replacement that matches, it creates a different event, which is not canceled and probably does not get caught by WorldGuard's list.
This shall be fixed shortly.
@Kiak
I am still not sure what you want to do; perhaps give a specific example? However, I'm sure Commander 2.0 will probably be able to fill this need with its Advanced Scripting functionality. It has if statements, which you can use to test permissions and branch the script accordingly. You might want to try that, if only to see if you can make it work.
As for your huge elaborate aliases, I'm sorry you're losing all that work. I highly doubt Commander will play nice with another plugin that does the same thing. Maybe you can work something out to keep it, but sometimes it is better to redo things from scratch. I'm happy to help convert to Commander, assuming I can understand the BetterAlias format.
Which reminds me, @iKeirNez, did you look at the advanced scripting recently? I know I still need to write up the API pages over on the Pages tab, but I wrote JavaDocs on stuff. I want to make sure that this all works for you, since you are using the codebase in your plugin.
@tustin2121
I can explain..
I use an old "Betteralias" plugin (which works in 1.3.1 but doesnt seem to be actively updated) and have huge elabourate aliases already made
I want my regular users to have access to certain commands but ONLY when other commands run (usually to increase balance) So i might use "/noobcommand1" to...
I know i can work around this in many alternate ways. I just always wished my old plugin had this feature some times
and another old plugin Gui Creator. DID have this functionality so i know it at least was possible.
Absolutely no pressing need for this functionality. i just think it would be a massive time saver for server setups
Hi, is it possible to have Commander hook into WorldGuard for its blocked-cmds flag? I've noticed that if you try to use a blocked command that has an alias in commander, the request will still go through and the command not be blocked.
Eg,
I have a warp called market, but I don't want users to have to type "/warp market" every time, so I have commander replace "/market" with "/warp market." Though I can block either "/warp" or "/market," neither will successfully "block" the warping. I believe this might just be a simple issue with priorities of the execution of the command.
Thanks!
@Kiak
Why not just give them the permission to begin with? I don't understand why you'd want a "temporary permission" beyond the sudo ability.
Actually, with sudo, you could do a temporary permission thing: make a script:
Okay thats fine
I have no idea how possible it is.
But if you could make aliases add a temporary permission or something so that a regular user can do a specific command without the associated permissions would really take this to the next level (like what i was saying previously)
@Kiak
Commander does no permission checking itself* - anyone can type any command they want. However, all Commander does is issue a replacement command in place of the typed command, acting as if the player typed this replacement command himself. Therefore, any permissions checking that the 3rd party plugin (ie WorldEdit) does when issued the command is still done. There's no circumventing of permissions going on here.
However, if you have a Commander replacement where the replacement command is preceded by the term "sudo", then the command will be issued as if the console had issued it, which might mess up permissions checking. In the case of WorldEdit though, I think it would whine that the command isn't being issued by a player and quit there.
tl;dr: no, no, and yes. :)
EDIT: *This is not strictly true anymore, as Commander's Advanced Scripting (version 2.0) has an if statement condition for checking if a player has a given permission. However, Commander itself never does any permissions checking, so this is still "technically" true.
Do i understand this correctly?
If i make an alias to use a World edit command could people who DONT have permission to use worldedit, use Commander to access that one command regardless of worldedit permissions?
Or is it just an alias that will still rely on peoples access to the resulting commands permissions?
@tustin2121
Good idea!
@iKeirNez
Actually, in that case I'll probably make another variable like
@__cancel__
for when you'd want to outright disregard the chat message. There are cases where you'd want to discard the word but not the whole chat.@tustin2121
If it doesn't work then you could make it so that if the replacement word is hide it will cancel the chat event but continue to run the Commander code.
@webshoptv
You can do command words by using one of the following in your playerchat.txt file:
Unfortunately, in version 1.2.2, you cannot choose what word replaces the command word in chat.
If you are willing to try out the alpha build of version 2.0, you can choose the replacement for the command word in script by setting the
@__repl__
variable. In this case, you can set that to nothing (I think...). In either case, you aren't able to outright cancel a chat message.Do note that my plugin handles command words in chat like normal chat replacements; that is, it does a "find" and not a full-text match like commands. So if your players say the word casually in a sentence, the command still executes.
First that's a really, really great plugin. :)
How do I do it that users have to type a special word (without a "/") and then it excute a command (like "/home") and don't display the word in chat.
Another alpha release, this one actually tested in game. It seems to work well enough.
I apologize for the horrid state that the previous alpha release was in. This one should work much better! ^_^;
I've also been working on the documentation over on the Pages tab. I need to write up something on the API stuff.
I have uploaded V1.2.2 to conform to the latest Bukkit RB. It should be available shortly, after file approval.
I have also uploaded an unstable alpha build of the advanced scripting build 2.0* (also conforming to the latest RB). Considering I have not had the chance yet to test the thing in-game, I fully expect everything to crash and burn the minute you type something into the command line. XD No, actually, I expect decent bugs will appear upon testing, but it should function on a basic level. I did unit test every scripting element every step of the way...
Which reminds me: I need to go write up a syntax guide for Advanced Scripting. *hurries off*
\*EDIT: Screw version 1.3, there's enough here to call it 2.0! MAJOR VERSION BUMP!! XD *ahem* sorry. *leaves*
@Digitalink2008
I have included ways to get variables from the server, via the probably poorly named "environment variables" functionality. This will also allow getting variables from cooperating plugins. This is an upcoming feature in the Advanced Scripting version, which is probably done at this point and just needs rigorous in-game testing.
Preview:
EDIT: Yes, what you want with that specific example is to use the special back reference $p, which gets the player which executed the command.
Hey Tustin. For the scripting functionality have you included any built in variables for us to use? I'd like to have a single command that executes a script but i need to include the users name. Or, at least I'd like to not have them have to include it in the command.
Possible or no?
Edit: Looks as if i just missed it in the description. Thanks much :)
@tustin2121
Okay we use these event handlers to replace chat and commands.
https://github.com/iKeirNez/Minecraft-CommandsEX/blob/master/CommandsEX/src/com/github/zathrus_writer/commandsex/handlers/Handler_replacechat.java https://github.com/iKeirNez/Minecraft-CommandsEX/blob/master/CommandsEX/src/com/github/zathrus_writer/commandsex/handlers/Handler_replaceconsolecommand.java https://github.com/iKeirNez/Minecraft-CommandsEX/blob/master/CommandsEX/src/com/github/zathrus_writer/commandsex/handlers/Handler_replaceplayercommand.java
I figured it would be easier to link you to the class files rather than listing every single method we use.
We have also copied in some class files here
https://github.com/iKeirNez/Minecraft-CommandsEX/tree/master/CommandsEX/src/com/github/zathrus_writer/commandsex/helpers/scripting
There are some methods in XMPP too
https://github.com/iKeirNez/Minecraft-CommandsEX/blob/master/CommandsEX/src/com/github/zathrus_writer/commandsex/helpers/XMPPer.java
If you need anymore info then please let me know.