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,59 +28,58 @@ 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
|
||||||
|
.op_permission_level
|
||||||
|
.min(sender.permission_lvl());
|
||||||
|
|
||||||
let new_level = BASIC_CONFIG
|
if player.permission_lvl.load() == new_level {
|
||||||
.op_permission_level
|
sender
|
||||||
.min(sender.permission_lvl());
|
.send_message(TextComponent::translate("commands.op.failed", []))
|
||||||
|
.await;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if player.permission_lvl.load() == new_level {
|
if let Some(op) = config
|
||||||
sender
|
.ops
|
||||||
.send_message(TextComponent::translate("commands.op.failed", []))
|
.iter_mut()
|
||||||
|
.find(|o| o.uuid == player.gameprofile.id)
|
||||||
|
{
|
||||||
|
op.level = new_level;
|
||||||
|
} else {
|
||||||
|
let op_entry = Op::new(
|
||||||
|
player.gameprofile.id,
|
||||||
|
player.gameprofile.name.clone(),
|
||||||
|
new_level,
|
||||||
|
false,
|
||||||
|
);
|
||||||
|
config.ops.push(op_entry);
|
||||||
|
}
|
||||||
|
|
||||||
|
config.save();
|
||||||
|
|
||||||
|
player
|
||||||
|
.set_permission_lvl(new_level, &server.command_dispatcher)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let player_name = &player.gameprofile.name;
|
||||||
|
sender
|
||||||
|
.send_message(TextComponent::translate(
|
||||||
|
"commands.op.success",
|
||||||
|
[player_name.clone().into()],
|
||||||
|
))
|
||||||
.await;
|
.await;
|
||||||
return Ok(());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(op) = config
|
|
||||||
.ops
|
|
||||||
.iter_mut()
|
|
||||||
.find(|o| o.uuid == player.gameprofile.id)
|
|
||||||
{
|
|
||||||
op.level = new_level;
|
|
||||||
} else {
|
|
||||||
let op_entry = Op::new(
|
|
||||||
player.gameprofile.id,
|
|
||||||
player.gameprofile.name.clone(),
|
|
||||||
new_level,
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
config.ops.push(op_entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
config.save();
|
|
||||||
|
|
||||||
player
|
|
||||||
.set_permission_lvl(new_level, &server.command_dispatcher)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
let player_name = &player.gameprofile.name;
|
|
||||||
sender
|
|
||||||
.send_message(TextComponent::translate(
|
|
||||||
"commands.op.success",
|
|
||||||
[player_name.clone().into()],
|
|
||||||
))
|
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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