Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.63 KB | None | 0 0
  1.  public void launch(int type, Object... o) {
  2.         if (!Plugin.pluginsList.isEmpty()) {
  3.             Plugin.pluginsList.forEach((Plugin plugin) -> {
  4.                 try {
  5.                     URLClassLoader ucl = new URLClassLoader(new URL[]{plugin.getDirectory()});
  6.                     Class<?> addonsMain = plugin.getMainClass();
  7.                     Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) ucl.loadClass("craftz.api.EventHandler");
  8.                     for (Method m : addonsMain.getMethods()) {
  9.                         if (m.isAnnotationPresent(annotationClass)) {
  10.                             Annotation annotation = m.getAnnotation(annotationClass);
  11.                             Method fieldInAnnotation = annotationClass.getMethod("type", (Class[]) null);
  12.                             int typeOfMethod = (int) fieldInAnnotation.invoke(annotation, (Object[]) null);
  13.                             if (typeOfMethod == type) {
  14.                                 m.invoke(addonsMain.newInstance(), (Object[]) null);
  15.                                 if (typeOfMethod < 0) {
  16.                                     m.invoke(addonsMain.newInstance(), o[0]);
  17.                                 }
  18.                             }
  19.                         }
  20.                     }
  21.                 } catch (ClassNotFoundException | SecurityException | InstantiationException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | InvocationTargetException ex) {
  22.                     Logger.getLogger(PluginsLoader.class.getName()).log(Level.SEVERE, null, ex);
  23.                 }
  24.             });
  25.         }
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement