Skip to content

Commit

Permalink
fix: fix getting plugins in router provider
Browse files Browse the repository at this point in the history
  • Loading branch information
duruer committed May 23, 2024
1 parent 99c321c commit 3b03706
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 8 additions & 0 deletions Pano/src/main/kotlin/com/panomc/platform/PluginManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.panomc.platform

import com.panomc.platform.SpringConfig.Companion.pluginEventManager
import com.panomc.platform.SpringConfig.Companion.pluginUiManager
import com.panomc.platform.api.PanoPlugin
import org.pf4j.*
import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.stereotype.Component
Expand Down Expand Up @@ -40,4 +41,11 @@ class PluginManager(importPaths: List<Path> = listOf(Paths.get(System.getPropert
return CompoundPluginLoader()
.add(PanoPluginLoader(this)) { this.isNotDevelopment }
}

fun getPanoPlugins(): List<PanoPlugin> = plugins.mapNotNull { plugin ->
runCatching {
val pluginWrapper = plugin as PluginWrapper
pluginWrapper.plugin as PanoPlugin
}.getOrNull()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.panomc.platform.route

import com.panomc.platform.PluginManager
import com.panomc.platform.annotation.Endpoint
import com.panomc.platform.api.PanoPlugin
import com.panomc.platform.config.ConfigManager
import com.panomc.platform.model.Route
import com.panomc.platform.model.RouteType
Expand All @@ -15,7 +14,6 @@ import io.vertx.ext.web.Router
import io.vertx.ext.web.handler.BodyHandler
import io.vertx.ext.web.handler.CorsHandler
import io.vertx.json.schema.SchemaParser
import org.pf4j.PluginWrapper
import org.springframework.context.annotation.AnnotationConfigApplicationContext

class RouterProvider private constructor(
Expand Down Expand Up @@ -79,10 +77,8 @@ class RouterProvider private constructor(
val routeList = mutableListOf<Route>()

routeList.addAll(applicationContext.getBeansWithAnnotation(Endpoint::class.java).map { it.value as Route })
routeList.addAll(pluginManager.plugins.map {
((it as PluginWrapper).plugin as PanoPlugin).pluginBeanContext.getBeansWithAnnotation(
Endpoint::class.java
)
routeList.addAll(pluginManager.getPanoPlugins().map {
it.pluginBeanContext.getBeansWithAnnotation(Endpoint::class.java)
}.flatMap { it.values }.map { it as Route })

router.route()
Expand Down

0 comments on commit 3b03706

Please sign in to comment.