Skip to content

server.cmd

Constants #

const arg_flag_valid = u32(0x100000)

Bedrock protocol "type_info" flags/values used to describe a command parameter to the client for autocomplete. The protocol package stores type_info as an opaque u32 (protocol/src/available_commands_packet.v).

const arg_flag_enum = u32(0x200000)
const arg_type_int = u32(1)
const arg_type_target = u32(8)
const arg_type_string = u32(56)
const arg_type_rawtext = u32(70)

fn new_registry #

fn new_registry() Registry

fn usage_line #

fn usage_line(cmd Command) string

fn validate_arguments #

fn validate_arguments(spec []Argument, raw []string) bool

fn visible #

fn visible(cmd Command, sender Sender) bool

visible reports whether sender is allowed to see/run cmd.

interface Argument #

interface Argument {
	name() string
	optional() bool
	// consumes_rest reports whether this argument swallows every remaining
	// raw token (e.g. a trailing chat message). Only the last argument in a command's list may do this.
	consumes_rest() bool
	// matches reports whether raw (a single token or the joined tail when consumes_rest() is true) is an acceptable value.
	matches(raw string) bool
	// network_type_info is the Bedrock protocol type_info payload for
	// non-enum arguments; unused for enum arguments (see enum_values()).
	network_type_info() u32
	// enum_values returns the accepted values for an enum style argument or an empty list for non enum arguments.
	enum_values() []string
}

Argument is one typed, positional slot in a command's syntax. Registry uses it to validate raw tokens before Command.execute runs and to build real CommandParameter data for the client's AvailableCommandsPacket, replacing per command manual arg-count checks.

interface Command #

interface Command {
	name() string
	description() string
	aliases() []string
	// permission returns the permission node required to run this command
	// or '' if it needs none (public to everyone).
	permission() string
	// arguments describes this command's expected syntax; Registry.dispatch
	// validates raw tokens against it before execute runs and available_commands() uses it to
	// build real client autocomplete data.
	arguments() []Argument
	execute(mut sender Sender, ctx Context) !
}

interface Sender #

interface Sender {
	has_permission(name string) bool
	name() string
	whitelist_enabled() bool
	whitelist_names() []string
	is_player() bool
mut:
	send_message(message string) !
	send_translation(key string, parameters []string) !
	set_gamemode(mode int)
	find_player(name string) ?Sender
	set_operator(value bool)
	kill()
	position() (f32, f32, f32)
	teleport(x f32, y f32, z f32)
	// place_water sets a water source at the block position and starts its spread.
	place_water(x int, y int, z int)
	clear_inventory()
	give_item(id string, count int) bool
	whitelist_add(name string)
	whitelist_remove(name string)
	whitelist_set_enabled(value bool)
	set_difficulty(value int)
	broadcast_message(text string)
	// show_title sends a title/subtitle/actionbar to this sender only.
	show_title(kind int, text string)
	// broadcast_title sends to every connected player (for /title @a).
	broadcast_title(kind int, text string)
	// show_scoreboard displays a sidebar scoreboard to this sender with the
	// given title and lines rendered top-to-bottom.
	show_scoreboard(title string, lines []string)
	// clear_scoreboard removes the sidebar scoreboard from this sender.
	clear_scoreboard()
	send_form(f form.Form) !
	// world management. Mutating ops return an error the command relays to the
	// sender; list/info are read-only snapshots.
	world_names() []string
	world_info(name string) ?WorldSummary
	// world_create's dimension and generator are names rather than the
	// world.Dimension/world.Generator types themselves, so the cmd layer never
	// depends on the world package directly.
	world_create(name string, dimension string, generator string) !
	world_load(name string) !
	world_delete(name string) !
	world_teleport(name string) !
}

Sender is the live connection that issued a cmd. Context carries read-only stats for building output; anything a Command needs to send back or mutate goes through Sender instead.

struct Context #

struct Context {
pub:
	lang           &language.Lang = unsafe { nil }
	sender_name    string
	player_count   int
	max_players    int
	server_motd    string
	uptime_seconds i64
	tps            f64
	load           f64
	args           []string
}

struct IntArgument #

struct IntArgument {
pub:
	arg_name     string
	arg_optional bool
}

fn (IntArgument) name #

fn (a IntArgument) name() string

fn (IntArgument) optional #

fn (a IntArgument) optional() bool

fn (IntArgument) consumes_rest #

fn (a IntArgument) consumes_rest() bool

fn (IntArgument) matches #

fn (a IntArgument) matches(raw string) bool

fn (IntArgument) network_type_info #

fn (a IntArgument) network_type_info() u32

fn (IntArgument) enum_values #

fn (a IntArgument) enum_values() []string

struct Registry #

struct Registry {
pub mut:
	commands map[string]Command
	aliases  map[string]string
}

fn (Registry) register #

fn (mut r Registry) register(cmd Command)

fn (Registry) unregister #

fn (mut r Registry) unregister(name string)

unregister removes a previously registered command (and any aliases pointing to it) by name.

fn (Registry) resolve #

fn (r &Registry) resolve(name string) ?Command

fn (Registry) dispatch #

fn (r &Registry) dispatch(line string, mut sender Sender, ctx_base Context) !

fn (Registry) names #

fn (r &Registry) names() []string

fn (Registry) available_commands #

fn (r &Registry) available_commands(sender Sender) protocol.AvailableCommandsPacket

struct StringArgument #

struct StringArgument {
pub:
	arg_name     string
	arg_optional bool
}

StringArgument matches a single non empty token (e.g. a player name).

fn (StringArgument) name #

fn (a StringArgument) name() string

fn (StringArgument) optional #

fn (a StringArgument) optional() bool

fn (StringArgument) consumes_rest #

fn (a StringArgument) consumes_rest() bool

fn (StringArgument) matches #

fn (a StringArgument) matches(raw string) bool

fn (StringArgument) network_type_info #

fn (a StringArgument) network_type_info() u32

fn (StringArgument) enum_values #

fn (a StringArgument) enum_values() []string

struct StringEnumArgument #

struct StringEnumArgument {
pub:
	arg_name     string
	arg_optional bool
	values       []string
}

StringEnumArgument matches a fixed and case-insensitive set of values (e.g. gamemode names).

fn (StringEnumArgument) name #

fn (a StringEnumArgument) name() string

fn (StringEnumArgument) optional #

fn (a StringEnumArgument) optional() bool

fn (StringEnumArgument) consumes_rest #

fn (a StringEnumArgument) consumes_rest() bool

fn (StringEnumArgument) matches #

fn (a StringEnumArgument) matches(raw string) bool

fn (StringEnumArgument) network_type_info #

fn (a StringEnumArgument) network_type_info() u32

fn (StringEnumArgument) enum_values #

fn (a StringEnumArgument) enum_values() []string

struct TargetArgument #

struct TargetArgument {
pub:
	arg_name     string
	arg_optional bool
}

TargetArgument matches a single token naming another connected player.

fn (TargetArgument) name #

fn (a TargetArgument) name() string

fn (TargetArgument) optional #

fn (a TargetArgument) optional() bool

fn (TargetArgument) consumes_rest #

fn (a TargetArgument) consumes_rest() bool

fn (TargetArgument) matches #

fn (a TargetArgument) matches(raw string) bool

fn (TargetArgument) network_type_info #

fn (a TargetArgument) network_type_info() u32

fn (TargetArgument) enum_values #

fn (a TargetArgument) enum_values() []string

struct TextArgument #

struct TextArgument {
pub:
	arg_name     string
	arg_optional bool
}

TextArgument consumes the rest of the line as one string (e.g. a chat/kick message). Must be the last argument in a command's list.

fn (TextArgument) name #

fn (a TextArgument) name() string

fn (TextArgument) optional #

fn (a TextArgument) optional() bool

fn (TextArgument) consumes_rest #

fn (a TextArgument) consumes_rest() bool

fn (TextArgument) matches #

fn (a TextArgument) matches(raw string) bool

fn (TextArgument) network_type_info #

fn (a TextArgument) network_type_info() u32

fn (TextArgument) enum_values #

fn (a TextArgument) enum_values() []string

struct WorldSummary #

struct WorldSummary {
pub:
	name       string
	generator  string
	dimension  string
	overrides  int
	is_default bool
	players    int
}

WorldSummary is a read-only snapshot of a loaded world, built for command output so the cmd layer never depends on the db types directly.