Skip to content

Commit

Permalink
increase timeout and fix server console delays
Browse files Browse the repository at this point in the history
  • Loading branch information
TabulateJarl8 committed Jun 8, 2021
1 parent 09339ab commit 5a8675e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.tabulate.modpackSwitcher</groupId>
<artifactId>switcher</artifactId>
<version>1.0</version>
<version>1.1</version>

<name>switcher</name>
<url>http://tabulatejarl8.github.io</url>
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/modpackSwitcher/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public boolean accept(File file, String s) {


// Print out modpack choices
System.out.println("Select a pack. Last used pack will be started in 5 seconds.");
System.out.println("Select a pack. Last used pack will be started in 10 seconds.");
for (int i = 0; i < (modpacks.length); i++) {
System.out.print((i + 1) + ". " + modpacks[i]);

Expand All @@ -157,7 +157,9 @@ public boolean accept(File file, String s) {
}
System.out.println();

stringChoice = getModpackSelectionWithTimeout(5, lastUsedPack, modpacks, ansi);
System.out.println("Which modpack? [1-" + modpacks.length + "] ");

stringChoice = getModpackSelectionWithTimeout(10, "> ", lastUsedPack, modpacks, ansi);
choice = Integer.parseInt(stringChoice);

// Write last used modpack if changed
Expand Down Expand Up @@ -251,7 +253,7 @@ public int writeFile(String directoryName, String fileName, String value){
}
}

public String getModpackSelectionWithTimeout(int delay, int defaultChoice, String[] modpacks, boolean ansi){
public String getModpackSelectionWithTimeout(int delay, String message, int defaultChoice, String[] modpacks, boolean ansi){
defaultChoice++;
Callable<Integer> k = new Callable<Integer>() {
@Override
Expand All @@ -264,7 +266,7 @@ public Integer call() {
boolean valid;
ExecutorService l = Executors.newFixedThreadPool(1);
Future<Integer> g;
System.out.print("Which modpack? [1-" + modpacks.length + "] ");
System.out.print(message);
g = l.submit(k);
done: while (System.currentTimeMillis() - start < delay * 1000L) {
do {
Expand All @@ -285,7 +287,7 @@ public Integer call() {
g = l.submit(k);
valid = false;
// Reset timer
System.out.print("Which modpack? [1-" + modpacks.length + "] ");
System.out.print(message);
start = System.currentTimeMillis();
}
}
Expand All @@ -309,4 +311,4 @@ class Fore {
public static String CYAN = "\u001b[36m";
public static String WHITE = "\u001b[37m";
public static String RESET = "\u001b[0m";
}
}

0 comments on commit 5a8675e

Please sign in to comment.