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