Skip to content

Latest commit

 

History

History
71 lines (53 loc) · 2.08 KB

README.md

File metadata and controls

71 lines (53 loc) · 2.08 KB

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 {
    maven("maven.mizu.wtf")
}
Install the dependency
dependencies {
    implementation("dev.nicolai", "brigadier-dsl", "1.0.0")
}
Create and register a command
// Import command DSL function and argument shorthands
import dev.nicolai.brigadier.dsl.command
import dev.nicolai.brigadier.arguments.*

// Declare source type
interface MessageSender {
    fun sendFeedback(feedback: String)
}

// 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
val dispatcher: CommandDispatcher<MessageSender> = /* ... */
dispatcher.register(whisper.buildLiteral())