From fce942e130a2616af9840c58e5627bd8b23af3a0 Mon Sep 17 00:00:00 2001 From: Jeremy Koletar Date: Thu, 7 Jul 2011 10:35:20 -0500 Subject: [PATCH 1/4] Allow a command to be passed to /ascend and /descend which ascends/descends multiple floors. --- .../commands/NavigationCommands.java | 57 +++++++++++++++---- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java index 4dea41a0c..37054690a 100644 --- a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java @@ -48,39 +48,74 @@ public class NavigationCommands { @Command( aliases = {"ascend"}, - usage = "", + usage = "[# of levels]", desc = "Go up a floor", min = 0, - max = 0 + max = 1 ) @CommandPermissions({"worldedit.navigation.ascend"}) public static void ascend(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - - if (player.ascendLevel()) { - player.print("Ascended a level."); + if (args.argsLength() == 0) { + if (player.ascendLevel()) { + player.print("Ascended a level."); + } else { + player.printError("No free spot above you found."); + } } else { - player.printError("No free spot above you found."); + Boolean ascentDone = false; + int ascentLevels = 1; + int levelsToAscend = args.getInteger(0); + while (!ascentDone) { + if (player.ascendLevel() && levelsToAscend != ascentLevels) { + ascentLevels++; + } else { + ascentDone = true; + } + } + if (ascentLevels == 0) { + player.printError("No free spot above you found."); + } else { + player.print("Ascended " + Integer.toString(ascentLevels) + " levels."); + } } } @Command( aliases = {"descend"}, - usage = "", + usage = "[# of floors]", desc = "Go down a floor", min = 0, - max = 0 + max = 1 ) @CommandPermissions({"worldedit.navigation.descend"}) public static void descend(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - if (player.descendLevel()) { - player.print("Descended a level."); + if (args.argsLength() == 0) { + if (player.descendLevel()) { + player.print("Descended a level."); + } else { + player.printError("No free spot above you found."); + } } else { - player.printError("No free spot below you found."); + Boolean descentDone = false; + int descentLevels = 1; + int levelsToDescend = args.getInteger(0); + while (!descentDone) { + if (player.descendLevel() && levelsToDescend != descentLevels) { + descentLevels++; + } else { + descentDone = true; + } + } + if (descentLevels == 0) { + player.printError("No free spot above you found."); + } else { + player.print("Descended " + Integer.toString(descentLevels) + " levels."); + } } } From 6b9dbe349a7a9cff9e00f050ec2e027a227021b6 Mon Sep 17 00:00:00 2001 From: Jeremy Koletar Date: Thu, 7 Jul 2011 12:35:08 -0500 Subject: [PATCH 2/4] Changes tabs to spaces, also removed extra boolean. --- .../commands/NavigationCommands.java | 75 ++++++++----------- 1 file changed, 33 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java index 37054690a..525e2b9c9 100644 --- a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java @@ -57,28 +57,24 @@ public class NavigationCommands { public static void ascend(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - if (args.argsLength() == 0) { - if (player.ascendLevel()) { - player.print("Ascended a level."); - } else { - player.printError("No free spot above you found."); - } + if (args.argsLength() == 0) { + if (player.ascendLevel()) { + player.print("Ascended a level."); + } else { + player.printError("No free spot above you found."); + } } else { - Boolean ascentDone = false; - int ascentLevels = 1; - int levelsToAscend = args.getInteger(0); - while (!ascentDone) { - if (player.ascendLevel() && levelsToAscend != ascentLevels) { - ascentLevels++; - } else { - ascentDone = true; - } - } - if (ascentLevels == 0) { - player.printError("No free spot above you found."); - } else { - player.print("Ascended " + Integer.toString(ascentLevels) + " levels."); - } + Boolean ascentDone = false; + int ascentLevels = 1; + int levelsToAscend = args.getInteger(0); + while (player.ascendLevel() && levelsToAscend != ascentLevels) { + ascentLevels++; + } + if (ascentLevels == 0) { + player.printError("No free spot above you found."); + } else { + player.print("Ascended " + Integer.toString(ascentLevels) + " levels."); + } } } @@ -94,28 +90,23 @@ public class NavigationCommands { LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - if (args.argsLength() == 0) { - if (player.descendLevel()) { - player.print("Descended a level."); - } else { - player.printError("No free spot above you found."); - } + if (args.argsLength() == 0) { + if (player.descendLevel()) { + player.print("Descended a level."); + } else { + player.printError("No free spot above you found."); + } } else { - Boolean descentDone = false; - int descentLevels = 1; - int levelsToDescend = args.getInteger(0); - while (!descentDone) { - if (player.descendLevel() && levelsToDescend != descentLevels) { - descentLevels++; - } else { - descentDone = true; - } - } - if (descentLevels == 0) { - player.printError("No free spot above you found."); - } else { - player.print("Descended " + Integer.toString(descentLevels) + " levels."); - } + int descentLevels = 1; + int levelsToDescend = args.getInteger(0); + while (player.descendLevel() && levelsToDescend != descentLevels) { + descentLevels++; + } + if (descentLevels == 0) { + player.printError("No free spot above you found."); + } else { + player.print("Descended " + Integer.toString(descentLevels) + " levels."); + } } } From 77172236865ae124ae245a26dc02b01c281df4e0 Mon Sep 17 00:00:00 2001 From: Jeremy Koletar Date: Thu, 7 Jul 2011 14:05:03 -0500 Subject: [PATCH 3/4] Some code tidying. --- .../commands/NavigationCommands.java | 47 +++++++++---------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java index 525e2b9c9..0cef16aa3 100644 --- a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java @@ -57,26 +57,23 @@ public class NavigationCommands { public static void ascend(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - if (args.argsLength() == 0) { - if (player.ascendLevel()) { - player.print("Ascended a level."); + int levelsToAscend = 0; + if (args.argsLength() == 0) { + levelsToAscend = 1; } else { - player.printError("No free spot above you found."); + levelsToAscend = args.getInteger(0); } - } else { - Boolean ascentDone = false; int ascentLevels = 1; - int levelsToAscend = args.getInteger(0); while (player.ascendLevel() && levelsToAscend != ascentLevels) { ascentLevels++; } if (ascentLevels == 0) { player.printError("No free spot above you found."); } else { - player.print("Ascended " + Integer.toString(ascentLevels) + " levels."); + player.print((ascentLevels != 1) ? "Ascended " + Integer.toString(ascentLevels) + " levels." : "Ascended a level."); } + } - } @Command( aliases = {"descend"}, @@ -89,25 +86,23 @@ public class NavigationCommands { public static void descend(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - - if (args.argsLength() == 0) { - if (player.descendLevel()) { - player.print("Descended a level."); - } else { - player.printError("No free spot above you found."); - } + int levelsToDescend = 0; + if (args.argsLength() == 0) { + levelsToDescend = 1; } else { - int descentLevels = 1; - int levelsToDescend = args.getInteger(0); - while (player.descendLevel() && levelsToDescend != descentLevels) { - descentLevels++; - } - if (descentLevels == 0) { - player.printError("No free spot above you found."); - } else { - player.print("Descended " + Integer.toString(descentLevels) + " levels."); - } + levelsToDescend = args.getInteger(0); } + + int descentLevels = 1; + while (player.descendLevel() && levelsToDescend != descentLevels) { + descentLevels++; + } + if (descentLevels == 0) { + player.printError("No free spot above you found."); + } else { + player.print((descentLevels != 1) ? "Descended " + Integer.toString(descentLevels) + " levels." : "Descended a level."); + } + } @Command( From 4b65cf5beab9c1da9591e289a363cb31ecbf7ef3 Mon Sep 17 00:00:00 2001 From: Jeremy Koletar Date: Thu, 7 Jul 2011 14:25:21 -0500 Subject: [PATCH 4/4] Curse you indentation man! --- .../commands/NavigationCommands.java | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java index 0cef16aa3..0380fec89 100644 --- a/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java +++ b/src/main/java/com/sk89q/worldedit/commands/NavigationCommands.java @@ -57,23 +57,23 @@ public class NavigationCommands { public static void ascend(CommandContext args, WorldEdit we, LocalSession session, LocalPlayer player, EditSession editSession) throws WorldEditException { - int levelsToAscend = 0; - if (args.argsLength() == 0) { - levelsToAscend = 1; - } else { - levelsToAscend = args.getInteger(0); - } - int ascentLevels = 1; - while (player.ascendLevel() && levelsToAscend != ascentLevels) { - ascentLevels++; - } - if (ascentLevels == 0) { - player.printError("No free spot above you found."); - } else { - player.print((ascentLevels != 1) ? "Ascended " + Integer.toString(ascentLevels) + " levels." : "Ascended a level."); - } - + int levelsToAscend = 0; + if (args.argsLength() == 0) { + levelsToAscend = 1; + } else { + levelsToAscend = args.getInteger(0); } + int ascentLevels = 1; + while (player.ascendLevel() && levelsToAscend != ascentLevels) { + ascentLevels++; + } + if (ascentLevels == 0) { + player.printError("No free spot above you found."); + } else { + player.print((ascentLevels != 1) ? "Ascended " + Integer.toString(ascentLevels) + " levels." : "Ascended a level."); + } + + } @Command( aliases = {"descend"}, @@ -92,15 +92,14 @@ public class NavigationCommands { } else { levelsToDescend = args.getInteger(0); } - int descentLevels = 1; while (player.descendLevel() && levelsToDescend != descentLevels) { descentLevels++; } if (descentLevels == 0) { - player.printError("No free spot above you found."); + player.printError("No free spot above you found."); } else { - player.print((descentLevels != 1) ? "Descended " + Integer.toString(descentLevels) + " levels." : "Descended a level."); + player.print((descentLevels != 1) ? "Descended " + Integer.toString(descentLevels) + " levels." : "Descended a level."); } }