Improve file extension fallback mechanism

This commit is contained in:
Brady 2019-12-18 15:19:58 -06:00
parent b4ddf38116
commit ea8d7fb3b9
No known key found for this signature in database
GPG Key ID: 73A788379A197567
3 changed files with 11 additions and 4 deletions

View File

@ -811,6 +811,12 @@ public final class Settings {
*/
public final Setting<Boolean> schematicOrientationZ = new Setting<>(false);
/**
* The fallback used by the build command when no extension is specified. This may be useful if schematics of a
* particular format are used often, and the user does not wish to have to specify the extension with every usage.
*/
public final Setting<String> schematicFallbackExtension = new Setting<>("schematic");
/**
* Distance to scan every tick for updates. Expanding this beyond player reach distance (i.e. setting it to 6 or above)
* is only necessary in very large schematics where rescanning the whole thing is costly.

View File

@ -17,6 +17,7 @@
package baritone.command.defaults;
import baritone.Baritone;
import baritone.api.IBaritone;
import baritone.api.utils.BetterBlockPos;
import baritone.api.command.Command;
@ -26,11 +27,11 @@ import baritone.api.command.exception.CommandException;
import baritone.api.command.exception.CommandInvalidStateException;
import baritone.api.command.argument.IArgConsumer;
import net.minecraft.client.Minecraft;
import org.apache.commons.io.FilenameUtils;
import java.io.File;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import java.util.stream.Stream;
public class BuildCommand extends Command {
@ -44,8 +45,8 @@ public class BuildCommand extends Command {
@Override
public void execute(String label, IArgConsumer args) throws CommandException {
File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile();
if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) {
file = new File(file.getAbsolutePath() + ".schematic");
if (FilenameUtils.getExtension(file.getAbsolutePath()).isEmpty()) {
file = new File(file.getAbsolutePath() + "." + Baritone.settings().schematicFallbackExtension);
}
BetterBlockPos origin = ctx.playerFeet();
BetterBlockPos buildOrigin;

View File

@ -65,6 +65,6 @@ public enum SchematicFormat {
public static Optional<SchematicFormat> getByExtension(String extension) {
return extension == null || extension.isEmpty()
? Optional.empty()
: Stream.of(values()).filter(format -> format.extension.equals(extension)).findFirst();
: Stream.of(values()).filter(format -> format.extension.equalsIgnoreCase(extension)).findFirst();
}
}