Skip to content

Commit 80558ef

Browse files
committed
⬆️(loader) v2.2.0.4
1 parent 6225f75 commit 80558ef

5 files changed

Lines changed: 23 additions & 35 deletions

File tree

build.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ fun RepositoryHandler.saRepository() {
6161

6262
allprojects {
6363
repositories {
64+
mavenLocal()
6465
mavenCentral()
6566
saRepository()
6667
maven(url = "https://www.jitpack.io") {
@@ -79,7 +80,7 @@ dependencies.constraints {
7980
api("dev.folia:folia-api:$bukkitVersion")
8081
}
8182
dependencies {
82-
val libraryVersion = "2.1.8.5"
83+
val libraryVersion = "2.2.0.4"
8384
api("cf.wayzer:ScriptAgent:${libraryVersion}")
8485
implementation("cf.wayzer:LibraryManager:1.6")
8586

loader/mindustry/src/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Main(private val loader: Plugin) : Plugin(), CommonMain {
5959
Log.info("&bQQ交流群: 1033116078")
6060
val all = ScriptRegistry.allScripts { true }
6161
Log.info(
62-
"&b共找到${all.size}脚本,加载成功${all.count { it.scriptState.loaded }},启用成功${all.count { it.scriptState.enabled }},出错${all.count { !it.transaction.ready() }}"
62+
"&b共找到${all.size}脚本,加载成功${all.count { it.scriptState.loaded }},启用成功${all.count { it.scriptState.enabled }},出错${all.count { !it.ready() }}"
6363
)
6464
if (!foundMain)
6565
Log.warn("&c未找到启动脚本(${Config.mainScript}),请下载安装脚本包,以发挥本插件功能")

scripts/coreLibrary/commands/control.kts

Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import cf.wayzer.placehold.PlaceHoldApi.with
44
import cf.wayzer.scriptAgent.state.ConditionState
55

66
suspend inline fun runIgnoreCancel(sync: Boolean, crossinline body: suspend () -> Unit) {
7+
//Need new Job, as it may restart this script.
8+
@Suppress("CoroutineContextWithJob")
79
val job = launch(Job()) { body() }
810
if (sync) job.join()
911
}
@@ -36,12 +38,12 @@ command("listFailed", "列出所有故障脚本".with(), commands = Commands.con
3638
body {
3739
val prefix = arg.firstOrNull().orEmpty()
3840
val scripts = ScriptRegistry.allScripts {
39-
it.id.startsWith(prefix) && !it.transaction.ready()
41+
it.id.startsWith(prefix) && !it.ready()
4042
}
4143
for (info in scripts) {
4244
reply(buildString {
4345
appendLine("[${info.scriptState}] ${info.id}")
44-
info.conditions.filter { it.status != ConditionState.Status.Success }.forEach { c ->
46+
info.lastConditions.filter { it.status != ConditionState.Status.Success }.forEach { c ->
4547
c.display().forEach {
4648
append(" ")
4749
appendLine(it)
@@ -74,8 +76,8 @@ command("list", "列出所有模块或模块内所有脚本".with(), commands =
7476
val list = ScriptRegistry.allScripts {
7577
it.id.startsWith(module + Config.idSeparator)
7678
}.map { script ->
77-
val color = if (script.transaction.ready()) "green" else "red"
78-
val conditions = script.conditions.filter { it.status != ConditionState.Status.Success }
79+
val color = if (script.ready()) "green" else "red"
80+
val conditions = script.lastConditions.filter { it.status != ConditionState.Status.Success }
7981
.joinToString("") { "${it.type}${it.status}" }
8082
"[$color]${script.id.padEnd(30)}[reset] [${script.scriptState}] $conditions"
8183
}
@@ -94,23 +96,21 @@ command("load", "(重新)加载一个脚本或者模块".with(), commands = Comm
9496
onComplete(0) { ScriptRegistry.allScripts { true }.map { it.id } }
9597
}
9698
body {
97-
val noCache = checkArg("--noCache")
9899
var noEnable = checkArg("--noEnable")
99100
val async = checkArg("--async")
100101

101102
if (arg.isEmpty()) replyUsage()
102103
val script = ScriptRegistry.getScriptInfo(arg[0])
103104
?: returnReply("[red]找不到模块或者脚本".with())
104-
if (noCache) {
105-
val file = Config.cacheFile(script.id)
106-
reply("[yellow]清理cache文件{name}".with("name" to file.name))
107-
file.delete()
108-
}
109105
runIgnoreCancel(!async) {
110106
ScriptManager.transactionV2 {
111-
unload(script)
112-
execute()
113-
(if (noEnable) load else enable)(script)
107+
if (script.scriptState.loaded) {
108+
reload(script)
109+
} else if (!noEnable) {
110+
enable(script)
111+
} else {
112+
load(script)
113+
}
114114
}.printResult()
115115
}
116116
}
@@ -129,12 +129,9 @@ command("compile", "(实验性)编译单个脚本(不影响运行中实例)".wit
129129
val script = ScriptRegistry.getScriptInfo(arg[0])
130130
?: returnReply("[red]找不到模块或者脚本".with())
131131
runIgnoreCancel(!async) {
132-
ConditionState("Compile", script.id).apply {
133-
run {
134-
script.transaction.compileScript()
135-
}
136-
reply(display().joinToString("\n").asPlaceHoldString())
137-
}
132+
ScriptManager.transactionV2 {
133+
compile(script)
134+
}.printResult()
138135
}
139136
}
140137
}
@@ -146,15 +143,8 @@ command("retry", "(实验性)重试事务".with(), commands = Commands.controlCo
146143
val async = checkArg("--async")
147144
runIgnoreCancel(!async) {
148145
ScriptManager.transactionV2 {
149-
ScriptRegistry.allScripts { !it.transaction.ready() }.forEach {
150-
put(it, it.userDemand)
151-
}
152-
//Clear conditions, and retry
153-
onEach {
154-
it.key.transaction.queueRun {
155-
setUserDemand(UserDemandState.CompileOnly);
156-
setUserDemand(it.value)
157-
}
146+
ScriptRegistry.allScripts { !it.ready() }.forEach {
147+
compile(it)
158148
}
159149
}.printResult()
160150
}

scripts/coreLibrary/commands/hotReload.kts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ fun enableWatch() {
3030
logger.info("脚本文件更新: ${event.kind().name()} ${script.id}")
3131
delay(1000)
3232
ScriptManager.transactionV2 {
33-
val old = script.userDemand
34-
unload(script)
35-
execute()
36-
old(script)
33+
reload(script)
3734
}.printResult()
3835
}
3936

scripts/coreLibrary/lib/CommandApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ open class Commands : CommandHandler, TabCompleter {
407407
if (it.script != null) append(" | ${it.script.id}")
408408
it.attr<Permission>().firstOrNull()?.let { append(" | ${it.permission}") }
409409
}
410-
return "[light_gray]{prefix}[light_yellow]{name}[gray]{aliases} [light_gray]{usage} [light_cyan]{desc}[gray]{detail}".with(
410+
return "[white]{prefix}[light_yellow]{name}[gray]{aliases} [white]{usage} [light_cyan]{desc}[gray]{detail}".with(
411411
"prefix" to prefix, "name" to it.name, "aliases" to alias,
412412
"usage" to it.usage, "desc" to it.description, "detail" to detail
413413
)

0 commit comments

Comments
 (0)