Advertisement
Guest User

Untitled

a guest
May 31st, 2023
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.86 KB | None | 0 0
  1. package pw.neynq.plugin.Initializers;
  2.  
  3. import org.bukkit.event.Listener;
  4.  
  5. import pw.neynq.plugin.Plugin;
  6. import com.google.common.reflect.ClassPath;
  7. import com.google.common.reflect.ClassPath.ClassInfo;
  8.  
  9. public class EventInit {
  10.     public static void init() {
  11.         try {
  12.             ClassPath cp = ClassPath.from(CommandInit.class.getClassLoader());
  13.             for (ClassInfo classInfo : cp.getTopLevelClassesRecursive("pw.neynq.plugin.Events")) {
  14.                 Class<?> clazz = Class.forName(classInfo.getName());
  15.                 try {
  16.                     if (Listener.class.isAssignableFrom(clazz)) {
  17.                         Listener event = (Listener) clazz.getDeclaredConstructor().newInstance();
  18.                         Plugin.plugin.getServer().getPluginManager().registerEvents(event, Plugin.plugin);
  19.                     }
  20.                 } catch (Exception e) {
  21.                     e.printStackTrace();
  22.                 }
  23.             }
  24.         } catch (Exception e) {
  25.             e.printStackTrace();
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement