Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed problems with locked plugin-jars on windows #439

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/kotlin/com/lambda/client/LambdaCoreMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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}.")
Expand Down
14 changes: 13 additions & 1 deletion src/main/kotlin/com/lambda/client/plugin/PluginError.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import java.io.File
internal enum class PluginError {
HOT_RELOAD,
DUPLICATE,
DEPRECATED,
UNSUPPORTED,
REQUIRED_PLUGIN,
OUTDATED_PLUGIN,
Expand All @@ -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}")
}
Expand All @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions src/main/kotlin/com/lambda/client/plugin/PluginManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<PluginLoader>> {
override var deferred: Deferred<List<PluginLoader>>? = null
Expand Down Expand Up @@ -79,6 +81,8 @@ internal object PluginManager : AsyncLoader<List<PluginLoader>> {
invalids.add(loader)
}

if (invalids.contains(loader)) continue

// Duplicate check
if (loadedPluginLoader.contains(loader)) {
loadedPlugins.firstOrNull { loader.name == it.name }?.let { plugin ->
Expand Down Expand Up @@ -107,11 +111,15 @@ internal object PluginManager : AsyncLoader<List<PluginLoader>> {
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)
}
}
Expand Down Expand Up @@ -162,9 +170,11 @@ internal object PluginManager : AsyncLoader<List<PluginLoader>> {
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)
}
Expand Down