support reason in kick command
This commit is contained in:
parent
df9ea7fe96
commit
c022914dbf
@ -2,6 +2,7 @@ use async_trait::async_trait;
|
|||||||
use pumpkin_util::text::color::NamedColor;
|
use pumpkin_util::text::color::NamedColor;
|
||||||
use pumpkin_util::text::TextComponent;
|
use pumpkin_util::text::TextComponent;
|
||||||
|
|
||||||
|
use crate::command::args::arg_message::MsgArgConsumer;
|
||||||
use crate::command::args::arg_players::PlayersArgumentConsumer;
|
use crate::command::args::arg_players::PlayersArgumentConsumer;
|
||||||
use crate::command::args::{Arg, ConsumedArgs};
|
use crate::command::args::{Arg, ConsumedArgs};
|
||||||
use crate::command::tree::CommandTree;
|
use crate::command::tree::CommandTree;
|
||||||
@ -13,7 +14,9 @@ use CommandError::InvalidConsumption;
|
|||||||
const NAMES: [&str; 1] = ["kick"];
|
const NAMES: [&str; 1] = ["kick"];
|
||||||
const DESCRIPTION: &str = "Kicks the target player from the server.";
|
const DESCRIPTION: &str = "Kicks the target player from the server.";
|
||||||
|
|
||||||
const ARG_TARGET: &str = "target";
|
const ARG_TARGETS: &str = "targets";
|
||||||
|
|
||||||
|
const ARG_REASON: &str = "reason";
|
||||||
|
|
||||||
struct KickExecutor;
|
struct KickExecutor;
|
||||||
|
|
||||||
@ -25,17 +28,17 @@ impl CommandExecutor for KickExecutor {
|
|||||||
_server: &crate::server::Server,
|
_server: &crate::server::Server,
|
||||||
args: &ConsumedArgs<'a>,
|
args: &ConsumedArgs<'a>,
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
let Some(Arg::Players(targets)) = args.get(&ARG_TARGET) else {
|
let Some(Arg::Players(targets)) = args.get(&ARG_TARGETS) else {
|
||||||
return Err(InvalidConsumption(Some(ARG_TARGET.into())));
|
return Err(InvalidConsumption(Some(ARG_TARGETS.into())));
|
||||||
|
};
|
||||||
|
|
||||||
|
let reason = match args.get(&ARG_REASON) {
|
||||||
|
Some(Arg::Msg(r)) => TextComponent::text(r.clone()),
|
||||||
|
_ => TextComponent::translate("multiplayer.disconnect.kicked", []),
|
||||||
};
|
};
|
||||||
|
|
||||||
for target in targets {
|
for target in targets {
|
||||||
target
|
target.kick(reason.clone()).await;
|
||||||
.kick(TextComponent::translate(
|
|
||||||
"multiplayer.disconnect.kicked",
|
|
||||||
[],
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
let name = &target.gameprofile.name;
|
let name = &target.gameprofile.name;
|
||||||
let msg = TextComponent::text(format!("Kicked: {name}"));
|
let msg = TextComponent::text(format!("Kicked: {name}"));
|
||||||
sender.send_message(msg.color_named(NamedColor::Blue)).await;
|
sender.send_message(msg.color_named(NamedColor::Blue)).await;
|
||||||
@ -47,6 +50,9 @@ impl CommandExecutor for KickExecutor {
|
|||||||
|
|
||||||
// TODO: Permission
|
// TODO: Permission
|
||||||
pub fn init_command_tree() -> CommandTree {
|
pub fn init_command_tree() -> CommandTree {
|
||||||
CommandTree::new(NAMES, DESCRIPTION)
|
CommandTree::new(NAMES, DESCRIPTION).with_child(
|
||||||
.with_child(argument(ARG_TARGET, PlayersArgumentConsumer).execute(KickExecutor))
|
argument(ARG_TARGETS, PlayersArgumentConsumer)
|
||||||
|
.execute(KickExecutor)
|
||||||
|
.with_child(argument(ARG_REASON, MsgArgConsumer).execute(KickExecutor)),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user