/
Main.java
73 lines (65 loc) · 2.75 KB
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package jmccc.cli;
import jmccc.cli.download.CliDownloader;
import jmccc.cli.download.ModLoaderDownloader;
import jmccc.cli.launch.CliLauncher;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.to2mbn.jmccc.option.MinecraftDirectory;
import org.to2mbn.jmccc.version.Version;
import java.util.concurrent.ExecutionException;
public class Main {
/**
* Arguments:
* [--player player_name] [--dir minecraft_directory] [version]
*/
public static void main(String... args) throws Exception {
//Parse args
OptionParser parser = new OptionParser();
OptionSpec<String> playerOption = parser.accepts("player").withOptionalArg().defaultsTo("Player");
OptionSpec<String> dirOption = parser.accepts("dir").withOptionalArg().defaultsTo(".minecraft");
OptionSpec<String> versionOption = parser.nonOptions();
OptionSet options = parser.parse(args);
String player = playerOption.value(options);
String dir = dirOption.value(options);
String version = versionOption.value(options);
MinecraftDirectory minecraftDirectory = new MinecraftDirectory(dir);
//Check special version
version = parseVersion(version);
System.out.println("Version: " + version);
//Download game if not exist
if (!minecraftDirectory.getVersionJson(version).exists()) {
Version v = CliDownloader.download(minecraftDirectory, version);
version = v.getVersion();
}
//Launch game
CliLauncher.launch(minecraftDirectory, version, player);
}
private static String parseVersion(String version) throws ExecutionException, InterruptedException {
if (version == null) {
version = "release";
}
switch (version) {
case "latest":
case "stable":
case "release":
return CliDownloader.getLatestRelease();
case "snapshot":
return CliDownloader.getLatestSnapshot();
case "forge":
return ModLoaderDownloader.getLatestForge().getVersionName();
case "liteloader":
return ModLoaderDownloader.getLatestLiteLoader().getVersionName();
case "fabric":
return ModLoaderDownloader.getLatestFabric().getVersionName();
case "fabric-snapshot":
return ModLoaderDownloader.getLatestFabricSnapshot().getVersionName();
case "quilt":
return ModLoaderDownloader.getLatestQuilt().getVersionName();
case "quilt-snapshot":
return ModLoaderDownloader.getLatestQuiltSnapshot().getVersionName();
default:
return version;
}
}
}