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
I tried to reproduce the errors I was getting (I had removed commander temporarily) and after downloading the latest version of commander and adding it again I dont even get the startup checks anymore? Its fixed now somehow for me, but that is extremely strange that it would change like that? my guess is updateing other plugins such as worldguard, essentials and factions has fixed whatever errors I was getting. sorry for bothering you before.
@iKeirNez
Unfortunately I don't really use Skype (I have one, same username as always, but I haven't used it in years).
However, you can help by telling me how you use the current code (ie, what functions are called and where), so I may build the API to suit your needs. Feel free to PM me, comment on commits on GitHub, or talk here. Idk, if it's that pressing I can try Skype or some other IM client, though I'm not available during the day.
@tustin2121
Wow yes that sounds awesome! Can I add you on Skype because I would really like to help even although I don't know much about regex's I am sure I can help with some other things. My skype is iKeirNez.
@iKeirNez
\*goes and checks out plugin* ...yes, indeed you do... I want to help:
With the impending advanced scripting update, EVERYTHING is going to change around (just go look at the branch on github). I want to make it so that you don't have to copy the code over and edit everything: I want to make an API you can use to access the scripting functionality you guys use with minimal changes needed on your end if everything changes on mine. That way, you guys can simply link the jar file as a library and when commander updates, it can be easily switched out.
I'm going to be doing an API as it is: the scripting update will allow other plugins to give data to the scripting engine via "environment variable modules" (yay for obtuse names). It wouldn't be much further to extend the API so that Commander can be called upon by other plugins entirely.
Thoughts? We can take this discussion elsewhere as well, if you want. :)
@tustin2121
No problem, it was a fairly simple change but I wanted to help as we use Commander in CommandsEX
@Dommbringer
Dear God, you do?! Now I sound inconsiderate. I thought it was a startup check, not EVERY F*CKING TIME SOMEONE SPEAKS.
Do me a favor: take just one or two of those chat events, maybe a short conversation, copy the chats and all the accompanying lines of severe errors and paste it in full as a comment here. Get the worst offender, if you want (presumably you get one for each player or something). I'll get you a build for this bukkit dev build while I spam the freaking commit comments about this... >:(
@tustin2121 I appreciate that you do not want to release an update until there is a rb, but could you release a version with the fixed chat event before then please. (I'm aware how inconsiderate I sound right now, im simply asking because I get around 50 lines of severe errors every time anyone says anything in the chat, and I can't deal with that for the next month.)
@iKeirNez
I thank you for your help on this, by the way. :)
@webshoptv
According to what I've seen on Guthub, bukkit still supports the old PlayerChatEvent message, but it is deprecated. This means that the plugin should still work, it's just using old APIs that they've changed and made better. Usually this is only a developer affair: I don't use deprecated APIs, and if I see, when I update Bukkit, that I am using deprecated APIs, I will adjust my code accordingly. No reason to worry the user base with this.
But now they've just stupidly decided to start warning everyone and their mother with 20,000 lines of stack trace that old plugins are using the deprecated event that they just freaking deprecated on a development build. So I am not going to build against a development build of Bukkit as of right now, but rest assured that the plugin will be updated in due course - as soon as they release their recommended build, I will release mine.
(Unless, of course, Commander is not working outright because of this, or they take a month to get the recommended build out, like they have before. I only want to slightly inconvenience everyone at start up because Bukkit has now inconvenienced all of its developers, and not outright remove the functionality of my plugin.)
I sent in a PR for support for 1.3.1, also I accidentally committed my classpath file.
https://github.com/tustin2121/Bukkit-Commander/pull/2
@webshoptv
As far as I can see the plugin is completely 1.3.1 compatible so far, unless any new changes are made by the Bukkit team. But for now it should be compatible.
EDIT: I was wrong, was using the wrong jar. I will update it and send in a PR
Pls update for 1.3.1 or release the src!
I'm sure you all will be happy to know that I have uploaded a double-point release of Commander that fixes the echo suppression bug. It has been approved and is now available.
I am currently working on advanced scripting again (now its own branch in the github repository - I've even made a script-testing JUnit environment, after 4 hours of work... O_o :) ).
I definitely require this! Keep up the work, we need large-scale aliases as comparable to the one command alias provided native in bukkit - It adds so much more customization to a server, because the commands belong to your server, not a bunch of extraneous plugins! :)
@tustin2121
Awesome!
@iKeirNez
Thanks for this. Ok, I'm installing Minecraft again (on my new AWESOME computer) and I'll start development on this again immediately. Submit your tickets now. :)
I updated Commands to CraftBukkit 1.2.5 R5.0 for you, not much needed done but I figured I may aswell give you the code as I updated it for CommandsEX.
Just add this code under the the updateInventory() method or wherever you want to.
http://pastie.org/private/zr3wvcpkma5gzebr2nlpa
@crfptb0808
I only have one other thing I can suggest then: perhaps there is an error parsing the file and it has to stop early. Try putting the rule at the top of the file, and watch the startup messages to see if there are any errors loading patterns.
@tustin2121
Hey thanks but this still doesnt work! It acts as though the command isnt in the commander config at all! But i have verified and made sure it was in the right file. Help again?
@nsordk
I don't recall what state of the cutoff option was in since I last did development on the plugin. It probably does not work as it is supposed to...
I have never heard of Royalcommands before. Technically, nothing should see the "sudo" keyword, as commander is supposed to parse it off before it passes it off to normal command parsing. What is the nature of the error message?
(I guess I should actually install minecraft again and fix some of these bugs...)