Compare commits

..

No commits in common. "3a099b72f6def81874563f015b21d8b207183327" and "d43b588e5160f416c62065391818fa8a5104e295" have entirely different histories.

12 changed files with 65 additions and 54 deletions

View file

@ -1,14 +1,16 @@
use super::{Command, Selector}; use super::{Command, Selector};
#[derive(Default)]
pub struct BanCommand { pub struct BanCommand {
target: Selector, target: Option<Selector>,
reason: Option<String>, reason: Option<String>,
ip: Option<bool>, ip: Option<bool>,
} }
impl BanCommand { impl BanCommand {
pub fn new(target: Selector) -> Self { pub fn target(mut self, target: Selector) -> Self {
Self { target, reason: None, ip: None } self.target = Some(target);
self
} }
pub fn reason(mut self, reason: impl Into<String>) -> Self { pub fn reason(mut self, reason: impl Into<String>) -> Self {
@ -22,7 +24,9 @@ impl BanCommand {
} }
pub fn build(self) -> Command { pub fn build(self) -> Command {
let target = self.target; let target = self
.target
.unwrap_or(Selector::Player("nonexistent".to_string()));
let ip = self.ip.unwrap_or(false); let ip = self.ip.unwrap_or(false);
let mut s = if ip { let mut s = if ip {
format!("ban-ip {target}") format!("ban-ip {target}")

View file

@ -1,6 +1,7 @@
use super::Command; use super::Command;
use std::marker::PhantomData; use std::marker::PhantomData;
#[derive(Default)]
pub struct BanlistCommand<State> { pub struct BanlistCommand<State> {
state: PhantomData<State>, state: PhantomData<State>,
} }

View file

@ -1,16 +1,18 @@
use super::{Command, Gamemode}; use super::{Command, Gamemode};
#[derive(Default)]
pub struct DefaultGamemodeCommand { pub struct DefaultGamemodeCommand {
gamemode: Gamemode, gamemode: Option<Gamemode>,
} }
impl DefaultGamemodeCommand { impl DefaultGamemodeCommand {
pub fn new(gamemode: Gamemode) -> Self { pub fn gamemode(mut self, gamemode: Gamemode) -> Self {
Self { gamemode } self.gamemode = Some(gamemode);
self
} }
pub fn build(self) -> Command { pub fn build(self) -> Command {
let gamemode = self.gamemode; let gamemode = self.gamemode.unwrap_or(Gamemode::Survival);
let s = format!("defaultgamemode {gamemode}"); let s = format!("defaultgamemode {gamemode}");
Command(s) Command(s)
} }

View file

@ -1,16 +1,18 @@
use super::{Command, Selector}; use super::{Command, Selector};
#[derive(Default)]
pub struct DeopCommand { pub struct DeopCommand {
target: Selector, target: Option<Selector>,
} }
impl DeopCommand { impl DeopCommand {
pub fn new(target: Selector) -> Self { pub fn target(mut self, target: Selector) -> Self {
Self { target } self.target = Some(target);
self
} }
pub fn build(self) -> Command { pub fn build(self) -> Command {
let target = self.target; let target = self.target.unwrap_or(Selector::Executor);
let s = format!("deop {target}"); let s = format!("deop {target}");
Command(s) Command(s)
} }

View file

@ -1,21 +1,18 @@
use super::{Command, Difficulty}; use super::{Command, Difficulty};
#[derive(Default)]
pub struct DifficultyCommand { pub struct DifficultyCommand {
difficulty: Option<Difficulty> difficulty: Option<Difficulty>
} }
impl DifficultyCommand { impl DifficultyCommand {
pub fn new() -> Self {
Self { difficulty: None }
}
pub fn difficulty(mut self, difficulty: Difficulty) -> Self { pub fn difficulty(mut self, difficulty: Difficulty) -> Self {
self.difficulty = Some(difficulty); self.difficulty = Some(difficulty);
self self
} }
pub fn build(self) -> Command { pub fn build(self) -> Command {
let mut s = "difficulty".to_string(); let mut s = format!("difficulty");
if let Some(difficulty) = self.difficulty { if let Some(difficulty) = self.difficulty {
s.push_str(&format!(" {difficulty}")) s.push_str(&format!(" {difficulty}"))
}; };

View file

@ -1,13 +1,15 @@
use super::{Command, Gamemode, Selector}; use super::{Command, Gamemode, Selector};
#[derive(Default)]
pub struct GamemodeCommand { pub struct GamemodeCommand {
gamemode: Gamemode, gamemode: Option<Gamemode>,
target: Option<Selector> target: Option<Selector>
} }
impl GamemodeCommand { impl GamemodeCommand {
pub fn new(gamemode: Gamemode) -> Self { pub fn gamemode(mut self, gamemode: Gamemode) -> Self {
Self { gamemode, target: None } self.gamemode = Some(gamemode);
self
} }
pub fn target(mut self, target: Selector) -> Self { pub fn target(mut self, target: Selector) -> Self {
@ -16,7 +18,7 @@ impl GamemodeCommand {
} }
pub fn build(self) -> Command { pub fn build(self) -> Command {
let gamemode = self.gamemode; let gamemode = self.gamemode.unwrap_or(Gamemode::Survival);
let mut s = format!("defaultgamemode {gamemode}"); let mut s = format!("defaultgamemode {gamemode}");
if let Some(target) = self.target { if let Some(target) = self.target {
s.push_str(&format!(" {target}")) s.push_str(&format!(" {target}"))

View file

@ -1,16 +1,18 @@
use super::{Command, Selector}; use super::{Command, Selector};
#[derive(Default)]
pub struct KillCommand { pub struct KillCommand {
target: Selector, target: Option<Selector>,
} }
impl KillCommand { impl KillCommand {
pub fn new(target: Selector) -> Self { pub fn target(mut self, target: Selector) -> Self {
Self { target } self.target = Some(target);
self
} }
pub fn build(self) -> Command { pub fn build(self) -> Command {
let target = self.target; let target = self.target.unwrap_or(Selector::Executor);
let s = format!("kill {target}"); let s = format!("kill {target}");
Command(s) Command(s)
} }

View file

@ -1,14 +1,11 @@
use super::Command; use super::Command;
#[derive(Default)]
pub struct ListCommand { pub struct ListCommand {
uuids: Option<bool>, uuids: Option<bool>,
} }
impl ListCommand { impl ListCommand {
pub fn new() -> Self {
Self { uuids: None }
}
pub fn uuids(mut self) -> Self { pub fn uuids(mut self) -> Self {
self.uuids = Some(true); self.uuids = Some(true);
self self

View file

@ -82,43 +82,43 @@ impl Command {
&self.0 &self.0
} }
pub fn say(message: impl Into<String>) -> say::SayCommand { pub fn say() -> say::SayCommand {
say::SayCommand::new(message.into()) say::SayCommand::default()
} }
pub fn list() -> list::ListCommand { pub fn list() -> list::ListCommand {
list::ListCommand::new() list::ListCommand::default()
} }
pub fn kill(target: Selector) -> kill::KillCommand { pub fn kill() -> kill::KillCommand {
kill::KillCommand::new(target) kill::KillCommand::default()
} }
pub fn ban(target: Selector) -> ban::BanCommand { pub fn ban() -> ban::BanCommand {
ban::BanCommand::new(target) ban::BanCommand::default()
} }
pub fn banlist() -> banlist::BanlistCommand<banlist::NoFilter> { pub fn banlist() -> banlist::BanlistCommand<banlist::NoFilter> {
banlist::BanlistCommand::new() banlist::BanlistCommand::new()
} }
pub fn defaultgamemode(gamemode: Gamemode) -> defaultgamemode::DefaultGamemodeCommand { pub fn defaultgamemode() -> defaultgamemode::DefaultGamemodeCommand {
defaultgamemode::DefaultGamemodeCommand::new(gamemode) defaultgamemode::DefaultGamemodeCommand::default()
} }
pub fn op(target: Selector) -> op::OpCommand { pub fn op() -> op::OpCommand {
op::OpCommand::new(target) op::OpCommand::default()
} }
pub fn deop(target: Selector) -> deop::DeopCommand { pub fn deop() -> deop::DeopCommand {
deop::DeopCommand::new(target) deop::DeopCommand::default()
} }
pub fn difficulty() -> difficulty::DifficultyCommand { pub fn difficulty() -> difficulty::DifficultyCommand {
difficulty::DifficultyCommand::new() difficulty::DifficultyCommand::default()
} }
pub fn gamemode(gamemode: Gamemode) -> gamemode::GamemodeCommand { pub fn gamemode() -> gamemode::GamemodeCommand {
gamemode::GamemodeCommand::new(gamemode) gamemode::GamemodeCommand::default()
} }
} }

View file

@ -1,16 +1,18 @@
use super::{Command, Selector}; use super::{Command, Selector};
#[derive(Default)]
pub struct OpCommand { pub struct OpCommand {
target: Selector, target: Option<Selector>,
} }
impl OpCommand { impl OpCommand {
pub fn new(target: Selector) -> Self { pub fn target(mut self, target: Selector) -> Self {
Self { target } self.target = Some(target);
self
} }
pub fn build(self) -> Command { pub fn build(self) -> Command {
let target = self.target; let target = self.target.unwrap_or(Selector::Executor);
let s = format!("op {target}"); let s = format!("op {target}");
Command(s) Command(s)
} }

View file

@ -1,16 +1,18 @@
use super::Command; use super::Command;
#[derive(Default)]
pub struct SayCommand { pub struct SayCommand {
message: String, message: Option<String>,
} }
impl SayCommand { impl SayCommand {
pub fn new(message: String) -> Self { pub fn message(mut self, msg: impl Into<String>) -> Self {
Self { message } self.message = Some(msg.into());
self
} }
pub fn build(self) -> Command { pub fn build(self) -> 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}");
Command(s) 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, Difficulty, Gamemode}; pub use command::{Command, Selector};