[FEATURE] Isolate Minecraft: Support add packages to ignore

This commit is contained in:
Gravita 2023-02-26 18:40:11 +07:00
parent bd4e454be9
commit ffad29f53b

View file

@ -5,11 +5,15 @@
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
public class ClientClassLoader extends URLClassLoader {
private static final ClassLoader SYSTEM_CLASS_LOADER = ClassLoader.getSystemClassLoader();
public String nativePath;
private List<String> packages = new ArrayList<>();
/**
* Constructs a new URLClassLoader for the specified URLs using the
* default delegation parent {@code ClassLoader}. The URLs will
@ -32,6 +36,8 @@ public class ClientClassLoader extends URLClassLoader {
*/
public ClientClassLoader(URL[] urls) {
super(urls);
packages.add("pro.gravit.launcher.");
packages.add("pro.gravit.utils.");
}
/**
@ -61,9 +67,13 @@ public ClientClassLoader(URL[] urls, ClassLoader parent) {
@Override
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
if(name != null && (name.startsWith("pro.gravit.launcher.") || name.startsWith("pro.gravit.utils."))) {
if(name != null) {
for(String pkg : packages) {
if(name.startsWith(pkg)) {
return SYSTEM_CLASS_LOADER.loadClass(name);
}
}
}
return super.loadClass(name, resolve);
}
@ -90,6 +100,10 @@ else if (JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX)
return "";
}
public void addAllowedPackage(String pkg) {
packages.add(pkg);
}
@Override
public void addURL(URL url) {
super.addURL(url);