Trait CommandArgumentType
pub trait CommandArgumentType:
Send
+ Sync
+ 'static {
// Required methods
fn kind(&self) -> CommandArgumentKind;
fn parse(&self, input: &str) -> Result<String, CommandArgumentError>;
fn suggest(&self, prefix: &str) -> Vec<CommandSuggestion>;
}Expand description
A command argument type a mod registers: how one kind of argument is validated and completed.
Register it once, from Hooks::register, with Registrar::register_command_argument. Its
namespaced id (mymod:machine) is the kind a Command usage names after the argument
name: Command::new("machine use <machine:mymod:machine>"). The game then parses the
argument with parse before calling run_mod_command, and asks
suggest for the chat box’s completions. Players’ clients that do not know
the type complete it from the server’s answer.
The game keeps one value per registered id and asks it from the server thread and, for a client command, from the window’s thread: implement it to be shared, without mutable state.
Required Methods§
fn kind(&self) -> CommandArgumentKind
fn kind(&self) -> CommandArgumentKind
The part of the line the argument takes. The same on every client.
fn parse(&self, input: &str) -> Result<String, CommandArgumentError>
fn parse(&self, input: &str) -> Result<String, CommandArgumentError>
Validate the text a client wrote and return the value run_mod_command receives.
input is one word (see CommandArgumentKind::Word for its characters), or the rest
of the line for CommandArgumentKind::Greedy. Return the canonical text to deliver (an
id, a lower-cased name, "3" for "03"), or the message shown to the player when the
input is not valid.
fn suggest(&self, prefix: &str) -> Vec<CommandSuggestion>
fn suggest(&self, prefix: &str) -> Vec<CommandSuggestion>
The completions for the text prefix being typed at this argument.
Return the values that match, in the order the chat should show them; the game keeps each suggestion’s replacement range and tooltip. An empty list leaves the input as typed.
Native and wasm results share the vanilla packet limits: completion text may contain at most 32767 UTF-16 code units; a literal tooltip may occupy at most 65535 bytes in Java modified UTF-8 (the NBT string limit). If any result exceeds either limit, the engine reports the refusal and discards the callback’s results, rather than truncating player-visible text. A panicking native callback is also refused.
Trait Implementations§
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".