[][src]Struct quill_prototype::CommandBuilder

pub struct CommandBuilder;

A builder for a command.

Example

A basic /msg command:

use quill_prototype::{CommandBuilder, State, EntityRef, SysResult};


CommandBuilder::new("msg")
    .alias("m")
    .build(on_msg, &mut setup);

fn on_msg(state: &mut State, sender: EntityRef, args: &[&str]) -> SysResult {
    if args.len() < 1 {
        sender.send_message("Usage: /msg <player> [message...]")?;
        // Note that a command executor should only return an `Err`
        // when an internal error occurs, not when user input is incorrect.
        // Returning an error will
        // send the player a "an internal error occurred while trying to execute
        // this command" message and print the error to the console.
        // Returning an `Err` is like throwing
        // an exception in Bukkit.
        return Ok(());
    }
    let target = match state.player_by_name(args[0]) {
        Some(player) => player,
        None => {
            sender.send_message(&format!("Player {} not found.", args[0]));
            return Ok(());
        }
    };
     
    // Build the message by accumulating `args`.
    let mut message = String::new();
    for arg in &args[1..] {
        message += arg;
        message.push(' ');
    }
    target.send_message(&message)?;
    Ok(())
}

Implementations

impl CommandBuilder[src]

pub fn new(_name: &str) -> Self[src]

Creates a new CommandBuilder for a command with the given name.

Example

Create a CommandBuilder for the /msg command:

use quill_prototype::CommandBuilder;
CommandBuilder::new("msg");

(Note the absence of a preceding slash.)

pub fn alias(&mut self, _alias: &str) -> &mut Self[src]

Adds an alias for this command.

pub fn build(&mut self, _executor: CommandExecutor, _setup: &mut Setup)[src]

Builds this CommandBuilder.

This function takes:

  • The function called when the command is executed
  • The Setup passed to your plugin's setup function and registers the command with the server.

Trait Implementations

impl Debug for CommandBuilder[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Component for T where
    T: Send + Sync + 'static, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Resource for T where
    T: Send + Sync + 'static, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.