FancyMcPlugins / FancyNpcs

FancyNpcs is a simple, lightweight and fast npc plugin using packets
https://modrinth.com/plugin/fancynpcs
MIT License
100 stars 23 forks source link

EntityToggleSitEvent is not triggered synchronously. #74

Closed vLuckyyy closed 5 months ago

vLuckyyy commented 5 months ago

Stacktrace:

[16:43:17 INFO]: issued server command: /npc attribute main pose sitting
[16:43:30 WARN]: [FancyNpcs] Plugin FancyNpcs v2.0.7 generated an exception while executing task 269
java.lang.IllegalStateException: EntityToggleSitEvent may only be triggered synchronously.
        at io.papermc.paper.plugin.manager.PaperEventManager.callEvent(PaperEventManager.java:42) ~[pufferfish-1.20.4.jar:git-Pufferfish-41]
        at io.papermc.paper.plugin.manager.PaperPluginManagerImpl.callEvent(PaperPluginManagerImpl.java:126) ~[pufferfish-1.20.4.jar:git-Pufferfish-41]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:617) ~[pufferfish-api-1.20.4-R0.1-SNAPSHOT.jar:?]
        at org.bukkit.event.Event.callEvent(Event.java:45) ~[pufferfish-api-1.20.4-R0.1-SNAPSHOT.jar:?]
        at net.minecraft.world.entity.animal.Panda.sit(Panda.java:141) ~[?:?]
        at de.oliver.fancynpcs.v1_20_4.attributes.PandaAttributes.setPose(PandaAttributes.java:53) ~[FancyNpcs-2.0.7.jar:?]
        at de.oliver.fancynpcs.api.NpcAttribute.apply(NpcAttribute.java:37) ~[FancyNpcs-2.0.7.jar:?]
        at de.oliver.fancynpcs.api.NpcData.applyAllAttributes(NpcData.java:306) ~[FancyNpcs-2.0.7.jar:?]
        at de.oliver.fancynpcs.v1_20_4.Npc_1_20_4.update(Npc_1_20_4.java:236) ~[FancyNpcs-2.0.7.jar:?]
        at de.oliver.fancynpcs.v1_20_4.Npc_1_20_4.spawn(Npc_1_20_4.java:123) ~[FancyNpcs-2.0.7.jar:?]
        at de.oliver.fancynpcs.tracker.NpcTracker.run(NpcTracker.java:50) ~[FancyNpcs-2.0.7.jar:?]
        at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftTask.run(CraftTask.java:101) ~[pufferfish-1.20.4.jar:git-Pufferfish-41]
        at org.bukkit.craftbukkit.v1_20_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:57) ~[pufferfish-1.20.4.jar:git-Pufferfish-41]
        at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[pufferfish-1.20.4.jar:?]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) ~[?:?]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) ~[?:?]
        at java.lang.Thread.run(Thread.java:840) ~[?:?]
vLuckyyy commented 5 months ago

This code has one major problem, for some reason everything tries to be async, it will take more work to fix this bug. I don't know why, but the async scheduler does several other sync schedules. I think trying to async in all places doesn't improve performance at all, quite the opposite. Delays load time by trying to be async.

OliverSchlueter commented 5 months ago

In the attributes, I'm trying to just modify the data of the entity object and to not call any events. Most of the times this works, but I haven't checked every attribute for every version.

But yeah, there might be some problems with the sync/async stuff.

OliverSchlueter commented 5 months ago

For the panda pose attribute it should be fixed now: Commit 8f40a4a8c11349b15b78010e34c2de8a270938b2 Build #95 (https://jenkins.fancyplugins.de/job/FancyNpcs/95/)