Skip to content

Commit

Permalink
Fix crash with embedded jvm, fix install on steam
Browse files Browse the repository at this point in the history
  • Loading branch information
buthed010203 committed Sep 25, 2024
1 parent 6810f7a commit 5930ad2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
12 changes: 6 additions & 6 deletions core/src/mindustry/client/Commands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import java.time.*
import java.time.temporal.*
import java.util.concurrent.*
import java.util.regex.*
import javax.script.*
import kotlin.math.*
import kotlin.random.*

Expand Down Expand Up @@ -204,21 +203,22 @@ fun setupCommands() {
Log.debug(out)
}

val kts by lazy { ScriptEngineManager().getEngineByExtension("kts") }
var installingKt = false
// This command doesn't work unless the supporting jar file is on the class path
register("kt <code...>", Core.bundle.get("client.command.kts.description")) { args, player: Player ->
try { ScriptEngineHolder } catch (_: Throwable) { player.sendMessage("[scarlet]The current java install does not support scripting. Please install a full jvm"); return@register }

if (installingKt) player.sendMessage("[scarlet]Already installing kotlin script support")
if (kts == null) ui.showConfirm("It seems that you do not have kotlin script support installed. Would you like to download it? (~60MB)") { // FINISHME: Bundle
if (ScriptEngineHolder.kts == null) ui.showConfirm("It seems that you do not have kotlin script support installed. Would you like to download it? (~60MB)") { // FINISHME: Bundle
installingKt = true
becontrol.downloadJar(
"https://github.com/mindustry-antigrief/kotlinScriptSupport/releases/latest/download/fooKotlinScriptSupport.jar",
Fi("fooKotlinScriptSupport.jar", Files.FileType.local),
Fi(ScriptEngineHolder::class.java.protectionDomain.codeSource.location.toURI().path).sibling("fooKotlinScriptSupport.jar"),
{ ui.showConfirm("Finished downloading kotlin script support. You must restart the game to use it. Restart now?") { restartGame() } },
{ player.sendMessage("[scarlet]Problem downloading kotlin script support ${it.printStackTrace()}") }
)
}
player.sendMessage("[accent]${try{ kts?.eval(args[0]) ?: return@register }catch(e: ScriptException){ e.message }}")
player.sendMessage("[accent]${try { ScriptEngineHolder.kts?.eval(args[0]) ?: return@register } catch (e: Throwable /* ScriptException */) { e.message }}")
}

register("/js <code...>", Core.bundle.get("client.command.serverjs.description")) { args, player ->
Expand Down Expand Up @@ -767,7 +767,7 @@ fun setupCommands() {
val current = ui.join.lastHost ?: return@register
if (current.group == null) current.group = ui.join.communityHosts.find { it == current } ?.group ?: return@register
switchTo = ui.join.communityHosts.filterTo(arrayListOf<Any>()) { it.group == current.group && it != current && (it.version == Version.build || Version.build == -1) }.apply { add(current); add(u) }
val first = switchTo!!.removeFirst() as Host
val first = switchTo!!.removeAt(0) as Host
NetClient.connect(first.address, first.port)
}

Expand Down
8 changes: 8 additions & 0 deletions core/src/mindustry/client/ScriptEngineHolder.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package mindustry.client

import javax.script.ScriptEngine
import javax.script.ScriptEngineManager

object ScriptEngineHolder {
val kts: ScriptEngine? by lazy { ScriptEngineManager().getEngineByExtension("kts") }
}

0 comments on commit 5930ad2

Please sign in to comment.