|
8 | 8 | import org.kettingpowered.launcher.utils.FileUtils;
|
9 | 9 |
|
10 | 10 | import java.io.*;
|
11 |
| -import java.util.ArrayList; |
12 |
| -import java.util.Arrays; |
13 |
| -import java.util.Comparator; |
14 |
| -import java.util.HashMap; |
15 |
| -import java.util.List; |
16 |
| -import java.util.Objects; |
| 11 | +import java.util.*; |
17 | 12 |
|
18 | 13 | /**
|
19 | 14 | * @author C0D3 M4513R
|
20 | 15 | */
|
21 | 16 | public class MCVersion {
|
22 | 17 | private static String mc;
|
23 |
| - public static String getMc(ParsedArgs args){ |
| 18 | + public static String getMc(ParsedArgs args, List<String> supportedMcVersions){ |
24 | 19 | if (mc != null) return mc;
|
25 | 20 |
|
26 | 21 | //Check for a mcversion.txt file, this has priority
|
@@ -88,16 +83,35 @@ public static String getMc(ParsedArgs args){
|
88 | 83 | System.out.println("There are multiple mapping configurations for multiple minecraft versions present in the libraries folder.");
|
89 | 84 | }
|
90 | 85 | }
|
91 |
| - //and now we are out of options. |
92 |
| - System.err.println(""" |
93 |
| - Could not determine the active server minecraft version. Please specify it, by specifying one of the following: |
94 |
| - - creating a file named 'mcversion.txt' with the desired minecraft version (e.g. 1.20.4). |
95 |
| - - the '--minecraftVersion' argument. E.g.: add ' --minecraftVersion 1.20.4 ' after the '-jar' argument |
96 |
| - - the java property 'kettinglauncher.minecraftVersion' E.g.: ' -Dkettinglauncher.minecraftVersion=1.20.4 ' before the '-jar' argument |
97 |
| - - the environment variable 'kettinglauncher_minecraftVersion' E.g. ' kettinglauncher_minecraftVersion=1.20.4 ' before the java executable. |
98 |
| - """); |
99 |
| - System.exit(1); |
100 |
| - throw new RuntimeException();//bogus, but has to be there to stop the compiler from complaining, that there is no return value here. |
| 86 | + //Ask for a version |
| 87 | + { |
| 88 | + System.out.println("Could not automatically determine the minecraft version."); |
| 89 | + System.out.println("Please enter the minecraft version you want to use"); |
| 90 | + System.out.println("The following versions are supported: " + String.join(", ", supportedMcVersions)); |
| 91 | + System.out.print("Minecraft version: "); |
| 92 | + |
| 93 | + int wrong = 0; |
| 94 | + |
| 95 | + Scanner console = new Scanner(System.in); |
| 96 | + while (true) { |
| 97 | + String answer = console.nextLine(); |
| 98 | + if (answer == null || answer.isBlank()) { |
| 99 | + if (wrong++ >= 2) { |
| 100 | + System.err.println("You have typed the wrong answer too many times. Exiting."); |
| 101 | + System.exit(1); |
| 102 | + } |
| 103 | + System.err.println("Please enter a valid version."); |
| 104 | + System.out.print("Minecraft version: "); |
| 105 | + continue; |
| 106 | + } |
| 107 | + if (supportedMcVersions.contains(answer.trim())) { |
| 108 | + mc = answer; |
| 109 | + return mc; |
| 110 | + } |
| 111 | + System.out.println("The version you entered is not supported."); |
| 112 | + System.out.print("Minecraft version: "); |
| 113 | + } |
| 114 | + } |
101 | 115 | }
|
102 | 116 |
|
103 | 117 | private static String readFromIS(@Nullable InputStream versionStream) {
|
|
0 commit comments