mirror of
https://github.com/PlaceholderAPI/PlaceholderAPI
synced 2024-11-18 00:46:55 +01:00
updated fileutil to load *vomit* all classes, closes #381
This commit is contained in:
parent
1993b2cd82
commit
134086f6a9
@ -27,6 +27,8 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarEntry;
|
||||
import java.util.jar.JarInputStream;
|
||||
|
||||
@ -43,7 +45,11 @@ public class FileUtil
|
||||
|
||||
final URL jar = file.toURI().toURL();
|
||||
|
||||
try (final URLClassLoader loader = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader()); final JarInputStream stream = new JarInputStream(jar.openStream()))
|
||||
final List<String> matches = new ArrayList<>();
|
||||
final List<Class<? extends T>> classes = new ArrayList<>();
|
||||
|
||||
|
||||
try (final JarInputStream stream = new JarInputStream(jar.openStream()); final URLClassLoader loader = new URLClassLoader(new URL[]{jar}, clazz.getClassLoader()))
|
||||
{
|
||||
JarEntry entry;
|
||||
while ((entry = stream.getNextJarEntry()) != null)
|
||||
@ -54,21 +60,25 @@ public class FileUtil
|
||||
continue;
|
||||
}
|
||||
|
||||
matches.add(name.substring(0, name.lastIndexOf('.')).replace('/', '.'));
|
||||
}
|
||||
|
||||
for (final String match : matches)
|
||||
{
|
||||
try
|
||||
{
|
||||
final Class<?> loaded = loader.loadClass(name.substring(0, name.lastIndexOf('.')).replace('/', '.'));
|
||||
final Class<?> loaded = loader.loadClass(match);
|
||||
if (clazz.isAssignableFrom(loaded))
|
||||
{
|
||||
return loaded.asSubclass(clazz);
|
||||
classes.add(loaded.asSubclass(clazz));
|
||||
}
|
||||
}
|
||||
catch (final NoClassDefFoundError ignored)
|
||||
{
|
||||
}
|
||||
{ }
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return classes.isEmpty() ? null : classes.get(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user