From 75cb5eafec099d7b9eb08d27d51beb28718aa4ce Mon Sep 17 00:00:00 2001 From: piegames Date: Sat, 8 Aug 2020 01:24:01 +0200 Subject: [PATCH] Minor improvements, documentation, code formatting --- .../de/piegames/blockmap/generate/Downloader.java | 2 ++ .../de/piegames/blockmap/generate/Generator.java | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/BlockMap-internal/src/main/java/de/piegames/blockmap/generate/Downloader.java b/BlockMap-internal/src/main/java/de/piegames/blockmap/generate/Downloader.java index ea45d45..8dabac1 100644 --- a/BlockMap-internal/src/main/java/de/piegames/blockmap/generate/Downloader.java +++ b/BlockMap-internal/src/main/java/de/piegames/blockmap/generate/Downloader.java @@ -52,6 +52,7 @@ public static void checkMinecraftVersions() throws IOException { .map(Optional::get) .collect(Collectors.toList()); log.debug("Latest known Minecraft versions: " + latestReleases.stream().map(v -> v.id).collect(Collectors.toList())); + for (MinecraftVersion version : MinecraftVersion.values()) { log.info("Checking " + version); Semver minecraftVersion = new Semver(version.versionName, SemverType.LOOSE); @@ -68,6 +69,7 @@ public static void checkMinecraftVersions() throws IOException { log.error("Specified URL does not match, should be " + latestMatching.url); } } + Semver latestRelease = latestReleases.stream() .map(v -> new Semver(v.id, SemverType.LOOSE)) .max(Comparator.naturalOrder()) diff --git a/BlockMap-internal/src/main/java/de/piegames/blockmap/generate/Generator.java b/BlockMap-internal/src/main/java/de/piegames/blockmap/generate/Generator.java index 0d82595..570dda6 100644 --- a/BlockMap-internal/src/main/java/de/piegames/blockmap/generate/Generator.java +++ b/BlockMap-internal/src/main/java/de/piegames/blockmap/generate/Generator.java @@ -78,14 +78,23 @@ public void generateData() throws Exception { { /* Call the Minecraft data report tool */ Path serverFile = OUTPUT_INTERNAL_CACHE.resolve("server-" + version.fileSuffix + ".jar"); - String serverHash = null, cachedServerHash = null; + + /* The hash of the current existing server.jar file */ + String serverHash; try { serverHash = Downloader.getHashSHA256(serverFile); + } finally { + } + + /* The hash of the server.jar at the time the data was generated. */ + String cachedServerHash = null; + try { cachedServerHash = Files.readString(extractedDataDirectory.resolve("server-sha256")); } catch (RuntimeException | IOException e) { } - if (serverHash == null || cachedServerHash == null || !serverHash.equals(cachedServerHash)) { + /* If the cached hash does not exist or does not match the current one, re-generate the data. */ + if (cachedServerHash == null || !serverHash.equals(cachedServerHash)) { log.info("Extracting Minecraft data for version " + version); FileUtils.deleteDirectory(extractedDataDirectory.toFile()); @@ -98,6 +107,7 @@ public void generateData() throws Exception { main.invoke(null, new Object[] { new String[] { "--reports", "--output=" + extractedDataDirectory } }); } + /* Write the hash last. Thus the presence of this file implies the existence of the data. */ Files.writeString(extractedDataDirectory.resolve("server-sha256"), serverHash); } else { log.info("Extracted Minecraft data for version " + version + " is up to date");