Play Strawberry Docs
Scripts

Tab-complete and command lists

Use the tab-complete and send-commands extension events to control completions and the command list.

Extension events

Some events reach scripts as extension events: each has a name and its own handler type instead of an event case. Two of them are about commands; others, such as PICK_ITEM, PICKUP_EXPERIENCE and PLAYER_LAUNCH_PROJECTILE, are described in Events and handler options.

  • TAB_COMPLETE ("tab-complete"): a player asks for the completions of a command (Paper's AsyncTabCompleteEvent). buffer() is what the player typed, with the leading slash; completions() and set_completions(list) read and replace the answer. Cancelled, the player gets no completions.
  • SEND_COMMANDS ("send-commands"): the server is about to send a player the list of commands the player may use (Paper's PlayerCommandSendEvent). commands() lists the top-level names; set_commands(list) keeps only those names. Cancelled, the list is empty.

Every extension event has name(), player(), is_cancelled() and set_cancelled(bool).

Register a handler

Context::register_extension_event_handler(name, handler, HandlerOptions) takes the event name, a handler (a closure Fn(Server, &ExtensionEvent) or a type implementing ExtensionEventHandler) and the same options as other events. A name the server does not know is an error. The SDK builds your script with the export these events need; another language must implement world extended-plugin.

rust
/// Players who are not logged in get no completions at all.
fn tab_complete_guard(_server: Server, event: &ExtensionEvent) {
    let allowed = event
        .player()
        .is_some_and(|player| with(|s| s.logged_in.contains(&player.get_name())));
    if !allowed {
        event.set_cancelled(true);
    }
}

/// Players who are not logged in see only /login and /register in their command list.
fn send_commands_guard(_server: Server, event: &ExtensionEvent) {
    let Some(player) = event.player() else {
        event.set_cancelled(true);
        return;
    };
    if !with(|s| s.logged_in.contains(&player.get_name())) {
        let keep: Vec<String> = event
            .commands()
            .into_iter()
            .filter(|name| name == "login" || name == "register")
            .collect();
        event.set_commands(&keep);
    }
}
rust
let password = ArgumentType::String(StringType::SingleWord);
for (name, handler_is_login) in [("register", false), ("login", true)] {
    let node = CommandNode::argument("password", &password);
    let node = if handler_is_login { node.execute(Login) } else { node.execute(Register) };
    // Sensitive: the server log shows "/login [arguments hidden]".
    let command = Command::new(&[name.to_string()], "Log in with a password.")
        .sensitive()
        .then(node);
    context.register_command(command, name);
}

let guard = HandlerOptions {
    priority: HandlerPriority::Lowest,
    blocking: true,
    ignore_cancelled: false,
    on_failure: FailureVerdict::Deny,
};
context.register_extension_event_handler(TAB_COMPLETE, tab_complete_guard, guard)?;
context.register_extension_event_handler(SEND_COMMANDS, send_commands_guard, guard)?;

context.schedule_repeating_async_task(1, 1, poll_jobs);

Send the list again

The client keeps the command list it got at join. When what a player may use changes (after a login, a rank change), call player.update_commands(): the server builds the list again, SEND_COMMANDS included, and sends it.

Which commands a player gets

The command list a player gets holds only the commands that player may use: commands for operators do not reach other players. Your handler can only remove names from that list, not add commands the player may not use.

On this page