From 6f2529c2431702ab4f49529adad1ffc77f61d6d0 Mon Sep 17 00:00:00 2001 From: 0x22 <0x22@futureclient.net> Date: Thu, 19 Sep 2019 18:54:24 -0400 Subject: [PATCH] Removed very angry code. Started feeding Codacy. --- src/api/java/baritone/api/Settings.java | 2 +- src/api/java/baritone/api/utils/BlockUtils.java | 2 +- .../api/utils/command/BaritoneChatControl.java | 2 +- .../utils/command/argparser/DefaultArgParsers.java | 6 +++--- .../api/utils/command/datatypes/ForWaypoints.java | 2 +- .../api/utils/command/datatypes/RelativeFile.java | 13 +++++++------ src/main/java/baritone/process/MineProcess.java | 3 ++- .../utils/command/defaults/EmptyCommand.java | 1 - .../command/defaults/ExploreFilterCommand.java | 2 +- .../baritone/utils/command/defaults/SelCommand.java | 2 +- .../utils/command/defaults/WaypointsCommand.java | 3 +++ 11 files changed, 21 insertions(+), 17 deletions(-) diff --git a/src/api/java/baritone/api/Settings.java b/src/api/java/baritone/api/Settings.java index 9a03fac2..8d54cbde 100644 --- a/src/api/java/baritone/api/Settings.java +++ b/src/api/java/baritone/api/Settings.java @@ -30,8 +30,8 @@ import java.awt.*; import java.lang.reflect.Field; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.util.*; import java.util.List; +import java.util.*; import java.util.function.Consumer; /** diff --git a/src/api/java/baritone/api/utils/BlockUtils.java b/src/api/java/baritone/api/utils/BlockUtils.java index 8fad35f8..43a97f83 100644 --- a/src/api/java/baritone/api/utils/BlockUtils.java +++ b/src/api/java/baritone/api/utils/BlockUtils.java @@ -41,7 +41,7 @@ public class BlockUtils { Block block = stringToBlockNullable(name); if (block == null) { - throw new NullPointerException(String.format("Invalid block name %s", name)); + throw new IllegalArgumentException(String.format("Invalid block name %s", name)); } return block; diff --git a/src/api/java/baritone/api/utils/command/BaritoneChatControl.java b/src/api/java/baritone/api/utils/command/BaritoneChatControl.java index 0c6fc5fd..84b6f927 100644 --- a/src/api/java/baritone/api/utils/command/BaritoneChatControl.java +++ b/src/api/java/baritone/api/utils/command/BaritoneChatControl.java @@ -106,7 +106,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener { return false; } if (msg.isEmpty()) { - msg = "help"; + return this.runCommand("help"); } Pair> pair = CommandExecution.expand(msg); String command = pair.first(); diff --git a/src/api/java/baritone/api/utils/command/argparser/DefaultArgParsers.java b/src/api/java/baritone/api/utils/command/argparser/DefaultArgParsers.java index f45f7faf..6e7e70bc 100644 --- a/src/api/java/baritone/api/utils/command/argparser/DefaultArgParsers.java +++ b/src/api/java/baritone/api/utils/command/argparser/DefaultArgParsers.java @@ -65,7 +65,7 @@ public class DefaultArgParsers { public Float parseArg(CommandArgument arg) throws RuntimeException { String value = arg.value; if (!value.matches("^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)|)$")) { - throw new RuntimeException("failed float format check"); + throw new IllegalArgumentException("failed float format check"); } return Float.parseFloat(value); } @@ -83,7 +83,7 @@ public class DefaultArgParsers { public Double parseArg(CommandArgument arg) throws RuntimeException { String value = arg.value; if (!value.matches("^([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)|)$")) { - throw new RuntimeException("failed double format check"); + throw new IllegalArgumentException("failed double format check"); } return Double.parseDouble(value); } @@ -107,7 +107,7 @@ public class DefaultArgParsers { } else if (FALSY_VALUES.contains(value.toLowerCase(Locale.US))) { return false; } else { - throw new RuntimeException("invalid boolean"); + throw new IllegalArgumentException("invalid boolean"); } } } diff --git a/src/api/java/baritone/api/utils/command/datatypes/ForWaypoints.java b/src/api/java/baritone/api/utils/command/datatypes/ForWaypoints.java index 6aef2187..53ee8837 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/ForWaypoints.java +++ b/src/api/java/baritone/api/utils/command/datatypes/ForWaypoints.java @@ -76,7 +76,7 @@ public class ForWaypoints implements IDatatypeFor { public static String[] getWaypointNames() { return Arrays.stream(getWaypoints()) .map(IWaypoint::getName) - .filter(name -> !name.equals("")) + .filter(name -> !"".equals(name)) .toArray(String[]::new); } diff --git a/src/api/java/baritone/api/utils/command/datatypes/RelativeFile.java b/src/api/java/baritone/api/utils/command/datatypes/RelativeFile.java index f67e4fab..c3d5479f 100644 --- a/src/api/java/baritone/api/utils/command/datatypes/RelativeFile.java +++ b/src/api/java/baritone/api/utils/command/datatypes/RelativeFile.java @@ -21,6 +21,7 @@ import baritone.api.utils.command.helpers.arguments.ArgConsumer; import java.io.File; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.FileSystems; import java.nio.file.InvalidPathException; import java.nio.file.Path; @@ -57,26 +58,26 @@ public class RelativeFile implements IDatatypePost { * * @param file File * @return Canonical file of file - * @author LoganDark and his hate of checked exceptions + * @author LoganDark */ - private static File SHUT_THE_FUCK_UP_IOEXCEPTION_NOBODY_LIKES_YOU(File file) { + private static File getCanonicalFileUnchecked(File file) { try { return file.getCanonicalFile(); } catch (IOException e) { - throw new RuntimeException("Fuck you", e); + throw new UncheckedIOException(e); } } public static Stream tabComplete(ArgConsumer consumer, File base0) { // I will not make the caller deal with this, seriously // Tab complete code is beautiful and I'm not going to bloat it with dumb ass checked exception bullshit - File base = SHUT_THE_FUCK_UP_IOEXCEPTION_NOBODY_LIKES_YOU(base0); + File base = getCanonicalFileUnchecked(base0); String currentPathStringThing = consumer.getString(); Path currentPath = FileSystems.getDefault().getPath(currentPathStringThing); Path basePath = currentPath.isAbsolute() ? currentPath.getRoot() : base.toPath(); boolean useParent = !currentPathStringThing.isEmpty() && !currentPathStringThing.endsWith(File.separator); File currentFile = currentPath.isAbsolute() ? currentPath.toFile() : new File(base, currentPathStringThing); - return Arrays.stream(Objects.requireNonNull(SHUT_THE_FUCK_UP_IOEXCEPTION_NOBODY_LIKES_YOU( + return Arrays.stream(Objects.requireNonNull(getCanonicalFileUnchecked( useParent ? currentFile.getParentFile() : currentFile @@ -89,7 +90,7 @@ public class RelativeFile implements IDatatypePost { @Override public File apply(File original) { - return SHUT_THE_FUCK_UP_IOEXCEPTION_NOBODY_LIKES_YOU(original.toPath().resolve(path).toFile()); + return getCanonicalFileUnchecked(original.toPath().resolve(path).toFile()); } public static File gameDir() { diff --git a/src/main/java/baritone/process/MineProcess.java b/src/main/java/baritone/process/MineProcess.java index a2e1f120..4043e627 100644 --- a/src/main/java/baritone/process/MineProcess.java +++ b/src/main/java/baritone/process/MineProcess.java @@ -408,7 +408,8 @@ public final class MineProcess extends BaritoneProcessHelper implements IMinePro this.filter = filter; if (filter != null && !Baritone.settings().allowBreak.value) { logDirect("Unable to mine when allowBreak is false!"); - filter = null; + this.mine(quantity, (BlockOptionalMetaLookup) null); + return; } this.desiredQuantity = quantity; this.knownOreLocations = new ArrayList<>(); diff --git a/src/main/java/baritone/utils/command/defaults/EmptyCommand.java b/src/main/java/baritone/utils/command/defaults/EmptyCommand.java index e673c0d2..c36bd044 100644 --- a/src/main/java/baritone/utils/command/defaults/EmptyCommand.java +++ b/src/main/java/baritone/utils/command/defaults/EmptyCommand.java @@ -34,7 +34,6 @@ public class EmptyCommand extends Command { @Override protected void executed(String label, ArgConsumer args, Settings settings) { - ; } @Override diff --git a/src/main/java/baritone/utils/command/defaults/ExploreFilterCommand.java b/src/main/java/baritone/utils/command/defaults/ExploreFilterCommand.java index 815dc8ac..cdbc0e8c 100644 --- a/src/main/java/baritone/utils/command/defaults/ExploreFilterCommand.java +++ b/src/main/java/baritone/utils/command/defaults/ExploreFilterCommand.java @@ -57,7 +57,7 @@ public class ExploreFilterCommand extends Command { } catch (JsonSyntaxException e) { throw new CommandInvalidStateException("Invalid JSON syntax"); } catch (Exception e) { - throw new RuntimeException(e); + throw new IllegalStateException(e); } logDirect(String.format("Explore filter applied. Inverted: %s", Boolean.toString(invert))); } diff --git a/src/main/java/baritone/utils/command/defaults/SelCommand.java b/src/main/java/baritone/utils/command/defaults/SelCommand.java index 25c3ffd8..dfa8e957 100644 --- a/src/main/java/baritone/utils/command/defaults/SelCommand.java +++ b/src/main/java/baritone/utils/command/defaults/SelCommand.java @@ -44,8 +44,8 @@ import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.Vec3i; import java.awt.*; -import java.util.*; import java.util.List; +import java.util.*; import java.util.function.Function; import java.util.stream.Stream; diff --git a/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java b/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java index 863c9754..c94d757d 100644 --- a/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java +++ b/src/main/java/baritone/utils/command/defaults/WaypointsCommand.java @@ -170,6 +170,9 @@ public class WaypointsCommand extends Command { throw new CommandInvalidStateException("No waypoints found"); case 1: waypoint = waypoints[0]; + break; + default: + break; } } if (waypoint == null) {