Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java testing #13

Merged
merged 9 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,28 @@ on: [push]

jobs:
build:
strategy:
matrix:
# Use these Java versions
java: [
17, # Current Java LTS & minimum supported by Minecraft
]

runs-on: ubuntu-latest

steps:
- name: checkout repository
uses: actions/checkout@v3
- name: setup jdk ${{ matrix.java }}
uses: actions/setup-java@v3
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: ${{ matrix.java }}
distribution: 'temurin'
distribution: 'temurin' # See 'Supported distributions' for available options
java-version: '17'

- name: build
run: mvn package

- name: l4j dl
run: curl -o l4j.tgz https://cytranet.dl.sourceforge.net/project/launch4j/launch4j-3/3.50/launch4j-3.50-linux-x64.tgz

- name: l4j unzip
run: tar -xzf l4j.tgz

- name: l4j run
run: java -jar launch4j/launch4j.jar launch4jConfig.xml

- name: capture build artifacts
uses: actions/upload-artifact@v3
with:
Expand Down
21 changes: 21 additions & 0 deletions launch4jConfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<launch4jConfig>
<headerType>console</headerType>
<outfile>target/dist/Toolbox2.0.exe</outfile>
<jar>target/dist/Toolbox2.0.jar</jar>
<icon>BattleModeIcon.ico</icon>
<jre>
<minVersion>17</minVersion>
<maxVersion>18</maxVersion>
</jre>
<versionInfo>
<fileVersion>2.0.0.0</fileVersion>
<txtFileVersion>2.0</txtFileVersion>
<productVersion>2.0.0.0</productVersion>
<txtProductVersion>2.0</txtProductVersion>
<fileDescription>All-in-one tools to manage your own LEM server</fileDescription>
<copyright>Legacy Edition Minigames Team</copyright>
<productName>Toolbox 2.0</productName>
<internalName>Toolbox 2.0</internalName>
<originalFilename>Toolbox2.0.exe</originalFilename>
</versionInfo>
</launch4jConfig>
25 changes: 1 addition & 24 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<groupId>net.kyrptonaught</groupId>
<artifactId>ToolBox2.0</artifactId>
<version>2.0.0</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>17</maven.compiler.source>
Expand Down Expand Up @@ -49,30 +50,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<groupId>com.akathist.maven.plugins.launch4j</groupId>
<artifactId>launch4j-maven-plugin</artifactId>
<executions>
<execution>
<id>l4j-clui</id>
<phase>package</phase>
<goals><goal>launch4j</goal></goals>
<configuration>
<headerType>console</headerType>
<outfile>target/dist/Toolbox2.0.exe</outfile>
<jar>target/dist/Toolbox2.0.jar</jar>
<icon>BattleModeIcon.ico</icon>
<jre><path>%JAVA_HOME%;%PATH%</path></jre>
<versionInfo>
<fileDescription>All-in-one tools to manage your own LEM server</fileDescription>
<copyright>Legacy Edition Minigames Team</copyright>
<productName>Toolbox 2.0</productName>
<internalName>Toolbox 2.0</internalName>
</versionInfo>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
4 changes: 3 additions & 1 deletion src/main/java/net/kyrptonaught/ToolBox/CMDArgsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public class CMDArgsParser {

private static String[] args;
public static String[] args;

public static void setArgs(String[] args) {
CMDArgsParser.args = args;
Expand Down Expand Up @@ -39,6 +39,8 @@ public static String getTargetServer() {
return null;
}

public static boolean autoUpdateToolbox() {return containsArgs("--autoUpdateToolbox");}

public static boolean updateServer() {
return containsArgs("--updateServer");
}
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/net/kyrptonaught/ToolBox/Main.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package net.kyrptonaught.ToolBox;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
//Γûä
public static void main(String[] args) {
if (args.length > 0 && args[0].equals("--autoHash")) {
AutoHash.autoHash();
return;
} else if (args.length > 0 && args[0].equals("--updater")) {
UpdateChecker.installUpdate();
return;
} else if (args.length > 0 && args[0].equals("--runToolbox")) {
Menu.startStateMachine(args);
} else {
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
CMDArgsParser.setArgs(args);
Menu.checkForUpdate(input);
}

Menu.startStateMachine(args);
}
}
101 changes: 71 additions & 30 deletions src/main/java/net/kyrptonaught/ToolBox/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,32 +19,26 @@
import java.util.stream.Stream;

public class Menu {
public static boolean SKIP_SHUTDOWN_TASKS = false;


public static State state;
public static Object stateData;

public static void startStateMachine(String[] args) {
CMDArgsParser.setArgs(args);

Runtime.getRuntime().addShutdownHook(new Thread(() -> {
if(!SKIP_SHUTDOWN_TASKS) {
System.out.println();
System.out.println();
System.out.println("SHUTTING DOWN");
System.out.println("Attempting to stop running servers");
ServerRunner.exit();
}
System.out.println();
System.out.println();
System.out.println("SHUTTING DOWN");
System.out.println("Attempting to stop running servers");
ServerRunner.exit();
}));
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));

CMDArgsParser.setArgs(args);

setState(CMDArgsParser.skipSplash() ? State.MENU : State.SPLASH);

Automation.run();

clearConsole();
//checkForUpdate(input);

while (true) {
clearConsole();
Expand Down Expand Up @@ -503,41 +497,88 @@ public static void checkEula(BufferedReader input, InstalledServerInfo serverInf

public static void checkForUpdate(BufferedReader input) {
System.out.println("Checking for Toolbox Updates...");
System.out.println();
System.out.println("Current version: Toolbox 2.0 v" + UpdateChecker.version);

String update = UpdateChecker.isUpdateAvailable();
if (update != null) {
System.out.println("An update for Toolbox is available: v" + update);
String installedVersion = UpdateBootstrapper.getInstalledVersion();
if (installedVersion.equals("0.0")) {
System.out.println("Toolbox is missing files require to run. The required files will be downloaded automatically.");
System.out.println();
System.out.println("1. View Release");
System.out.println("2. Download Update");

System.out.println("0. Ignore");

System.out.println("1. View Latest Release");
System.out.println("2. Download");
System.out.println("0. Exit");
System.out.println();
System.out.print("Select Option: ");

if(CMDArgsParser.autoUpdateToolbox()){
System.out.println("Auto Accepting update...");
UpdateBootstrapper.installUpdate();
UpdateBootstrapper.runToolbox();
return ;
}

int selection = readInt(input);
if (selection == 1) {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
try {
Desktop.getDesktop().browse(new URI(UpdateChecker.URL));
Desktop.getDesktop().browse(new URI(UpdateBootstrapper.URL));
} catch (Exception e) {
e.printStackTrace();
}
}
clearConsole();
checkForUpdate(input);
} else if (selection == 2) {
System.out.println("Installing update");
UpdateChecker.prepUpdate();
System.out.println("Installing latest version");
UpdateBootstrapper.installUpdate();
UpdateBootstrapper.runToolbox();
return;
} else if (selection == 0) {
System.out.println("Exiting...");
System.exit(0);
}
}

String update = UpdateBootstrapper.isUpdateAvailable();
if (update != null) {
Path versionFile = Paths.get(".toolbox/VERSION");
if (FileHelper.exists(versionFile)) {
System.out.println("Current version: Toolbox 2.0 v" + installedVersion);
System.out.println();
System.out.println("Update installed. Closing Toolbox. Please ");
pressEnterToCont(input);
setState(State.EXIT);
System.out.println("An update for Toolbox is available: v" + update);
System.out.println();
System.out.println("1. View Release");
System.out.println("2. Download Update");
System.out.println("0. Ignore");
System.out.println();
System.out.print("Select Option: ");

if(CMDArgsParser.autoUpdateToolbox()){
System.out.println("Auto Accepting update...");
UpdateBootstrapper.installUpdate();
UpdateBootstrapper.runToolbox();
return ;
}

int selection = readInt(input);
if (selection == 1) {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
try {
Desktop.getDesktop().browse(new URI(UpdateBootstrapper.URL));
} catch (Exception e) {
e.printStackTrace();
}
}
clearConsole();
checkForUpdate(input);

} else if (selection == 2) {
System.out.println("Installing update");
UpdateBootstrapper.installUpdate();
UpdateBootstrapper.runToolbox();
return;
}
}
}
System.out.println("Already up to date");
UpdateBootstrapper.runToolbox();
}

public static void clearConsole() {
Expand Down
Loading
Loading