Compare commits

...

5 commits

Author SHA1 Message Date
Raptorox
32304f4ea0
make say use Option 2026-07-28 17:34:33 +02:00
Raptorox
f01661339e
add kill 2026-07-28 17:31:47 +02:00
Raptorox
dbf872baeb
implement Display for Selector 2026-07-28 17:31:37 +02:00
Raptorox
398615573c
make list use Option 2026-07-28 17:25:04 +02:00
Raptorox
3122f68720
add selector 2026-07-28 17:24:10 +02:00
5 changed files with 49 additions and 7 deletions

17
src/command/kill.rs Normal file
View file

@ -0,0 +1,17 @@
#[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)]
pub struct ListCommand {
uuids: bool
uuids: Option<bool>
}
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");

View file

@ -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 {

View file

@ -1,16 +1,16 @@
#[derive(Default)]
pub struct SayCommand {
message: String
message: Option<String>
}
impl SayCommand {
pub fn message(mut self, msg: impl Into<String>) -> 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)
}

View file

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