Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of combined flags in worldedit commands crashing the plot #161

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions crates/core/src/plot/worldedit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,12 @@ pub fn execute_command(
let flag_descs = command.flags;

let mut ctx_flags = Vec::new();
let mut arg_removal_idxs = Vec::new();
for (i, arg) in args.iter().enumerate() {

let total_arg_count = args.len();
let mut arg_iter = args.iter().copied().enumerate();
let mut args = Vec::new();

while let Some((i, arg)) = arg_iter.next() {
if arg.starts_with('-') {
let mut with_argument = false;
let flags = arg.chars();
Expand All @@ -104,20 +108,24 @@ pub fn execute_command(
player.send_error_message(&format!("Unknown flag: {}", flag));
return true;
};
arg_removal_idxs.push(i);
if flag_desc.argument_type.is_some() {
arg_removal_idxs.push(i + 1);
if let Some(argument_type) = flag_desc.argument_type {
if (i + 1) >= total_arg_count {
player.send_error_message(&format!(
"Missing {:?} argument for {} flag",
argument_type, flag
));
return true;
}
arg_iter.next();
with_argument = true;
}
ctx_flags.push(flag);
}
} else {
args.push(arg);
}
}

for idx in arg_removal_idxs.iter().rev() {
args.remove(*idx);
}

let arg_descs = command.arguments;

if args.len() > arg_descs.len() {
Expand Down
Loading