Skip to content

Commit

Permalink
Fix being unable to type in the console after you accepted the eula
Browse files Browse the repository at this point in the history
  • Loading branch information
JustRed23 committed Mar 26, 2023
1 parent 92ec40a commit b731e7f
Showing 1 changed file with 27 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,40 +71,39 @@ public static boolean checkEula(Path path_to_eula) throws IOException {

int wrong = 0;

try (InputStreamReader reader = new InputStreamReader(System.in); BufferedReader input = new BufferedReader(reader)) {
while (true) {
String answer = input.readLine();
if (answer == null || answer.isBlank()) {
Console console = System.console();
while (true) {
String answer = console.readLine();
if (answer == null || answer.isBlank()) {
if (wrong++ >= 2) {
System.err.println("You have typed the wrong answer too many times. Exiting.");
return false;
}
System.out.println("Please type 'yes' or 'no'.");
System.out.print("Do you accept? (yes/no): ");
continue;
}

switch (answer.toLowerCase()) {
case "y", "yes" -> {
file.delete();
file.createNewFile();
try (FileWriter writer = new FileWriter(file)) {
writer.write("eula=true");
}
return true;
}
case "n", "no" -> {
System.err.println("You must accept the EULA to continue. Exiting.");
return false;
}
default -> {
if (wrong++ >= 2) {
System.err.println("You have typed the wrong answer too many times. Exiting.");
return false;
}
System.out.println("Please type 'yes' or 'no'.");
System.out.print("Do you accept? (yes/no): ");
continue;
}

switch (answer.toLowerCase()) {
case "y", "yes" -> {
file.delete();
file.createNewFile();
try (FileWriter writer = new FileWriter(file)) {
writer.write("eula=true");
}
return true;
}
case "n", "no" -> {
System.err.println("You must accept the EULA to continue. Exiting.");
return false;
}
default -> {
if (wrong++ >= 2) {
System.err.println("You have typed the wrong answer too many times. Exiting.");
return false;
}
System.out.println("Please type 'yes' or 'no'.");
System.out.print("Do you accept? (yes/no): ");
}
}
}
}
Expand Down

0 comments on commit b731e7f

Please sign in to comment.