diff --git a/src/main/kotlin/com/lambda/client/LambdaCoreMod.kt b/src/main/kotlin/com/lambda/client/LambdaCoreMod.kt index a5468f79b..29de461cb 100644 --- a/src/main/kotlin/com/lambda/client/LambdaCoreMod.kt +++ b/src/main/kotlin/com/lambda/client/LambdaCoreMod.kt @@ -34,7 +34,7 @@ class LambdaCoreMod : IFMLLoadingPlugin { MixinBootstrap.init() Mixins.addConfigurations("mixins.lambda.json", "mixins.baritone.json") - PluginManager.getLoaders() + PluginManager.checkPluginLoaders(PluginManager.getLoaders()) .filter { it.info.mixins.isNotEmpty() } .forEach { logger.info("Initialised mixins of ${it.info.name}.") diff --git a/src/main/kotlin/com/lambda/client/plugin/PluginError.kt b/src/main/kotlin/com/lambda/client/plugin/PluginError.kt index 995099e3c..7c1638021 100644 --- a/src/main/kotlin/com/lambda/client/plugin/PluginError.kt +++ b/src/main/kotlin/com/lambda/client/plugin/PluginError.kt @@ -7,6 +7,7 @@ import java.io.File internal enum class PluginError { HOT_RELOAD, DUPLICATE, + DEPRECATED, UNSUPPORTED, REQUIRED_PLUGIN, OUTDATED_PLUGIN, @@ -23,6 +24,9 @@ internal enum class PluginError { DUPLICATE -> { log("Duplicate plugin $loader.") } + DEPRECATED -> { + log("Plugin $loader is deprecated due to the presence of a newer version: $message") + } UNSUPPORTED -> { log("Unsupported plugin $loader. Minimum required Lambda version: ${loader.info.minApiVersion}") } @@ -46,7 +50,15 @@ internal enum class PluginError { } } - loader.file.renameTo(File("${loader.file.path}.disabled")) + // append .disabled to the file name + // if a file with the same name exists, append a number to the end + var disabledFile = File("${loader.file.path}.disabled") + var i = 1 + while (disabledFile.exists()) { + disabledFile = File("${loader.file.path}.disabled$i") + i++ + } + loader.file.renameTo(disabledFile) } fun log(message: String?, throwable: Throwable? = null) { diff --git a/src/main/kotlin/com/lambda/client/plugin/PluginManager.kt b/src/main/kotlin/com/lambda/client/plugin/PluginManager.kt index 19c65c3d1..739d074f0 100644 --- a/src/main/kotlin/com/lambda/client/plugin/PluginManager.kt +++ b/src/main/kotlin/com/lambda/client/plugin/PluginManager.kt @@ -9,10 +9,12 @@ import com.lambda.client.plugin.api.Plugin import com.lambda.client.util.FolderUtils import com.lambda.client.util.text.MessageSendHelper import kotlinx.coroutines.Deferred +import net.minecraft.launchwrapper.Launch import net.minecraft.util.text.TextFormatting import org.apache.maven.artifact.versioning.DefaultArtifactVersion import java.io.File import java.io.FileNotFoundException +import java.util.jar.JarFile internal object PluginManager : AsyncLoader> { override var deferred: Deferred>? = null @@ -79,6 +81,8 @@ internal object PluginManager : AsyncLoader> { invalids.add(loader) } + if (invalids.contains(loader)) continue + // Duplicate check if (loadedPluginLoader.contains(loader)) { loadedPlugins.firstOrNull { loader.name == it.name }?.let { plugin -> @@ -107,11 +111,15 @@ internal object PluginManager : AsyncLoader> { PluginError.DUPLICATE.handleError(it) invalids.add(it) } + nowVersion > thenVersion -> { upgradeLoader = true + PluginError.DEPRECATED.handleError(it, loader.toString()) invalids.add(it) } + else -> { + PluginError.DEPRECATED.handleError(loader, it.toString()) invalids.add(loader) } } @@ -162,9 +170,11 @@ internal object PluginManager : AsyncLoader> { is ClassNotFoundException -> { PluginError.CLASS_NOT_FOUND.handleError(loader, throwable = it) } + is IllegalAccessException -> { PluginError.ILLEGAL_ACCESS.handleError(loader, throwable = it) } + else -> { PluginError.OTHERS.handleError(loader, throwable = it) }