Setting up CSBF
First things first...
I highly suggest reading the about page first.
This tool is designed to be used by multiple plugins at the same time. As such, it needs to be loaded into the server as a plugin. After that, make sure to set it as a depends in your plugin's YML file, like so:
depend: [Corries Super Bukkit Framework]
Once you've done that, add the jar to your project's build path (eclipse: right click > properties > java build path > libraries tab > add external jar)
Getting the Tools!
I highly suggest nabbing all of the tools when you first boot up your plugin. You should do something like this
public class MyPlugin extends JavaPlugin { private CSBFCommandMap cmdMap; private CommandMetadataManager metaManager; private PlayerDataAccessor dataAccessor; public void onEnable(){ cmdMap = CSBFPlugin.getCmdMap(); metaManager = CSBFPlugin.getMetadataManager(); dataAccessor = CSBFPlugin.getDataManager().getAccessor(this); } }
This should be everything you need to get yourself going!
Registering a Command
The first thing you'll need to do when registering a new command is to create the metadata object. This thing has a pretty wicked constructor, so bear with me.
Heres the one i used for my test plugin
CommandMetadata cm = new CommandMetadata("command", null, "this is a command", "/command", null, CommandType.REQUIRES_PLAYER, 1, true, this);

Okay, yes its a gigantic constructor! Lets break it down.
The first parameter is the commands name. This is the one that you type in to execute the command. In this case, it would be /command.
The second parameter is a string, the permission to use the command. You can pass in null for no permission required.
The third string is the command description, and the fourth is the command usage.
The fifth is a String array. Your labels. Pass in null for no aliases, or a string array if you want aliases.
The sixth one is where stuff gets fun. This is the command type. There are four, OPTIONAL, DIFFERENTIATE, REQUIRES_PLAYER, and REQUIRES_CONSOLE. The command executor class I give you will know what to do with it. Use OPTIONAL if you dont care, and just want the commandsender object (you'll find this command in the optionalCommand() method). Use REQUIRES_PLAYER if you require a player. if anything but a player tries to access the command, it will tell them theyre not a player, and exit quickly. You'll find these commands in the "playerCommand()" method, in your executor. REQUIRES_CONSOLE is basically the same thing as requires_player, but for the console (using the consoleCommand() method). DIFFERENTIATE is an interesting one, as depending on if it the sender is a console or player, it will go to the consoleCommand() and playerCommand() methods respectively.
The seventh parameter is the MINIMUM number of arguments that the CommandSender must supply. If they don't supply the adequate ammount, your command executor wont ever even see the command.
The eight parameter is what i like to call the "sensitive command" boolean. If true, it will log any and all usage (failed or succeeded) of that command in a file. Basically, if you wanna know if a player has been attempting to get creative mode or something, while you're not watching the console. Great usage for that!
The ninth parameter is your plugin instance.
Setting up your Command Metadata Manager
This section is purely just my own preference when it comes to stuff like this, but because of the way CSBF works, you'll probably want to tuck all of the command creation and registration way in the back of your plugin somewhere, in a single class. For reference, before i had coded CSBF, i created an Enumerator for all of this, and heres what it looked like. I would suggest creating a method to set up all of your commands, and all that jazz. Not necessary, but one of my biggest beefs is to try and compartmentalize your code. If you string all of your command registrations down across all of your command executor classes, it makes them hard to track down when you need to make a change.
Using your newly Registered Command
Okay cool! So you've got your command registered within the command metadata manager! Next step up is actually registering it to a command executor. To do that, you'll need to specially use the constructor for CSBFCmdExe as such:
public class MyClass extends CSBFCmdExe { public MyClass(String myClassName, JavaPlugin myPlugin){ super(myClassName, myPlugin, //*strings here*//); } }
The last parameter is your list of commands, by actual command name (not alias). Feel free to put strings there, or a string array, as the parameter on the other side is "String cmds..." the superconstructor will automatically communicate with the command map, and register the command to your executor. For instance, if you wanted the command "derp" to be registered to MyClass, then you'd do this:
public class MyClass extends CSBFCmdExe { public MyClass(String myClassName, JavaPlugin myPlugin){ super(myClassName, myPlugin, "derp"); //Or, new String[]{"derp"} } }
Because of how highly specialized these commands are, you'll need to use them as the CSBFCommand I've given you.
To obtain your command:
Command c = CSBFPlugin.getCmdMap().getCommand(); //Check if it is a CSBFCommand if(c instanceof CSBFCommand){ CSBFCommand cc = (CSBFCommand)c; //do code } else { //this isnt a command we can use }
Now that you've got the command, lets do something fancy with it!
Comments