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 no idea how to make a command run more commands. Can anyone send me an example of 1 command, running 2 commands?
@kbryantLA24
This is a bug with the other plugin. It is expecting a decimal value and instead finding nothing at all. I suggest you use "commander debug" from the console to make sure your replacement is sending the command you think it is before bringing this up to the developer of floAuction. Once you have information on what command is actually being sent, alert them that they are not gracefully handling a case where you are perhaps missing an argument from the command being sent. The relevant bit of the stack trace is near the end after the "Caused by:". :)
PS: I could have sworn I fixed this error reporting. Maybe I never released the fix... :/
Not sure if I should report this to your plugin or floAuction, but I get this error in console:
2012-11-24 18:55:31 [SEVERE] [Commander] An exception was caught during player command replacem ent processing! Command passed through. org.bukkit.command.CommandException: Unhandled exception executing command 'auction' in plugin floAuction v2.6.7 at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:186) at org.bukkit.craftbukkit.CraftServer.dispatchCommand(CraftServer.java:502) at org.digiplex.bukkitplugin.commander.scripting.ScriptLine.execute(ScriptLine.java:52) at org.digiplex.bukkitplugin.commander.replacement.ReplacementCommand.executeEffects(Re placementCommand.java:40) at org.digiplex.bukkitplugin.commander.module.PlayerCommandModule.onPlayerCommandPrepro cess(PlayerCommandModule.java:55) at sun.reflect.GeneratedMethodAccessor260.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43 ) at java.lang.reflect.Method.invoke(Method.java:601) at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:339) at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477) at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462) at net.minecraft.server.NetServerHandler.handleCommand(NetServerHandler.java:977) at net.minecraft.server.NetServerHandler.chat(NetServerHandler.java:903) at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:858) at net.minecraft.server.Packet3Chat.handle(Packet3Chat.java:44) at net.minecraft.server.NetworkManager.b(NetworkManager.java:290) at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:113) at net.minecraft.server.ServerConnection.b(SourceFile:39) at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30) at net.minecraft.server.MinecraftServer.r(MinecraftServer.java:595) at net.minecraft.server.DedicatedServer.r(DedicatedServer.java:222) at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:493) at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:426) at net.minecraft.server.ThreadServerApplication.run(SourceFile:856) Caused by: java.lang.NumberFormatException: empty String at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1011) at java.lang.Double.parseDouble(Double.java:540) at com.flobi.floAuction.Auction.parseArgStartingBid(Auction.java:422) at com.flobi.floAuction.Auction.parseArgs(Auction.java:338) at com.flobi.floAuction.Auction.isValid(Auction.java:187) at com.flobi.floAuction.floAuction.queueAuction(floAuction.java:511) at com.flobi.floAuction.floAuction.onCommand(floAuction.java:765) at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ... 25 more
EDIT: Oh, nvm I just found it (<3 scripting)
@tustin2121:
Is it also possible to change a command with multiple commands, like example
"/demote sep98 " gets replaced by "/mandemote sep98 Default" and will also "/broadcast <playername> has been demoted." ?
Would be awesome if that option was enabled in the plugin ;)
~ Sep98
@kbryantLA24
An interesting problem. I don't think there's a way to do a "replace all" as it currently stands (in commands - in regular chat it is by default a replace all).
Without the addition of more directives (which is a possibility, a [replaceall] directive or something), I think the closest thing you'll get is if you repeat that replacement with an additional $ for each line. As so:
Commander will move through the list in order and match and use the first applicable match (note, I changed the regex here to check for everything not a dollar sign, as the dot will match subsequent dollar signs and fire prematurely).
Actually never mind, I found a different solution to the problem I'm having. With this is a new question... Is there a way to replace each instance of "$" in a command with "\$"?
Basically my problem is this... I'm using a Shout plugin, where a player types "/shout <message>" to chat with the entire server. This plugin is buggy in that when a player types "/shout selling for $100", the plugin throws an internal error because of the "$" sign. If the player uses "/shout selling for \$100" then it works fine. Is there a way to replace every single "$" if the player shouts a message with multiple "$? Right now I'm using:
http://pastebin.com/raw.php?i=Pkhp4Z5w
But that only works if the player only has one "$"
@kbryantLA24
Assuming that the say command is not something that the player can use, no there is no built in way to do that. If the say command does indeed only work with the server, I can make a built in command similar to the echo command.
I've searched through all your docs but couldn't find the answer to my question... I know there's "command words" where saying something in chat will execute a command, but is there a way to do the opposite? A player will run a command and force them to say something after running it?
@joshwenke @NyanCraftDe
I'm pretty sure I do not hard code my folder name, so you should be able to change the name of my plugin's jar and it will change the name of the generated folder respectfully.
@tustin2121 Yeah it adds commands to buttons and pressure plates and such.
@NyanCraftDe Rename one of the commanders to Commander2.jar or something like that. If they both make a folder "Commander", then you'll have to go into one of the jars and change its folder generation settings. If you can't do this let me know over PM.
@NyanCraftDe
There's another plugin called Commander??
I already have a plugin which is called "commander.jar" how can i usw both of them?
@tustin2121
Well, sorry to bother you with these bugs!
OK, so I made some testing on a clean 1.3.2 server with ShowCaseStandalone and Commander (advanced scripting). Both are updated. The bug still occurs, whereas casting "/scs sell this" works fine. (By the way, on startup, Commander is having trouble generating files. It generates one file at a time so after a few server restarts it doesn't output anymore errors)
Here is my revised playercmd.txt:
I was a bit worried when I realized that I had trouble with the plugin while my server was in version 1.2.5 (I forgot to mention this) but it doesn't seem to be the issue according to the my results with 1.3.2.^^
In case you'd like to know, here is the small bug with file generation:
@xou816 Well, that's why we test these things... :j
Well, it's the weekend now, so I should have time to look into this now. What's the smallest possible setup you have for this to work? Presumably, the Commander plugin (obviously), the Citizen plugin or the StandAloneShowcase plugin (either one alone), and a replacement that activates the former's "/NPC equip" command or the latter's "/scs sell this " command. Am I missing anything?
If all else fails, I can always attach a debugger to minecraft and step through it. I've done it before (it's fun stepping through game code! :D).
@tustin2121
(Thank you for the tip!)
Unfortunately it seems you were wrong about that... I made some tests:
Test with "/npc equip":
Test with "/scs sell this 1":
@xou816
(Tip: \s means "all whitespace characters", and the capital form negates that. So "(\S+)" will probably do the same as what you have for your first group there. :P )
So "/npc equip" in Citizens has the same bug? In both of these, you must type in the command, which activates the "next click" mechanism, and this doesn't fire? Hm, that may be a bug.
For the sake of argument, try this: type in the full command (bypassing Commander - disable it entirely if you want for this test). Then, before clicking, type in another command completely unrelated to the plugin you are using. THEN try clicking to select. I have a sneaking suspicion that this might do exactly the same as using Commander, and if it does, then I know what the problem is.
@tustin2121
I think I had checked right, but I'll look into that and edit this message later! I had the same problem with the command "/npc equip" from Citizens. Oh and I was referring to Commander's replacements. I didn't even know there was a built-in alias functionality in Bukkit!
Here's my "code" and the debug output:
(french alias lol)
I made a clean install with the latest version of Commander (advanced scripting branch).
@xou816
Unfortunately that's not really enough to diagnose a problem. When you say "alias", you are referring to Commander's replacements, correct? As opposed to Bukkit's built-in alias functionality.
If it's a problem with a command, make sure that you test the command without going through Commander first (the full command). Then make sure the replacement is properly formatted. You can use, from the console, the command "/commander debug" to enable command debugging, which will make it so Commander outputs every replacement it does and its result on the console. The Echo Suppression System may be blocking feedback to your command if you have echo set on by default (in the config file) (make sure you have the latest Commander update, as there was a bug with Echo Suppression in earlier versions).
Commander should not be affecting clicking functionality AT ALL, so, assuming your replacements are all correct, it might be a bug with the other plugin. But check your replacements first.
@tustin2121
Thank you for the regex thingy. Always nice to know!
Oh and by the way, I think I found a bug. I get no log from console but some events are cancelled with aliases. I made a simple alias for the command "/scs sell this ..." (from the plugin ShowCaseStandalone) which require right-clicking a block right after casting the command, but the right-click does not work. Hope I'm clear enough :)
Thanks!
@xou816
Yes. Generally anywhere you see regex, it will work the same. There are subtle differences between different implementation, which are all documented at www.regular-expressions.com. :)
Edit: the differences are usually for advanced functions, like look-backs and comments. The core stuff is always the same.