You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.3 KiB

mod gamemode;
use valence::prelude::{
event::{CommandExecution, RequestCommandCompletions},
*,
};
pub struct Command {
pub name: String,
pub args: Option<Vec<String>>,
}
impl Command {
pub fn parse(command: String) -> Self {
let command = command
.split(" ")
.map(|e| e.to_string())
.collect::<Vec<String>>();
let name = command[0].clone();
let args = if command.len() > 1 {
Some(command.as_slice()[1..].to_vec())
} else {
None
};
Self { name, args }
}
}
pub fn command_executor(
mut clients: Query<(&mut Client, &mut GameMode)>,
mut events: EventReader<CommandExecution>,
) {
for event in events.iter() {
let cmd = Command::parse(event.command.to_string());
let (mut client, mut gamemode) = clients.get_mut(event.client).unwrap();
match cmd.name.as_str() {
"gamemode" => gamemode::run(cmd, &mut client, &mut gamemode),
_ => client.send_message(format!("Command {} not found!", cmd.name)),
}
}
}
pub fn command_suggestor(
mut clients: Query<&mut Client>,
mut events: EventReader<RequestCommandCompletions>,
) {
for event in events.iter() {
let _client = clients.get_mut(event.client).unwrap();
println!("{:?}", event);
}
}