From 760f77e6811fd6b4d4983a667b524475b3cb8266 Mon Sep 17 00:00:00 2001 From: aumgn Date: Tue, 13 Mar 2012 10:02:00 +0100 Subject: [PATCH] Make inset/outset use varargs contract/expand, so they can be used with cylinders and ellipses. --- .../worldedit/commands/SelectionCommands.java | 58 +++++++------------ 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java index 03cc81a6e..d97e8ceaa 100644 --- a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java @@ -19,6 +19,7 @@ package com.sk89q.worldedit.commands; +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.logging.Logger; @@ -438,31 +439,11 @@ public class SelectionCommands { @CommandPermissions("worldedit.selection.outset") public void outset(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - int change = args.getInteger(0); - Region region = session.getSelection(player.getWorld()); - - try { - if (!args.hasFlag('h')) { - region.expand((new Vector(0, 1, 0)).multiply(change)); - region.expand((new Vector(0, -1, 0)).multiply(change)); - } - - if (!args.hasFlag('v')) { - region.expand((new Vector(1, 0, 0)).multiply(change)); - region.expand((new Vector(-1, 0, 0)).multiply(change)); - region.expand((new Vector(0, 0, 1)).multiply(change)); - region.expand((new Vector(0, 0, -1)).multiply(change)); - } - - session.getRegionSelector(player.getWorld()).learnChanges(); - - session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); - - player.print("Region outset."); - } catch (RegionOperationException e) { - player.printError(e.getMessage()); - } + region.expand(getChangesForEachDir(args)); + session.getRegionSelector(player.getWorld()).learnChanges(); + session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); + player.print("Region outset."); } @Command( @@ -481,27 +462,30 @@ public class SelectionCommands { @CommandPermissions("worldedit.selection.inset") public void inset(CommandContext args, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { + Region region = session.getSelection(player.getWorld()); + region.contract(getChangesForEachDir(args)); + session.getRegionSelector(player.getWorld()).learnChanges(); + session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); + player.print("Region inset."); + } + + private Vector[] getChangesForEachDir(CommandContext args) { + List changes = new ArrayList(6); int change = args.getInteger(0); - Region region = session.getSelection(player.getWorld()); - if (!args.hasFlag('h')) { - region.contract((new Vector(0, 1, 0)).multiply(change)); - region.contract((new Vector(0, -1, 0)).multiply(change)); + changes.add((new Vector(0, 1, 0)).multiply(change)); + changes.add((new Vector(0, -1, 0)).multiply(change)); } if (!args.hasFlag('v')) { - region.contract((new Vector(1, 0, 0)).multiply(change)); - region.contract((new Vector(-1, 0, 0)).multiply(change)); - region.contract((new Vector(0, 0, 1)).multiply(change)); - region.contract((new Vector(0, 0, -1)).multiply(change)); + changes.add((new Vector(1, 0, 0)).multiply(change)); + changes.add((new Vector(-1, 0, 0)).multiply(change)); + changes.add((new Vector(0, 0, 1)).multiply(change)); + changes.add((new Vector(0, 0, -1)).multiply(change)); } - session.getRegionSelector(player.getWorld()).learnChanges(); - - session.getRegionSelector(player.getWorld()).explainRegionAdjust(player, session); - - player.print("Region inset."); + return changes.toArray(new Vector[0]); } @Command(