Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPCLib cannot run in two different plugins #79

Closed
skylerush opened this issue Apr 26, 2020 · 6 comments
Closed

NPCLib cannot run in two different plugins #79

skylerush opened this issue Apr 26, 2020 · 6 comments
Labels
bug Something isn't working

Comments

@skylerush
Copy link

skylerush commented Apr 26, 2020

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

@skylerush skylerush added the bug Something isn't working label Apr 26, 2020
@skylerush
Copy link
Author

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]

@JitseB
Copy link
Owner

JitseB commented Apr 26, 2020

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.

@JitseB
Copy link
Owner

JitseB commented Apr 26, 2020

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

Closing issue. Ticket may be reopened at any time.

@JitseB JitseB closed this as completed Apr 26, 2020
@skylerush
Copy link
Author

Thanks for the suggestions!
and a fast response!

@JitseB
Copy link
Owner

JitseB commented Apr 26, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants