Skip to main content

Overview

The CommandManager handles all command-related functionality in LiquidBounce, including command registration, parsing, execution, and auto-completion. It provides a flexible system for creating commands with parameters and subcommands. Package: net.ccbluex.liquidbounce.features.command

Object Declaration

object CommandManager : Collection<Command>

Global Settings

object GlobalSettings : ValueGroup("Commands") {
    var prefix by text("Prefix", ".")
    val hintCount by int("HintCount", 5, 0..10)
}
prefix
String
default:"."
Command prefix character(s)
var prefix: String
Example: .friend add Player
hintCount
Int
default:"5"
Number of command suggestions to show for unknown commands
val hintCount: Int

Core Methods

Command Registration

registerInbuilt()
fun registerInbuilt()
Registers all built-in LiquidBounce commands.
fun registerInbuilt()
Registers commands including:
  • Client Management: Client, Config, LocalConfig, Debug
  • Module Control: Toggle, Bind, Hide, Panic, Value
  • Friends: Friend
  • Utility: Help, Clear, Targets
  • Script: Script
  • Creative: ItemRename, ItemGive, ItemSkull, ItemStack, ItemEnchant
  • Teleport: VClip, Teleport, PlayerTeleport
  • Info: Ping, Tps, ServerInfo, Username, Coordinates
  • Other: Say, FakePlayer, RemoteView, XRay, AutoDisable, Models, Translate, AutoTranslate, Marketplace
addCommand()
fun addCommand(command: Command)
Adds a custom command to the manager.
fun addCommand(command: Command)
Throws an error if command name already exists.
removeCommand()
fun removeCommand(command: Command)
Removes a command from the manager.
fun removeCommand(command: Command)

Command Execution

execute()
fun execute(cmd: String)
Executes a command string.
@ScriptApiRequired
fun execute(cmd: String)
Example:
CommandManager.execute(".toggle KillAura")
CommandManager.execute(".friend add \"Senk Ju\"")
Throws: CommandException if command is invalid or parameters are incorrect

Command Parsing

tokenizeCommand()
fun tokenizeCommand(line: String): Pair<List<String>, List<Int>>
Tokenizes a command string into arguments.
fun tokenizeCommand(line: String): Pair<List<String>, List<Int>>
Returns: Pair of tokenized arguments and their starting indicesExample:
// Input: `.friend add "Senk Ju"`
// Output: [[`.friend`, `add`, `Senk Ju`], [0, 8, 12]]
val (args, indices) = CommandManager.tokenizeCommand(".friend add \"Senk Ju\"")
Features:
  • Quoted strings with spaces: "My Name"
  • Escape characters: \", \\
  • Multi-word arguments

Auto-Completion

autoComplete()
fun autoComplete(origCmd: String, start: Int): CompletableFuture<Suggestions>
Provides auto-completion suggestions for partial commands.
fun autoComplete(origCmd: String, start: Int): CompletableFuture<Suggestions>
Parameters:
  • origCmd - Full command text including prefix
  • start - Cursor position
Returns: Suggestions for completion

Usage Examples

Executing Commands

// Simple command
CommandManager.execute(".help")

// Command with arguments
CommandManager.execute(".toggle KillAura")

// Command with quoted arguments
CommandManager.execute(".friend add \"Senk Ju\"")

// Nested subcommands
CommandManager.execute(".config load HypixelBedwars")

Tokenizing Commands

val (args, indices) = CommandManager.tokenizeCommand(".friend add Player137")
println(args) // [.friend, add, Player137]
println(indices) // [0, 8, 12]

// With quotes
val (args2, _) = CommandManager.tokenizeCommand(".say \"Hello World\"")
println(args2) // [.say, Hello World]

Creating Custom Command

val myCommand = Command(
    name = "greet",
    aliases = listOf("hello", "hi")
) {
    val nameParam = parameter<String>(
        name = "name",
        required = true
    )
    
    handler { context ->
        val name = context[nameParam]
        chat("Hello, $name!")
    }
}

CommandManager.addCommand(myCommand)

// Usage: .greet YourName

Command with Subcommands

val configCommand = Command("config") {
    subcommand("load") {
        val nameParam = parameter<String>("name", required = true)
        handler { context ->
            val name = context[nameParam]
            // Load config
        }
    }
    
    subcommand("save") {
        val nameParam = parameter<String>("name", required = true)
        handler { context ->
            val name = context[nameParam]
            // Save config
        }
    }
}

CommandManager.addCommand(configCommand)

Error Handling

CommandException

Thrown when command execution fails:
try {
    CommandManager.execute(".invalid command")
} catch (e: CommandException) {
    // Handle error
    println(e.message)
    println(e.usageInfo) // Suggested commands
}

Common Errors

  1. Unknown Command - Command not found, suggestions provided
  2. Invalid Usage - Wrong number of arguments
  3. Command Takes No Parameters - Arguments provided to parameterless command
  4. Parameter Required - Missing required parameter
  5. Unknown Parameter - Too many arguments
  6. Invalid Parameter Value - Parameter validation failed

Command Suggestions

When an unknown command is entered, CommandManager uses Levenshtein distance to suggest similar commands:
// Input: .toggl KillAura
// Suggestions:
//   - toggle
//   - binds
//   - bind
Number of suggestions controlled by GlobalSettings.hintCount.

Best Practices

  1. Use descriptive command names - Clear and concise
  2. Provide aliases - Common abbreviations for frequently used commands
  3. Add parameter validation - Prevent invalid input
  4. Support auto-completion - Improve user experience
  5. Handle errors gracefully - Provide helpful error messages
  6. Use subcommands - Organize complex command hierarchies

See Also

Build docs developers (and LLMs) love