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
e81c6f21bf
commit
61bfd46a15
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.JsonProperty;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.github.steveice10.mc.protocol.MinecraftConstants;
|
||||
import lombok.Getter;
|
||||
import org.geysermc.connector.GeyserConnector;
|
||||
|
||||
|
@ -35,7 +36,10 @@ import java.io.*;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
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;
|
||||
|
||||
public class LocaleUtils {
|
||||
|
@ -70,7 +74,7 @@ public class LocaleUtils {
|
|||
// Get the url for the latest version of the games manifest
|
||||
String latestInfoURL = "";
|
||||
for (Version version : versionManifest.getVersions()) {
|
||||
if (version.getId().equals(versionManifest.getLatestVersion().getRelease())) {
|
||||
if (version.getId().equals(MinecraftConstants.GAME_VERSION)) {
|
||||
latestInfoURL = version.getUrl();
|
||||
break;
|
||||
}
|
||||
|
@ -84,14 +88,11 @@ public class LocaleUtils {
|
|||
// Get the individual version manifest
|
||||
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
|
||||
int currentSize = Integer.MAX_VALUE;
|
||||
for (VersionDownload download : versionInfo.getDownloads().values()) {
|
||||
if (download.getUrl().endsWith(".jar") && download.getSize() < currentSize) {
|
||||
// Get the client jar for use when downloading the en_us locale
|
||||
GeyserConnector.getInstance().getLogger().debug(GeyserConnector.JSON_MAPPER.writeValueAsString(versionInfo.getDownloads()));
|
||||
VersionDownload download = versionInfo.getDownloads().get("client");
|
||||
GeyserConnector.getInstance().getLogger().debug(GeyserConnector.JSON_MAPPER.writeValueAsString(download));
|
||||
smallestURL = download.getUrl();
|
||||
currentSize = download.getSize();
|
||||
}
|
||||
}
|
||||
|
||||
// Get the assets list
|
||||
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
|
||||
*/
|
||||
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
|
||||
if (localeFile.exists()) {
|
||||
|
@ -212,21 +213,21 @@ public class LocaleUtils {
|
|||
|
||||
// Load in the JAR as a zip and extract the file
|
||||
ZipFile localeJar = new ZipFile(tmpFilePath.toString());
|
||||
InputStream inputStream = localeJar.getInputStream(localeJar.getEntry("assets/minecraft/lang/en_us.json"));
|
||||
FileOutputStream outputStream = new FileOutputStream(localeFile);
|
||||
InputStream fileStream = localeJar.getInputStream(localeJar.getEntry("assets/minecraft/lang/en_us.json"));
|
||||
FileOutputStream outStream = new FileOutputStream(localeFile);
|
||||
|
||||
// Write the file to the locale dir
|
||||
int data = inputStream.read();
|
||||
while(data != -1){
|
||||
outputStream.write(data);
|
||||
data = inputStream.read();
|
||||
byte[] buf = new byte[fileStream.available()];
|
||||
int length;
|
||||
while ((length = fileStream.read(buf)) != -1) {
|
||||
outStream.write(buf, 0, length);
|
||||
}
|
||||
|
||||
// Flush all changes to disk and cleanup
|
||||
outputStream.flush();
|
||||
outputStream.close();
|
||||
outStream.flush();
|
||||
outStream.close();
|
||||
|
||||
inputStream.close();
|
||||
fileStream.close();
|
||||
localeJar.close();
|
||||
|
||||
// Delete the nolonger needed client/server jar
|
||||
|
|
Loading…
Reference in a new issue