Skip to main content
The CommandManager is a singleton object that manages LiquidBounce’s command system. It handles command registration, execution, parsing, and autocompletion.

Object Declaration

object CommandManager : Collection<Command>
CommandManager implements Collection<Command>, providing access to all registered commands through standard collection operations.

Global Settings

Prefix

The command prefix used to invoke commands.
CommandManager.GlobalSettings.prefix // Default: "."
GlobalSettings.prefix
String
default:"."
The prefix character(s) required before command names
Example:
.friend add "Senk Ju"
^
prefix (.)

Hint Count

Number of suggestions to show for unknown commands.
CommandManager.GlobalSettings.hintCount // Default: 5, Range: 0..10
GlobalSettings.hintCount
Int
default:"5"
How many command suggestions to display when an unknown command is entered

Methods

registerInbuilt()

Registers all built-in LiquidBounce commands.
fun registerInbuilt()
This method is called during initialization to register default commands like:
  • CommandClient - Client management
  • CommandFriend - Friend list management
  • CommandToggle - Module toggling
  • CommandBind - Keybind management
  • And many more…

addCommand()

Adds a new command to the registry.
fun addCommand(command: Command)
command
Command
required
The command instance to register
Throws: IllegalStateException if a command with the same name already exists Example:
val myCommand = Command(
    name = "test",
    aliases = listOf("t"),
    parameters = emptyList(),
    subcommands = emptyList(),
    executable = true,
    handler = Command.Handler { /* implementation */ },
    requiresIngame = false
)

CommandManager.addCommand(myCommand)

removeCommand()

Removes a command from the registry.
fun removeCommand(command: Command)
command
Command
required
The command instance to unregister
Throws: IllegalStateException if the command doesn’t exist

execute()

Executes a command from a string input.
@ScriptApiRequired
@JvmName("execute")
fun execute(cmd: String)
cmd
String
required
The full command string to execute (including prefix)
Throws: CommandException for various error conditions:
  • Unknown command
  • Invalid usage
  • Missing required parameters
  • Invalid parameter values
Example:
CommandManager.execute(".friend add Player123")

tokenizeCommand()

Tokenizes a command string into arguments and their positions.
fun tokenizeCommand(line: String): Pair<List<String>, List<Int>>
line
String
required
The command line to tokenize
return
Pair<List<String>, List<Int>>
A pair containing:
  • First: List of tokenized arguments
  • Second: List of starting indices for each token
Features:
  • Handles quoted strings with spaces
  • Supports escape characters ()
  • Preserves unclosed quotes in output
Example:
tokenizeCommand(".friend add \"Senk Ju\"")
// Returns: ([".friend", "add", "Senk Ju"], [0, 8, 12])

autoComplete()

Provides autocompletion suggestions for command input.
fun autoComplete(origCmd: String, start: Int): CompletableFuture<Suggestions>
origCmd
String
required
The original command string being typed
start
Int
required
The cursor position in the command
return
CompletableFuture<Suggestions>
A future containing autocompletion suggestions based on registered commands and their parameters
Features:
  • Suggests command names based on prefix matching
  • Suggests subcommands when appropriate
  • Delegates to parameter autocompletion handlers
  • Uses case-insensitive matching

Internal Data Structures

Root Command Map

A case-insensitive sorted map for fast command lookup.
private val rootCommandMap = Object2ObjectRBTreeMap<String, Command>(String.CASE_INSENSITIVE_ORDER)
  • Key: Command name or alias
  • Value: Command instance
  • Order: Case-insensitive alphabetical

Command Set

A sorted set of all registered commands.
private val commandSet = ObjectRBTreeSet<Command>(Comparator.comparing({ it.name }, String.CASE_INSENSITIVE_ORDER))

Error Handling

CommandManager uses CommandException for error reporting with helpful hints:
throw CommandException(
    translation("liquidbounce.commandManager.unknownCommand", args[0]),
    usageInfo = commandSet.sortedBy { command ->
        levenshtein(args[0], command.name)
    }.take(GlobalSettings.hintCount)
)
When an unknown command is entered, the system:
  1. Calculates Levenshtein distance to all commands
  2. Returns the closest matches (up to hintCount)
  3. Displays suggestions with aliases

Usage Examples

Checking if a Command Exists

if (CommandManager.any { it.name == "friend" }) {
    println("Friend command is registered")
}

Iterating All Commands

CommandManager.forEach { command ->
    println("${command.name}: ${command.description}")
}

Getting Command Count

val count = CommandManager.size
println("Total commands: $count")

Script API Access

The execute() method is marked with @ScriptApiRequired, making it accessible from scripts:
// In a LiquidBounce script
const commandManager = Client.commandManager;
commandManager.execute(".friend add ScriptedFriend");

Built-in Command Categories

Commands registered by registerInbuilt() include: Client Commands:
  • CommandClient - Client settings
  • CommandConfig - Configuration management
  • CommandScript - Script management
  • CommandMarketplace - Marketplace access
Gameplay Commands:
  • CommandToggle - Module control
  • CommandBind - Keybinding
  • CommandPanic - Emergency module disable
  • CommandValue - Module setting adjustment
Social Commands:
  • CommandFriend - Friend management
  • CommandTargets - Target management
In-Game Commands:
  • CommandPing - Server ping
  • CommandTps - Server TPS
  • CommandServerInfo - Server information
  • CommandCoordinates - Position display
Creative Commands:
  • CommandItemGive - Item spawning
  • CommandItemRename - Item renaming
  • CommandItemEnchant - Item enchanting
  • CommandItemStack - Stack manipulation
Utility Commands:
  • CommandFakePlayer - Fake player spawning
  • CommandTeleport - Teleportation
  • CommandVClip - Vertical clipping
  • CommandRemoteView - Remote viewing

See Also

Build docs developers (and LLMs) love