Fix some horrendous code where methods supposed to return a boolean only ever return true (#1718)

This commit is contained in:
Jordan 2022-04-24 17:03:40 +01:00 committed by GitHub
parent 82ba96bf71
commit e294245ec4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 24 deletions

View File

@ -70,56 +70,56 @@ public class LocationMaskedPlayerWrapper extends AsyncPlayer {
@Override @Override
public boolean ascendLevel() { public boolean ascendLevel() {
if (allowTeleport) { if (allowTeleport && super.ascendLevel()) {
super.ascendLevel();
update(); update();
return true;
} }
return true; return false;
} }
@Override @Override
public boolean descendLevel() { public boolean descendLevel() {
if (allowTeleport) { if (allowTeleport && super.descendLevel()) {
super.descendLevel();
update(); update();
return true;
} }
return true; return false;
} }
@Override @Override
public boolean ascendToCeiling(int clearance) { public boolean ascendToCeiling(int clearance) {
if (allowTeleport) { if (allowTeleport && super.ascendToCeiling(clearance)) {
super.ascendToCeiling(clearance);
update(); update();
return true;
} }
return true; return false;
} }
@Override @Override
public boolean ascendToCeiling(int clearance, boolean alwaysGlass) { public boolean ascendToCeiling(int clearance, boolean alwaysGlass) {
if (allowTeleport) { if (allowTeleport && super.ascendToCeiling(clearance, alwaysGlass)) {
super.ascendToCeiling(clearance, alwaysGlass);
update(); update();
return true;
} }
return true; return false;
} }
@Override @Override
public boolean ascendUpwards(int distance) { public boolean ascendUpwards(int distance) {
if (allowTeleport) { if (allowTeleport && super.ascendUpwards(distance)) {
super.ascendUpwards(distance);
update(); update();
return true;
} }
return true; return false;
} }
@Override @Override
public boolean ascendUpwards(int distance, boolean alwaysGlass) { public boolean ascendUpwards(int distance, boolean alwaysGlass) {
if (allowTeleport) { if (allowTeleport && super.ascendUpwards(distance, alwaysGlass)) {
super.ascendUpwards(distance, alwaysGlass);
update(); update();
return true;
} }
return true; return false;
} }
@Override @Override

View File

@ -29,13 +29,11 @@ import com.sk89q.worldedit.command.util.Logging;
import com.sk89q.worldedit.entity.Player; import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.util.Location; import com.sk89q.worldedit.util.Location;
import com.sk89q.worldedit.util.formatting.text.TextComponent; 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.Command;
import org.enginehub.piston.annotation.CommandContainer; import org.enginehub.piston.annotation.CommandContainer;
import org.enginehub.piston.annotation.param.Arg; import org.enginehub.piston.annotation.param.Arg;
import org.enginehub.piston.annotation.param.Switch; 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.google.common.base.Preconditions.checkNotNull;
import static com.sk89q.worldedit.command.util.Logging.LogMode.POSITION; 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") @Arg(desc = "# of levels to ascend", def = "1")
int levels int levels
) throws WorldEditException { ) throws WorldEditException {
World world = player.getWorld();
checkArgument(levels >= 1 && levels <= (world.getMaxY() - world.getMinY()), "1 <= levels <= world height");
int ascentLevels = 0; int ascentLevels = 0;
while (player.ascendLevel()) { while (player.ascendLevel()) {
++ascentLevels; ++ascentLevels;
@ -106,8 +102,6 @@ public class NavigationCommands {
@Arg(desc = "# of levels to descend", def = "1") @Arg(desc = "# of levels to descend", def = "1")
int levels int levels
) throws WorldEditException { ) throws WorldEditException {
World world = player.getWorld();
checkArgument(levels >= 1 && levels <= (world.getMaxY() - world.getMinY()), "1 <= levels <= world height");
int descentLevels = 0; int descentLevels = 0;
while (player.descendLevel()) { while (player.descendLevel()) {
++descentLevels; ++descentLevels;