Improve file extension fallback mechanism
This commit is contained in:
parent
b4ddf38116
commit
ea8d7fb3b9
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user