https://github.com/oroarmor/json-to-brigadier
Allows JSON files to be converted into brigadier commands
https://github.com/oroarmor/json-to-brigadier
brigadier json minecraft minecraft-api
Last synced: about 1 month ago
JSON representation
Allows JSON files to be converted into brigadier commands
- Host: GitHub
- URL: https://github.com/oroarmor/json-to-brigadier
- Owner: OroArmor
- License: mit
- Created: 2021-06-02T19:23:14.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-06-15T01:14:03.000Z (over 4 years ago)
- Last Synced: 2025-04-19T20:59:14.275Z (6 months ago)
- Topics: brigadier, json, minecraft, minecraft-api
- Language: Java
- Homepage:
- Size: 102 KB
- Stars: 7
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Json To Brigadier
This library converts JSON files into a corresponding `ArgumentBuilder` that represents a command structure. This is meant to reduce the challenge of lining up hard to see parenthesis and chained commands in your code.
## Usage
### Inclusion
Add `mavenCentral()` to the repositories section of your `build.gradle`
Add the dependency via `implementation "com.oroarmor:json-to-brigadier:1.0.0`
### Code
The API has two main methods to use. `JsonToBrigadier.parse(Path)` and `JsonToBrigadier.parse(String)`. The first method takes in a path to the file, and then calls the second with the contents of that file. They both return an `ArgumentBuilder` object representing the command structure specified by the JSON string or file.
The method given in `executes` must have the signature `public static int`.
Example:
```json
{
"name": "test",
"argument" : {
"type": "brigadier:literal"
},
"children": [
{
"name": "value",
"argument": {
"type": "brigadier:integer",
"min": 0,
"max": 1
},
"executes": "com.example.TestSimpleCommand::runCommand"
}
]
}
```
```java
ArgumentBuilder builder = JsonToBrigadier.parse(json);
```is the same as writing
```java
ArgumentBuilder builder = literal("test")
.then(argument("value", integer(0, 1))
.executes(TestSimpleCommand::runCommand));
```### Supported Types
This library only supports the default argument types in Brigadier. For a library that supports Minecraft's arguments, look at \.
Type | Name | Parameters | Example
---- | ---- | ---------- | -------
Boolean | `"brigadier:boolean"` | None | ```"argument": { "type": "brigadier:boolean"} ```
Float | `"brigadier:float"` | `min`, `max`. `min` is required for `max` | ```"argument": { "type": "brigadier:float", "min": 1} ```
Double | `"brigadier:double"` | `min`, `max`. `min` is required for `max` | ```"argument": { "type": "brigadier:double", "min": 0, "max": 100} ```
Long | `"brigadier:long"` | `min`, `max`. `min` is required for `max` | ```"argument": { "type": "brigadier:long"} ```
Integer | `"brigadier:integer"` | `min`, `max`. `min` is required for `max` | ```"argument": { "type": "brigadier:integer"} ```
String | `"brigadier:string"` | `string_type`: `word`, `greedy`, `string`. Defaults to `string` | ```"argument": { "type": "brigadier:string"} ```
Literal | `"brigadier:literal"` | None | ```"argument": { "type": "brigadier:literal"} ```