Skip to content
iLexiconn edited this page Mar 23, 2016 · 1 revision

Command builder

Creating a command

Creating a new Command instance can be done by calling:

Command.create()

The method has one argument, the command name.

Adding arguments

Once you've got yourself a Command instance, you can start adding arguments. There are 2 argument types, required arguments and optional ones. You MUST register the required arguments BEFORE the optional ones. To do this you call one of the following methods:

command.addRequiredArgument()

or

command.addOptionalArgument()

Both methods have 2 arguents, the argument name and the argument type. Each type needs a type adapter. Luckely there are a few built-in ones, so you don't have to make them yourself. The built-in adapters are as follows: Integer, Boolean, String, Float, Double, EntityPlayer and ItemStack. If LLibrary can't find an adapter for the specified type, it'll skip the argument.

Adding an adapter

You can add custom adapters for custom classes. Note that adapters have to be registered BEFORE you add an argument with its type. You can add your own adapter by calling the following method:

CommandHandler.INSTANCE.registerArgumentParser()

This method asks for the type, and the IArgumentParser instance.

Registering your command

You can register your command instance by calling:

CommandHandler.INSTANCE.registerCommand()

This method asks for a FMLServerStartingEvent instance. This means the command has to be registered inside that event. The second argument is the command instance, and the third a new ICommandExecutor instance.

Executing your command

Every time the user executes the command with all the required commands, ICommandExecutor#execute will be called. You have acces to the parsed arguments, the sender and the Minecraft server there. You can get a command argument by calling arguments.getArgument().

Example

You can fnd a working example in the command test.

Clone this wiki locally