pub fn execute_command(
    plot: &mut Plot,
    player_uuid: u128,
    command: &str,
    args: &mut Vec<&str>,
) -> bool {
    let command = if let Some(command) = COMMANDS.get(command) {
        command
    } else if let Some(command) = ALIASES.get(command) {
        let mut alias: Vec<&str> = command.split(' ').collect();
        let command = alias.remove(0);
        if alias.len() > 1 {
            args.append(&mut alias);
        }
        &COMMANDS[command]
    } else {
        return false;
    };

    let mut ctx = CommandExecuteContext {
        plot,
        player_uuid,
        arguments: Vec::new(),
        flags: Vec::new(),
    };

    if !command.permission_node.is_empty()
        && !ctx.get_player_mut().has_permission(command.permission_node)
    {
        ctx.get_player_mut().send_no_permission_message();
        return true;
    }

    if command.requires_positions {
        let plot_x = ctx.plot.x;
        let plot_z = ctx.plot.z;
        let player = ctx.get_player_mut();
        if player.first_position.is_none() || player.second_position.is_none() {
            player.send_error_message("Make a region selection first.");
            return true;
        }
        let first_pos = player.first_position.unwrap();
        let second_pos = player.second_position.unwrap();
        if !Plot::in_plot_bounds(plot_x, plot_z, first_pos.x, first_pos.z) {
            player.send_system_message("First position is outside plot bounds!");
            return true;
        }
        if !Plot::in_plot_bounds(plot_x, plot_z, second_pos.x, second_pos.z) {
            player.send_system_message("Second position is outside plot bounds!");
            return true;
        }
    }

    if command.requires_clipboard {
        let player = ctx.get_player_mut();
        if player.worldedit_clipboard.is_none() {
            player.send_error_message("Your clipboard is empty. Use //copy first.");
            return true;
        }
    }

    let flag_descs = command.flags;

    let mut arg_removal_idxs = Vec::new();
    for (i, arg) in args.iter().enumerate() {
        if arg.starts_with('-') {
            let mut with_argument = false;
            let flags = arg.chars();
            for flag in flags.skip(1) {
                if with_argument {
                    ctx.get_player_mut()
                        .send_error_message("Flag with argument must be last in grouping");
                    return true;
                }
                let flag_desc = if let Some(desc) = flag_descs.iter().find(|d| d.letter == flag) {
                    desc
                } else {
                    ctx.get_player_mut()
                        .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);
                    with_argument = true;
                }
                ctx.flags.push(flag);
            }
        }
    }

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

    let arg_descs = command.arguments;

    if args.len() > arg_descs.len() {
        ctx.get_player_mut()
            .send_error_message("Too many arguments.");
        return true;
    }

    for (i, arg_desc) in arg_descs.iter().enumerate() {
        let arg = args.get(i).copied();
        match Argument::parse(&ctx, arg_desc.argument_type, arg) {
            Ok(default_arg) => ctx.arguments.push(default_arg),
            Err(err) => {
                ctx.get_player_mut().send_error_message(&err.to_string());
                return true;
            }
        }
    }
    ctx.plot.reset_redpiler();
    (command.execute_fn)(ctx);
    true
}
// Attempts to execute a worldedit command. Returns true of the command was handled.
// The command is not handled if it is not found in the worldedit commands and alias lists.
Attempts to execute a worldedit command. Returns true of the command was handled.
The command is not handled if it is not found in the worldedit commands and alias lists.
Attempts to execute a worldedit command . Returns true of the command was handled . The command is not handled if it is not found in the worldedit commands and alias lists .
pub fn execute_command(
    plot: &mut Plot,
    player_uuid: u128,
    command: &str,
    args: &mut Vec<&str>,
) -> bool {
    let command = if let Some(command) = COMMANDS.get(command) {
        command
    } else if let Some(command) = ALIASES.get(command) {
        let mut alias: Vec<&str> = command.split(' ').collect();
        let command = alias.remove(0);
        if alias.len() > 1 {
            args.append(&mut alias);
        }
        &COMMANDS[command]
    } else {
        return false;
    };
    let mut ctx = CommandExecuteContext {
        plot,
        player_uuid,
        arguments: Vec::new(),
        flags: Vec::new(),
    };
    if !command.permission_node.is_empty()
        && !ctx.get_player_mut().has_permission(command.permission_node)
    {
        ctx.get_player_mut().send_no_permission_message();
        return true;
    }
    if command.requires_positions {
        let plot_x = ctx.plot.x;
        let plot_z = ctx.plot.z;
        let player = ctx.get_player_mut();
        if player.first_position.is_none() || player.second_position.is_none() {
            player.send_error_message("Make a region selection first.");
            return true;
        }
        let first_pos = player.first_position.unwrap();
        let second_pos = player.second_position.unwrap();
        if !Plot::in_plot_bounds(plot_x, plot_z, first_pos.x, first_pos.z) {
            player.send_system_message("First position is outside plot bounds!");
            return true;
        }
        if !Plot::in_plot_bounds(plot_x, plot_z, second_pos.x, second_pos.z) {
            player.send_system_message("Second position is outside plot bounds!");
            return true;
        }
    }
    if command.requires_clipboard {
        let player = ctx.get_player_mut();
        if player.worldedit_clipboard.is_none() {
            player.send_error_message("Your clipboard is empty. Use //copy first.");
            return true;
        }
    }
    let flag_descs = command.flags;
    let mut arg_removal_idxs = Vec::new();
    for (i, arg) in args.iter().enumerate() {
        if arg.starts_with('-') {
            let mut with_argument = false;
            let flags = arg.chars();
            for flag in flags.skip(1) {
                if with_argument {
                    ctx.get_player_mut()
                        .send_error_message("Flag with argument must be last in grouping");
                    return true;
                }
                let flag_desc = if let Some(desc) = flag_descs.iter().find(|d| d.letter == flag) {
                    desc
                } else {
                    ctx.get_player_mut()
                        .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);
                    with_argument = true;
                }
                ctx.flags.push(flag);
            }
        }
    }
    for idx in arg_removal_idxs.iter().rev() {
        args.remove(*idx);
    }
    let arg_descs = command.arguments;
    if args.len() > arg_descs.len() {
        ctx.get_player_mut()
            .send_error_message("Too many arguments.");
        return true;
    }
    for (i, arg_desc) in arg_descs.iter().enumerate() {
        let arg = args.get(i).copied();
        match Argument::parse(&ctx, arg_desc.argument_type, arg) {
            Ok(default_arg) => ctx.arguments.push(default_arg),
            Err(err) => {
                ctx.get_player_mut().send_error_message(&err.to_string());
                return true;
            }
        }
    }
    ctx.plot.reset_redpiler();
    (command.execute_fn)(ctx);
    true
}
pub fn execute_command ( plot : & mut Plot , player_uuid : u128 , command : & str , args : & mut Vec < & str > , ) -> bool { let command = if let Some ( command ) = COMMANDS . get ( command ) { command } else if let Some ( command ) = ALIASES . get ( command ) { let mut alias : Vec < & str > = command . split ( ' ' ) . collect ( ) ; let command = alias . remove ( 0 ) ; if alias . len ( ) > 1 { args . append ( & mut alias ) ; } & COMMANDS [ command ] } else { return false ; } ; let mut ctx = CommandExecuteContext { plot , player_uuid , arguments : Vec :: new ( ) , flags : Vec :: new ( ) , } ; if ! command . permission_node . is_empty ( ) && ! ctx . get_player_mut ( ) . has_permission ( command . permission_node ) { ctx . get_player_mut ( ) . send_no_permission_message ( ) ; return true ; } if command . requires_positions { let plot_x = ctx . plot . x ; let plot_z = ctx . plot . z ; let player = ctx . get_player_mut ( ) ; if player . first_position . is_none ( ) || player . second_position . is_none ( ) { player . send_error_message ( " " ) ; return true ; } let first_pos = player . first_position . unwrap ( ) ; let second_pos = player . second_position . unwrap ( ) ; if ! Plot :: in_plot_bounds ( plot_x , plot_z , first_pos . x , first_pos . z ) { player . send_system_message ( " " ) ; return true ; } if ! Plot :: in_plot_bounds ( plot_x , plot_z , second_pos . x , second_pos . z ) { player . send_system_message ( " " ) ; return true ; } } if command . requires_clipboard { let player = ctx . get_player_mut ( ) ; if player . worldedit_clipboard . is_none ( ) { player . send_error_message ( " " ) ; return true ; } } let flag_descs = command . flags ; let mut arg_removal_idxs = Vec :: new ( ) ; for ( i , arg ) in args . iter ( ) . enumerate ( ) { if arg . starts_with ( '-' ) { let mut with_argument = false ; let flags = arg . chars ( ) ; for flag in flags . skip ( 1 ) { if with_argument { ctx . get_player_mut ( ) . send_error_message ( " " ) ; return true ; } let flag_desc = if let Some ( desc ) = flag_descs . iter ( ) . find ( | d | d . letter == flag ) { desc } else { ctx . get_player_mut ( ) . send_error_message ( & format ! ( " " flag ) ) ; return true ; } ; arg_removal_idxs . push ( i ) ; if flag_desc . argument_type . is_some ( ) { arg_removal_idxs . push ( i + 1 ) ; with_argument = true ; } ctx . flags . push ( flag ) ; } } } for idx in arg_removal_idxs . iter ( ) . rev ( ) { args . remove ( * idx ) ; } let arg_descs = command . arguments ; if args . len ( ) > arg_descs . len ( ) { ctx . get_player_mut ( ) . send_error_message ( " " ) ; return true ; } for ( i , arg_desc ) in arg_descs . iter ( ) . enumerate ( ) { let arg = args . get ( i ) . copied ( ) ; match Argument :: parse ( & ctx , arg_desc . argument_type , arg ) { Ok ( default_arg ) => ctx . arguments . push ( default_arg ) , Err ( err ) => { ctx . get_player_mut ( ) . send_error_message ( & err . to_string ( ) ) ; return true ; } } } ctx . plot . reset_redpiler ( ) ; ( command . execute_fn ) ( ctx ) ; true }
Attempts to execute a worldedit command.
Attempts to execute a worldedit command .
plot
&mut Plot
player_uuid
u128
command
&str
args
&mut Vec<&str>