From 92f0986f9fe09eb778fe37cb279616dc8078cf9e Mon Sep 17 00:00:00 2001 From: twisti-dev <76837088+twisti-dev@users.noreply.github.com> Date: Mon, 22 Jun 2026 00:57:40 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A7=20chore:=20update=20version=20to?= =?UTF-8?q?=203.27.5=20and=20improve=20service=20loader=20fallback=20metho?= =?UTF-8?q?d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - increment version in gradle.properties to 3.27.5 - refactor requiredService function to simplify service loading logic - add deprecated method for binary compatibility with existing code --- gradle.properties | 2 +- .../dev/slne/surf/api/core/util/service-util.kt | 15 +++++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/gradle.properties b/gradle.properties index 73205ffb..fd483fa7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,6 +7,6 @@ org.jetbrains.dokka.experimental.gradle.pluginMode=V2Enabled javaVersion=25 mcVersion=26.2 group=dev.slne.surf.api -version=3.27.4 +version=3.27.5 relocationPrefix=dev.slne.surf.api.libs snapshot=false diff --git a/surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/util/service-util.kt b/surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/util/service-util.kt index 4a8fb1fa..817d589d 100644 --- a/surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/util/service-util.kt +++ b/surf-api-core/surf-api-core/src/main/kotlin/dev/slne/surf/api/core/util/service-util.kt @@ -13,19 +13,22 @@ import java.util.* * @return the service instance of type [T] * @throws ServiceConfigurationError if the service of type [T] is not available */ -inline fun requiredService(): T = ServiceUtil.serviceWithFallback( - ServiceLoader.load( - T::class.java, - getCallerClass(-1)?.classLoader ?: T::class.java.classLoader - ), T::class.java -) ?: throw ServiceConfigurationError("Service ${T::class.java.name} not available") +inline fun requiredService(): T = ServiceUtil.serviceWithFallback(T::class.java) + ?: throw ServiceConfigurationError("Service ${T::class.java.name} not available") object ServiceUtil { @Suppress("UnstableApiUsage") private val SERVICE_LOAD_FAILURES_ARE_FATAL = AdventureProperties.SERVICE_LOAD_FAILURES_ARE_FATAL.value() == true + @Deprecated("Binary compatibility", ReplaceWith("serviceWithFallback(loader, type)"), DeprecationLevel.HIDDEN) @PublishedApi internal fun serviceWithFallback(loader: ServiceLoader, type: Class): T? { + return serviceWithFallback(type) + } + + @PublishedApi + internal fun serviceWithFallback(type: Class): T? { + val loader = ServiceLoader.load(type, type.classLoader) val iterator = loader.iterator() var firstFallback: T? = null