Skip to content

Managers

SenkJu edited this page Jul 11, 2019 · 8 revisions

Description

Each module, command or inventory tab has to be registered in the script's body otherwise it will not be available in the client. The script API offers different managers for inventory tabs, modules and commands. They can also be used to retreive modules or commands from the client.

Register an inventory tab

function InventoryTab() {
    // ...
}

var inventoryTab = new InventoryTab();

function onLoad() {
    creativeTabs.registerTab(inventoryTab);
}

Register a module

function Module() {
    // ...
}

var module = new Module(); // The module has to be instantiated before it can be registered.
var moduleClient; // A second variable has to be declared inside the script's body which will later contain a reference to the module used by the client. 

function onEnable() {
    moduleClient = moduleManager.registerModule(module); // The response has to be stored in the variable declared above.
};

function onDisable() {
    moduleManager.unregisterModule(moduleClient); // When unregistering the module, the client reference of it has to be used instead of the script's instance.
}

Register a command

function Command() {
    // ...
}

// References above
var command = new Command();
var commandClient;

function onEnable() {
    commandClient = commandManager.registerCommand(command);
};

function onDisable() {
    commandManager.unregisterCommand(commandClient);
}

Retreive a module

// Gets a module from the ModuleManager (Returns module)
var killAuraModule = moduleManager.getModule("KillAura");

var name = killAuraModule.getName(); // Returns the name of the module (String)
var description = killAuraModule.getDescription(); // Returns the description of the module (String)
var category = killAuraModule.getCategory(); // Returns the category of the module (String)
var state = killAuraModule.getState(); // Returns whether a module is toggled (Boolean)
var keyBind = killAuraModule.getBind(); // Returns the code of the key the module is bound to (Integer)
var range = killAuraModule.getValue("Range"); // Gets a value of the module (Integer, Double, String)

killAuraModule.setValue("Range", 5); // Sets a value of the module

killAuraModule.setState(true); // Enables the module
killAuraModule.setState(false); // Disables the module

killAuraModule.setBind(-1); // Sets the bind of a module to a key code (Takes Integer)

killAuraModule.unregister(); // Unregisters the module from the ModuleManager
killAuraModule.register(); // Registers the module to the ModuleManager

Retreive a command

commandManager.executeCommand(command, arguments);
commandManager.executeCommand(command);

// Example
commandManager.executeCommand(".help");