Closed AllanWang closed 3 years ago
I don't think this is related to the Plugin.findClazz
of MCCoroutine but you are right that something breaks during scope disposing. It seems like the PluginClassLoader
of Bukkit fails to load a Class of Kotlin Coroutines on the job.cancelChildren
call of MCCoroutine.
Did you replace your Plugin.jar
during runtime?
If you did then it is not an error per say because replacing the jar file during runtime will always cause unintended side effects which MCCoroutine might not be able to solve. If you did not replace your jar file before executing reload
then it is indeed an error.
A possible workaround might be simply calling job.cancelChildren()
at plugin enable inside MCCoroutine, so that all required classes for disposing are already cached by the classloader when it is finally required on PluginDisable
.
You could try to simply call this.scope.cancelChildren()
at the beginning of your fun onEnable()
and take a look if it helps.
I've done a few more tests, and this is a problem with coroutines in general. Not sure if we need to await on cancel. I'm calling it during onDisable, though I wonder if it matters at all. Upon reload, I assume the plugin will get a new scope, so calling it during onEnable before anything else might not do anything.
Can you please share your sample code how to replicate this error?
I'm testing out coroutines by routing all events to a shared flow. I'm getting the following error on
/reload
:Perhaps this is related to how the scope is disposed? Or more specifically, usage of
Plugin.findClazz