Get started
This is a guide to learn how to start with SmartCommands.
Initialize SmartCommands API
To use the API, you must first initialize it by using the ApiBuilder
class. If you don't know how to use it, you can read the guide below.
Create a command
Using JSON
To create a command, you must first register it in a json
file. In your project, create a file called commands.json
. If you're using IntelliJ, you can use a resources folder to store your command files.
Using this API requires knowledge of the JSON format. You can read about it on the official website.
Now, let's register our command. Open your commands.json
file, open embraces, write the name of your command and reopen embraces.
Here we will create a /item
command so our command name is item
.
Let's add different properties to our commands. The available properties are:
Property | Type | Description |
|
| The description of the command |
|
| The usage of the command |
|
| The path to the resource file of the command |
|
| Set |
|
| The aliases of the command |
|
| The type of issuer which can use the command ( |
|
| Set |
Properties tabComplete
and resourceOnly
are available only if you're using a command resource file.
Example
To get more information about command resource files, you can read the guide below.
pageAdd contents to your commandsRegister your command
Prerequisite
To register our command in our plugin, we will need the CommandManager
class. You don't have to create a new instance of this class because it automatically while initializing the API.
First, let's get this class:
Registration
Now, let's use the registerCommand()
method from the CommandManager
class. This method has two parameters:
Parameter | Type | Description |
|
| The name of the command you want to register. |
|
| The class in which you want to register the command. |
If your command class does not exist, create it and import the methods of CommandExecutor
interface.
Example
Great, your command is registered. Now you can modify its behavior by adding code into the onCommand()
method or add tab completions into the onTabComplete()
method.
Check if a command is registered
You can check if a command is registered by using the isRegistered()
method from the CommandManager class.
Parameter | Type | Description |
|
| The name of the command you want to check |
Example
This method will return true
if the command is registered or else it will return false
.
Check if a command is registered by a plugin
You can also check if a command is already registered by a plugin by using the isRegistered()
method from the CommandManager
class.
Parameter | Type | Description |
|
| The name of the plugin you want to check that it has registered the command |
|
| The name of the command you want to check |
This method will return true
if the command is registered by the plugin or else it will return false
.
Example
Unregister commands
You can unregister a command by using the unregisterCommand()
method from the CommandManager class.
Parameter | Type | Description |
|
| The name of the plugin that has registered the command to want to remove |
|
| The name of the command you want to remove |
This method will remove the command and all its aliases.
Be sure the command is registered before using this method or you will have a NullPointerException
.
Example
Last updated