Skip to content

Commit 272172a

Browse files
Fixed problems with locked plugin-jars on windows (#439)
1 parent 099b0ec commit 272172a

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

src/main/kotlin/com/lambda/client/LambdaCoreMod.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class LambdaCoreMod : IFMLLoadingPlugin {
3434
MixinBootstrap.init()
3535
Mixins.addConfigurations("mixins.lambda.json", "mixins.baritone.json")
3636

37-
PluginManager.getLoaders()
37+
PluginManager.checkPluginLoaders(PluginManager.getLoaders())
3838
.filter { it.info.mixins.isNotEmpty() }
3939
.forEach {
4040
logger.info("Initialised mixins of ${it.info.name}.")

src/main/kotlin/com/lambda/client/plugin/PluginError.kt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import java.io.File
77
internal enum class PluginError {
88
HOT_RELOAD,
99
DUPLICATE,
10+
DEPRECATED,
1011
UNSUPPORTED,
1112
REQUIRED_PLUGIN,
1213
OUTDATED_PLUGIN,
@@ -23,6 +24,9 @@ internal enum class PluginError {
2324
DUPLICATE -> {
2425
log("Duplicate plugin $loader.")
2526
}
27+
DEPRECATED -> {
28+
log("Plugin $loader is deprecated due to the presence of a newer version: $message")
29+
}
2630
UNSUPPORTED -> {
2731
log("Unsupported plugin $loader. Minimum required Lambda version: ${loader.info.minApiVersion}")
2832
}
@@ -46,7 +50,15 @@ internal enum class PluginError {
4650
}
4751
}
4852

49-
loader.file.renameTo(File("${loader.file.path}.disabled"))
53+
// append .disabled to the file name
54+
// if a file with the same name exists, append a number to the end
55+
var disabledFile = File("${loader.file.path}.disabled")
56+
var i = 1
57+
while (disabledFile.exists()) {
58+
disabledFile = File("${loader.file.path}.disabled$i")
59+
i++
60+
}
61+
loader.file.renameTo(disabledFile)
5062
}
5163

5264
fun log(message: String?, throwable: Throwable? = null) {

src/main/kotlin/com/lambda/client/plugin/PluginManager.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import com.lambda.client.plugin.api.Plugin
99
import com.lambda.client.util.FolderUtils
1010
import com.lambda.client.util.text.MessageSendHelper
1111
import kotlinx.coroutines.Deferred
12+
import net.minecraft.launchwrapper.Launch
1213
import net.minecraft.util.text.TextFormatting
1314
import org.apache.maven.artifact.versioning.DefaultArtifactVersion
1415
import java.io.File
1516
import java.io.FileNotFoundException
17+
import java.util.jar.JarFile
1618

1719
internal object PluginManager : AsyncLoader<List<PluginLoader>> {
1820
override var deferred: Deferred<List<PluginLoader>>? = null
@@ -79,6 +81,8 @@ internal object PluginManager : AsyncLoader<List<PluginLoader>> {
7981
invalids.add(loader)
8082
}
8183

84+
if (invalids.contains(loader)) continue
85+
8286
// Duplicate check
8387
if (loadedPluginLoader.contains(loader)) {
8488
loadedPlugins.firstOrNull { loader.name == it.name }?.let { plugin ->
@@ -107,11 +111,15 @@ internal object PluginManager : AsyncLoader<List<PluginLoader>> {
107111
PluginError.DUPLICATE.handleError(it)
108112
invalids.add(it)
109113
}
114+
110115
nowVersion > thenVersion -> {
111116
upgradeLoader = true
117+
PluginError.DEPRECATED.handleError(it, loader.toString())
112118
invalids.add(it)
113119
}
120+
114121
else -> {
122+
PluginError.DEPRECATED.handleError(loader, it.toString())
115123
invalids.add(loader)
116124
}
117125
}
@@ -162,9 +170,11 @@ internal object PluginManager : AsyncLoader<List<PluginLoader>> {
162170
is ClassNotFoundException -> {
163171
PluginError.CLASS_NOT_FOUND.handleError(loader, throwable = it)
164172
}
173+
165174
is IllegalAccessException -> {
166175
PluginError.ILLEGAL_ACCESS.handleError(loader, throwable = it)
167176
}
177+
168178
else -> {
169179
PluginError.OTHERS.handleError(loader, throwable = it)
170180
}

0 commit comments

Comments
 (0)