From 7b306160d7d7520618df5c6bb59c65efe2b0b6c8 Mon Sep 17 00:00:00 2001 From: masteroftime Date: Wed, 10 Aug 2011 22:56:45 +0200 Subject: [PATCH] Added optional position parameter to //pos1 and //pos2 --- .../worldedit/commands/SelectionCommands.java | 53 ++++++++++++++++--- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java index e6a98d60e..892858b56 100644 --- a/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/SelectionCommands.java @@ -41,47 +41,84 @@ import com.sk89q.worldedit.blocks.*; public class SelectionCommands { @Command( aliases = {"/pos1"}, - usage = "", + usage = "[coordinates]", desc = "Set position 1", min = 0, - max = 0 + max = 1 ) @CommandPermissions({"worldedit.selection.pos"}) public static void pos1(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { + + Vector pos; + + if(args.argsLength() == 1) + { + if(args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) + { + String[] coords = args.getString(0).split(","); + pos = new Vector(Integer.parseInt(coords[0]), + Integer.parseInt(coords[1]), + Integer.parseInt(coords[2])); + } + else + { + player.printError("Invalid coordinates " + args.getString(0)); + return; + } + } + else pos = player.getBlockIn(); if (!session.getRegionSelector(player.getWorld()) - .selectPrimary(player.getBlockIn())) { + .selectPrimary(pos)) { player.printError("Position already set."); return; } session.getRegionSelector(player.getWorld()) - .explainPrimarySelection(player, session, player.getBlockIn()); + .explainPrimarySelection(player, session, pos); } @Command( aliases = {"/pos2"}, - usage = "", + usage = "[coordinates]", desc = "Set position 2", min = 0, - max = 0 + max = 2 ) @CommandPermissions({"worldedit.selection.pos"}) public static void pos2(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { + + Vector pos; + if(args.argsLength() == 1) + { + if(args.getString(0).matches("-?\\d+,-?\\d+,-?\\d+")) + { + String[] coords = args.getString(0).split(","); + pos = new Vector(Integer.parseInt(coords[0]), + Integer.parseInt(coords[1]), + Integer.parseInt(coords[2])); + } + else + { + player.printError("Invalid coordinates " + args.getString(0)); + return; + } + } + else pos = player.getBlockIn(); if (!session.getRegionSelector(player.getWorld()) - .selectSecondary(player.getBlockIn())) { + .selectSecondary(pos)) { player.printError("Position already set."); return; } session.getRegionSelector(player.getWorld()) - .explainSecondarySelection(player, session, player.getBlockIn()); + .explainSecondarySelection(player, session, pos); } @Command(