Coding Table

328 Downloads

Coding Table provides a dynamic registration system for commands and event handlers. This allows developers to stop writing boilerplate code for managing these aspects and get back to writing the code that matters. Registering a command is as simple as implementing an interface and adding an annotation to the class. Once your done, a single line of code will pull together all your commands, and register them with the server. Better yet, you can define sub-commands and the library will take care of passing your arguments where they need to go.

Writing a Command

@DynamicCommand(value = "commandname", format = "{ARG}  tp {VARARGS}" )
public class NewCommand implements ExecutableCommand
{

    @Override
    public List<String> validate(CommandSender sender, String[] args)
    {
        //If there are any problems, return a list of errors that will display to the player
        return new ArrayList<String>();
    }

    @Override
    public List<String> tabComplete(Command command, String[] args) 
    {
        //If you want to support tab completing, return a list of possible next arguments to the player
        return null;
    }

    @Override
    public void execute(CommandSender sender, String[] args) 
    {
        //If there were no validation errors, execute the command!
    }

}

The value in the annotation is the name of your command, as you want the player to type it. It is required.
The format in the annotation is the format of any arguments you want to accept, and is optional.

The example above would translate into the command : /commandname <argument> tp <variable length argument>.
This real command would match this command: /commandname Raemis tp hello there, buddy.
This command would not: /commandname Hi there, buddy tp Raemis

When the arguments make it into the command, they'll have been grouped together, based on the format. This means that the "hello there, buddy" from the working command will come across as one value in the array, rather than the usual three.

To register all your commands:

new DefaultDynamicCommandExecutor().loadCommands("fully.qualified.package.name.to.your.commands", "YourPluginsName");

You can get your plugins name with JavaPlugin's getName() method.

Writing a Listener

Write normal listeners and then register them with:

 new DefaultDynamicEventManager().registerEvents("fully.qualified.package.name.to.your.listeners", "YourPluginName");

You can unregister them with:

new DefaultDynamicEventManager().unregisterEvents("YourPluginsName");

Installing this Library

Provide a classpath entry in your jar, pointing to this library on the server. It is recommended that you create a folder named 'lib' in your plugins directory, and place this library jar inside that directory. The classpath entry for your jar would then point to "./lib/Coding-Bench.jar" A more comprehensive tutorial is in the works, as well as maven support.