/brigadier-dsl

A fluent Kotlin DSL for Mojang's brigadier command library

Primary LanguageKotlinApache License 2.0Apache-2.0

Brigadier DSL License Kotlin CI with Gradle

Brigadier DSL is a Kotlin library that adds a new fluent DSL on top of Mojang's Brigadier, that makes it easier to write commands. For more information read the Motivation page.

Features

  • Fluent and easy to use Kotlin DSL
  • Lexically scoped type-safe arguments
  • Automatic and safe retrieval of values
  • Optional and default value arguments
  • Dynamic default values from command source

Quickstart

Add the repository
repositories {
    mavenCentral()
}
Install the dependency
dependencies {
    implementation("dev.nicolai:brigadier-dsl:{current_version}")
}
Create and register a command
// Import command DSL function and argument shorthands
import dev.nicolai.brigadier.dsl.command
import dev.nicolai.brigadier.arguments.*

// Declare command with source of type MessageSender
val whisper = command<MessageSender>("whisper") {
    // Declare our recipient and message arguments
    val recipient by string("recipient")
    val message by greedyString("message")

    // Code to be run when the command is executed
    runs {
        // Access argument value as variables
        val feedback = "Sent '$message' to $recipient"

        // Source and context are implicitly available in the runs block
        source.sendFeedback(feedback)
    }
}

// Build the command literal and register it
dispatcher.register(whisper.buildLiteral())