mirror of
https://github.com/Anuken/Mindustry.git
synced 2024-09-11 08:15:35 +03:00
Removed useless code from ScriptMainGenerator
This commit is contained in:
parent
ef83af5f15
commit
b5db3ca6af
@ -18,9 +18,6 @@ import mindustry.world.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
|
||||
public class ScriptMainGenerator{
|
||||
|
||||
@ -116,53 +113,7 @@ public class ScriptMainGenerator{
|
||||
}
|
||||
|
||||
public static Seq<Class> getClasses(String packageName) throws Exception{
|
||||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
|
||||
|
||||
Seq<File> dirs = new Seq<>();
|
||||
|
||||
for(URL resource : Collections.list(classLoader.getResources(packageName.replace('.', '/')))){
|
||||
dirs.add(new File(resource.getFile()));
|
||||
}
|
||||
|
||||
Seq<Class> classes = new Seq<>();
|
||||
for(File directory : dirs){
|
||||
classes.addAll(findClasses(directory, packageName));
|
||||
}
|
||||
return classes;
|
||||
}
|
||||
|
||||
public static Seq<Class> findClasses(File directory, String packageName) throws Exception{
|
||||
Seq<Class> classes = new Seq<>();
|
||||
String dir = directory.toString();
|
||||
if(dir.startsWith("file:")){
|
||||
directory = new File(dir.substring("file:".length()).replace("!/arc", "").replace("!/mindustry", ""));
|
||||
}
|
||||
if(!directory.exists()) return classes;
|
||||
|
||||
if(directory.getName().endsWith(".jar")){
|
||||
ZipInputStream zip = new ZipInputStream(new FileInputStream(directory));
|
||||
for(ZipEntry entry = zip.getNextEntry(); entry != null; entry = zip.getNextEntry()){
|
||||
if(!entry.isDirectory() && entry.getName().endsWith(".class")){
|
||||
String className = entry.getName().replace('/', '.');
|
||||
className = className.substring(0, className.length() - ".class".length());
|
||||
if(className.startsWith(packageName)){
|
||||
Class res = Class.forName(className, false, Thread.currentThread().getContextClassLoader());
|
||||
classes.add(res);
|
||||
//classes.addAll(res.getDeclaredClasses()); //????
|
||||
}
|
||||
}
|
||||
}
|
||||
}else{
|
||||
File[] files = directory.listFiles();
|
||||
for(File file : files){
|
||||
if(file.isDirectory()){
|
||||
classes.addAll(findClasses(file, packageName + "." + file.getName()));
|
||||
}else if(file.getName().endsWith(".class")){
|
||||
classes.add(Class.forName(packageName + '.' + file.getName().substring(0, file.getName().length() - 6), false, Thread.currentThread().getContextClassLoader()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return classes;
|
||||
//TODO doesn't work, a java release broke it, look into alternative solutions (or just don't, Javascript modding is a bad idea anyway)
|
||||
return new Seq<>();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user