Compare commits

..

No commits in common. "32304f4ea0d403871580883c11b45cf028abf459" and "37e89d6dc51eeb2a5afd86994e207262bfc2dd18" have entirely different histories.

5 changed files with 7 additions and 49 deletions

View file

@ -1,17 +0,0 @@
#[derive(Default)]
pub struct KillCommand {
target: Option<super::Selector>
}
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)
}
}

View file

@ -1,16 +1,16 @@
#[derive(Default)] #[derive(Default)]
pub struct ListCommand { pub struct ListCommand {
uuids: Option<bool> uuids: bool
} }
impl ListCommand { impl ListCommand {
pub fn uuids(mut self) -> Self { pub fn uuids(mut self) -> Self {
self.uuids = Some(true); self.uuids = true;
self self
} }
pub fn build(self) -> super::Command { pub fn build(self) -> super::Command {
let uuids = self.uuids.unwrap_or(false); let uuids = self.uuids;
let mut s = format!("list"); let mut s = format!("list");
if uuids { if uuids {
s.push_str(" uuids"); s.push_str(" uuids");

View file

@ -1,32 +1,7 @@
use std::fmt::Display;
pub struct Command(String); 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 say;
mod list; mod list;
mod kill;
impl Command { impl Command {
pub fn raw(cmd: &str) -> Self { pub fn raw(cmd: &str) -> Self {

View file

@ -1,16 +1,16 @@
#[derive(Default)] #[derive(Default)]
pub struct SayCommand { pub struct SayCommand {
message: Option<String> message: String
} }
impl SayCommand { impl SayCommand {
pub fn message(mut self, msg: impl Into<String>) -> Self { pub fn message(mut self, msg: impl Into<String>) -> Self {
self.message = Some(msg.into()); self.message = msg.into();
self self
} }
pub fn build(self) -> super::Command { pub fn build(self) -> super::Command {
let message = self.message.unwrap_or("Hello, world!".to_string()); let message = self.message;
let s = format!("say {message}"); let s = format!("say {message}");
super::Command(s) super::Command(s)
} }

View file

@ -2,4 +2,4 @@ mod client;
pub use client::{RconClient, RconError, RconResult}; pub use client::{RconClient, RconError, RconResult};
mod command; mod command;
pub use command::{Command, Selector}; pub use command::Command;