lanthanide
lanthanide

Reputation: 13

GraalPy interoperability does not recognize classes of plugin in Minecraft Spigot

Following this document, I was able to run Python code in a Java application and access objects of Java in Python code.

When I use the same logic and run it as a Spigot Plugin, it says that the object I tried to interoperate is not defined.

This is my code to run Python code:

public class PythonManager {
    public static Context context = Context.newBuilder("python")
            .allowAllAccess(true)
            .build();

    public static void testPython() {
        context.eval("python", """
                import java
                
                print(java.type("kr.lanthanide.PythonManager"))
                """);
    }
}

When I build it as executable JAR and call PythonManager.testPython() in main(String[] args), it works very well printing "kr.lanthanide.PythonManager" indicating it has found the object. When I run it in onEnable() of Spigot plugin, it prints this error:

[00:46:06 ERROR]: Error occurred while enabling MySpigotPlugin v1.0.0 (Is it up to date?)
org.graalvm.polyglot.PolyglotException: KeyError: host symbol kr.lanthanide.PythonManager is not defined or access has been denied
        at <python>.<module>(Unknown) ~[?:?]
        at GraalPyTester-1.0-SNAPSHOT-all.jar/org.graalvm.polyglot.Context.eval(Context.java:428) ~[GraalPyTester-1.0-SNAPSHOT-all.jar:?]
        at GraalPyTester-1.0-SNAPSHOT-all.jar/kr.lanthanide.PythonManager.testPython(PythonManager.java:11) ~[GraalPyTester-1.0-SNAPSHOT-all.jar:?]
        at GraalPyTester-1.0-SNAPSHOT-all.jar/kr.lanthanide.TestPlugin.onEnable(TestPlugin.java:10) ~[GraalPyTester-1.0-SNAPSHOT-all.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:284) ~[paper-api-1.21.4-R0.1-SNAPSHOT.jar:?]
        at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:202) ~[paper-1.21.4.jar:1.21.4-121-88bbead]
        at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.enablePlugin(PaperPluginManagerImpl.java:109) ~[paper-1.21.4.jar:1.21.4-121-88bbead]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:520) ~[paper-api-1.21.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.craftbukkit.CraftServer.enablePlugin(CraftServer.java:656) ~[paper-1.21.4.jar:1.21.4-121-88bbead]
        at org.bukkit.craftbukkit.CraftServer.enablePlugins(CraftServer.java:605) ~[paper-1.21.4.jar:1.21.4-121-88bbead]
        at net.minecraft.server.MinecraftServer.loadWorld0(MinecraftServer.java:743) ~[paper-1.21.4.jar:1.21.4-121-88bbead]
        at net.minecraft.server.MinecraftServer.loadLevel(MinecraftServer.java:488) ~[paper-1.21.4.jar:1.21.4-121-88bbead]
        at net.minecraft.server.dedicated.DedicatedServer.initServer(DedicatedServer.java:322) ~[paper-1.21.4.jar:1.21.4-121-88bbead]
        at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1163) ~[paper-1.21.4.jar:1.21.4-121-88bbead]
        at net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:310) ~[paper-1.21.4.jar:1.21.4-121-88bbead]
        at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
[00:46:06 INFO]: [MySpigotPlugin] Disabling MySpigotPlugin v1.0.0

Is it a fundamental limitation of Spigot plugins? Or am I missing something? Also, if it is caused by how GraalPy interoperability works, can you recommend me some alternatives?

What I have tried:

  1. Try other objects : It works with Java builtin objects and things from Bukkit. But it does not work with anything from my plugin, including GraalPy.
  2. Call it after plugin initialization : Nothing changes. I got same stacktrace.

Upvotes: 0

Views: 32

Answers (0)

Related Questions