Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClassCastException when using interfaces in a paper plugin #6

Closed
FllipEis opened this issue Jun 26, 2024 · 2 comments · Fixed by #7
Closed

ClassCastException when using interfaces in a paper plugin #6

FllipEis opened this issue Jun 26, 2024 · 2 comments · Fixed by #7
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@FllipEis
Copy link
Contributor

FllipEis commented Jun 26, 2024

I'm getting this error when I'm using this library in a paper plugin:

  [11:28:08 WARN]: Exception in thread "DefaultDispatcher-worker-1" java.lang.ClassCastException: class io.papermc.paper.plugin.entrypoint.classloader.PaperPluginClassLoader cannot be cast to class org.bukkit.plugin.java.PluginClassLoader (io.papermc.paper.plugin.entrypoint.classloader.PaperPluginClassLoader and org.bukkit.plugin.java.PluginClassLoader are in unnamed module of loader java.net.URLClassLoader @421faab1)
  [11:28:08 WARN]: 	at com.noxcrew.interfaces.utilities.ThreadUtilsKt.runSync(ThreadUtils.kt:13)
  [11:28:08 WARN]: 	at com.noxcrew.interfaces.view.AbstractInterfaceView.renderToInventory$suspendImpl(AbstractInterfaceView.kt:397)
  [11:28:08 WARN]: 	at com.noxcrew.interfaces.view.AbstractInterfaceView.renderToInventory(AbstractInterfaceView.kt)
  [11:28:08 WARN]: 	at com.noxcrew.interfaces.view.AbstractInterfaceView$renderAndOpen$2.invokeSuspend(AbstractInterfaceView.kt:209)
  [11:28:08 WARN]: 	at com.noxcrew.interfaces.view.AbstractInterfaceView$renderAndOpen$2.invoke(AbstractInterfaceView.kt)
  [11:28:08 WARN]: 	at com.noxcrew.interfaces.view.AbstractInterfaceView$renderAndOpen$2.invoke(AbstractInterfaceView.kt)
  [11:28:08 WARN]: 	at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturnIgnoreTimeout(Undispatched.kt:53)
  [11:28:08 WARN]: 	at kotlinx.coroutines.TimeoutKt.setupTimeout(Timeout.kt:148)
  [11:28:08 WARN]: 	at kotlinx.coroutines.TimeoutKt.withTimeout(Timeout.kt:43)
  [11:28:08 WARN]: 	at kotlinx.coroutines.TimeoutKt.withTimeout-KLykuaI(Timeout.kt:71)
  [11:28:08 WARN]: 	at com.noxcrew.interfaces.view.AbstractInterfaceView.renderAndOpen(AbstractInterfaceView.kt:207)
  [11:28:08 WARN]: 	at com.noxcrew.interfaces.view.AbstractInterfaceView.access$renderAndOpen(AbstractInterfaceView.kt:38)
  [11:28:08 WARN]: 	at com.noxcrew.interfaces.view.AbstractInterfaceView$applyTransforms$1$1.invokeSuspend(AbstractInterfaceView.kt:261)
  [11:28:08 WARN]: 	at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
  [11:28:08 WARN]: 	at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:102)
  [11:28:08 WARN]: 	at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:589)
  [11:28:08 WARN]: 	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:816)
  [11:28:08 WARN]: 	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:720)
  [11:28:08 WARN]: 	at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:707)
  [11:28:08 WARN]: 	Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [CoroutineName(interfaces), StandaloneCoroutine{Cancelling}@79af45cc, Dispatchers.Default]

I think this can be resolved by changing the following line in ThreadUtils and adding a check for the PaperPluginClassLoader. If you want, I can create a pull request to fix this, but I would like to discuss it here before 😄

@kezz kezz added bug Something isn't working good first issue Good for newcomers labels Jun 26, 2024
@kezz
Copy link
Member

kezz commented Jun 26, 2024

Sounds like a good fix to me. I think a proper fix might be to bring the runSync method inside InterfaceListeners and using the plugin instance that we have stored there. That way we don't need to touch any class loaders.

@FllipEis
Copy link
Contributor Author

Sounds like a good fix to me. I think a proper fix might be to bring the runSync method inside InterfaceListeners and using the plugin instance that we have stored there. That way we don't need to touch any class loaders.

Yeah sure, I will create a pull request for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Development

Successfully merging a pull request may close this issue.

2 participants