From 16ec9a37880e79504752665719995231bf7e0117 Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 3 Nov 2016 16:12:32 +0100 Subject: [PATCH] Added downloading plugins to a temp place (#18) --- src/main/java/buttondevteam/lib/TBMCCoreAPI.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/buttondevteam/lib/TBMCCoreAPI.java b/src/main/java/buttondevteam/lib/TBMCCoreAPI.java index 318788c..163d7c6 100644 --- a/src/main/java/buttondevteam/lib/TBMCCoreAPI.java +++ b/src/main/java/buttondevteam/lib/TBMCCoreAPI.java @@ -7,6 +7,7 @@ import java.io.InputStream; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; +import java.nio.file.Files; import java.util.ArrayList; import java.util.List; @@ -45,11 +46,18 @@ public final class TBMCCoreAPI { Bukkit.getLogger().info("Updating TBMC plugin: " + correctname); String ret = ""; URL url; + File result = new File("plugins/" + correctname + ".jar_tmp"); + File finalresult = new File("plugins/" + correctname + ".jar"); try { url = new URL("https://jitpack.io/com/github/TBMCPlugins/" + (correctname.equals("ButtonCore") ? "ButtonCore/ButtonCore" : correctname) + "/master-SNAPSHOT/" + correctname + "-master-SNAPSHOT.jar"); // ButtonCore exception required since it hosts Towny as well - FileUtils.copyURLToFile(url, new File("plugins/" + correctname + ".jar")); + FileUtils.copyURLToFile(url, result); + if (!result.exists() || result.length() < 25) { + result.delete(); + ret = "The downloaded JAR is too small (smnaller than 25 bytes). Am I downloading from the right place?"; + } else + Files.move(result.toPath(), finalresult.toPath()); } catch (FileNotFoundException e) { ret = "Can't find JAR, the build probably failed. Build log (scroll to bottom):\nhttps://jitpack.io/com/github/TBMCPlugins/" + correctname + "/master-SNAPSHOT/build.log";