Added downloading plugins to a temp place (#18)

This commit is contained in:
Norbi Peti 2016-11-03 16:12:32 +01:00
parent c452c1a375
commit 16ec9a3788

View file

@ -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";