Partial 7.0 merge - API preview

This commit is contained in:
Anuken
2021-06-02 11:08:08 -04:00
parent ea75a357ca
commit 28b235ef07
531 changed files with 12356 additions and 6286 deletions

View File

@@ -0,0 +1,35 @@
package mindustry.mod;
import arc.struct.*;
public class ModClassLoader extends ClassLoader{
private Seq<ClassLoader> children = new Seq<>();
private volatile boolean inChild = false;
public void addChild(ClassLoader child){
children.add(child);
}
@Override
protected synchronized Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException{
//always try the superclass first
try{
return super.loadClass(name, resolve);
}catch(ClassNotFoundException error){
//a child may try to delegate class loading to its parent, which is *this class loader* - do not let that happen
if(inChild) throw error;
int size = children.size;
//if it doesn't exist in the main class loader, try all the children
for(int i = 0; i < size; i++){
try{
inChild = true;
var out = children.get(i).loadClass(name);
inChild = false;
return out;
}catch(ClassNotFoundException ignored){
}
}
throw error;
}
}
}