From 7c9e98bdc011873605937b2acc5d10bfe350d98f Mon Sep 17 00:00:00 2001 From: Username404 Date: Thu, 15 Jul 2021 17:10:50 +0200 Subject: [PATCH] Don't use URLClassLoader instances on fabric --- .../main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt index bd90afa..a61d956 100644 --- a/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt +++ b/fabric/src/main/kotlin/fr/username404/snowygui/fabric/FabricInit.kt @@ -8,7 +8,7 @@ import net.fabricmc.api.ClientModInitializer import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback.EVENT import net.fabricmc.loader.api.FabricLoader -import java.net.URLClassLoader +import net.fabricmc.loader.launch.common.FabricLauncherBase import kotlin.io.path.exists import kotlin.io.path.isDirectory import kotlin.io.path.listDirectoryEntries @@ -28,12 +28,11 @@ class FabricInit: Snowy(), ClientModInitializer { val modsPaths = FabricLoader.getInstance().allMods.map { it.getPath(FeaturePackage.replace('.', '/')) }.filter { it.exists() && it.isDirectory() } - val buttonsLoader = URLClassLoader(modsPaths.map { it.toUri().toURL() }.toTypedArray(), Thread.currentThread().contextClassLoader) annotatedButtons = modsPaths.flatMap { buttonsDirectory -> val classSet = mutableSetOf>() buttonsDirectory.run { listDirectoryEntries("*.class").forEach { file -> - val foundClass = buttonsLoader.loadClass(file.pathString.drop(1).replace('/', '.').removeSuffix(".class")) + val foundClass = FabricLauncherBase.getClass(file.pathString.drop(1).replace('/', '.').removeSuffix(".class")) if (foundClass.isValidForButtonCollection()) classSet.add(foundClass.asSubclass(ButtonImpl::class.java)) } }