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

Add worldedit //shift command #41

Merged
merged 1 commit into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
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
18 changes: 17 additions & 1 deletion src/plot/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ lazy_static! {
// 0: Root Node
Node {
flags: CommandFlags::ROOT.bits() as i8,
children: vec![1, 4, 5, 6, 11, 12, 14, 16, 18, 19, 20, 21, 22, 23, 24, 26, 29, 31, 32, 34, 36],
children: vec![1, 4, 5, 6, 11, 12, 14, 16, 18, 19, 20, 21, 22, 23, 24, 26, 29, 31, 32, 34, 36, 47],
redirect_node: None,
name: None,
parser: None,
Expand Down Expand Up @@ -699,6 +699,22 @@ lazy_static! {
name: Some("tp"),
parser: None,
},
// 47: //shift
Node {
flags: (CommandFlags::LITERAL | CommandFlags::EXECUTABLE).bits() as i8,
children: vec![35],
redirect_node: None,
name: Some("/shift"),
parser: None,
},
// 48: //shift [amount]
Node {
flags: (CommandFlags::ARGUMENT | CommandFlags::EXECUTABLE).bits() as i8,
children: vec![],
redirect_node: None,
name: Some("amount"),
parser: Some(Parser::Integer(0, 256)),
},
],
root_index: 0
}.encode();
Expand Down
34 changes: 34 additions & 0 deletions src/plot/worldedit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,16 @@ lazy_static! {
description: "Contract the selection area",
..Default::default()
},
"/shift" => WorldeditCommand {
arguments: &[
argument!("amount", UnsignedInteger, "Amount to shift the selection by"),
argument!("direction", Direction, "Direction to shift")
],
requires_positions: true,
execute_fn: execute_shift,
description: "Shift the selection area",
..Default::default()
},
"/help" => WorldeditCommand {
arguments: &[
argument!("command", String, "Command to retrieve help for"),
Expand Down Expand Up @@ -1426,6 +1436,30 @@ fn execute_contract(mut ctx: CommandExecuteContext<'_>) {
player.send_worldedit_message(&format!("Region expanded {} block(s).", amount));
}

fn execute_shift(mut ctx: CommandExecuteContext<'_>) {
let amount = ctx.arguments[0].unwrap_uint();
let direction = ctx.arguments[1].unwrap_direction();
let player = ctx.get_player_mut();
let first_pos = player.first_position.unwrap();
let second_pos = player.second_position.unwrap();

let mut move_both_points = |x, y, z| {
player.worldedit_set_first_position(BlockPos::new(first_pos.x + x, first_pos.y + y, first_pos.z + z));
player.worldedit_set_second_position(BlockPos::new(second_pos.x + x, second_pos.y + y, second_pos.z + z));
};

match direction {
BlockFacing::Up => move_both_points(0, amount as i32, 0),
BlockFacing::Down => move_both_points(0, -(amount as i32), 0),
BlockFacing::East => move_both_points(amount as i32, 0, 0),
BlockFacing::West => move_both_points(-(amount as i32), 0, 0),
BlockFacing::South => move_both_points(0, 0, amount as i32),
BlockFacing::North => move_both_points(0, 0, -(amount as i32)),
}

player.send_worldedit_message(&format!("Region shifted {} block(s).", amount));
}

fn execute_help(mut ctx: CommandExecuteContext<'_>) {
let command_name = ctx.arguments[0].unwrap_string().clone();
let slash_command_name = "/".to_owned() + &command_name;
Expand Down