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:
Kristian Knarvik 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); 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 * 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 javax.swing.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.io.File;
import java.util.Objects; import java.util.Objects;
/** /**
@ -21,6 +22,7 @@ public class ServerLauncherMenu implements ActionListener {
private JCheckBoxMenuItem downloadJarsCheckBoxMenuItem; private JCheckBoxMenuItem downloadJarsCheckBoxMenuItem;
private JMenuItem javaCommandMenuItem; private JMenuItem javaCommandMenuItem;
private JMenuItem oldJavaCommandMenuItem; private JMenuItem oldJavaCommandMenuItem;
private JMenuItem deleteBuiltJarsMenuItem;
//Help //Help
private JMenuItem errorsMenuItem; private JMenuItem errorsMenuItem;
private JMenuItem setupMenuItem; private JMenuItem setupMenuItem;
@ -31,6 +33,7 @@ public class ServerLauncherMenu implements ActionListener {
private JMenuItem downloadJarsMenuItem; private JMenuItem downloadJarsMenuItem;
private JMenuItem javaCommandInfoMenuItem; private JMenuItem javaCommandInfoMenuItem;
private JMenuItem oldJavaCommandInfoMenuItem; private JMenuItem oldJavaCommandInfoMenuItem;
private JMenuItem deleteBuiltJarsInfoMenuItem;
//Info/about //Info/about
private JMenuItem aboutMenuItem; private JMenuItem aboutMenuItem;
private JMenuItem storyMenuItem; private JMenuItem storyMenuItem;
@ -93,6 +96,8 @@ public class ServerLauncherMenu implements ActionListener {
configureJava(false); configureJava(false);
} else if (actionSource == oldJavaCommandMenuItem) { } else if (actionSource == oldJavaCommandMenuItem) {
configureJava(true); configureJava(true);
} else if (actionSource == deleteBuiltJarsMenuItem) {
deleteBuiltJars();
} else if (actionSource == errorsMenuItem) { } else if (actionSource == errorsMenuItem) {
CommonFunctions.goToURL(serverLauncherGUI.getMessage("infoURL")); CommonFunctions.goToURL(serverLauncherGUI.getMessage("infoURL"));
} else if (actionSource == setupMenuItem) { } else if (actionSource == setupMenuItem) {
@ -109,6 +114,8 @@ public class ServerLauncherMenu implements ActionListener {
serverLauncherGUI.showMessage("Java command", serverLauncherGUI.getMessage("javaCommandText")); serverLauncherGUI.showMessage("Java command", serverLauncherGUI.getMessage("javaCommandText"));
} else if (actionSource == oldJavaCommandInfoMenuItem) { } else if (actionSource == oldJavaCommandInfoMenuItem) {
serverLauncherGUI.showMessage("Old Java command", serverLauncherGUI.getMessage("oldJavaCommandText")); 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) { } else if (actionSource == aboutMenuItem) {
serverLauncherGUI.showMessage("About", serverLauncherGUI.getMessage("aboutText")); serverLauncherGUI.showMessage("About", serverLauncherGUI.getMessage("aboutText"));
} else if (actionSource == storyMenuItem) { } else if (actionSource == storyMenuItem) {
@ -127,6 +134,7 @@ public class ServerLauncherMenu implements ActionListener {
downloadJarsCheckBoxMenuItem = createCheckBoxMenuItem("Download jars", mnOptions); downloadJarsCheckBoxMenuItem = createCheckBoxMenuItem("Download jars", mnOptions);
javaCommandMenuItem = createMenuItem("Java command", mnOptions); javaCommandMenuItem = createMenuItem("Java command", mnOptions);
oldJavaCommandMenuItem = createMenuItem("Old 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); downloadJarsMenuItem = createMenuItem("Download jars", mnOptionsInfo);
javaCommandInfoMenuItem = createMenuItem("Java command", mnOptionsInfo); javaCommandInfoMenuItem = createMenuItem("Java command", mnOptionsInfo);
oldJavaCommandInfoMenuItem = createMenuItem("Old Java command", mnOptionsInfo); oldJavaCommandInfoMenuItem = createMenuItem("Old Java command", mnOptionsInfo);
deleteBuiltJarsInfoMenuItem = createMenuItem("Delete build jar files", mnOptionsInfo);
JMenu mnAbout = new JMenu("About"); JMenu mnAbout = new JMenu("About");
mnInfo.add(mnAbout); 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 * Asks the user for a delay if checked, and sets the value to the current profile
*/ */

View File

@ -8,3 +8,4 @@ manualUpdateURL=https://git.knarcraft.net/KnarCraft/Minecraft-Server-Launcher/re
storyURL=https://archive.knarcraft.net/Scripts/BungeeMinecraftServerLauncherStory/ 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. 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. 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.
Can't render this file because it contains an unexpected character in line 9 and column 136.