From 65c3614e7b09fc01217e5cb8160f9f0da908bb18 Mon Sep 17 00:00:00 2001 From: wizjany Date: Fri, 2 Aug 2013 22:55:38 -0400 Subject: [PATCH] Support for listing in expand, contract, and shift. Support listing in these commands by replacing a single Vector with a List and then iterating through it in a foreach loop. Region changes are still performed individually, no extra complicated math involved. --- .../worldedit/commands/SelectionCommands.java | 89 ++++++++++++++----- 1 file changed, 69 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java index 702b2e76c..5914ae29b 100644 --- a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java @@ -334,7 +334,7 @@ public class SelectionCommands { return; } - Vector dir; + List dirs = new ArrayList(); int change = args.getInteger(0); int reverseChange = 0; @@ -343,30 +343,49 @@ public class SelectionCommands { // Either a reverse amount or a direction try { reverseChange = args.getInteger(1); - dir = we.getDirection(player, "me"); + dirs.add(we.getDirection(player, "me")); } catch (NumberFormatException e) { - dir = we.getDirection(player, - args.getString(1).toLowerCase()); + if (args.getString(1).contains(",")) { + String[] split = args.getString(1).split(","); + for (String s : split) { + dirs.add(we.getDirection(player, s.toLowerCase())); + } + } else { + dirs.add(we.getDirection(player, args.getString(1).toLowerCase())); + } } break; case 3: // Both reverse amount and direction reverseChange = args.getInteger(1); - dir = we.getDirection(player, - args.getString(2).toLowerCase()); + if (args.getString(2).contains(",")) { + String[] split = args.getString(2).split(","); + for (String s : split) { + dirs.add(we.getDirection(player, s.toLowerCase())); + } + } else { + dirs.add(we.getDirection(player, args.getString(2).toLowerCase())); + } break; + default: - dir = we.getDirection(player, "me"); + dirs.add(we.getDirection(player, "me")); + break; + } Region region = session.getSelection(player.getWorld()); int oldSize = region.getArea(); if (reverseChange == 0) { - region.expand(dir.multiply(change)); + for (Vector dir : dirs) { + region.expand(dir.multiply(change)); + } } else { - region.expand(dir.multiply(change), dir.multiply(-reverseChange)); + for (Vector dir : dirs) { + region.expand(dir.multiply(change), dir.multiply(-reverseChange)); + } } session.getRegionSelector(player.getWorld()).learnChanges(); @@ -389,7 +408,7 @@ public class SelectionCommands { public void contract(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - Vector dir; + List dirs = new ArrayList(); int change = args.getInteger(0); int reverseChange = 0; @@ -398,28 +417,48 @@ public class SelectionCommands { // Either a reverse amount or a direction try { reverseChange = args.getInteger(1); - dir = we.getDirection(player, "me"); + dirs.add(we.getDirection(player, "me")); } catch (NumberFormatException e) { - dir = we.getDirection(player, args.getString(1).toLowerCase()); + if (args.getString(1).contains(",")) { + String[] split = args.getString(1).split(","); + for (String s : split) { + dirs.add(we.getDirection(player, s.toLowerCase())); + } + } else { + dirs.add(we.getDirection(player, args.getString(1).toLowerCase())); + } } break; case 3: // Both reverse amount and direction reverseChange = args.getInteger(1); - dir = we.getDirection(player, args.getString(2).toLowerCase()); + if (args.getString(2).contains(",")) { + String[] split = args.getString(2).split(","); + for (String s : split) { + dirs.add(we.getDirection(player, s.toLowerCase())); + } + } else { + dirs.add(we.getDirection(player, args.getString(2).toLowerCase())); + } break; + default: - dir = we.getDirection(player, "me"); + dirs.add(we.getDirection(player, "me")); + break; } try { Region region = session.getSelection(player.getWorld()); int oldSize = region.getArea(); if (reverseChange == 0) { - region.contract(dir.multiply(change)); + for (Vector dir : dirs) { + region.contract(dir.multiply(change)); + } } else { - region.contract(dir.multiply(change), dir.multiply(-reverseChange)); + for (Vector dir : dirs) { + region.contract(dir.multiply(change), dir.multiply(-reverseChange)); + } } session.getRegionSelector(player.getWorld()).learnChanges(); int newSize = region.getArea(); @@ -444,18 +483,28 @@ public class SelectionCommands { @CommandPermissions("worldedit.selection.shift") public void shift(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - Vector dir; + List dirs = new ArrayList(); int change = args.getInteger(0); if (args.argsLength() == 2) { - dir = we.getDirection(player, args.getString(1).toLowerCase()); + if (args.getString(1).contains(",")) { + for (String s : args.getString(1).split(",")) { + dirs.add(we.getDirection(player, s.toLowerCase())); + } + } else { + dirs.add(we.getDirection(player, args.getString(1).toLowerCase())); + } } else { - dir = we.getDirection(player, "me"); + dirs.add(we.getDirection(player, "me")); } try { Region region = session.getSelection(player.getWorld()); - region.shift(dir.multiply(change)); + + for (Vector dir : dirs) { + region.shift(dir.multiply(change)); + } + session.getRegionSelector(player.getWorld()).learnChanges(); session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session);