From e294245ec41000b1058904816b9a7b3d7cb19561 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 24 Apr 2022 17:03:40 +0100 Subject: [PATCH] Fix some horrendous code where methods supposed to return a boolean only ever return true (#1718) --- .../wrappers/LocationMaskedPlayerWrapper.java | 36 +++++++++---------- .../worldedit/command/NavigationCommands.java | 6 ---- 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/LocationMaskedPlayerWrapper.java b/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/LocationMaskedPlayerWrapper.java index a92f7514c..1e7d568ac 100644 --- a/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/LocationMaskedPlayerWrapper.java +++ b/worldedit-core/src/main/java/com/fastasyncworldedit/core/wrappers/LocationMaskedPlayerWrapper.java @@ -70,56 +70,56 @@ public class LocationMaskedPlayerWrapper extends AsyncPlayer { @Override public boolean ascendLevel() { - if (allowTeleport) { - super.ascendLevel(); + if (allowTeleport && super.ascendLevel()) { update(); + return true; } - return true; + return false; } @Override public boolean descendLevel() { - if (allowTeleport) { - super.descendLevel(); + if (allowTeleport && super.descendLevel()) { update(); + return true; } - return true; + return false; } @Override public boolean ascendToCeiling(int clearance) { - if (allowTeleport) { - super.ascendToCeiling(clearance); + if (allowTeleport && super.ascendToCeiling(clearance)) { update(); + return true; } - return true; + return false; } @Override public boolean ascendToCeiling(int clearance, boolean alwaysGlass) { - if (allowTeleport) { - super.ascendToCeiling(clearance, alwaysGlass); + if (allowTeleport && super.ascendToCeiling(clearance, alwaysGlass)) { update(); + return true; } - return true; + return false; } @Override public boolean ascendUpwards(int distance) { - if (allowTeleport) { - super.ascendUpwards(distance); + if (allowTeleport && super.ascendUpwards(distance)) { update(); + return true; } - return true; + return false; } @Override public boolean ascendUpwards(int distance, boolean alwaysGlass) { - if (allowTeleport) { - super.ascendUpwards(distance, alwaysGlass); + if (allowTeleport && super.ascendUpwards(distance, alwaysGlass)) { update(); + return true; } - return true; + return false; } @Override 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 d6b02af3b..22e8a12ec 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,13 +29,11 @@ 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; @@ -79,8 +77,6 @@ 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; @@ -106,8 +102,6 @@ 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;