Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void launch(int type, Object... o) {
- if (!Plugin.pluginsList.isEmpty()) {
- Plugin.pluginsList.forEach((Plugin plugin) -> {
- try {
- URLClassLoader ucl = new URLClassLoader(new URL[]{plugin.getDirectory()});
- Class<?> addonsMain = plugin.getMainClass();
- Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) ucl.loadClass("craftz.api.EventHandler");
- for (Method m : addonsMain.getMethods()) {
- if (m.isAnnotationPresent(annotationClass)) {
- Annotation annotation = m.getAnnotation(annotationClass);
- Method fieldInAnnotation = annotationClass.getMethod("type", (Class[]) null);
- int typeOfMethod = (int) fieldInAnnotation.invoke(annotation, (Object[]) null);
- if (typeOfMethod == type) {
- m.invoke(addonsMain.newInstance(), (Object[]) null);
- if (typeOfMethod < 0) {
- m.invoke(addonsMain.newInstance(), o[0]);
- }
- }
- }
- }
- } catch (ClassNotFoundException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | InvocationTargetException ex) {
- Logger.getLogger(PluginsLoader.class.getName()).log(Level.SEVERE, null, ex);
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement