mc-rcon/src/command/mod.rs
2026-08-01 14:24:17 +02:00

63 lines
No EOL
1.3 KiB
Rust

use std::fmt::Display;
pub struct Command(String);
pub enum Selector {
NearestPlayer, // @p
RandomPlayer, // @r
AllPlayers, // @a
AllEntities, // @e
Executor, // @s
NearestEntity, // @n,
Player(String)
}
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"),
Self::Player(name) => write!(f, "{name}")
}
}
}
mod say;
mod list;
mod kill;
mod ban;
mod banlist;
impl Command {
pub fn raw(cmd: &str) -> Self {
Self(cmd.to_string())
}
pub fn as_str(&self) -> &str {
&self.0
}
pub fn say() -> say::SayCommand {
say::SayCommand::default()
}
pub fn list() -> list::ListCommand {
list::ListCommand::default()
}
pub fn kill() -> kill::KillCommand {
kill::KillCommand::default()
}
pub fn ban() -> ban::BanCommand {
ban::BanCommand::default()
}
pub fn banlist() -> banlist::BanlistCommand<banlist::NoFilter> {
banlist::BanlistCommand::new()
}
}