#[derive(Debug, Clone)]
pub struct CommandContext {
pub name: String,
pub args: String,
pub source: String,
pub uuid: String,
}
impl CommandContext {
pub fn arg_list(&self) -> Vec<&str> {
self.args.split_whitespace().collect()
}
pub fn typed_args(&self) -> Vec<&str> {
if self.args.is_empty() { vec![] } else { self.args.split('\t').collect() }
}
pub fn arg_str(&self, idx: usize) -> Option<&str> {
if self.args.is_empty() { return None; }
self.args.split('\t').nth(idx)
}
pub fn arg_int(&self, idx: usize) -> Option<i32> {
self.arg_str(idx)?.parse().ok()
}
pub fn arg_float(&self, idx: usize) -> Option<f32> {
self.arg_str(idx)?.parse().ok()
}
pub fn arg_player(&self, idx: usize) -> Option<&str> {
self.arg_str(idx)
}
pub fn arg_blockpos(&self, idx: usize) -> Option<(i32, i32, i32)> {
let s = self.arg_str(idx)?;
let mut it = s.split(',');
let x = it.next()?.parse().ok()?;
let y = it.next()?.parse().ok()?;
let z = it.next()?.parse().ok()?;
Some((x, y, z))
}
}