NPCLib icon indicating copy to clipboard operation
NPCLib copied to clipboard

When using NPCLib in two plugins, one of the NPCs does not work properly

Open ByOuHuang opened this issue 7 months ago • 4 comments

Describe the bug When using NPCLib in two plugins, one of the NPCs does not work properly

NPCLib usage option 3 and relocations are used

NPCLib JAR name npclib-plugin-2.13.1-SNAPSHOT.jar

Server version Current: git-Purpur-2062 (MC: 1.20.1)*

To Reproduce https://github.com/ThePitCommunity/ThePitPremium/blob/master/src/main/java/cn/charlotte/pit/npc/NpcFactory.java I modified it based on this, the code flow has not changed, and there is no error in the background

Expected behavior There is no problem with using a single plugin, but there is a problem with more than two plugins. One of the NPCs in one of the plugins will disappear, and the UUID of a certain NPC in the other plugin that does not disappear will be abnormal. He will become the UUID of another NPC that disappeared, causing the NPC to execute the wrong code.

ByOuHuang avatar May 10 '25 21:05 ByOuHuang

Hi! Thanks for opening this issue.

Since I have not posted the library to the central Maven repo yet, I am assuming you have added the npclib-plugin-2.13.1-SNAPSHOT artifact to your local Maven repo manually?

Also, just to be sure, the relocations are not mapped to the same package?

JitseB avatar May 10 '25 22:05 JitseB

Yes, I added it manually to the local Maven library. Most of my plugin libs use relocation, and each plugin will only call its own relocated lib

ByOuHuang avatar May 11 '25 06:05 ByOuHuang

Considering the plugins work independent from one-another, I am tempted to say that there is an issue with the shading process. This has to do with the fact that the NPCBase class generates a new (random) UUID, which has a probability of next-to-none when it comes to generating duplicates. Therefore, the issue must lie with the operation of the NPCManager class. The only way for the two plugins to be able to access the same NPCManager class is if they are in the same package (confusing the class managers of the two plugins).

Would you mind sharing the relevant pieces of your pom.xml files? I then hope to be able to reproduce your issue.

JitseB avatar May 11 '25 10:05 JitseB

https://privatebin.net/?93e4752686c94858#As3tRVWwhenh3dfw5xpU8N1khz5MSrsm6qGV9ZXnVxs2 https://privatebin.net/?9abc0f85e0da74d6#5Fh33TW6PPKZ8o1qHqT4u7XtvYx58KQpm2cwQJLhaWMe I don't understand, maybe it's a problem with Google Translate. Should both plugins use the same NPCManager class?

ByOuHuang avatar May 11 '25 15:05 ByOuHuang