[FEATURE] Support mittot/generate option in downloadClient

This commit is contained in:
Gravita 2021-05-07 20:19:02 +07:00
parent 21a203356f
commit afe3dd543e

View file

@ -29,7 +29,7 @@ public DownloadClientCommand(LaunchServer server) {
@Override @Override
public String getArgsDescription() { public String getArgsDescription() {
return "[version] [dir]"; return "[version] [dir] (mirror/generate)";
} }
@Override @Override
@ -45,6 +45,11 @@ public void invoke(String... args) throws IOException, CommandException {
String dirName = IOHelper.verifyFileName(args[1]); String dirName = IOHelper.verifyFileName(args[1]);
Path clientDir = server.updatesDir.resolve(args[1]); Path clientDir = server.updatesDir.resolve(args[1]);
boolean isMirrorClientDownload = false;
if(args.length > 2) {
isMirrorClientDownload = args[2].equals("mirror");
}
// Create client dir // Create client dir
logger.info("Creating client dir: '{}'", dirName); logger.info("Creating client dir: '{}'", dirName);
Files.createDirectory(clientDir); Files.createDirectory(clientDir);
@ -56,14 +61,21 @@ public void invoke(String... args) throws IOException, CommandException {
// Create profile file // Create profile file
logger.info("Creaing profile file: '{}'", dirName); logger.info("Creaing profile file: '{}'", dirName);
ClientProfile client; ClientProfile client = null;
try { try {
ClientProfile.Version version = ClientProfile.Version.byName(versionName); String internalVersion = versionName;
if(internalVersion.contains("-")) {
internalVersion = internalVersion.substring(0, versionName.indexOf('-'));
}
ClientProfile.Version version = ClientProfile.Version.byName(internalVersion);
if(version.compareTo(ClientProfile.Version.MC164) <= 0) { if(version.compareTo(ClientProfile.Version.MC164) <= 0) {
logger.warn("Minecraft 1.6.4 and below not supported. Use at your own risk"); logger.warn("Minecraft 1.6.4 and below not supported. Use at your own risk");
} }
client = SaveProfilesCommand.makeProfile(version, dirName, SaveProfilesCommand.getMakeProfileOptionsFromDir(clientDir, version)); client = SaveProfilesCommand.makeProfile(version, dirName, SaveProfilesCommand.getMakeProfileOptionsFromDir(clientDir, version));
} catch (Throwable e) { } catch (Throwable e) {
isMirrorClientDownload = true;
}
if(isMirrorClientDownload) {
JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName); JsonElement clientJson = server.mirrorManager.jsonRequest(null, "GET", "clients/%s.json", versionName);
client = Launcher.gsonManager.configGson.fromJson(clientJson, ClientProfile.class); client = Launcher.gsonManager.configGson.fromJson(clientJson, ClientProfile.class);
client.setTitle(dirName); client.setTitle(dirName);