> For the complete documentation index, see [llms.txt](https://docsv1.polyfrost.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docsv1.polyfrost.org/commands/tree-based-commands.md).

# Tree-based commands

OneConfig uses the Minecraft command system ([Brigadier](https://github.com/Mojang/Brigadier)) for non annotation based commands, however it provides some utility functions.

You can create a simple command like the following.

{% tabs %}
{% tab title="Java" %}

```java
var builder = CommandManager.literal("examplemod");
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
val builder = CommandManager.literal("examplemod")
```

{% endtab %}
{% endtabs %}

From here, if you want to do something when the command is run on it's own (f.ex `/examplemod`), you can use the `executes` method to define what is executed, like so:

{% tabs %}
{% tab title="Java" %}

```java
builder.executes(ctx -> {
    System.out.println("Hello, OneConfig!"); 
    
    return Command.SINGLE_SUCCESS;
});
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
builder.executes { ctx ->
    println("Hello, OneConfig!")
    
    Command.SINGLE_SUCCESS
}
```

{% endtab %}
{% endtabs %}

Finally, to register your command, you can simply use `CommandManager.register` like so:

{% tabs %}
{% tab title="Java" %}

```java
CommandManager.register(builder);
```

{% endtab %}

{% tab title="Kotlin" %}

```kotlin
CommandManager.register(builder)
```

{% endtab %}
{% endtabs %}

For a more detailed documentation of Brigadier, and it's API you can check out following resources:

* [Creating Commands | Fabric Docs](https://docs.fabricmc.net/develop/commands/basics)
* [Readme | Brigadier Repository](https://github.com/Mojang/Brigadier)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docsv1.polyfrost.org/commands/tree-based-commands.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
