executeWithResult
fun <S> ArgumentBuilder<S, *>.executeWithResult(command: CommandActionWithResult<S>)
Content copied to clipboard
Sets the action the command will take when executed.
If command returns CommandResult.Success, the command will return with CommandResult.Success.result.
If command returns CommandResult.Failure, the command will throw a CommandException containing the returned CommandResult.Failure.message.
Author
Cypher121
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
dispatcher.register("repeat") {
required(string("string"), integer("times")) { getString, getTimes ->
executeWithResult {
val times = getTimes().value()
if (times % 2 == 1) {
CommandResult.failure(Text.literal("times must be even"))
} else {
repeat(times) {
println(getString().value())
}
CommandResult.success(times)
}
}
}
}
//sampleEnd
}
See also
com.mojang.brigadier.builder.ArgumentBuilder