[NodeMod Core]
/ .. / default
Class: default
Defined in: src/core/cmd.ts:65
Command manager for handling both client and server commands in the nodemod plugin system.
Example
// Register a client command
nodemodCore.cmd.add({
name\: 'hello',
type\: 'client',
handler\: (ctx) => {
console.log(`Hello ${ctx.client.name}!`);
}
});
// Register a server command
nodemodCore.cmd.add({
name\: 'restart',
type\: 'server',
handler\: () => {
console.log('Server restarting...');
}
});
Constructors
Constructor
new default():
NodemodCmd
Defined in: src/core/cmd.ts:115
Creates a new NodemodCmd instance and sets up command event listeners. Automatically handles client command events from the nodemod system.
Returns
NodemodCmd
Properties
commands
private
commands:CommandOptions
[] =[]
Defined in: src/core/cmd.ts:67
Array of registered commands
Methods
parseCommand()
private
parseCommand(command
):string
[]
Defined in: src/core/cmd.ts:81
Parses a command string into an array of arguments, respecting quoted strings.
Parameters
command
string
The raw command string to parse
Returns
string
[]
Array of parsed arguments
Example
parseCommand('say "hello world" test') // Returns\: ['say', 'hello world', 'test']
parseCommand('kick player reason') // Returns\: ['kick', 'player', 'reason']
getCommand()
getCommand(
commandName
,type
):undefined
|CommandOptions
Defined in: src/core/cmd.ts:138
Retrieves a registered command by name and type.
Parameters
commandName
string
The name of the command to find
type
string
The type of command ('client' or 'server')
Returns
undefined
| CommandOptions
The command options if found, undefined otherwise
add()
add(
options
):void
Defined in: src/core/cmd.ts:169
Adds a new command to the command registry. For server commands, automatically registers them with the native engine.
Parameters
options
Command configuration options
Returns
void
Example
// Client command
nodemodCore.cmd.add({
name\: 'info',
type\: 'client',
handler\: (ctx) => {
console.log(`Player\: ${ctx.client.name}, Args\: ${ctx.args.join(' ')}`);
}
});
// Server command
nodemodCore.cmd.add({
name\: 'status',
type\: 'server',
handler\: () => {
console.log('Server is running');
}
});
register()
register(
name
,handler
):void
Defined in: src/core/cmd.ts:200
Convenience method to register a client command with a simplified handler signature. The handler receives the client entity and arguments (excluding the command name).
Parameters
name
string
The command name
handler
(client
, args
) => void
Function that receives the client and arguments
Returns
void
Example
nodemodCore.cmd.register('kick', (client, args) => {
const targetName = args[0];
const reason = args.slice(1).join(' ');
console.log(`${client.name} wants to kick ${targetName}\: ${reason}`);
});
run()
run(
command
):void
Defined in: src/core/cmd.ts:221
Executes a server command through the native engine. Automatically appends a newline character to the command.
Parameters
command
string
The server command to execute
Returns
void
Example
nodemodCore.cmd.run('changelevel de_dust2');
nodemodCore.cmd.run('kick "Player Name"');
nodemodCore.cmd.run('say "Server announcement"');