Skip to content

ElytraServers/BrigadierX

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BrigadierX

BrigadierX is a library for Brigadier of Mojang. It adds a Kotlin-friendly extended functions.

Installation

To install BrigadierX, you need have Brigadier installed first.

Gradle

  1. First include Jitpack's repository:
maven {
    url "https://jitpack.io"
}
  1. And then use BrigadierX:
implementation "com.github.taskeren:brigadier-x:<the-latest-version>"

Maven

  1. First include Jitpack's repository:
<repository>
    <id>jitpack</id>
    <url>https://jitpack.io</url>
</repository>
  1. And then use BrigadierX:
<dependency>
    <groupId>com.github.taskeren</groupId>
    <artifactId>brigadier-x</artifactId>
    <version>(the latest version)</version>
</dependency>

Usage

You are supposed to read Brigadier's Usage first, if you are new using Brigadier.

Few methods in ArgumentBuilder(LiteralArgumentBuilder, RequiredArgumentBuilder, etc.) are extended like following:

val dispatcher = CommandDispatcher<String>()

dispatcher.register("root") { // this: LiteralArgumentBuilder<String>

	// The executor without returning
	executesX { // it: CommandContext<String>
		println(it.source)
	}

	// Creating the subcommand(child node)
	literal("list") { // this: LiteralArgumentBuilder<String>

		executesX { // it: CommandContext<String>
			println("@Sub ${it.source}")
		}
	}

	literal("add") { // this: LiteralArgumentBuilder<String>

		executesX { // it: CommandContext<String>
			println("Usage: /root add <value>")
		}

		// import com.mojang.brigadier.arguments.StringArgumentType
		// Adding argument node
		argument("value", StringArgumentType.string()) {

			executesX { // it: CommandContext<String>
				val theValue = StringArgumentType.getString(it, "value")
				println("The value is $theValue")
			}
		}
	}
}