This decreased compile time by 30%, Plugins also are not required anymore to use async_trait when adding custom Commands
48 lines
1.3 KiB
Rust
48 lines
1.3 KiB
Rust
use pumpkin_data::world::SAY_COMMAND;
|
|
use pumpkin_util::text::TextComponent;
|
|
|
|
use crate::command::{
|
|
CommandError, CommandExecutor, CommandResult, CommandSender,
|
|
args::{Arg, ConsumedArgs, message::MsgArgConsumer},
|
|
tree::{CommandTree, builder::argument},
|
|
};
|
|
use CommandError::InvalidConsumption;
|
|
|
|
const NAMES: [&str; 1] = ["say"];
|
|
|
|
const DESCRIPTION: &str = "Broadcast a message to all Players.";
|
|
|
|
const ARG_MESSAGE: &str = "message";
|
|
|
|
struct Executor;
|
|
|
|
impl CommandExecutor for Executor {
|
|
fn execute<'a>(
|
|
&'a self,
|
|
sender: &'a CommandSender,
|
|
server: &'a crate::server::Server,
|
|
args: &'a ConsumedArgs<'a>,
|
|
) -> CommandResult<'a> {
|
|
Box::pin(async move {
|
|
let Some(Arg::Msg(msg)) = args.get(ARG_MESSAGE) else {
|
|
return Err(InvalidConsumption(Some(ARG_MESSAGE.into())));
|
|
};
|
|
|
|
server
|
|
.broadcast_message(
|
|
&TextComponent::text(msg.clone()),
|
|
&TextComponent::text(format!("{sender}")),
|
|
SAY_COMMAND,
|
|
None,
|
|
)
|
|
.await;
|
|
Ok(())
|
|
})
|
|
}
|
|
}
|
|
|
|
pub fn init_command_tree() -> CommandTree {
|
|
CommandTree::new(NAMES, DESCRIPTION)
|
|
.then(argument(ARG_MESSAGE, MsgArgConsumer).execute(Executor))
|
|
}
|