forked from GeyserMC/Geyser
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:
parent
1a08e1104d
commit
1c7567d79d
2 changed files with 12 additions and 7 deletions
|
@ -36,6 +36,7 @@ import org.reflections.util.ConfigurationBuilder;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
@ -62,7 +63,8 @@ public class FileUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T loadJson(InputStream src, Class<T> valueType) throws IOException {
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class ResourcePack {
|
||||||
// As we just created the directory it will be empty
|
// As we just created the directory it will be empty
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (File file : directory.listFiles()) {
|
for (File file : directory.listFiles()) {
|
||||||
if (file.getName().endsWith(".zip") || file.getName().endsWith(".mcpack")) {
|
if (file.getName().endsWith(".zip") || file.getName().endsWith(".mcpack")) {
|
||||||
ResourcePack pack = new ResourcePack();
|
ResourcePack pack = new ResourcePack();
|
||||||
|
@ -77,12 +77,15 @@ public class ResourcePack {
|
||||||
if (x.getName().contains("manifest.json")) {
|
if (x.getName().contains("manifest.json")) {
|
||||||
try {
|
try {
|
||||||
ResourcePackManifest manifest = FileUtils.loadJson(zip.getInputStream(x), ResourcePackManifest.class);
|
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());
|
||||||
|
|
||||||
pack.file = file;
|
PACKS.put(pack.getManifest().getHeader().getUuid().toString(), pack);
|
||||||
pack.manifest = manifest;
|
}
|
||||||
pack.version = ResourcePackManifest.Version.fromArray(manifest.getHeader().getVersion());
|
|
||||||
|
|
||||||
PACKS.put(pack.getManifest().getHeader().getUuid().toString(), pack);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue