[−][src]Struct quill_prototype::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'ssetup
function and registers the command with the server.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for CommandBuilder
impl Send for CommandBuilder
impl Sync for CommandBuilder
impl Unpin for CommandBuilder
impl UnwindSafe for CommandBuilder
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Component for T where
T: Send + Sync + 'static,
[src]
T: Send + Sync + 'static,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Resource for T where
T: Send + Sync + 'static,
[src]
T: Send + Sync + 'static,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,