Skip to content
This repository has been archived by the owner on Jul 13, 2024. It is now read-only.

Commit

Permalink
Add argument -accepteula for accept eula automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
TonimatasDEV committed Mar 1, 2024
1 parent 2a842e0 commit c308f6e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ jobs:
- name: Run
timeout-minutes: 10
run: echo "stop" | java -jar mossy*.jar
run: echo "stop" | java -jar mossy*.jar -accepteula
3 changes: 2 additions & 1 deletion src/main/java/dev/tonimatas/mossy/launcher/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@

import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;

public class Main {
public static void main(String[] args) {
LibraryInstaller.init();

try {
if (!ServerEula.checkEula(Path.of("eula.txt"))) return;
if (!ServerEula.checkEula(Path.of("eula.txt"), Arrays.stream(args).toList().contains("-accepteula"))) return;
} catch (IOException e) {
Logger.error("Error on load eula.");
throw new RuntimeException(e);
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/dev/tonimatas/mossy/launcher/ServerEula.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,22 @@ private void saveDefaults() {
}

@SuppressWarnings("ResultOfMethodCallIgnored")
public static boolean checkEula(Path path) throws IOException {
public static boolean checkEula(Path path, boolean accepteula) throws IOException {
File file = path.toFile();
ServerEula eula = new ServerEula(path);

if (!eula.hasAgreedToEULA()) {
Logger.warn("WARNING: It appears you have not agreed to the EULA.\nPlease read the EULA (https://account.mojang.com/documents/minecraft_eula) and type 'yes' to continue.");
System.out.print("Do you accept? (yes/no): ");

int wrong = 0;

Scanner console = new Scanner(System.in);
Scanner console = null;
if (!accepteula) {
Logger.warn("WARNING: It appears you have not agreed to the EULA.\nPlease read the EULA (https://account.mojang.com/documents/minecraft_eula) and type 'yes' to continue.");
System.out.print("Do you accept? (yes/no): ");
console = new Scanner(System.in);
}

while (true) {
String answer = console.nextLine();
String answer = console != null ? console.nextLine() : "yes";
if (answer == null || answer.isBlank()) {
if (wrong++ >= 2) {
Logger.error("You have typed the wrong answer too many times. Exiting.");
Expand Down

0 comments on commit c308f6e

Please sign in to comment.