Fixed: nullable patches
This commit is contained in:
@@ -37,18 +37,24 @@ public class PatchPreLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void init() {
|
public void init() {
|
||||||
for(File patch : Objects.requireNonNull(patches.listFiles((dir, name) -> name.endsWith(".jar")))) {
|
if(!patches.exists() && !patches.mkdir()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final File[] files = patches.listFiles((dir, name) -> name.endsWith(".jar"));
|
||||||
|
if(files != null) {
|
||||||
|
for (File patch : files) {
|
||||||
try {
|
try {
|
||||||
final URLClassLoader mainLoader = new URLClassLoader(new URL[]{patch.toURL()});
|
final URLClassLoader mainLoader = new URLClassLoader(new URL[]{patch.toURL()});
|
||||||
final JSONObject description = new JSONObject(new String(mainLoader.getResourceAsStream("patch.json").readAllBytes()));
|
final JSONObject description = new JSONObject(new String(mainLoader.getResourceAsStream("patch.json").readAllBytes()));
|
||||||
|
|
||||||
final JSONArray list = description.optJSONArray("hooks", null);
|
final JSONArray list = description.optJSONArray("hooks", null);
|
||||||
if(list != null)
|
if (list != null)
|
||||||
for(int i = 0;i < list.length();i++)
|
for (int i = 0; i < list.length(); i++)
|
||||||
Main.INSTANCE.add(list.optString(i));
|
Main.INSTANCE.add(list.optString(i));
|
||||||
|
|
||||||
final String main = description.optString("main", null);
|
final String main = description.optString("main", null);
|
||||||
if(main != null) {
|
if (main != null) {
|
||||||
Class<?> clazz = mainLoader.loadClass(main);
|
Class<?> clazz = mainLoader.loadClass(main);
|
||||||
clazz.getMethod("onPreLoader").invoke(clazz.getConstructor().newInstance());
|
clazz.getMethod("onPreLoader").invoke(clazz.getConstructor().newInstance());
|
||||||
|
|
||||||
@@ -60,4 +66,5 @@ public class PatchPreLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user