Struct CommandBuilder

Source
pub struct CommandBuilder;
Expand description

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§

Source§

impl CommandBuilder

Source

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

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.)

Source

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

Adds an alias for this command.

Source

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

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§

Source§

impl Debug for CommandBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

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

Source§

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