From 0018816d90b7e88c86a56e728ce1d10aa857a5f5 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Mon, 2 Aug 2021 21:50:12 +0200 Subject: [PATCH] Makes the software build Spigot and CraftBukkit jars if the latest version is chosen --- .../server/servertypes/CraftBukkit.java | 31 ++++++++++++++++++- .../utility/JarBuilder.java | 14 +++++++-- src/main/resources/servertypes.csv | 4 +-- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/server/servertypes/CraftBukkit.java b/src/main/java/net/knarcraft/minecraftserverlauncher/server/servertypes/CraftBukkit.java index 0f8967e..41caff2 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/server/servertypes/CraftBukkit.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/server/servertypes/CraftBukkit.java @@ -1,5 +1,10 @@ package net.knarcraft.minecraftserverlauncher.server.servertypes; +import net.knarcraft.minecraftserverlauncher.Main; +import net.knarcraft.minecraftserverlauncher.profile.ServerLauncherController; +import net.knarcraft.minecraftserverlauncher.userinterface.GUI; +import net.knarcraft.minecraftserverlauncher.utility.JarBuilder; + import java.io.File; import java.nio.file.Paths; @@ -31,7 +36,31 @@ public class CraftBukkit extends AbstractServerType { String targetFile = this.getName() + version + ".jar"; String file = downloadURLPart + version + ".jar"; File filePath = new File(folder + targetFile); - return filePath.isFile() || downloadFile(downloadURL + file, Paths.get(filePath.toURI())); + + if (version.equals("Latest")) { + return filePath.isFile() || buildJar(folder); + } else { + return filePath.isFile() || downloadFile(downloadURL + file, Paths.get(filePath.toURI())); + } + } + + /** + * Builds the necessary .jar file + * + * @param folder

The folder the build file should be moved to

+ * @return

True if the build was successful

+ */ + private boolean buildJar(String folder) { + String buildToolsDirectory = Main.getApplicationWorkDirectory() + File.separator + "files" + File.separator + + "BuildTools" + File.separator; + + GUI gui = ServerLauncherController.getInstance().getGUI(); + JarBuilder jarBuilder = new JarBuilder(buildToolsDirectory, folder, gui); + if (this instanceof Spigot) { + return jarBuilder.buildSpigotJar(); + } else { + return jarBuilder.buildBukkitJar(); + } } } diff --git a/src/main/java/net/knarcraft/minecraftserverlauncher/utility/JarBuilder.java b/src/main/java/net/knarcraft/minecraftserverlauncher/utility/JarBuilder.java index 81ae888..a1b7e7f 100644 --- a/src/main/java/net/knarcraft/minecraftserverlauncher/utility/JarBuilder.java +++ b/src/main/java/net/knarcraft/minecraftserverlauncher/utility/JarBuilder.java @@ -42,24 +42,32 @@ public class JarBuilder { /** * Builds the latest version of the spigot .jar file */ - public void buildSpigotJar() { + public boolean buildSpigotJar() { + gui.setStatus("Building Spigot jar ..."); downloadBuildTools(); ProcessBuilder processBuilder = new ProcessBuilder(javaCommand, "-jar", "BuildTools.jar", "--rev", "latest", "--output-dir", jarDirectory); if (executeBuildProcess(processBuilder) && moveBuiltJar("spigot-", "SpigotLatest.jar")) { gui.setStatus("Finished moving spigot.jar"); + return true; + } else { + return false; } } /** * Builds the latest version of the craftbukkit .jar file */ - public void buildBukkitJar() { + public boolean buildBukkitJar() { + gui.setStatus("Building Bukkit jar ..."); downloadBuildTools(); ProcessBuilder processBuilder = new ProcessBuilder(javaCommand, "-jar", "BuildTools.jar", "--compile", "craftbukkit", "--rev", "latest", "--output-dir", jarDirectory); if (executeBuildProcess(processBuilder) && moveBuiltJar("craftbukkit-", "BukkitLatest.jar")) { gui.setStatus("Finished moving craftbukkit.jar"); + return true; + } else { + return false; } } @@ -133,7 +141,7 @@ public class JarBuilder { writer.flush(); if (process.exitValue() == 0) { - gui.showMessage("Jar building process finished successfully."); + gui.setStatus("Jar building process finished successfully."); return true; } else { gui.showError("Jar building process failed with exit code " + process.exitValue() + diff --git a/src/main/resources/servertypes.csv b/src/main/resources/servertypes.csv index 17a1979..eb8a917 100644 --- a/src/main/resources/servertypes.csv +++ b/src/main/resources/servertypes.csv @@ -1,8 +1,8 @@ Vanilla;Latest,Snapshot,1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.8.9,1.7.10,1.6.4,1.5.2,1.4.7,1.3.2,1.2.5;https://launchermeta.mojang.com/mc/game/version_manifest.json;"release":";";https://s3.amazonaws.com/Minecraft.Download/versions/ -Spigot;1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.9.4,1.8.8,1.7.10,1.6.4-R2.1,1.5.2-R1.1,1.4.7-R1.1;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Spigot/;spigot- +Spigot;Latest,1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.9.4,1.8.8,1.7.10,1.6.4-R2.1,1.5.2-R1.1,1.4.7-R1.1;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Spigot/;spigot- Paper;1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.8.8;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Paper/;Paper- SpongeVanilla;1.12.2,1.11.2,1.10.2,1.8.9;https://dl-api.spongepowered.org/v1/org.spongepowered/spongevanilla/downloads?type=stable&minecraft=;"version":";",;https://repo.spongepowered.org/maven/org/spongepowered/spongevanilla/;/spongevanilla- -Craftbukkit;1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.8.8,1.7.10-R0.1,1.6.4-R2.0,1.5.2-R1.0,1.4.6-R0.3,1.3.2-R3.0,1.2.5-R2.0,1.1-R6,1.0.1-R1,b1.8.1,b1.7.3;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Bukkit/;craftbukkit- +Craftbukkit;Latest,1.17.1,1.16.5,1.15.2,1.14.4,1.13.2,1.12.2,1.11.2,1.10.2,1.9.4,1.8.8,1.7.10-R0.1,1.6.4-R2.0,1.5.2-R1.0,1.4.6-R0.3,1.3.2-R3.0,1.2.5-R2.0,1.1-R6,1.0.1-R1,b1.8.1,b1.7.3;https://static.knarcraft.net/archive/downloads/minecraftserverjars/Bukkit/;craftbukkit- SpongeForge;1.12.2,1.11.2,1.10.2;https://dl-api.spongepowered.org/v1/org.spongepowered/spongeforge/downloads?type=stable&minecraft=;"version":";",;https://repo.spongepowered.org/maven/org/spongepowered/spongeforge/;/spongeforge- MCPCplus;1.6.4,1.6.2,1.5.2,1.4.7;https://static.knarcraft.net/archive/downloads/minecraftserverjars/MCPC+/;mcpcplus Bungee;Latest,1.7.10,1.6.4,1.5.2,1.4.7;https://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/bootstrap/target/;Artifacts of BungeeCord #; ;http://ci.md-5.net/job/BungeeCord/lastSuccessfulBuild/artifact/bootstrap/target/BungeeCord.jar;https://static.knarcraft.net/archive/downloads/minecraftserverjars/BungeeCord/;BungeeCord-