Skip to content

Console

import { Console } from "@sagl/server";

server.console: the operator console on stdin, started by listen() unless { console: false }.

Built-in commands: help, players, time [HH:MM], freeze, unfreeze, skin <id> <model|random>, say <text>, kick <id> [reason], tp <id> <x> <y> <z>, hp <id> <health> [armour], heal <id>.

command(name, usage, run)

command(name: string, usage: string, run: (args: string[], rest: string) => void): this

Adds a command.

Parameter Type Description
name string What's typed first.
usage string Shown by help.
run function Gets the words after the name, and the rest of the line as typed. Throwing prints the error.
server.console.command("give", "give <id> <amount>", ([id, amount]) => {
  const player = server.player(Number(id));
  if (!player) throw new Error(`no player ${id}`);
  player.giveMoney(Number(amount));
});

server.console.command("announce", "announce <text>", (_args, rest) => {
  server.broadcast(rest, Color.Yellow);
});

run(line)

run(line: string): void

Runs a line as if typed.

server.console.run("say Server restarting in 5 minutes");