mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2025-02-14 11:31:45 +01:00
Merge branch 'master' into feat/entity
This commit is contained in:
commit
eb017ccba4
@ -39,10 +39,11 @@
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.net.URI;
|
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.*;
|
import java.nio.file.FileSystem;
|
||||||
|
import java.nio.file.FileSystems;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.security.DigestInputStream;
|
import java.security.DigestInputStream;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
@ -53,7 +54,7 @@
|
|||||||
public class MinecraftVersion {
|
public class MinecraftVersion {
|
||||||
private static final Gson GSON = new Gson();
|
private static final Gson GSON = new Gson();
|
||||||
|
|
||||||
private static final String LATEST_KNOWN_VERSION = "1.20.6";
|
private static final String LATEST_KNOWN_VERSION = "1.21.4";
|
||||||
private static final String EARLIEST_RESOURCEPACK_VERSION = "1.13";
|
private static final String EARLIEST_RESOURCEPACK_VERSION = "1.13";
|
||||||
private static final String EARLIEST_DATAPACK_VERSION = "1.19.4";
|
private static final String EARLIEST_DATAPACK_VERSION = "1.19.4";
|
||||||
|
|
||||||
@ -143,7 +144,7 @@ private static void download(VersionManifest.Version version, Path file) throws
|
|||||||
try {
|
try {
|
||||||
try (
|
try (
|
||||||
DigestInputStream in = new DigestInputStream(
|
DigestInputStream in = new DigestInputStream(
|
||||||
new URI(download.getUrl()).toURL().openStream(),
|
download.createInputStream(),
|
||||||
MessageDigest.getInstance("SHA-1")
|
MessageDigest.getInstance("SHA-1")
|
||||||
);
|
);
|
||||||
OutputStream out = Files.newOutputStream(unverifiedFile)
|
OutputStream out = Files.newOutputStream(unverifiedFile)
|
||||||
@ -165,7 +166,7 @@ private static void download(VersionManifest.Version version, Path file) throws
|
|||||||
// rename once verified
|
// rename once verified
|
||||||
FileHelper.atomicMove(unverifiedFile, file);
|
FileHelper.atomicMove(unverifiedFile, file);
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException | IOException | URISyntaxException ex) {
|
} catch (NoSuchAlgorithmException | IOException ex) {
|
||||||
Logger.global.logWarning("Failed to download '" + download.getUrl() + "': " + ex);
|
Logger.global.logWarning("Failed to download '" + download.getUrl() + "': " + ex);
|
||||||
} finally {
|
} finally {
|
||||||
Files.deleteIfExists(unverifiedFile);
|
Files.deleteIfExists(unverifiedFile);
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -48,6 +48,8 @@ public class VersionManifest {
|
|||||||
public static final String DOMAIN = "https://piston-meta.mojang.com/";
|
public static final String DOMAIN = "https://piston-meta.mojang.com/";
|
||||||
public static final String MANIFEST_URL = DOMAIN + "mc/game/version_manifest.json";
|
public static final String MANIFEST_URL = DOMAIN + "mc/game/version_manifest.json";
|
||||||
|
|
||||||
|
private static final int CONNECTION_TIMEOUT = 10000;
|
||||||
|
|
||||||
private static final Gson GSON = new GsonBuilder()
|
private static final Gson GSON = new GsonBuilder()
|
||||||
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter())
|
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeAdapter())
|
||||||
.create();
|
.create();
|
||||||
@ -71,7 +73,7 @@ public static VersionManifest getOrFetch() throws IOException {
|
|||||||
|
|
||||||
public static VersionManifest fetch() throws IOException {
|
public static VersionManifest fetch() throws IOException {
|
||||||
try (
|
try (
|
||||||
InputStream in = new URL(MANIFEST_URL).openStream();
|
InputStream in = openInputStream(MANIFEST_URL);
|
||||||
Reader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))
|
Reader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))
|
||||||
) {
|
) {
|
||||||
instance = GSON.fromJson(reader, VersionManifest.class);
|
instance = GSON.fromJson(reader, VersionManifest.class);
|
||||||
@ -118,7 +120,7 @@ public static class Version implements Comparable<Version> {
|
|||||||
public synchronized VersionDetail fetchDetail() throws IOException {
|
public synchronized VersionDetail fetchDetail() throws IOException {
|
||||||
if (detail == null) {
|
if (detail == null) {
|
||||||
try (
|
try (
|
||||||
InputStream in = new URL(url).openStream();
|
InputStream in = openInputStream(url);
|
||||||
Reader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))
|
Reader reader = new BufferedReader(new InputStreamReader(in, StandardCharsets.UTF_8))
|
||||||
) {
|
) {
|
||||||
detail = GSON.fromJson(reader, VersionDetail.class);
|
detail = GSON.fromJson(reader, VersionDetail.class);
|
||||||
@ -153,6 +155,23 @@ public static class Download {
|
|||||||
private String url;
|
private String url;
|
||||||
private long size;
|
private long size;
|
||||||
private String sha1;
|
private String sha1;
|
||||||
|
|
||||||
|
public InputStream createInputStream() throws IOException {
|
||||||
|
return openInputStream(url);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InputStream openInputStream(String urlPath) throws IOException {
|
||||||
|
try {
|
||||||
|
URL downloadUrl = new URI(urlPath).toURL();
|
||||||
|
URLConnection connection = downloadUrl.openConnection();
|
||||||
|
connection.setConnectTimeout(CONNECTION_TIMEOUT);
|
||||||
|
connection.setReadTimeout(CONNECTION_TIMEOUT);
|
||||||
|
return connection.getInputStream();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
throw new IOException(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user