项目作者: nicolaic

项目描述 :
A fluent Kotlin DSL for Mojang's brigadier command library
高级语言: Kotlin
项目地址: git://github.com/nicolaic/brigadier-dsl.git
创建时间: 2020-04-29T21:55:54Z
项目社区:https://github.com/nicolaic/brigadier-dsl

开源协议:Apache License 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
  1. repositories {
  2. mavenCentral()
  3. }
Install the dependency
  1. dependencies {
  2. implementation("dev.nicolai:brigadier-dsl:{current_version}")
  3. }
Create and register a command
  1. // Import command DSL function and argument shorthands
  2. import dev.nicolai.brigadier.dsl.command
  3. import dev.nicolai.brigadier.arguments.*
  4. // Declare command with source of type MessageSender
  5. val whisper = command<MessageSender>("whisper") {
  6. // Declare our recipient and message arguments
  7. val recipient by string("recipient")
  8. val message by greedyString("message")
  9. // Code to be run when the command is executed
  10. runs {
  11. // Access argument value as variables
  12. val feedback = "Sent '$message' to $recipient"
  13. // Source and context are implicitly available in the runs block
  14. source.sendFeedback(feedback)
  15. }
  16. }
  17. // Build the command literal and register it
  18. dispatcher.register(whisper.buildLiteral())