Solved Adding event listener from groovy

Discussion in 'Plugin Development' started by regic, Apr 9, 2022.

  1. Offline



    I'm trying to add a simple login event listener from groovy, but it gives the error:

    java.lang.IllegalArgumentException: class LoginListener is not provided by class
        at ~[purpur-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.EventExecutor.create( ~[purpur-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at ~[purpur-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.SimplePluginManager.registerEvents( ~[purpur-api-1.18.1-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.plugin.PluginManager$ Source) ~[?:?]
        at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall( ~[bukkit-groovy-1-jar-with-dependencies.jar:?]
        at ~[bukkit-groovy-1-jar-with-dependencies.jar:?]
        at ~[bukkit-groovy-1-jar-with-dependencies.jar:?]
        at OnLogin.onLoad(on_login.groovy:34) ~[?:?]
    groovy script attached. OnLogin's onLoad is called when the plugin is loaded:
                LoadableScript script = (LoadableScript), binding);
                scripts.put(fullName, script);
                Bukkit.getLogger().info("Script loaded: " + fullName);
    Maybe java reflection doesn't work with groovy classes the way bukkit expects it to?

    One possible problem: groovy cannot export 2 classes from the same script, see

    Edit: even if I export only one class I get the same error

    I've found the problem. This is probably way too specific to be useful to anyone, but who knows...

    always set the return value of event handler functions to void. It won't always cause a problem if you don't but a warning explicitly says it is unsupported and will stop working in the future.

    Long version
    The problem is that groovy did not define the return value of the onLogin function as void, which meant the
    EventExecutor.create function tries to print a warning which includes the plugin's name. The problem is that it tries to find the plugin's name through the classloader (!) of the event handler class (see line 55 in the in purpur version 1.18.2):
               final plugin =;
               org.bukkit.Bukkit.getLogger().warning("@EventHandler method " + m.getDeclaringClass().getName() + (Modifier.isStatic(m.getModifiers()) ? '.' : '#') + m.getName()
                    + " returns non-void type " + m.getReturnType().getName() + ". This is unsupported behavior and will no longer work in a future version of Paper."
                    + " This should be reported to the developers of " + plugin.getDescription().getFullName() + " (" + String.join(",", plugin.getDescription().getAuthors()) + ')');
    Since the class was created in groovy, its classloader is GroovyClassLoader not JavaPluginClassLoader (which is normally used to load the classes inside a plugin). See line 427 in (purpur 1.18.2):
            final ClassLoader cl = clazz.getClassLoader();
            if (!(cl instanceof PluginClassLoader)) {
                throw new IllegalArgumentException(clazz + " is not provided by " + PluginClassLoader.class);
    If I explicitly set the return value to void in the groovy script, the problem goes away. I don't know if this behavior is present in other paper forks as well, but I guess it is.

    Attached Files:

    Last edited by a moderator: Apr 10, 2022
  2. Offline


    Why not try to let the class in the script extend JavaPlugin too, and register the listener using that same class? I've done this before to load a plugin in pure Groovy, and idk why I feel like this may not work now for some reasons.

    I mean, void or not, it still calls the method without caring about the returned result, so that shouldn't be a big problem. But still, it's better to put it as void, cuz you never know if the Spigot/Paper dudes decide to use that returned result in the future, ig.
  3. Offline


    The return value only mattered because it triggered a warning (otherwise paper doesn't care about it) and one information included in the warning's text (the plugin's name) is not available if the classloader is not the JavaPluginClassLoader.

    You are right: the warning explicitly says the return value should be void, but to be honest I'm just inexperienced in groovy and thought it will infer the return type from function body.

    Writing the whole plugin in groovy is an interesting idea, but for now this will suffice. The java part is a fairly minimal script loader anyway. The goal is to be able to reload scripts on the fly without reloading the whole plugin so I don't want to pre-compile them.
    Last edited: Apr 10, 2022

Share This Page