Skip to content

Commit

Permalink
Fix auto configuration issue of support module
Browse files Browse the repository at this point in the history
  • Loading branch information
vjh0107 committed Jan 25, 2024
1 parent 96ca8cf commit 4e9a5da
Show file tree
Hide file tree
Showing 15 changed files with 53 additions and 41 deletions.
3 changes: 1 addition & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
kotlin.code.style=official

project.group=kr.summitsystems
project.version=0.0.8-beta6
project.version=0.0.8-beta7
project.name=spring-bukkit
project.url=https://github.com/summit-systems/spring-bukkit
project.url.scm=https://github.com/summit-systems/spring-bukkit.git
Expand All @@ -18,7 +18,6 @@ [email protected]
# Spigot
spigot.version=1.20.2-R0.1-SNAPSHOT
mock.bukkit.version=3.58.0
protocollib.version=5.1.0

# Jakarta EE
jakarta.annotation.version=2.1.1
Expand Down
Binary file modified project-dependency-graph.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ dependencyResolutionManagement {
library("paper", "io.papermc.paper:paper-api:${extra["spigot.version"]}")
library("folia", "dev.folia:folia-api:${extra["spigot.version"]}")
library("mockbukkit", "com.github.seeseemelk:MockBukkit-v1.20:${extra["mock.bukkit.version"]}")
library("protocollib", "com.comphenix.protocol:ProtocolLib:${extra["protocollib.version"]}")

library("kotlin-stdlib", "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${extra["kotlin.version"]}")
library("kotlin-reflect", "org.jetbrains.kotlin:kotlin-reflect:${extra["kotlin.version"]}")
Expand Down
2 changes: 1 addition & 1 deletion spring-bukkit-kotlinx-coroutines/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ dependencies {
api(libs.kotlinx.coroutines.core)

api(projects.core)
implementation(projects.command)
compileOnly(projects.command)

testImplementation(libs.spigot)
testImplementation(libs.spring.test)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import kotlinx.coroutines.launch
import kr.summitsystems.springbukkit.command.*
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.config.BeanDefinition
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Primary
import org.springframework.context.annotation.Role
import org.springframework.core.KotlinDetector
import org.springframework.core.convert.ConversionService
import org.springframework.stereotype.Component
import kotlin.reflect.full.callSuspend
import kotlin.reflect.jvm.kotlinFunction

@Primary
@Component
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
class CoroutinesCommandExecutor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import kotlinx.coroutines.CoroutineScope
import kr.summitsystems.springbukkit.core.listener.EventExecutorFactory
import org.bukkit.plugin.EventExecutor
import org.springframework.beans.factory.config.BeanDefinition
import org.springframework.context.annotation.Primary
import org.springframework.context.annotation.Role
import org.springframework.stereotype.Component
import java.lang.reflect.Method

@Primary
@Component
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
class CoroutinesEventExecutorFactory(private val coroutineScope: CoroutineScope) : EventExecutorFactory {
Expand Down
4 changes: 2 additions & 2 deletions spring-bukkit-reactive/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
dependencies {
compileOnly(libs.spigot)
api(libs.reactor)

api(projects.core)
api(libs.reactor)
implementation(projects.view)
compileOnly(projects.view)

testImplementation(libs.paper)
testImplementation(libs.spring.test)
Expand Down
2 changes: 1 addition & 1 deletion spring-bukkit-starter/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ dependencies {
api(projects.core)
api(projects.command)
api(projects.view)
runtimeOnly(projects.support)
api(projects.support)

api(libs.jakarta.annotation)
api(libs.spring.tx)
Expand Down
5 changes: 1 addition & 4 deletions spring-bukkit-support/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
dependencies {
compileOnly(libs.paper)
compileOnly(libs.folia)
compileOnly(libs.protocollib)

api(projects.core)
implementation(projects.command)
implementation(projects.view)
implementation(projects.kotlinxCoroutines)
compileOnly(projects.kotlinxCoroutines)

testImplementation(libs.spigot)
testImplementation(libs.spring.test)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kr.summitsystems.springbukkit.support.folia

import org.springframework.context.annotation.Conditional

@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
@Conditional(FoliaCondition::class)
annotation class ConditionalOnFolia
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package kr.summitsystems.springbukkit.support.folia

import org.springframework.context.annotation.Condition
import org.springframework.context.annotation.ConditionContext
import org.springframework.core.type.AnnotatedTypeMetadata

class FoliaCondition : Condition {
override fun matches(context: ConditionContext, metadata: AnnotatedTypeMetadata): Boolean {
return FoliaUtils.isUsingFolia()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ package kr.summitsystems.springbukkit.support.folia

import kr.summitsystems.springbukkit.core.scheduler.BukkitTaskScheduler
import org.bukkit.plugin.Plugin
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Primary

@Configuration
class FoliaConfiguration {
@ConditionalOnClass(name = ["io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler"])
@Primary
@ConditionalOnFolia
@Bean
fun foliaBukkitTaskScheduler(plugin: Plugin): BukkitTaskScheduler {
fun foliaBukkitTaskScheduler(
plugin: Plugin
): BukkitTaskScheduler {
return FoliaBukkitTaskScheduler(plugin)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package kr.summitsystems.springbukkit.support.folia

object FoliaUtils {
fun isUsingFolia(): Boolean {
return classExists("io.papermc.paper.threadedregions.RegionizedServer")
}

private fun classExists(className: String): Boolean {
return try {
Class.forName(className)
true
} catch (ex: ClassNotFoundException) {
false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,20 @@ package kr.summitsystems.springbukkit.support.folia.coroutines
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.MainCoroutineDispatcher
import kotlinx.coroutines.internal.MainDispatcherFactory
import kr.summitsystems.springbukkit.support.folia.FoliaUtils

@OptIn(InternalCoroutinesApi::class)
class FoliaMainDispatcherFactory : MainDispatcherFactory {
override val loadPriority: Int
get() = -1

override fun createDispatcher(allFactories: List<MainDispatcherFactory>): MainCoroutineDispatcher {
return if (classExists("io.papermc.paper.threadedregions.scheduler.GlobalRegionScheduler")) {
return if (FoliaUtils.isUsingFolia()) {
FoliaMainDispatcher()
} else {
allFactories
.first { it.loadPriority != this.loadPriority }
.createDispatcher(allFactories)
}
}

private fun classExists(className: String): Boolean {
return try {
Class.forName(className)
true
} catch (ex: ClassNotFoundException) {
false
}
}
}

This file was deleted.

0 comments on commit 4e9a5da

Please sign in to comment.