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.
48 lines
1.2 KiB
48 lines
1.2 KiB
mod game;
|
|
|
|
use valence::prelude::{event::CommandExecution, *};
|
|
|
|
use crate::GameState;
|
|
|
|
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>,
|
|
uuids: Query<&UniqueId, With<Client>>,
|
|
mut events: EventReader<CommandExecution>,
|
|
mut next_state: ResMut<NextState<GameState>>,
|
|
state: Res<State<GameState>>
|
|
) {
|
|
for event in events.iter() {
|
|
let cmd = Command::parse(event.command.to_string());
|
|
let mut client = clients.get_mut(event.client).unwrap();
|
|
let uuid = uuids.get(event.client).unwrap();
|
|
|
|
match cmd.name.as_str() {
|
|
"game" => game::run(cmd, &mut client, uuid.0, &mut next_state, &state),
|
|
_ => client.send_message(format!("Command {} not found!", cmd.name)),
|
|
}
|
|
}
|
|
}
|