Does some much needed cleanup, adds the Paper server type and fixes broken downloads
Some checks failed
KnarCraft/Minecraft-Server-Launcher/pipeline/head There was a failure building this commit
Some checks failed
KnarCraft/Minecraft-Server-Launcher/pipeline/head There was a failure building this commit
This commit is contained in:
@ -0,0 +1,68 @@
|
||||
package net.knarcraft.minecraftserverlauncher.utility;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
|
||||
import net.knarcraft.minecraftserverlauncher.server.ServerTypeHandler;
|
||||
import net.knarcraft.minecraftserverlauncher.userinterface.GUI;
|
||||
|
||||
import javax.naming.ConfigurationException;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This class handles all downloading of .jar files
|
||||
*/
|
||||
public class JarDownloader {
|
||||
|
||||
private final String jarDirectory;
|
||||
private GUI gui;
|
||||
|
||||
/**
|
||||
* Initializes a jar downloader
|
||||
*
|
||||
* @param gui <p>The GUI to use for displaying messages</p>
|
||||
* @param jarDirectory <p>The directory to download jar files to</p>
|
||||
*/
|
||||
public JarDownloader(GUI gui, String jarDirectory) {
|
||||
this.gui = gui;
|
||||
this.jarDirectory = jarDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads all jars to the program directory.
|
||||
*
|
||||
* @throws IOException On version file failure or folder creation failure
|
||||
*/
|
||||
public void downloadJars() throws IOException {
|
||||
if (!new File(jarDirectory).exists() && !new File(jarDirectory).mkdirs()) {
|
||||
gui.showError("Could not create the Jars folder. Please run the program with admin permissions, or move it to " +
|
||||
"a writable directory.");
|
||||
throw new FileNotFoundException("Unable to create jars folder");
|
||||
}
|
||||
try {
|
||||
downloadAll();
|
||||
gui.printMessageToGUI("Finished downloading jars");
|
||||
} catch (FileNotFoundException | ConfigurationException e) {
|
||||
throw new FileNotFoundException("One or more downloads failed: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Downloads jar files for all possible server versions
|
||||
*
|
||||
* @throws IOException <p>If a jar fails to download</p>
|
||||
*/
|
||||
private void downloadAll() throws IOException, ConfigurationException {
|
||||
for (ServerType type : ServerTypeHandler.getServerTypes()) {
|
||||
if (type.getName().equals("Custom")) {
|
||||
continue;
|
||||
}
|
||||
for (String version : type.getVersions()) {
|
||||
boolean success = type.downloadJar(jarDirectory, version);
|
||||
if (!success) {
|
||||
throw new FileNotFoundException("Unable to download the jar file for " + type.getName() + version);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user