Skip to main content
The Command class represents a command in LiquidBounce’s command system. Commands can have subcommands, parameters, aliases, and custom handlers.

Class Signature

class Command(
    val name: String,
    val aliases: List<String>,
    val parameters: List<Parameter<*>>,
    val subcommands: List<Command>,
    val executable: Boolean,
    val handler: Handler?,
    val requiresIngame: Boolean,
)

Properties

name
String
required
The primary name of the command
aliases
List<String>
Alternative names that can be used to invoke the command
parameters
List<Parameter<*>>
List of parameters the command accepts. See Parameter API for details.
subcommands
List<Command>
Nested commands that can be executed as part of this command
executable
Boolean
required
Whether the command can be executed directly or is just a hub for subcommands
handler
Handler?
The function that executes when the command is invoked
requiresIngame
Boolean
default:"false"
Whether the command requires the player to be in-game
parentCommand
Command?
Reference to the parent command if this is a subcommand

Methods

usage()

Returns the formatted usage information for the command.
fun usage(): List<Component>
return
List<Component>
A list of formatted usage components showing how to use the command and its subcommands
Example output:
command_name subcommand_name <required_arg> [[<optional_vararg>]...

nameAsText()

Returns the command name as a formatted text component with hover description.
fun nameAsText(): Component
return
Component
Text component with the command name and hover tooltip showing description

result()

Creates a translated result message for the command.
fun result(key: String, vararg args: Any): MutableComponent
key
String
required
Translation key suffix (will be prefixed with command’s translation base)
args
Array<Any>
Arguments to pass to the translation
return
MutableComponent
Translated and formatted text component

printStyledText()

Sends a styled command result with copyable content.
fun printStyledText(
    key: String,
    data: String? = null,
    formatting: (MutableComponent) -> MutableComponent = ::regular,
    hover: HoverEvent? = HoverEvent.ShowText(translation("liquidbounce.tooltip.clickToCopy")),
    click: ClickEvent? = data?.let(ClickEvent::CopyToClipboard)
)
key
String
required
Translation key for the result message
data
String?
Optional data to display and copy
formatting
Function
Function to apply formatting to the text (default: regular)
hover
HoverEvent?
Custom hover event (defaults to “Click to copy” tooltip)
click
ClickEvent?
Custom click action (defaults to copy to clipboard)

autoComplete()

Provides autocompletion suggestions for the command.
fun autoComplete(
    builder: SuggestionsBuilder,
    tokenizationResult: Pair<List<String>, List<Int>>,
    commandIdx: Int,
    isNewParameter: Boolean
)
builder
SuggestionsBuilder
required
The builder to add suggestions to
tokenizationResult
Pair<List<String>, List<Int>>
required
Tokenized command input and token positions
commandIdx
Int
required
Current position in the command hierarchy
isNewParameter
Boolean
required
Whether we’re starting a new parameter

Handler Interface

The command handler interface that processes command execution.
fun interface Handler {
    operator fun Context.invoke()

    class Context(
        @JvmField val command: Command,
        @JvmField val args: Array<out Any>
    )
}
Context.command
Command
The command being executed
Context.args
Array<out Any>
Parsed arguments passed to the command

Factory Interface

Provides a command to the CommandManager.
fun interface Factory {
    fun createCommand(): Command
}

Usage Example

From the source code, here’s how commands are structured:
val commands = arrayOf(
    CommandClient,
    CommandFriend,
    CommandToggle,
    CommandBind,
    // ... more commands
)

commands.forEach {
    addCommand(it.createCommand())
}

Translation Keys

Each command uses a translation base key:
liquidbounce.command.{command_name}.description
liquidbounce.command.{command_name}.result.{result_key}
liquidbounce.command.{command_name}.parameter.{param_name}.description
For subcommands:
liquidbounce.command.{parent}.subcommand.{child}.description

See Also

Build docs developers (and LLMs) love