Adds a menu item for easily delete built .jar files
All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good

This commit is contained in:
2021-08-03 11:06:02 +02:00
parent 429b1fcec0
commit 6ca49d2ccd
3 changed files with 47 additions and 1 deletions

View File

@ -236,6 +236,15 @@ public class ServerLauncherController {
this.currentProfile = getProfileByName(profileName);
}
/**
* Gets the directory containing .jar files
*
* @return <p>The directory containing .jar files</p>
*/
public String getJarDirectory() {
return this.jarDirectory;
}
/**
* Saves the state of the entire application to disk
*/

View File

@ -7,6 +7,7 @@ import net.knarcraft.minecraftserverlauncher.utility.CommonFunctions;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Objects;
/**
@ -21,6 +22,7 @@ public class ServerLauncherMenu implements ActionListener {
private JCheckBoxMenuItem downloadJarsCheckBoxMenuItem;
private JMenuItem javaCommandMenuItem;
private JMenuItem oldJavaCommandMenuItem;
private JMenuItem deleteBuiltJarsMenuItem;
//Help
private JMenuItem errorsMenuItem;
private JMenuItem setupMenuItem;
@ -31,6 +33,7 @@ public class ServerLauncherMenu implements ActionListener {
private JMenuItem downloadJarsMenuItem;
private JMenuItem javaCommandInfoMenuItem;
private JMenuItem oldJavaCommandInfoMenuItem;
private JMenuItem deleteBuiltJarsInfoMenuItem;
//Info/about
private JMenuItem aboutMenuItem;
private JMenuItem storyMenuItem;
@ -93,6 +96,8 @@ public class ServerLauncherMenu implements ActionListener {
configureJava(false);
} else if (actionSource == oldJavaCommandMenuItem) {
configureJava(true);
} else if (actionSource == deleteBuiltJarsMenuItem) {
deleteBuiltJars();
} else if (actionSource == errorsMenuItem) {
CommonFunctions.goToURL(serverLauncherGUI.getMessage("infoURL"));
} else if (actionSource == setupMenuItem) {
@ -109,6 +114,8 @@ public class ServerLauncherMenu implements ActionListener {
serverLauncherGUI.showMessage("Java command", serverLauncherGUI.getMessage("javaCommandText"));
} else if (actionSource == oldJavaCommandInfoMenuItem) {
serverLauncherGUI.showMessage("Old Java command", serverLauncherGUI.getMessage("oldJavaCommandText"));
} else if (actionSource == deleteBuiltJarsInfoMenuItem) {
serverLauncherGUI.showMessage("Delete build jar files", serverLauncherGUI.getMessage("deleteBuiltJarFilesText"));
} else if (actionSource == aboutMenuItem) {
serverLauncherGUI.showMessage("About", serverLauncherGUI.getMessage("aboutText"));
} else if (actionSource == storyMenuItem) {
@ -127,6 +134,7 @@ public class ServerLauncherMenu implements ActionListener {
downloadJarsCheckBoxMenuItem = createCheckBoxMenuItem("Download jars", mnOptions);
javaCommandMenuItem = createMenuItem("Java command", mnOptions);
oldJavaCommandMenuItem = createMenuItem("Old Java command", mnOptions);
deleteBuiltJarsMenuItem = createMenuItem("Delete build jar files", mnOptions);
}
/**
@ -143,6 +151,7 @@ public class ServerLauncherMenu implements ActionListener {
downloadJarsMenuItem = createMenuItem("Download jars", mnOptionsInfo);
javaCommandInfoMenuItem = createMenuItem("Java command", mnOptionsInfo);
oldJavaCommandInfoMenuItem = createMenuItem("Old Java command", mnOptionsInfo);
deleteBuiltJarsInfoMenuItem = createMenuItem("Delete build jar files", mnOptionsInfo);
JMenu mnAbout = new JMenu("About");
mnInfo.add(mnAbout);
@ -197,6 +206,33 @@ public class ServerLauncherMenu implements ActionListener {
}
}
/**
* Deletes build Spigot and Bukkit .jar files if the user accepts
*/
private void deleteBuiltJars() {
int answer = JOptionPane.showConfirmDialog(null, "This will delete build .jar files, causing them " +
"to be rebuilt on the next run. Do you want to continue?", "Delete build .jar files",
JOptionPane.YES_NO_OPTION
);
if (answer == JOptionPane.YES_NO_OPTION) {
String jarDirectory = controller.getJarDirectory();
File spigotFile = new File(jarDirectory + "SpigotLatest");
File bukkitFile = new File(jarDirectory + "BukkitLatest");
boolean success = true;
if (spigotFile.exists() && !spigotFile.delete()) {
serverLauncherGUI.showError("Unable to delete latest spigot .jar");
success = false;
}
if (bukkitFile.exists() && !bukkitFile.delete()) {
serverLauncherGUI.showError("Unable to delete latest bukkit .jar");
success = false;
}
if (success) {
serverLauncherGUI.showMessage("Deletion successful", "Deleted build .jar files");
}
}
}
/**
* Asks the user for a delay if checked, and sets the value to the current profile
*/