KovuTheHusky / dynmap-structures

A Bukkit plugin that shows your world's structures (such as Villages, Strongholds, and Pyramids) on Dynmap.
MIT License
20 stars 18 forks source link

StructureLocateEvent can only be called synchronously #37

Closed embeddedt closed 3 years ago

embeddedt commented 3 years ago

Describe the bug

The server console gets filled with a warning (see below). The thread number changes for each instance of the warning, but the stack trace is the same.

[09:47:08 WARN]: Exception in thread "Thread-388" java.lang.IllegalStateException: StructureLocateEvent may only be triggered synchronously.
[09:47:08 WARN]:        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:595)
[09:47:08 WARN]:        at org.bukkit.event.Event.callEvent(Event.java:45)
[09:47:08 WARN]:        at net.minecraft.server.v1_16_R3.ChunkGenerator.findNearestMapFeature(ChunkGenerator.java:132)
[09:47:08 WARN]:        at org.bukkit.craftbukkit.v1_16_R3.CraftWorld.locateNearestStructure(CraftWorld.java:2513)
[09:47:08 WARN]:        at com.kovuthehusky.dynmap.structures.DynmapStructuresPlugin$DynmapStructuresRunnable.run(DynmapStructuresPlugin.java:328)
[09:47:08 WARN]:        at java.lang.Thread.run(Thread.java:748)

To Reproduce

Run the server version specified below with dynmap-structures installed.

Expected behavior

The plugin should run without printing a warning.

Desktop (please complete the following information):

Additional context

The error only seems to have started occuring with this version of Paper, unless I missed something in server logs. Previously I was using git-Paper-352 (for 1.16.4).

At first glance, the issue may be here. If my understanding of the API is correct, this function needs to be called on the main thread, not another one.

kongming819 commented 3 years ago

I am also having this problem, only started happening with new Paper 1.16.5, Java 11 OpenJ9

embeddedt commented 3 years ago

Probably caused by https://github.com/PaperMC/Paper/commit/193f80148c02700d0a1bf0f28727a89478c5dfb5

This event didn't exist before so the illegal access from another thread probably went unnoticed. In order to fix this I think locateNearestStructure will need to be invoked on the sync thread and the other thread will have to wait for it.

KovuTheHusky commented 3 years ago

Please give 2.3.1 a shot!