mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-11-15 11:39:11 +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.URL;
|
||||||
import java.net.URLClassLoader;
|
import java.net.URLClassLoader;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ClientClassLoader extends URLClassLoader {
|
public class ClientClassLoader extends URLClassLoader {
|
||||||
private static final ClassLoader SYSTEM_CLASS_LOADER = ClassLoader.getSystemClassLoader();
|
private static final ClassLoader SYSTEM_CLASS_LOADER = ClassLoader.getSystemClassLoader();
|
||||||
public String nativePath;
|
public String nativePath;
|
||||||
|
|
||||||
|
private List<String> packages = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new URLClassLoader for the specified URLs using the
|
* Constructs a new URLClassLoader for the specified URLs using the
|
||||||
* default delegation parent {@code ClassLoader}. The URLs will
|
* default delegation parent {@code ClassLoader}. The URLs will
|
||||||
|
@ -32,6 +36,8 @@ public class ClientClassLoader extends URLClassLoader {
|
||||||
*/
|
*/
|
||||||
public ClientClassLoader(URL[] urls) {
|
public ClientClassLoader(URL[] urls) {
|
||||||
super(urls);
|
super(urls);
|
||||||
|
packages.add("pro.gravit.launcher.");
|
||||||
|
packages.add("pro.gravit.utils.");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,8 +67,12 @@ public ClientClassLoader(URL[] urls, ClassLoader parent) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
|
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) {
|
||||||
return SYSTEM_CLASS_LOADER.loadClass(name);
|
for(String pkg : packages) {
|
||||||
|
if(name.startsWith(pkg)) {
|
||||||
|
return SYSTEM_CLASS_LOADER.loadClass(name);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return super.loadClass(name, resolve);
|
return super.loadClass(name, resolve);
|
||||||
}
|
}
|
||||||
|
@ -90,6 +100,10 @@ else if (JVMHelper.OS_TYPE == JVMHelper.OS.MACOSX)
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addAllowedPackage(String pkg) {
|
||||||
|
packages.add(pkg);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addURL(URL url) {
|
public void addURL(URL url) {
|
||||||
super.addURL(url);
|
super.addURL(url);
|
||||||
|
|
Loading…
Reference in a new issue