Conditionally add DH import command

This commit is contained in:
mcrcortex
2025-04-18 20:51:54 +10:00
parent 432d078212
commit 3b2614631d
3 changed files with 43 additions and 26 deletions

View File

@@ -25,32 +25,37 @@ import java.util.concurrent.CompletableFuture;
public class VoxyCommands {
public static LiteralArgumentBuilder<FabricClientCommandSource> register() {
var imports = ClientCommandManager.literal("import")
.then(ClientCommandManager.literal("world")
.then(ClientCommandManager.argument("world_name", StringArgumentType.string())
.suggests(VoxyCommands::importWorldSuggester)
.executes(VoxyCommands::importWorld)))
.then(ClientCommandManager.literal("bobby")
.then(ClientCommandManager.argument("world_name", StringArgumentType.string())
.suggests(VoxyCommands::importBobbySuggester)
.executes(VoxyCommands::importBobby)))
.then(ClientCommandManager.literal("raw")
.then(ClientCommandManager.argument("path", StringArgumentType.string())
.executes(VoxyCommands::importRaw)))
.then(ClientCommandManager.literal("zip")
.then(ClientCommandManager.argument("zipPath", StringArgumentType.string())
.executes(VoxyCommands::importZip)
.then(ClientCommandManager.argument("innerPath", StringArgumentType.string())
.executes(VoxyCommands::importZip))))
.then(ClientCommandManager.literal("cancel")
.executes(VoxyCommands::cancelImport));
if (DHImporter.HasRequiredLibraries) {
imports = imports
.then(ClientCommandManager.literal("distant_horizons")
.then(ClientCommandManager.argument("sqlDbPath", StringArgumentType.string())
.executes(VoxyCommands::importDistantHorizons)));
}
return ClientCommandManager.literal("voxy").requires((ctx)-> VoxyCommon.getInstance() != null)
.then(ClientCommandManager.literal("reload")
.executes(VoxyCommands::reloadInstance))
.then(ClientCommandManager.literal("import")
.then(ClientCommandManager.literal("world")
.then(ClientCommandManager.argument("world_name", StringArgumentType.string())
.suggests(VoxyCommands::importWorldSuggester)
.executes(VoxyCommands::importWorld)))
.then(ClientCommandManager.literal("bobby")
.then(ClientCommandManager.argument("world_name", StringArgumentType.string())
.suggests(VoxyCommands::importBobbySuggester)
.executes(VoxyCommands::importBobby)))
.then(ClientCommandManager.literal("raw")
.then(ClientCommandManager.argument("path", StringArgumentType.string())
.executes(VoxyCommands::importRaw)))
.then(ClientCommandManager.literal("zip")
.then(ClientCommandManager.argument("zipPath", StringArgumentType.string())
.executes(VoxyCommands::importZip)
.then(ClientCommandManager.argument("innerPath", StringArgumentType.string())
.executes(VoxyCommands::importZip))))
.then(ClientCommandManager.literal("distant_horizons")
.then(ClientCommandManager.argument("sqlDbPath", StringArgumentType.string())
.executes(VoxyCommands::importDistantHorizons)))
.then(ClientCommandManager.literal("cancel")
.executes(VoxyCommands::cancelImport))
);
.then(imports);
}
private static int reloadInstance(CommandContext<FabricClientCommandSource> ctx) {

View File

@@ -376,13 +376,20 @@ public class DHImporter implements IDataImporter {
private static VarHandle create(Class<?> viewArrayClass) {
return MethodHandles.byteArrayViewVarHandle(viewArrayClass, ByteOrder.BIG_ENDIAN);
}
public static final boolean HasRequiredLibraries;
private static final VarHandle LONG = create(long[].class);
static {
boolean hasJDBC = false;
try {
Class.forName("org.sqlite.JDBC");
hasJDBC = true;
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
//throw new RuntimeException(e);
Logger.error("Unable to load sqlite JDBC, DHImporting wont be available", e);
}
HasRequiredLibraries = hasJDBC;
}
}