Changed code around to support possibly a method that adds all subpackages within the given package
@@ -11,17 +11,27 @@ import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
+import java.util.Set;
/**
* Created on 5/16/2017 by fr1kin
*/
public class ForgeHaxModLoader implements Globals {
- @SuppressWarnings("unchecked")
+
public static Collection<Class<? extends BaseMod>> getClassesInPackage(String pack) {
- final List<Class<? extends BaseMod>> classes = Lists.newArrayList();
try {
ClassPath classPath = ClassPath.from(getClassLoader());
- classPath.getTopLevelClasses(pack).forEach(info -> {
+ return filterClasses(classPath.getTopLevelClasses(pack));
+ } catch (IOException e) {
+ Helper.handleThrowable(e);
+ }
+ return Collections.emptyList();
+ }
+
+ @SuppressWarnings("unchecked")
+ private static Collection<Class<? extends BaseMod>> filterClasses(Set<ClassPath.ClassInfo> input) {
+ final List<Class<? extends BaseMod>> classes = Lists.newArrayList();
+ input.forEach(info -> {
try {
Class<?> clazz = info.load();
if(clazz.isAnnotationPresent(RegisterMod.class)
@@ -34,9 +44,6 @@ public class ForgeHaxModLoader implements Globals {
Helper.getLog().warn(String.format("[%s] '%s' is not a valid mod class: %s", e.getClass().getSimpleName(), info.getSimpleName(), e.getMessage()));
}
});
- } catch (IOException e) {
- e.printStackTrace();
- }
return Collections.unmodifiableCollection(classes);
}
