ScriptManager is a singleton object that manages LiquidBounce’s script system. It handles loading, unloading, and managing scripts written in various languages supported by GraalVM.
Object Declaration
Overview
ScriptManager allows extending the client by loading scripts at runtime. Scripts can:- Add custom modules
- Register commands
- Create custom modes
- Hook into game events
- Interact with the client through the Script API
Properties
scripts
Mutable set of all currently loaded scripts.Collection of all loaded script instances
root
The directory where scripts are stored.Root directory for script storage. Created automatically if it doesn’t exist.
<config_folder>/scripts/
Methods
initializeEngine()
Initializes the GraalVM polyglot engine.- Creates the GraalVM engine
- Logs supported languages
- Initializes the tick scheduler
loadAll()
Loads all scripts from the scripts directory.- Scans the
rootdirectory for script files - Looks for
main.*files in subdirectories - Loads scripts from marketplace installations
- Enables all loaded scripts
IllegalStateException if engine is not initialized
Directory structure example:
loadScript()
Loads a specific script file.The script file to load
Script language (auto-detected from file extension if not specified)
Debug configuration for the script
The loaded and initialized script instance
IllegalStateException if engine is not initialized
Example:
unloadScript()
Unloads a specific script.The script instance to unload
- Disables the script
- Closes the script context
- Removes from the scripts collection
unloadAll()
Unloads all currently loaded scripts.- Disables all scripts
- Closes all script contexts
- Clears the scripts collection
- Clears tick scheduler
- Cleans up script context provider
enableAll()
Enables all loaded scripts.- Enables each script in the collection
- Reloads ClickGUI if any scripts were enabled
- Calls each script’s
enableevent handler
disableAll()
Disables all loaded scripts.disable event handler and deactivates all script features.
reload()
Reloads all scripts from disk.- Disables all scripts
- Unloads all scripts
- Loads all scripts from directory
- Enables all scripts
- Logs success message
Script Loading Process
When a script is loaded:Initialization Steps
-
Context Creation - GraalVM context is created with:
- Host access enabled
- IO access enabled
- Working directory set to script’s parent folder
- Language-specific options (e.g., CommonJS for JavaScript)
-
Binding Setup - Global bindings are registered:
registerScript- Script registration functionmc- Minecraft client instanceClient- ScriptClient object- Utility classes (RotationUtil, ItemUtil, etc.)
- Script Evaluation - Source code is executed
-
Load Event - Script’s
loadevent handler is called - Validation - Ensures script has required metadata (name, version, authors)
Language Support
Supported languages depend on GraalVM installation:JavaScript
Built-in support with ECMAScript 2023 and CommonJS
Python
Requires GraalPython installation
Ruby
Requires TruffleRuby installation
R
Requires FastR installation
Usage Examples
Basic Script Management
Loading Individual Scripts
Checking Loaded Scripts
Script Access from Scripts
Debug Support
Scripts can be loaded with debugging enabled:INSPECT- Chrome DevTools ProtocolDAP- Debug Adapter Protocol (VS Code)
Integration with Marketplace
ScriptManager automatically loads scripts from marketplace installations:Error Handling
All script loading operations use error catching:See Also
- PolyglotScript - Individual script instance API
- Script Bindings - Available APIs in scripts
- Creating Scripts - Guide to writing scripts
- ScriptClient - Client API access