Skip to content

Commit 622fc3a

Browse files
committed
hopefully fix recursive issue
1 parent 54cce70 commit 622fc3a

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

src/main/kotlin/com/lambda/loader/LoaderUpdater.kt

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.lambda.loader
22

33
import com.lambda.loader.config.ConfigManager
4+
import net.fabricmc.loader.api.metadata.ModOrigin
45
import java.io.File
56
import java.io.IOException
67
import java.nio.file.Files
@@ -22,19 +23,22 @@ class LoaderUpdater(
2223
*/
2324
private fun getCurrentLoaderJarPath(): File? {
2425
return try {
25-
val codeSource = this::class.java.protectionDomain.codeSource
26-
if (codeSource != null) {
27-
val location = codeSource.location
28-
val path = location.toURI().path
29-
val file = File(path)
30-
31-
if (file.exists() && file.name.endsWith(".jar")) {
32-
if (ConfigManager.config.debug) logger.info("Current loader JAR: ${file.absolutePath}")
33-
return file
26+
val fabricLoader = net.fabricmc.loader.api.FabricLoader.getInstance()
27+
val loaderMod = fabricLoader.getModContainer("lambda-loader")
28+
29+
if (loaderMod.isPresent) {
30+
val origin = loaderMod.get().origin
31+
if (origin.kind == ModOrigin.Kind.PATH) {
32+
val paths = origin.paths
33+
if (paths.isNotEmpty()) {
34+
val file = paths[0].toFile()
35+
if (ConfigManager.config.debug) logger.info("Current loader JAR: ${file.absolutePath}")
36+
return file
37+
}
3438
}
3539
}
3640

37-
logger.warning("Could not determine loader JAR path from code source")
41+
logger.warning("Could not determine loader JAR path from Fabric Loader metadata")
3842
null
3943
} catch (e: Exception) {
4044
logger.warning("Error getting current loader JAR path: ${e.message}")

0 commit comments

Comments
 (0)