Merge pull request #953 from 0-x-2-2/commands

Removed very angry code. Started feeding Codacy.
This commit is contained in:
Leijurv 2019-09-19 16:30:42 -07:00 committed by GitHub
commit 5d9209ce80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 21 additions and 17 deletions

View File

@ -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;
/**

View File

@ -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;

View File

@ -106,7 +106,7 @@ public class BaritoneChatControl implements Helper, AbstractGameEventListener {
return false;
}
if (msg.isEmpty()) {
msg = "help";
return this.runCommand("help");
}
Pair<String, List<CommandArgument>> pair = CommandExecution.expand(msg);
String command = pair.first();

View File

@ -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");
}
}
}

View File

@ -76,7 +76,7 @@ public class ForWaypoints implements IDatatypeFor<IWaypoint[]> {
public static String[] getWaypointNames() {
return Arrays.stream(getWaypoints())
.map(IWaypoint::getName)
.filter(name -> !name.equals(""))
.filter(name -> !"".equals(name))
.toArray(String[]::new);
}

View File

@ -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<File, File> {
*
* @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<String> 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<File, File> {
@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() {

View File

@ -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<>();

View File

@ -34,7 +34,6 @@ public class EmptyCommand extends Command {
@Override
protected void executed(String label, ArgConsumer args, Settings settings) {
;
}
@Override

View File

@ -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)));
}

View File

@ -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;

View File

@ -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) {