JitseB / NPCLib

(Minecraft) NPCLib – Basic non-player character library.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NPCLib cannot run in two different plugins

skylerush opened this issue · comments

commented

Describe the bug
Task #52306 for plugin generated an exception
26.04 12:35:52 [Server] INFO java.lang.LinkageError: net/jitse/npclib/NPCLib

NPCLib JAR name
E.g. npclib-plugin-2.7.jar

Server version
1.15.2

To Reproduce
run two plugins using NPClib and see the error after trying to spawn both of them

Expected behavior
The Library will be managed to run on two or more separated plugin

commented

Task #1674 for generated an exception
26.04 14:10:09 [Server] INFO java.lang.LinkageError: loader (instance of org/bukkit/plugin/java/PluginClassLoader): attempted duplicate class definition for name: "net/jitse/npclib/NPCLib"
26.04 14:10:09 [Server] INFO at java.lang.ClassLoader.defineClass1(Native Method) ~[?:1.8.0_242]
26.04 14:10:09 [Server] INFO at java.lang.ClassLoader.defineClass(ClassLoader.java:757) ~[?:1.8.0_242]
26.04 14:10:09 [Server] INFO at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[?:1.8.0_242]
26.04 14:10:09 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:163) ~[Spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
26.04 14:10:09 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader.getClassByName(JavaPluginLoader.java:202) ~[Spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
26.04 14:10:09 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:107) ~[Spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
26.04 14:10:09 [Server] INFO at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:96) ~[Spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
26.04 14:10:09 [Server] INFO at java.lang.ClassLoader.loadClass(ClassLoader.java:419) ~[?:1.8.0_242]
26.04 14:10:09 [Server] INFO at java.lang.ClassLoader.loadClass(ClassLoader.java:352) ~[?:1.8.0_242]

Hi, thanks for creating this issue ticket!

I never intended NPCLib to be used by multiple plugins at the same time. The easiest workaround right now is to strip the library from your plugin and run the NPCLib plugin (which loads all classes for you) in your server.

In the meantime I'll see if I can get the system to figure out if the classes are already loaded into the JVM.

EDIT 1: Another easy way you could resolve this, is by repacking the code of NPCLib and port it to a different package. Therefore it can't get duplicate classes.
Still looking for a way to register NPCLib as a service, similar to ProtocolLib.

EDIT 2: Yep, I found a way to make it work. But it'll require some work on my end. For now I recommend one of the upper solutions. I'll publish the real solution in a major release which I'll start working on.

EDIT 3: After thinking about this for a while I have come to the following conclusion; Registering the library as a service in the server will require the library to run as a standalone plugin on the server at all times. Some developers don't like doing this. They want to shade the library into their plugins.
With that in mind, I think it's best to do to shade the library and repack it in a different package.

I'll add the solution to the README on the main page as well.

Closing issue. Ticket may be reopened at any time.

commented

Thanks for the suggestions!
and a fast response!

Not a problem! Best of luck with your plugin. :)