From 82ba96bf71e2573db2b41cb30c56c3f9c15b6d8a Mon Sep 17 00:00:00 2001 From: dordsor21 Date: Sun, 24 Apr 2022 00:11:57 +0100 Subject: [PATCH] Add constraints to //asc and //desc --- .../com/sk89q/worldedit/command/NavigationCommands.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java b/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java index 22e8a12ec..d6b02af3b 100644 --- a/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java +++ b/worldedit-core/src/main/java/com/sk89q/worldedit/command/NavigationCommands.java @@ -29,11 +29,13 @@ import com.sk89q.worldedit.command.util.Logging; import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.formatting.text.TextComponent; +import com.sk89q.worldedit.world.World; import org.enginehub.piston.annotation.Command; import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Switch; +import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION; @@ -77,6 +79,8 @@ public class NavigationCommands { @Arg(desc = "# of levels to ascend", def = "1") int levels ) throws WorldEditException { + World world = player.getWorld(); + checkArgument(levels >= 1 && levels <= (world.getMaxY() - world.getMinY()), "1 <= levels <= world height"); int ascentLevels = 0; while (player.ascendLevel()) { ++ascentLevels; @@ -102,6 +106,8 @@ public class NavigationCommands { @Arg(desc = "# of levels to descend", def = "1") int levels ) throws WorldEditException { + World world = player.getWorld(); + checkArgument(levels >= 1 && levels <= (world.getMaxY() - world.getMinY()), "1 <= levels <= world height"); int descentLevels = 0; while (player.descendLevel()) { ++descentLevels;