Skip to content

Commit

Permalink
fix: fix not unregistering singleton beans
Browse files Browse the repository at this point in the history
  • Loading branch information
duruer committed Jun 1, 2024
1 parent 8c91b24 commit 5974e42
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Pano/src/main/kotlin/com/panomc/platform/api/PanoPlugin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.coroutines.runBlocking
import org.pf4j.Plugin
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.support.BeanDefinitionRegistry
import org.springframework.beans.factory.support.DefaultListableBeanFactory
import org.springframework.context.annotation.AnnotationConfigApplicationContext

abstract class PanoPlugin : Plugin() {
Expand Down Expand Up @@ -42,6 +42,12 @@ abstract class PanoPlugin : Plugin() {
return
}

println()
println(pluginId)
println(bean.javaClass.name)

println()

pluginGlobalBeanContext.beanFactory.registerSingleton(bean.javaClass.name, bean)

registeredBeans.add(bean)
Expand All @@ -56,9 +62,9 @@ abstract class PanoPlugin : Plugin() {
return
}

val registry = pluginGlobalBeanContext.beanFactory as BeanDefinitionRegistry
val registry = pluginGlobalBeanContext.beanFactory as DefaultListableBeanFactory

registry.removeBeanDefinition(bean.javaClass.name)
registry.destroySingleton(bean.javaClass.name)

registeredBeans.remove(bean)
}
Expand All @@ -81,7 +87,11 @@ abstract class PanoPlugin : Plugin() {
val copyOfRegisteredBeans = registeredBeans.toList()

copyOfRegisteredBeans.forEach {
unRegisterGlobal(it)
try {
unRegisterGlobal(it)
} catch (e: Exception) {
e.printStackTrace()
}
}

pluginEventManager.unregisterPlugin(this)
Expand Down

0 comments on commit 5974e42

Please sign in to comment.