@@ -30,11 +30,22 @@ public class BukkitClassSourceLookup extends ClassSourceLookup.ByClassLoader {
3030 private static final Class <?> PLUGIN_CLASS_LOADER ;
3131 private static final Field PLUGIN_FIELD ;
3232
33+ private static final Class <?> PAPER_PLUGIN_CLASS_LOADER ;
34+ private static final Field PAPER_PLUGIN_FIELD ;
35+
3336 static {
3437 try {
3538 PLUGIN_CLASS_LOADER = Class .forName ("org.bukkit.plugin.java.PluginClassLoader" );
3639 PLUGIN_FIELD = PLUGIN_CLASS_LOADER .getDeclaredField ("plugin" );
3740 PLUGIN_FIELD .setAccessible (true );
41+
42+ PAPER_PLUGIN_CLASS_LOADER = getPaperPluginClassLoader ();
43+ if (PAPER_PLUGIN_CLASS_LOADER != null ) {
44+ PAPER_PLUGIN_FIELD = PAPER_PLUGIN_CLASS_LOADER .getDeclaredField ("loadedJavaPlugin" );
45+ PAPER_PLUGIN_FIELD .setAccessible (true );
46+ } else {
47+ PAPER_PLUGIN_FIELD = null ;
48+ }
3849 } catch (ReflectiveOperationException e ) {
3950 throw new ExceptionInInitializerError (e );
4051 }
@@ -45,8 +56,19 @@ public String identify(ClassLoader loader) throws ReflectiveOperationException {
4556 if (PLUGIN_CLASS_LOADER .isInstance (loader )) {
4657 JavaPlugin plugin = (JavaPlugin ) PLUGIN_FIELD .get (loader );
4758 return plugin .getName ();
59+ } else if (PAPER_PLUGIN_CLASS_LOADER != null && PAPER_PLUGIN_CLASS_LOADER .isInstance (loader )) {
60+ JavaPlugin plugin = (JavaPlugin ) PAPER_PLUGIN_FIELD .get (loader );
61+ return plugin .getName ();
4862 }
4963 return null ;
5064 }
65+
66+ private static Class <?> getPaperPluginClassLoader () {
67+ try {
68+ return Class .forName ("io.papermc.paper.plugin.entrypoint.classloader.PaperPluginClassLoader" );
69+ } catch (ClassNotFoundException e ) {
70+ return null ;
71+ }
72+ }
5173}
5274
0 commit comments