Improve file extension fallback mechanism
This commit is contained in:
@@ -811,6 +811,12 @@ public final class Settings {
|
|||||||
*/
|
*/
|
||||||
public final Setting<Boolean> schematicOrientationZ = new Setting<>(false);
|
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)
|
* 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.
|
* is only necessary in very large schematics where rescanning the whole thing is costly.
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
package baritone.command.defaults;
|
package baritone.command.defaults;
|
||||||
|
|
||||||
|
import baritone.Baritone;
|
||||||
import baritone.api.IBaritone;
|
import baritone.api.IBaritone;
|
||||||
import baritone.api.utils.BetterBlockPos;
|
import baritone.api.utils.BetterBlockPos;
|
||||||
import baritone.api.command.Command;
|
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.exception.CommandInvalidStateException;
|
||||||
import baritone.api.command.argument.IArgConsumer;
|
import baritone.api.command.argument.IArgConsumer;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class BuildCommand extends Command {
|
public class BuildCommand extends Command {
|
||||||
@@ -44,8 +45,8 @@ public class BuildCommand extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public void execute(String label, IArgConsumer args) throws CommandException {
|
public void execute(String label, IArgConsumer args) throws CommandException {
|
||||||
File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile();
|
File file = args.getDatatypePost(RelativeFile.INSTANCE, schematicsDir).getAbsoluteFile();
|
||||||
if (!file.getName().toLowerCase(Locale.US).endsWith(".schematic")) {
|
if (FilenameUtils.getExtension(file.getAbsolutePath()).isEmpty()) {
|
||||||
file = new File(file.getAbsolutePath() + ".schematic");
|
file = new File(file.getAbsolutePath() + "." + Baritone.settings().schematicFallbackExtension);
|
||||||
}
|
}
|
||||||
BetterBlockPos origin = ctx.playerFeet();
|
BetterBlockPos origin = ctx.playerFeet();
|
||||||
BetterBlockPos buildOrigin;
|
BetterBlockPos buildOrigin;
|
||||||
|
@@ -65,6 +65,6 @@ public enum SchematicFormat {
|
|||||||
public static Optional<SchematicFormat> getByExtension(String extension) {
|
public static Optional<SchematicFormat> getByExtension(String extension) {
|
||||||
return extension == null || extension.isEmpty()
|
return extension == null || extension.isEmpty()
|
||||||
? Optional.empty()
|
? Optional.empty()
|
||||||
: Stream.of(values()).filter(format -> format.extension.equals(extension)).findFirst();
|
: Stream.of(values()).filter(format -> format.extension.equalsIgnoreCase(extension)).findFirst();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user