use new() with primary argument instead of default()
This commit is contained in:
parent
25052c00e0
commit
3a099b72f6
11 changed files with 53 additions and 64 deletions
|
|
@ -1,16 +1,14 @@
|
|||
use super::{Command, Selector};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct BanCommand {
|
||||
target: Option<Selector>,
|
||||
target: Selector,
|
||||
reason: Option<String>,
|
||||
ip: Option<bool>,
|
||||
}
|
||||
|
||||
impl BanCommand {
|
||||
pub fn target(mut self, target: Selector) -> Self {
|
||||
self.target = Some(target);
|
||||
self
|
||||
pub fn new(target: Selector) -> Self {
|
||||
Self { target, reason: None, ip: None }
|
||||
}
|
||||
|
||||
pub fn reason(mut self, reason: impl Into<String>) -> Self {
|
||||
|
|
@ -24,9 +22,7 @@ impl BanCommand {
|
|||
}
|
||||
|
||||
pub fn build(self) -> Command {
|
||||
let target = self
|
||||
.target
|
||||
.unwrap_or(Selector::Player("nonexistent".to_string()));
|
||||
let target = self.target;
|
||||
let ip = self.ip.unwrap_or(false);
|
||||
let mut s = if ip {
|
||||
format!("ban-ip {target}")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use super::Command;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct BanlistCommand<State> {
|
||||
state: PhantomData<State>,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
use super::{Command, Gamemode};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DefaultGamemodeCommand {
|
||||
gamemode: Option<Gamemode>,
|
||||
gamemode: Gamemode,
|
||||
}
|
||||
|
||||
impl DefaultGamemodeCommand {
|
||||
pub fn gamemode(mut self, gamemode: Gamemode) -> Self {
|
||||
self.gamemode = Some(gamemode);
|
||||
self
|
||||
pub fn new(gamemode: Gamemode) -> Self {
|
||||
Self { gamemode }
|
||||
}
|
||||
|
||||
pub fn build(self) -> Command {
|
||||
let gamemode = self.gamemode.unwrap_or(Gamemode::Survival);
|
||||
let gamemode = self.gamemode;
|
||||
let s = format!("defaultgamemode {gamemode}");
|
||||
Command(s)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
use super::{Command, Selector};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DeopCommand {
|
||||
target: Option<Selector>,
|
||||
target: Selector,
|
||||
}
|
||||
|
||||
impl DeopCommand {
|
||||
pub fn target(mut self, target: Selector) -> Self {
|
||||
self.target = Some(target);
|
||||
self
|
||||
pub fn new(target: Selector) -> Self {
|
||||
Self { target }
|
||||
}
|
||||
|
||||
pub fn build(self) -> Command {
|
||||
let target = self.target.unwrap_or(Selector::Executor);
|
||||
let target = self.target;
|
||||
let s = format!("deop {target}");
|
||||
Command(s)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,21 @@
|
|||
use super::{Command, Difficulty};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct DifficultyCommand {
|
||||
difficulty: Option<Difficulty>
|
||||
}
|
||||
|
||||
impl DifficultyCommand {
|
||||
pub fn new() -> Self {
|
||||
Self { difficulty: None }
|
||||
}
|
||||
|
||||
pub fn difficulty(mut self, difficulty: Difficulty) -> Self {
|
||||
self.difficulty = Some(difficulty);
|
||||
self
|
||||
}
|
||||
|
||||
pub fn build(self) -> Command {
|
||||
let mut s = format!("difficulty");
|
||||
let mut s = "difficulty".to_string();
|
||||
if let Some(difficulty) = self.difficulty {
|
||||
s.push_str(&format!(" {difficulty}"))
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
use super::{Command, Gamemode, Selector};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct GamemodeCommand {
|
||||
gamemode: Option<Gamemode>,
|
||||
gamemode: Gamemode,
|
||||
target: Option<Selector>
|
||||
}
|
||||
|
||||
impl GamemodeCommand {
|
||||
pub fn gamemode(mut self, gamemode: Gamemode) -> Self {
|
||||
self.gamemode = Some(gamemode);
|
||||
self
|
||||
pub fn new(gamemode: Gamemode) -> Self {
|
||||
Self { gamemode, target: None }
|
||||
}
|
||||
|
||||
pub fn target(mut self, target: Selector) -> Self {
|
||||
|
|
@ -18,7 +16,7 @@ impl GamemodeCommand {
|
|||
}
|
||||
|
||||
pub fn build(self) -> Command {
|
||||
let gamemode = self.gamemode.unwrap_or(Gamemode::Survival);
|
||||
let gamemode = self.gamemode;
|
||||
let mut s = format!("defaultgamemode {gamemode}");
|
||||
if let Some(target) = self.target {
|
||||
s.push_str(&format!(" {target}"))
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
use super::{Command, Selector};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct KillCommand {
|
||||
target: Option<Selector>,
|
||||
target: Selector,
|
||||
}
|
||||
|
||||
impl KillCommand {
|
||||
pub fn target(mut self, target: Selector) -> Self {
|
||||
self.target = Some(target);
|
||||
self
|
||||
pub fn new(target: Selector) -> Self {
|
||||
Self { target }
|
||||
}
|
||||
|
||||
pub fn build(self) -> Command {
|
||||
let target = self.target.unwrap_or(Selector::Executor);
|
||||
let target = self.target;
|
||||
let s = format!("kill {target}");
|
||||
Command(s)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,14 @@
|
|||
use super::Command;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct ListCommand {
|
||||
uuids: Option<bool>,
|
||||
}
|
||||
|
||||
impl ListCommand {
|
||||
pub fn new() -> Self {
|
||||
Self { uuids: None }
|
||||
}
|
||||
|
||||
pub fn uuids(mut self) -> Self {
|
||||
self.uuids = Some(true);
|
||||
self
|
||||
|
|
|
|||
|
|
@ -82,43 +82,43 @@ impl Command {
|
|||
&self.0
|
||||
}
|
||||
|
||||
pub fn say() -> say::SayCommand {
|
||||
say::SayCommand::default()
|
||||
pub fn say(message: impl Into<String>) -> say::SayCommand {
|
||||
say::SayCommand::new(message.into())
|
||||
}
|
||||
|
||||
pub fn list() -> list::ListCommand {
|
||||
list::ListCommand::default()
|
||||
list::ListCommand::new()
|
||||
}
|
||||
|
||||
pub fn kill() -> kill::KillCommand {
|
||||
kill::KillCommand::default()
|
||||
pub fn kill(target: Selector) -> kill::KillCommand {
|
||||
kill::KillCommand::new(target)
|
||||
}
|
||||
|
||||
pub fn ban() -> ban::BanCommand {
|
||||
ban::BanCommand::default()
|
||||
pub fn ban(target: Selector) -> ban::BanCommand {
|
||||
ban::BanCommand::new(target)
|
||||
}
|
||||
|
||||
pub fn banlist() -> banlist::BanlistCommand<banlist::NoFilter> {
|
||||
banlist::BanlistCommand::new()
|
||||
}
|
||||
|
||||
pub fn defaultgamemode() -> defaultgamemode::DefaultGamemodeCommand {
|
||||
defaultgamemode::DefaultGamemodeCommand::default()
|
||||
pub fn defaultgamemode(gamemode: Gamemode) -> defaultgamemode::DefaultGamemodeCommand {
|
||||
defaultgamemode::DefaultGamemodeCommand::new(gamemode)
|
||||
}
|
||||
|
||||
pub fn op() -> op::OpCommand {
|
||||
op::OpCommand::default()
|
||||
pub fn op(target: Selector) -> op::OpCommand {
|
||||
op::OpCommand::new(target)
|
||||
}
|
||||
|
||||
pub fn deop() -> deop::DeopCommand {
|
||||
deop::DeopCommand::default()
|
||||
pub fn deop(target: Selector) -> deop::DeopCommand {
|
||||
deop::DeopCommand::new(target)
|
||||
}
|
||||
|
||||
pub fn difficulty() -> difficulty::DifficultyCommand {
|
||||
difficulty::DifficultyCommand::default()
|
||||
difficulty::DifficultyCommand::new()
|
||||
}
|
||||
|
||||
pub fn gamemode() -> gamemode::GamemodeCommand {
|
||||
gamemode::GamemodeCommand::default()
|
||||
pub fn gamemode(gamemode: Gamemode) -> gamemode::GamemodeCommand {
|
||||
gamemode::GamemodeCommand::new(gamemode)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,18 +1,16 @@
|
|||
use super::{Command, Selector};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct OpCommand {
|
||||
target: Option<Selector>,
|
||||
target: Selector,
|
||||
}
|
||||
|
||||
impl OpCommand {
|
||||
pub fn target(mut self, target: Selector) -> Self {
|
||||
self.target = Some(target);
|
||||
self
|
||||
pub fn new(target: Selector) -> Self {
|
||||
Self { target }
|
||||
}
|
||||
|
||||
pub fn build(self) -> Command {
|
||||
let target = self.target.unwrap_or(Selector::Executor);
|
||||
let target = self.target;
|
||||
let s = format!("op {target}");
|
||||
Command(s)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
use super::Command;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct SayCommand {
|
||||
message: Option<String>,
|
||||
message: String,
|
||||
}
|
||||
|
||||
impl SayCommand {
|
||||
pub fn message(mut self, msg: impl Into<String>) -> Self {
|
||||
self.message = Some(msg.into());
|
||||
self
|
||||
pub fn new(message: String) -> Self {
|
||||
Self { message }
|
||||
}
|
||||
|
||||
pub fn build(self) -> Command {
|
||||
let message = self.message.unwrap_or("Hello, world!".to_string());
|
||||
let message = self.message;
|
||||
let s = format!("say {message}");
|
||||
Command(s)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue