Closed 2008Choco closed 3 years ago
My guess is this might be a bug in Citizens, related to your NPC not necessarily actually being spawned when your hologram code runs.
This would bug because: https://github.com/CitizensDev/Citizens2/blob/14a6004adf96d27e3da909a568518a4d0354fe56/main/src/main/java/net/citizensnpcs/trait/HologramTrait.java#L54-L58
The addLine
section calls a fake-respawn, even if the NPC is not spawned. This means when the NPC later actually spawns, it's effectively a duplicated onSpawn
call, doubling the number of NPCs.
The solution naturally is that code should have an isSpawned
check around the onDespawn
and onSpawn
calls.
A similar check would need to be added to all other matching sections, or the 'fake respawn' logic be refactored into its own method called by each part.
That's a good lead and was my initial thought as well, though the "3 NPCs > 2 lines" really threw me off. This would apply also to pretty much anything else calling onDespawn()
and onSpawn()
though (including the setLineHeight()
and setDirection()
methods) so preferably those methods themselves would include a check for isSpawned()
https://github.com/CitizensDev/Citizens2/commit/11c48c4e09cf83a5113b172cc037342044e5ed6d is a much quicker and dirtier version of the solution but should work and is available in build 2364+ from https://ci.citizensnpcs.co/job/Citizens2/
The output of command
/version
on my server is:git-Tuinity-"23247c4" (MC: 1.16.5)
The output of command/version citizens
on my server is:2.0.28-SNAPSHOT (build 2357)
(though we were running2.0.27-SNAPSHOT
prior, I updated thinking it would resolve it but all it had done was clean up the error message)Error:
Relevant code:
The error repeats until the NPC is successfully spawned. For just one NPC, it generates roughly 20 errors. I've jerry-rigged the code in numerous different formations, commented out a number of different lines, did nothing more than some simple getOrAddTrait() and addLine() calls and I continue to receive the same error each and every time. Perhaps I'm misunderstanding the API but after browsing the source of HologramTrait, I cannot understand for what reason 3 holograms would be created instead of just 2 despite only 2 lines being added to the NPC.
Perhaps I'm misunderstanding how to use the HologramTrait API, but I've toyed with the spawning of holograms far too much to believe this is a fault on my part :/ Any help or insight would be appreciated.