fix: op command allow multiple targets
This commit is contained in:
parent
c022914dbf
commit
daf3b29bb2
@ -14,7 +14,7 @@ use CommandError::InvalidConsumption;
|
|||||||
|
|
||||||
const NAMES: [&str; 1] = ["op"];
|
const NAMES: [&str; 1] = ["op"];
|
||||||
const DESCRIPTION: &str = "Grants operator status to a player.";
|
const DESCRIPTION: &str = "Grants operator status to a player.";
|
||||||
const ARG_TARGET: &str = "player";
|
const ARG_TARGETS: &str = "targets";
|
||||||
|
|
||||||
struct OpExecutor;
|
struct OpExecutor;
|
||||||
|
|
||||||
@ -28,13 +28,11 @@ impl CommandExecutor for OpExecutor {
|
|||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
let mut config = OPERATOR_CONFIG.write().await;
|
let mut config = OPERATOR_CONFIG.write().await;
|
||||||
|
|
||||||
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())));
|
||||||
};
|
};
|
||||||
|
|
||||||
// from the command tree, the command can only be executed with one player
|
for player in targets {
|
||||||
let player = &targets[0];
|
|
||||||
|
|
||||||
let new_level = BASIC_CONFIG
|
let new_level = BASIC_CONFIG
|
||||||
.op_permission_level
|
.op_permission_level
|
||||||
.min(sender.permission_lvl());
|
.min(sender.permission_lvl());
|
||||||
@ -43,7 +41,7 @@ impl CommandExecutor for OpExecutor {
|
|||||||
sender
|
sender
|
||||||
.send_message(TextComponent::translate("commands.op.failed", []))
|
.send_message(TextComponent::translate("commands.op.failed", []))
|
||||||
.await;
|
.await;
|
||||||
return Ok(());
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(op) = config
|
if let Some(op) = config
|
||||||
@ -75,6 +73,7 @@ impl CommandExecutor for OpExecutor {
|
|||||||
[player_name.clone().into()],
|
[player_name.clone().into()],
|
||||||
))
|
))
|
||||||
.await;
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -82,5 +81,5 @@ impl CommandExecutor for OpExecutor {
|
|||||||
|
|
||||||
pub fn init_command_tree() -> CommandTree {
|
pub fn init_command_tree() -> CommandTree {
|
||||||
CommandTree::new(NAMES, DESCRIPTION)
|
CommandTree::new(NAMES, DESCRIPTION)
|
||||||
.with_child(argument(ARG_TARGET, PlayersArgumentConsumer).execute(OpExecutor))
|
.with_child(argument(ARG_TARGETS, PlayersArgumentConsumer).execute(OpExecutor))
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user