diff --git a/src/command/kill.rs b/src/command/kill.rs new file mode 100644 index 0000000..bc8b1a2 --- /dev/null +++ b/src/command/kill.rs @@ -0,0 +1,17 @@ +#[derive(Default)] +pub struct KillCommand { + target: Option +} + +impl KillCommand { + pub fn target(mut self, target: super::Selector) -> Self { + self.target = Some(target); + self + } + + pub fn build(self) -> super::Command { + let target = self.target.unwrap_or(super::Selector::Executor); + let s = format!("kill {target}"); + super::Command(s) + } +} \ No newline at end of file diff --git a/src/command/list.rs b/src/command/list.rs index 23dad11..fed9ccd 100644 --- a/src/command/list.rs +++ b/src/command/list.rs @@ -1,16 +1,16 @@ #[derive(Default)] pub struct ListCommand { - uuids: bool + uuids: Option } impl ListCommand { pub fn uuids(mut self) -> Self { - self.uuids = true; + self.uuids = Some(true); self } pub fn build(self) -> super::Command { - let uuids = self.uuids; + let uuids = self.uuids.unwrap_or(false); let mut s = format!("list"); if uuids { s.push_str(" uuids"); diff --git a/src/command/mod.rs b/src/command/mod.rs index e9c5ad9..20a4275 100644 --- a/src/command/mod.rs +++ b/src/command/mod.rs @@ -1,7 +1,32 @@ +use std::fmt::Display; + pub struct Command(String); +pub enum Selector { + NearestPlayer, // @p + RandomPlayer, // @r + AllPlayers, // @a + AllEntities, // @e + Executor, // @s + NearestEntity // @n +} + +impl Display for Selector { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::NearestPlayer => write!(f, "@p"), + Self::RandomPlayer => write!(f, "@r"), + Self::AllPlayers => write!(f, "@a"), + Self::AllEntities => write!(f, "@e"), + Self::Executor => write!(f, "@s"), + Self::NearestEntity => write!(f, "@n") + } + } +} + mod say; mod list; +mod kill; impl Command { pub fn raw(cmd: &str) -> Self { diff --git a/src/command/say.rs b/src/command/say.rs index 471e694..6f92b75 100644 --- a/src/command/say.rs +++ b/src/command/say.rs @@ -1,16 +1,16 @@ #[derive(Default)] pub struct SayCommand { - message: String + message: Option } impl SayCommand { pub fn message(mut self, msg: impl Into) -> Self { - self.message = msg.into(); + self.message = Some(msg.into()); self } pub fn build(self) -> super::Command { - let message = self.message; + let message = self.message.unwrap_or("Hello, world!".to_string()); let s = format!("say {message}"); super::Command(s) } diff --git a/src/lib.rs b/src/lib.rs index b80ff33..2a184a5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,4 +2,4 @@ mod client; pub use client::{RconClient, RconError, RconResult}; mod command; -pub use command::Command; \ No newline at end of file +pub use command::{Command, Selector}; \ No newline at end of file