refactor: get mappings from jar rather than file

This commit is contained in:
Sculas 2024-03-20 18:19:45 +01:00
parent 6e12d17cd4
commit f48c48e6e5
No known key found for this signature in database
GPG Key ID: 1530BFF96D1EEB89
1 changed files with 89 additions and 93 deletions

View File

@ -214,19 +214,15 @@ public final class Limbo {
internalDataFolder.mkdirs();
}
String mappingName = "mapping.json";
File mappingFile = new File(internalDataFolder, mappingName);
if (!mappingFile.exists()) {
try (InputStream in = getClass().getClassLoader().getResourceAsStream(mappingName)) {
Files.copy(in, mappingFile.toPath());
} catch (IOException e) {
e.printStackTrace();
}
}
console.sendMessage("Loading packet id mappings from mapping.json ...");
InputStreamReader reader = new InputStreamReader(Files.newInputStream(mappingFile.toPath()), StandardCharsets.UTF_8);
InputStream mappingStream = getClass().getClassLoader().getResourceAsStream("mapping.json");
if (mappingStream == null) {
console.sendMessage("Failed to load mapping.json from jar!");
System.exit(1);
}
InputStreamReader reader = new InputStreamReader(mappingStream, StandardCharsets.UTF_8);
JSONObject json = (JSONObject) new JSONParser().parse(reader);
reader.close();