CommandMessage
This is a guide to learn how to get easily your command messages.
What is CommandMessage ?
CommandMessage
is a class which allows you to get your command messages at a specific path from a json
file. This class is very useful to centralize all your command messages in a single file without using a config file.
How to create CommandMessage ?
At this point, you should have something like this in your command resource file.
Remember that my command's name is item
so I will write the following codes into the command_item.json
file.
To create a CommandMessage
, write the following code into the item section:
So you should have something like this:
How to use CommandMessage ?
You've created your CommandMessage
. Now, let's use it. First of all, to get a message stored in the commandMessage
section in the json file, you must retrieve the getCommandMessage()
method from the SmartCommand
class.
This is an example in the onCommand()
method:
Let's see the available methods of this class:
Method | Type | Description |
|
| Get a |
|
| Get a |
|
| Get a |
|
| Get an |
|
| Get a |
|
| Get a |
|
| Get a |
|
| Get a |
|
| Get an |
|
| Get a |
|
| Get a |
How it works ?
To get our command messages, we need to specify an access path. Indeed, a JsonObject
stores values from keys so we will use them to create a path that points to our values.
Example 1
To get the value "It's a test"
, which is directly in the commandMessage
object, the path is "test"
.
So the code to retrieve this message is:
Example 2
Here, we have two values which are in a sub object of commandMessage
. So to get them, we have to specify the sub object and the key where our values is stored.
For example, the path of "The first message"
value if "messages.firstMessage"
and that of "Another message"
is "messages.anotherMessage"
.
Let's see the code to retrieve these two messages:
Last updated