register

fun <S> CommandDispatcher<S>.register(command: String, action: LiteralArgumentBuilder<S>.() -> Unit)

Registers a command under command as the name.

Author

Oliver-makes-code (Emma)

Samples

import com.mojang.brigadier.CommandDispatcher
import net.minecraft.command.argument.PosArgument
import net.minecraft.command.argument.Vec3ArgumentType
import net.minecraft.network.MessageType
import net.minecraft.server.command.ServerCommandSource
import net.minecraft.text.Text
import net.minecraft.util.math.Vec3d
import org.quiltmc.qkl.wrapper.minecraft.brigadier.*
import org.quiltmc.qkl.wrapper.minecraft.brigadier.argument.*
import org.quiltmc.qkl.wrapper.minecraft.brigadier.util.entity
import org.quiltmc.qkl.wrapper.minecraft.brigadier.util.required
import org.quiltmc.qkl.wrapper.minecraft.brigadier.util.sendFeedback
import org.quiltmc.qkl.wrapper.minecraft.brigadier.util.server
import kotlin.random.Random
fun main() { 
   //sampleStart 
   val dispatcher: CommandDispatcher<ServerCommandSource> = stub()

dispatcher.register("echo") {
    //register arguments with extension methods
    required(string("message")) { message -> // treat the argument as a key
        required(boolean("toCaps")) { getToCaps -> // or as an accessor
            //standard builder methods can be called as normal
            requires {
                it.player.experienceLevel > Random.nextInt()
            }

            //execute the command with an extension method
            execute {
                val response = if (getToCaps().value()) {
                    this[message].value().uppercase()
                } else {
                    this[message].value()
                }

                //use utility extensions for common actions
                sendFeedback(Text.literal(response))
            }
        }
    }
} 
   //sampleEnd
}