Skip to content

A fluent Kotlin DSL for Mojang's brigadier command library

License

Notifications You must be signed in to change notification settings

MizuSoftware/brigadier-dsl

 
 

Repository files navigation

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())

About

A fluent Kotlin DSL for Mojang's brigadier command library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%