mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 03:31:15 +03:00
[FEATURE] Isolate Minecraft: Support add packages to ignore
This commit is contained in:
parent
bd4e454be9
commit
ffad29f53b
1 changed files with 16 additions and 2 deletions
|
@ -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,8 +67,12 @@ 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."))) {
|
||||
return SYSTEM_CLASS_LOADER.loadClass(name);
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue