forked from GeyserMC/Geyser
Fix en_us locale downloading (#809)
Fixes occasional inventories not working because of being unable to read the locale.
This commit is contained in:
parent
d516dc5b90
commit
5b147f8dd1
1 changed files with 22 additions and 21 deletions
|
@ -28,6 +28,7 @@ package org.geysermc.connector.utils;
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
import com.fasterxml.jackson.databind.JsonNode;
|
import com.fasterxml.jackson.databind.JsonNode;
|
||||||
|
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.geysermc.connector.GeyserConnector;
|
import org.geysermc.connector.GeyserConnector;
|
||||||
|
|
||||||
|
@ -35,7 +36,10 @@ import java.io.*;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.zip.ZipFile;
|
import java.util.zip.ZipFile;
|
||||||
|
|
||||||
public class LocaleUtils {
|
public class LocaleUtils {
|
||||||
|
@ -70,7 +74,7 @@ public class LocaleUtils {
|
||||||
// Get the url for the latest version of the games manifest
|
// Get the url for the latest version of the games manifest
|
||||||
String latestInfoURL = "";
|
String latestInfoURL = "";
|
||||||
for (Version version : versionManifest.getVersions()) {
|
for (Version version : versionManifest.getVersions()) {
|
||||||
if (version.getId().equals(versionManifest.getLatestVersion().getRelease())) {
|
if (version.getId().equals(MinecraftConstants.GAME_VERSION)) {
|
||||||
latestInfoURL = version.getUrl();
|
latestInfoURL = version.getUrl();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -84,14 +88,11 @@ public class LocaleUtils {
|
||||||
// Get the individual version manifest
|
// Get the individual version manifest
|
||||||
VersionInfo versionInfo = GeyserConnector.JSON_MAPPER.readValue(WebUtils.getBody(latestInfoURL), VersionInfo.class);
|
VersionInfo versionInfo = GeyserConnector.JSON_MAPPER.readValue(WebUtils.getBody(latestInfoURL), VersionInfo.class);
|
||||||
|
|
||||||
// Get the smallest jar for use when downloading the en_us locale, will be either the server or client
|
// Get the client jar for use when downloading the en_us locale
|
||||||
int currentSize = Integer.MAX_VALUE;
|
GeyserConnector.getInstance().getLogger().debug(GeyserConnector.JSON_MAPPER.writeValueAsString(versionInfo.getDownloads()));
|
||||||
for (VersionDownload download : versionInfo.getDownloads().values()) {
|
VersionDownload download = versionInfo.getDownloads().get("client");
|
||||||
if (download.getUrl().endsWith(".jar") && download.getSize() < currentSize) {
|
GeyserConnector.getInstance().getLogger().debug(GeyserConnector.JSON_MAPPER.writeValueAsString(download));
|
||||||
smallestURL = download.getUrl();
|
smallestURL = download.getUrl();
|
||||||
currentSize = download.getSize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the assets list
|
// Get the assets list
|
||||||
JsonNode assets = GeyserConnector.JSON_MAPPER.readTree(WebUtils.getBody(versionInfo.getAssetIndex().getUrl())).get("objects");
|
JsonNode assets = GeyserConnector.JSON_MAPPER.readTree(WebUtils.getBody(versionInfo.getAssetIndex().getUrl())).get("objects");
|
||||||
|
@ -160,7 +161,7 @@ public class LocaleUtils {
|
||||||
* @param locale Locale to load
|
* @param locale Locale to load
|
||||||
*/
|
*/
|
||||||
private static void loadLocale(String locale) {
|
private static void loadLocale(String locale) {
|
||||||
File localeFile = new File("locales/" + locale + ".json");
|
File localeFile = GeyserConnector.getInstance().getBootstrap().getConfigFolder().resolve("locales/" + locale + ".json").toFile();
|
||||||
|
|
||||||
// Load the locale
|
// Load the locale
|
||||||
if (localeFile.exists()) {
|
if (localeFile.exists()) {
|
||||||
|
@ -212,21 +213,21 @@ public class LocaleUtils {
|
||||||
|
|
||||||
// Load in the JAR as a zip and extract the file
|
// Load in the JAR as a zip and extract the file
|
||||||
ZipFile localeJar = new ZipFile(tmpFilePath.toString());
|
ZipFile localeJar = new ZipFile(tmpFilePath.toString());
|
||||||
InputStream inputStream = localeJar.getInputStream(localeJar.getEntry("assets/minecraft/lang/en_us.json"));
|
InputStream fileStream = localeJar.getInputStream(localeJar.getEntry("assets/minecraft/lang/en_us.json"));
|
||||||
FileOutputStream outputStream = new FileOutputStream(localeFile);
|
FileOutputStream outStream = new FileOutputStream(localeFile);
|
||||||
|
|
||||||
// Write the file to the locale dir
|
// Write the file to the locale dir
|
||||||
int data = inputStream.read();
|
byte[] buf = new byte[fileStream.available()];
|
||||||
while(data != -1){
|
int length;
|
||||||
outputStream.write(data);
|
while ((length = fileStream.read(buf)) != -1) {
|
||||||
data = inputStream.read();
|
outStream.write(buf, 0, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Flush all changes to disk and cleanup
|
// Flush all changes to disk and cleanup
|
||||||
outputStream.flush();
|
outStream.flush();
|
||||||
outputStream.close();
|
outStream.close();
|
||||||
|
|
||||||
inputStream.close();
|
fileStream.close();
|
||||||
localeJar.close();
|
localeJar.close();
|
||||||
|
|
||||||
// Delete the nolonger needed client/server jar
|
// Delete the nolonger needed client/server jar
|
||||||
|
@ -357,4 +358,4 @@ class Asset {
|
||||||
|
|
||||||
@JsonProperty("size")
|
@JsonProperty("size")
|
||||||
private int size;
|
private int size;
|
||||||
}
|
}
|
Loading…
Reference in a new issue