2020-04-08 23:20:41 +00:00
|
|
|
/*
|
2021-01-01 15:10:36 +00:00
|
|
|
* Copyright (c) 2019-2021 GeyserMC. http://geysermc.org
|
2020-04-08 23:20:41 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* @author GeyserMC
|
|
|
|
* @link https://github.com/GeyserMC/Geyser
|
|
|
|
*/
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
package org.geysermc.geyser.utils;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
|
|
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
|
|
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
|
|
|
import com.fasterxml.jackson.databind.JsonNode;
|
|
|
|
import lombok.Getter;
|
2021-11-20 21:34:30 +00:00
|
|
|
import org.geysermc.geyser.GeyserImpl;
|
|
|
|
import org.geysermc.geyser.network.MinecraftProtocol;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
|
|
|
import java.io.*;
|
2020-04-09 13:36:32 +00:00
|
|
|
import java.nio.file.Files;
|
2020-06-20 17:54:40 +00:00
|
|
|
import java.nio.file.Path;
|
2021-09-29 18:49:20 +00:00
|
|
|
import java.util.*;
|
2021-07-18 20:20:40 +00:00
|
|
|
import java.util.concurrent.CompletableFuture;
|
2020-04-09 13:36:32 +00:00
|
|
|
import java.util.zip.ZipFile;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
|
|
|
public class LocaleUtils {
|
|
|
|
|
|
|
|
public static final Map<String, Map<String, String>> LOCALE_MAPPINGS = new HashMap<>();
|
|
|
|
|
2020-04-08 23:20:41 +00:00
|
|
|
private static final Map<String, Asset> ASSET_MAP = new HashMap<>();
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2020-11-16 23:57:57 +00:00
|
|
|
private static VersionDownload clientJarInfo;
|
2020-04-09 13:36:32 +00:00
|
|
|
|
2020-04-08 23:20:41 +00:00
|
|
|
static {
|
|
|
|
// Create the locales folder
|
2021-11-20 21:34:30 +00:00
|
|
|
File localesFolder = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales").toFile();
|
2020-06-20 17:54:40 +00:00
|
|
|
//noinspection ResultOfMethodCallIgnored
|
2020-04-08 23:20:41 +00:00
|
|
|
localesFolder.mkdir();
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2020-04-08 23:20:41 +00:00
|
|
|
// Download the latest asset list and cache it
|
2021-07-18 20:20:40 +00:00
|
|
|
generateAssetCache().whenComplete((aVoid, ex) -> downloadAndLoadLocale(LanguageUtils.getDefaultLocale()));
|
2020-04-08 23:20:41 +00:00
|
|
|
}
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2020-04-21 05:28:44 +00:00
|
|
|
/**
|
|
|
|
* Fetch the latest versions asset cache from Mojang so we can grab the locale files later
|
|
|
|
*/
|
2021-07-18 20:20:40 +00:00
|
|
|
private static CompletableFuture<Void> generateAssetCache() {
|
|
|
|
return CompletableFuture.supplyAsync(() -> {
|
|
|
|
try {
|
|
|
|
// Get the version manifest from Mojang
|
2021-11-20 21:34:30 +00:00
|
|
|
VersionManifest versionManifest = GeyserImpl.JSON_MAPPER.readValue(WebUtils.getBody("https://launchermeta.mojang.com/mc/game/version_manifest.json"), VersionManifest.class);
|
2021-07-18 20:20:40 +00:00
|
|
|
|
|
|
|
// Get the url for the latest version of the games manifest
|
|
|
|
String latestInfoURL = "";
|
|
|
|
for (Version version : versionManifest.getVersions()) {
|
2021-11-14 05:07:24 +00:00
|
|
|
if (version.getId().equals(MinecraftProtocol.getJavaVersion())) {
|
2021-07-18 20:20:40 +00:00
|
|
|
latestInfoURL = version.getUrl();
|
|
|
|
break;
|
|
|
|
}
|
2020-04-08 20:11:56 +00:00
|
|
|
}
|
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
// Make sure we definitely got a version
|
|
|
|
if (latestInfoURL.isEmpty()) {
|
|
|
|
throw new Exception(LanguageUtils.getLocaleStringLog("geyser.locale.fail.latest_version"));
|
|
|
|
}
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
// Get the individual version manifest
|
2021-11-20 21:34:30 +00:00
|
|
|
VersionInfo versionInfo = GeyserImpl.JSON_MAPPER.readValue(WebUtils.getBody(latestInfoURL), VersionInfo.class);
|
2020-04-09 13:36:32 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
// Get the client jar for use when downloading the en_us locale
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().debug(GeyserImpl.JSON_MAPPER.writeValueAsString(versionInfo.getDownloads()));
|
2021-07-18 20:20:40 +00:00
|
|
|
clientJarInfo = versionInfo.getDownloads().get("client");
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().debug(GeyserImpl.JSON_MAPPER.writeValueAsString(clientJarInfo));
|
2020-04-09 13:36:32 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
// Get the assets list
|
2021-11-20 21:34:30 +00:00
|
|
|
JsonNode assets = GeyserImpl.JSON_MAPPER.readTree(WebUtils.getBody(versionInfo.getAssetIndex().getUrl())).get("objects");
|
2020-04-08 23:20:41 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
// Put each asset into an array for use later
|
|
|
|
Iterator<Map.Entry<String, JsonNode>> assetIterator = assets.fields();
|
|
|
|
while (assetIterator.hasNext()) {
|
|
|
|
Map.Entry<String, JsonNode> entry = assetIterator.next();
|
2021-07-25 14:11:53 +00:00
|
|
|
if (!entry.getKey().startsWith("minecraft/lang/")) {
|
|
|
|
// No need to cache non-language assets as we don't use them
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
Asset asset = GeyserImpl.JSON_MAPPER.treeToValue(entry.getValue(), Asset.class);
|
2021-07-18 20:20:40 +00:00
|
|
|
ASSET_MAP.put(entry.getKey(), asset);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().error(LanguageUtils.getLocaleStringLog("geyser.locale.fail.asset_cache", (!e.getMessage().isEmpty() ? e.getMessage() : e.getStackTrace())));
|
2020-04-08 20:11:56 +00:00
|
|
|
}
|
2021-07-18 20:20:40 +00:00
|
|
|
return null;
|
|
|
|
});
|
2020-04-08 20:11:56 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 05:28:44 +00:00
|
|
|
/**
|
|
|
|
* Downloads a locale from Mojang if its not already loaded
|
|
|
|
*
|
|
|
|
* @param locale Locale to download and load
|
|
|
|
*/
|
2020-04-08 20:11:56 +00:00
|
|
|
public static void downloadAndLoadLocale(String locale) {
|
2021-09-29 18:49:20 +00:00
|
|
|
locale = locale.toLowerCase(Locale.ROOT);
|
|
|
|
if (locale.equals("nb_no")) {
|
|
|
|
// Different locale code - https://minecraft.fandom.com/wiki/Language
|
|
|
|
locale = "no_no";
|
|
|
|
}
|
2020-04-21 05:28:44 +00:00
|
|
|
|
|
|
|
// Check the locale isn't already loaded
|
2020-04-08 23:20:41 +00:00
|
|
|
if (!ASSET_MAP.containsKey("minecraft/lang/" + locale + ".json") && !locale.equals("en_us")) {
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().warning(LanguageUtils.getLocaleStringLog("geyser.locale.fail.invalid", locale));
|
2020-04-08 23:20:41 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().debug("Downloading and loading locale: " + locale);
|
2020-04-08 23:20:41 +00:00
|
|
|
|
2020-04-08 20:11:56 +00:00
|
|
|
downloadLocale(locale);
|
|
|
|
loadLocale(locale);
|
|
|
|
}
|
|
|
|
|
2020-04-21 05:28:44 +00:00
|
|
|
/**
|
|
|
|
* Downloads the specified locale if its not already downloaded
|
|
|
|
*
|
|
|
|
* @param locale Locale to download
|
|
|
|
*/
|
2020-04-08 20:11:56 +00:00
|
|
|
private static void downloadLocale(String locale) {
|
2021-11-20 21:34:30 +00:00
|
|
|
File localeFile = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales/" + locale + ".json").toFile();
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2020-04-21 05:28:44 +00:00
|
|
|
// Check if we have already downloaded the locale file
|
2020-04-08 23:20:41 +00:00
|
|
|
if (localeFile.exists()) {
|
2020-11-16 23:57:57 +00:00
|
|
|
String curHash = "";
|
2021-06-21 01:42:22 +00:00
|
|
|
String targetHash;
|
2020-11-16 23:57:57 +00:00
|
|
|
|
|
|
|
if (locale.equals("en_us")) {
|
|
|
|
try {
|
2021-11-20 21:34:30 +00:00
|
|
|
File hashFile = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales/en_us.hash").toFile();
|
2020-11-22 10:40:53 +00:00
|
|
|
if (hashFile.exists()) {
|
2021-01-12 20:41:15 +00:00
|
|
|
try (BufferedReader br = new BufferedReader(new FileReader(hashFile))) {
|
|
|
|
curHash = br.readLine().trim();
|
|
|
|
}
|
2020-11-16 23:57:57 +00:00
|
|
|
}
|
|
|
|
} catch (IOException ignored) { }
|
2021-02-21 23:57:09 +00:00
|
|
|
|
|
|
|
if (clientJarInfo == null) {
|
|
|
|
// Likely failed to download
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().debug("Skipping en_US hash check as client jar is null.");
|
2021-02-21 23:57:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-11-16 23:57:57 +00:00
|
|
|
targetHash = clientJarInfo.getSha1();
|
|
|
|
} else {
|
|
|
|
curHash = byteArrayToHexString(FileUtils.calculateSHA1(localeFile));
|
|
|
|
targetHash = ASSET_MAP.get("minecraft/lang/" + locale + ".json").getHash();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!curHash.equals(targetHash)) {
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().debug("Locale out of date; re-downloading: " + locale);
|
2020-11-16 23:57:57 +00:00
|
|
|
} else {
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().debug("Locale already downloaded and up-to date: " + locale);
|
2020-11-16 23:57:57 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-04-08 23:20:41 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 20:11:56 +00:00
|
|
|
// Create the en_us locale
|
2020-04-08 23:20:41 +00:00
|
|
|
if (locale.equals("en_us")) {
|
2020-04-09 13:36:32 +00:00
|
|
|
downloadEN_US(localeFile);
|
2020-04-08 23:20:41 +00:00
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-21 23:57:09 +00:00
|
|
|
try {
|
|
|
|
// Get the hash and download the locale
|
|
|
|
String hash = ASSET_MAP.get("minecraft/lang/" + locale + ".json").getHash();
|
|
|
|
WebUtils.downloadFile("https://resources.download.minecraft.net/" + hash.substring(0, 2) + "/" + hash, localeFile.toString());
|
|
|
|
} catch (Exception e) {
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().error("Unable to download locale file hash", e);
|
2021-02-21 23:57:09 +00:00
|
|
|
}
|
2020-04-08 23:20:41 +00:00
|
|
|
}
|
|
|
|
|
2020-04-21 05:28:44 +00:00
|
|
|
/**
|
|
|
|
* Loads a locale already downloaded, if the file doesn't exist it just logs a warning
|
|
|
|
*
|
|
|
|
* @param locale Locale to load
|
|
|
|
*/
|
2020-04-08 23:20:41 +00:00
|
|
|
private static void loadLocale(String locale) {
|
2021-11-20 21:34:30 +00:00
|
|
|
File localeFile = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales/" + locale + ".json").toFile();
|
2020-04-08 20:11:56 +00:00
|
|
|
|
|
|
|
// Load the locale
|
|
|
|
if (localeFile.exists()) {
|
|
|
|
// Read the localefile
|
|
|
|
InputStream localeStream;
|
|
|
|
try {
|
|
|
|
localeStream = new FileInputStream(localeFile);
|
|
|
|
} catch (FileNotFoundException e) {
|
2020-07-05 23:35:51 +00:00
|
|
|
throw new AssertionError(LanguageUtils.getLocaleStringLog("geyser.locale.fail.file", locale, e.getMessage()));
|
2020-04-08 20:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the file as json
|
2020-04-08 23:20:41 +00:00
|
|
|
JsonNode localeObj;
|
2020-04-08 20:11:56 +00:00
|
|
|
try {
|
2021-11-20 21:34:30 +00:00
|
|
|
localeObj = GeyserImpl.JSON_MAPPER.readTree(localeStream);
|
2020-04-08 20:11:56 +00:00
|
|
|
} catch (Exception e) {
|
2020-07-05 23:35:51 +00:00
|
|
|
throw new AssertionError(LanguageUtils.getLocaleStringLog("geyser.locale.fail.json", locale), e);
|
2020-04-08 20:11:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parse all the locale fields
|
2020-04-08 23:20:41 +00:00
|
|
|
Iterator<Map.Entry<String, JsonNode>> localeIterator = localeObj.fields();
|
2020-04-08 20:11:56 +00:00
|
|
|
Map<String, String> langMap = new HashMap<>();
|
|
|
|
while (localeIterator.hasNext()) {
|
|
|
|
Map.Entry<String, JsonNode> entry = localeIterator.next();
|
|
|
|
langMap.put(entry.getKey(), entry.getValue().asText());
|
|
|
|
}
|
|
|
|
|
2021-09-29 18:49:20 +00:00
|
|
|
String bedrockLocale = locale.toLowerCase(Locale.ROOT);
|
|
|
|
if (bedrockLocale.equals("no_no")) {
|
|
|
|
// Store this locale under the Bedrock locale so we don't need to do this check over and over
|
|
|
|
bedrockLocale = "nb_no";
|
|
|
|
}
|
|
|
|
|
2020-04-08 20:11:56 +00:00
|
|
|
// Insert the locale into the mappings
|
2021-09-29 18:49:20 +00:00
|
|
|
LOCALE_MAPPINGS.put(bedrockLocale, langMap);
|
2021-01-12 20:06:48 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
localeStream.close();
|
|
|
|
} catch (IOException e) {
|
|
|
|
throw new AssertionError(LanguageUtils.getLocaleStringLog("geyser.locale.fail.file", locale, e.getMessage()));
|
|
|
|
}
|
2020-04-08 20:11:56 +00:00
|
|
|
} else {
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().warning(LanguageUtils.getLocaleStringLog("geyser.locale.fail.missing", locale));
|
2020-04-08 20:11:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 05:28:44 +00:00
|
|
|
/**
|
|
|
|
* Download then en_us locale by downloading the server jar and extracting it from there.
|
|
|
|
*
|
|
|
|
* @param localeFile File to save the locale to
|
|
|
|
*/
|
2020-04-09 13:36:32 +00:00
|
|
|
private static void downloadEN_US(File localeFile) {
|
|
|
|
try {
|
|
|
|
// Let the user know we are downloading the JAR
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().info(LanguageUtils.getLocaleStringLog("geyser.locale.download.en_us"));
|
|
|
|
GeyserImpl.getInstance().getLogger().debug("Download URL: " + clientJarInfo.getUrl());
|
2020-04-09 13:36:32 +00:00
|
|
|
|
|
|
|
// Download the smallest JAR (client or server)
|
2021-11-20 21:34:30 +00:00
|
|
|
Path tmpFilePath = GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("tmp_locale.jar");
|
2020-11-16 23:57:57 +00:00
|
|
|
WebUtils.downloadFile(clientJarInfo.getUrl(), tmpFilePath.toString());
|
2020-04-09 13:36:32 +00:00
|
|
|
|
|
|
|
// Load in the JAR as a zip and extract the file
|
2021-02-16 21:25:46 +00:00
|
|
|
try (ZipFile localeJar = new ZipFile(tmpFilePath.toString())) {
|
|
|
|
try (InputStream fileStream = localeJar.getInputStream(localeJar.getEntry("assets/minecraft/lang/en_us.json"))) {
|
|
|
|
try (FileOutputStream outStream = new FileOutputStream(localeFile)) {
|
|
|
|
|
|
|
|
// Write the file to the locale dir
|
|
|
|
byte[] buf = new byte[fileStream.available()];
|
|
|
|
int length;
|
|
|
|
while ((length = fileStream.read(buf)) != -1) {
|
|
|
|
outStream.write(buf, 0, length);
|
|
|
|
}
|
2020-04-09 13:36:32 +00:00
|
|
|
|
2021-02-16 21:25:46 +00:00
|
|
|
// Flush all changes to disk and cleanup
|
|
|
|
outStream.flush();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-04-09 13:36:32 +00:00
|
|
|
|
2020-11-16 23:57:57 +00:00
|
|
|
// Store the latest jar hash
|
2021-11-20 21:34:30 +00:00
|
|
|
FileUtils.writeFile(GeyserImpl.getInstance().getBootstrap().getConfigFolder().resolve("locales/en_us.hash").toString(), clientJarInfo.getSha1().toCharArray());
|
2020-11-16 23:57:57 +00:00
|
|
|
|
2020-04-09 13:36:32 +00:00
|
|
|
// Delete the nolonger needed client/server jar
|
2020-06-20 17:54:40 +00:00
|
|
|
Files.delete(tmpFilePath);
|
2021-09-11 01:12:12 +00:00
|
|
|
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().info(LanguageUtils.getLocaleStringLog("geyser.locale.download.en_us.done"));
|
2020-04-09 13:36:32 +00:00
|
|
|
} catch (Exception e) {
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().error(LanguageUtils.getLocaleStringLog("geyser.locale.fail.en_us"), e);
|
2020-04-09 13:36:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-21 05:28:44 +00:00
|
|
|
/**
|
|
|
|
* Translate the given language string into the given locale, or falls back to the default locale
|
|
|
|
*
|
|
|
|
* @param messageText Language string to translate
|
|
|
|
* @param locale Locale to translate to
|
|
|
|
* @return Translated string or the original message if it was not found in the given locale
|
|
|
|
*/
|
2020-04-08 20:11:56 +00:00
|
|
|
public static String getLocaleString(String messageText, String locale) {
|
|
|
|
Map<String, String> localeStrings = LocaleUtils.LOCALE_MAPPINGS.get(locale.toLowerCase());
|
2020-09-01 22:29:53 +00:00
|
|
|
if (localeStrings == null) {
|
2020-11-12 00:28:45 +00:00
|
|
|
localeStrings = LocaleUtils.LOCALE_MAPPINGS.get(LanguageUtils.getDefaultLocale());
|
|
|
|
if (localeStrings == null) {
|
|
|
|
// Don't cause a NPE if the locale is STILL missing
|
2021-11-20 21:34:30 +00:00
|
|
|
GeyserImpl.getInstance().getLogger().debug("MISSING DEFAULT LOCALE: " + LanguageUtils.getDefaultLocale());
|
2020-11-12 00:28:45 +00:00
|
|
|
return messageText;
|
|
|
|
}
|
2020-09-01 22:29:53 +00:00
|
|
|
}
|
2020-04-08 20:11:56 +00:00
|
|
|
|
|
|
|
return localeStrings.getOrDefault(messageText, messageText);
|
|
|
|
}
|
|
|
|
|
2020-11-16 23:57:57 +00:00
|
|
|
/**
|
|
|
|
* Convert a byte array into a hex string
|
|
|
|
*
|
|
|
|
* @param b Byte array to convert
|
|
|
|
* @return The hex representation of the given byte array
|
|
|
|
*/
|
|
|
|
private static String byteArrayToHexString(byte[] b) {
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
|
|
for (byte value : b) {
|
|
|
|
result.append(Integer.toString((value & 0xff) + 0x100, 16).substring(1));
|
|
|
|
}
|
|
|
|
return result.toString();
|
|
|
|
}
|
|
|
|
|
2020-04-08 20:11:56 +00:00
|
|
|
public static void init() {
|
|
|
|
// no-op
|
|
|
|
}
|
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
|
|
@Getter
|
|
|
|
static class VersionManifest {
|
|
|
|
@JsonProperty("latest")
|
|
|
|
private LatestVersion latestVersion;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("versions")
|
|
|
|
private List<Version> versions;
|
|
|
|
}
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
|
|
@Getter
|
|
|
|
static class LatestVersion {
|
|
|
|
@JsonProperty("release")
|
|
|
|
private String release;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("snapshot")
|
|
|
|
private String snapshot;
|
|
|
|
}
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
|
|
@Getter
|
|
|
|
static class Version {
|
|
|
|
@JsonProperty("id")
|
|
|
|
private String id;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("type")
|
|
|
|
private String type;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("url")
|
|
|
|
private String url;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("time")
|
|
|
|
private String time;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("releaseTime")
|
|
|
|
private String releaseTime;
|
|
|
|
}
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
|
|
@Getter
|
|
|
|
static class VersionInfo {
|
|
|
|
@JsonProperty("id")
|
|
|
|
private String id;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("type")
|
|
|
|
private String type;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("time")
|
|
|
|
private String time;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("releaseTime")
|
|
|
|
private String releaseTime;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("assetIndex")
|
|
|
|
private AssetIndex assetIndex;
|
2020-04-09 13:36:32 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("downloads")
|
|
|
|
private Map<String, VersionDownload> downloads;
|
|
|
|
}
|
2020-04-09 13:36:32 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
|
|
@Getter
|
|
|
|
static class VersionDownload {
|
|
|
|
@JsonProperty("sha1")
|
|
|
|
private String sha1;
|
2020-04-09 13:36:32 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("size")
|
|
|
|
private int size;
|
2020-04-09 13:36:32 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("url")
|
|
|
|
private String url;
|
|
|
|
}
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
|
|
@Getter
|
|
|
|
static class AssetIndex {
|
|
|
|
@JsonProperty("id")
|
|
|
|
private String id;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("sha1")
|
|
|
|
private String sha1;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("size")
|
|
|
|
private int size;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("totalSize")
|
|
|
|
private int totalSize;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("url")
|
|
|
|
private String url;
|
|
|
|
}
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
|
|
|
@Getter
|
|
|
|
static class Asset {
|
|
|
|
@JsonProperty("hash")
|
|
|
|
private String hash;
|
2020-04-08 20:11:56 +00:00
|
|
|
|
2021-07-18 20:20:40 +00:00
|
|
|
@JsonProperty("size")
|
|
|
|
private int size;
|
|
|
|
}
|
2020-06-27 05:58:52 +00:00
|
|
|
}
|