Compare commits
5 commits
37e89d6dc5
...
32304f4ea0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32304f4ea0 | ||
|
|
f01661339e | ||
|
|
dbf872baeb | ||
|
|
398615573c | ||
|
|
3122f68720 |
5 changed files with 49 additions and 7 deletions
17
src/command/kill.rs
Normal file
17
src/command/kill.rs
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct ListCommand {
|
pub struct ListCommand {
|
||||||
uuids: bool
|
uuids: Option<bool>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ListCommand {
|
impl ListCommand {
|
||||||
pub fn uuids(mut self) -> Self {
|
pub fn uuids(mut self) -> Self {
|
||||||
self.uuids = true;
|
self.uuids = Some(true);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self) -> super::Command {
|
pub fn build(self) -> super::Command {
|
||||||
let uuids = self.uuids;
|
let uuids = self.uuids.unwrap_or(false);
|
||||||
let mut s = format!("list");
|
let mut s = format!("list");
|
||||||
if uuids {
|
if uuids {
|
||||||
s.push_str(" uuids");
|
s.push_str(" uuids");
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,32 @@
|
||||||
|
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 {
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,16 @@
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct SayCommand {
|
pub struct SayCommand {
|
||||||
message: String
|
message: Option<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 = msg.into();
|
self.message = Some(msg.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn build(self) -> super::Command {
|
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}");
|
let s = format!("say {message}");
|
||||||
super::Command(s)
|
super::Command(s)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
pub use command::{Command, Selector};
|
||||||
Loading…
Add table
Add a link
Reference in a new issue