mc-rcon/src/command/ban.rs
2026-08-01 13:43:35 +02:00

33 lines
No EOL
889 B
Rust

#[derive(Default)]
pub struct BanCommand {
target: Option<super::Selector>,
reason: Option<String>,
ip: Option<bool>
}
impl BanCommand {
pub fn target(mut self, target: super::Selector) -> Self {
self.target = Some(target);
self
}
pub fn reason(mut self, reason: impl Into<String>) -> Self {
self.reason = Some(reason.into());
self
}
pub fn ip(mut self) -> Self {
self.ip = Some(true);
self
}
pub fn build(self) -> super::Command {
let target = self.target.unwrap_or(super::Selector::Player("nonexistent".to_string()));
let ip = self.ip.unwrap_or(false);
let mut s = if ip { format!("ban-ip {target}") } else { format!("ban {target}") };
if let Some(reason) = self.reason {
s.push_str(&format!(" {reason}"));
};
super::Command(s)
}
}