diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java index 6b995f0d9..d60f0961f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/core/services/MetricsService.java @@ -187,11 +187,16 @@ public class MetricsService { * The version to download. */ private boolean download(int version) { - File f = new File(parentFolder, "Metrics-" + version + ".jar"); + File file = new File(parentFolder, "Metrics-" + version + ".jar"); try { plugin.getLogger().log(Level.INFO, "# Starting download of MetricsModule build: #{0}", version); - + + if (file.exists()) { + // Delete the file in case we accidentally downloaded it before + Files.delete(file.toPath()); + } + AtomicInteger lastPercentPosted = new AtomicInteger(); GetRequest request = Unirest.get(GH_RELEASES + "/" + version + "/" + REPO_NAME + ".jar"); @@ -202,14 +207,14 @@ public class MetricsService { plugin.getLogger().info("# Downloading... " + percent + "% " + "(" + bytesWritten + "/" + totalBytes + " bytes)"); lastPercentPosted.set(percent); } - }).asFile(f.getPath()); + }).asFile(file.getPath()); if (response.isSuccess()) { plugin.getLogger().log(Level.INFO, "Successfully downloaded {0} build: #{1}", new Object[] { REPO_NAME, version }); // Replace the metric file with the new one cleanUp(); - Files.move(f.toPath(), metricsModuleFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + Files.move(file.toPath(), metricsModuleFile.toPath(), StandardCopyOption.REPLACE_EXISTING); metricVersion = String.valueOf(version); hasDownloadedUpdate = true;