Various resource pack fixes (#1769)

- Fixes an instance where an invalid pack_manifest file could be present
- Fixes instances where JSON files were not read as UTF-8
This commit is contained in:
Camotoy 2021-01-03 12:53:26 -05:00 committed by GitHub
parent 1a08e1104d
commit 1c7567d79d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View file

@ -36,6 +36,7 @@ import org.reflections.util.ConfigurationBuilder;
import java.io.*;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.security.MessageDigest;
import java.util.function.Function;
@ -62,7 +63,8 @@ public class FileUtils {
}
public static <T> T loadJson(InputStream src, Class<T> valueType) throws IOException {
return GeyserConnector.JSON_MAPPER.readValue(src, valueType);
// Read specifically with UTF-8 to allow any non-UTF-encoded JSON to read
return GeyserConnector.JSON_MAPPER.readValue(new InputStreamReader(src, StandardCharsets.UTF_8), valueType);
}
/**

View file

@ -77,12 +77,15 @@ public class ResourcePack {
if (x.getName().contains("manifest.json")) {
try {
ResourcePackManifest manifest = FileUtils.loadJson(zip.getInputStream(x), ResourcePackManifest.class);
// Sometimes a pack_manifest file is present and not in a valid format,
// but a manifest file is, so we null check through that one
if (manifest.getHeader().getUuid() != null) {
pack.file = file;
pack.manifest = manifest;
pack.version = ResourcePackManifest.Version.fromArray(manifest.getHeader().getVersion());
PACKS.put(pack.getManifest().getHeader().getUuid().toString(), pack);
}
} catch (Exception e) {
e.printStackTrace();
}