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