diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/profile/ServerLauncherController.java b/src/main/java/net/knarcraft/minecraftserverlauncher/profile/ServerLauncherController.java index 1f59f25..a427597 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/profile/ServerLauncherController.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/profile/ServerLauncherController.java @@ -236,6 +236,15 @@ public class ServerLauncherController { this.currentProfile = getProfileByName(profileName); } + /** + * Gets the directory containing .jar files + * + * @return

The directory containing .jar files

+ */ + public String getJarDirectory() { + return this.jarDirectory; + } + /** * Saves the state of the entire application to disk */ diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherMenu.java b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherMenu.java index f695ef3..9df7390 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherMenu.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/userinterface/ServerLauncherMenu.java @@ -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 */ diff --git a/src/main/resources/menumsg.csv b/src/main/resources/menumsg.csv index 0c37914..e3162f5 100644 --- a/src/main/resources/menumsg.csv +++ b/src/main/resources/menumsg.csv @@ -7,4 +7,5 @@ infoURL=https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncherInfo/ manualUpdateURL=https://git.knarcraft.net/KnarCraft/Minecraft-Server-Launcher/releases storyURL=https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncherStory/ javaCommandText=This option allows you to set a custom command/path to the Java executable used for Minecraft 1.17 and above._BREAK_If "java" is currently pointing to Java 8, you can use this to set a custom one for running new Minecraft servers and BuildTools. -oldJavaCommandText=This option allows you to set a custom command/path to the Java executable used for Minecraft 1.16 and below._BREAK_If "java" is currently pointing to Java 16, you can use this to set a custom one for running old Minecraft servers. \ No newline at end of file +oldJavaCommandText=This option allows you to set a custom command/path to the Java executable used for Minecraft 1.16 and below._BREAK_If "java" is currently pointing to Java 16, you can use this to set a custom one for running old Minecraft servers. +deleteBuiltJarFilesText=This option allows you to easily delete built Spigot and Bukkit .jar files._BREAK_You should occasionally run this option to update the built .jar files to ensure you're running the latest update. \ No newline at end of file