@@ -2,18 +2,17 @@ package coreLibrary.commands
22
33import cf.wayzer.placehold.PlaceHoldApi.with
44
5- onEnable {
6- Commands .controlCommand + = CommandInfo (this , " config" , " 查看或修改配置" ) {
7- usage = " [help/arg...]"
8- permission = " scriptAgent.config"
9- onComplete {
10- onComplete(0 ) { listOf (" help" , " reload" ) + ConfigBuilder .all.keys }
11- onComplete(1 ) { listOf (" set" , " write" , " reset" ) }
12- }
13- body {
14- if (arg.isEmpty() || arg[0 ].equals(" help" , true ))
15- returnReply(
16- """
5+ command(" config" , " 查看或修改配置" .with (), commands = Commands .controlCommand) {
6+ usage = " [help/arg...]"
7+ permission = " scriptAgent.config"
8+ onComplete {
9+ onComplete(0 ) { listOf (" help" , " reload" ) + ConfigBuilder .all.keys }
10+ onComplete(1 ) { listOf (" set" , " write" , " reset" ) }
11+ }
12+ body {
13+ if (arg.isEmpty() || arg[0 ].equals(" help" , true ))
14+ returnReply(
15+ """
1716 [yellow]可用操作
1817 [purple]config reload [light_purple]重载配置文件
1918 [purple]config list [页码] [light_purple]列出配置项
@@ -22,60 +21,59 @@ onEnable {
2221 [purple]config <配置项> write [light_purple]写入默认值到配置文件
2322 [purple]config <配置项> reset [light_purple]恢复默认值(从配置文件移除默认值)
2423 """ .trimIndent().with ()
24+ )
25+ if (arg[0 ].equals(" list" , true )) {
26+ val page = arg.getOrNull(1 )?.toIntOrNull() ? : 1
27+ returnReply(menu(" 配置项" , ConfigBuilder .all.values.sortedBy { it.path }, page, 15 ) {
28+ " [green]{key} [blue]{desc}" .with (
29+ " key" to it.path,
30+ " desc" to (it.desc.firstOrNull() ? : " " )
2531 )
26- if (arg[0 ].equals(" list" , true )) {
27- val page = arg.getOrNull(1 )?.toIntOrNull() ? : 1
28- returnReply(menu(" 配置项" , ConfigBuilder .all.values.sortedBy { it.path }, page, 15 ) {
29- " [green]{key} [blue]{desc}" .with (
30- " key" to it.path,
31- " desc" to (it.desc.firstOrNull() ? : " " )
32- )
33- })
34- }
35- if (arg[0 ].equals(" reload" , true )) {
36- if (! hasPermission(" $permission .reload" ))
37- replyNoPermission()
38- ConfigBuilder .reloadFile()
39- returnReply(" [green]重载成功" .with ())
40- }
41- val config = arg.firstOrNull()?.let { ConfigBuilder .all[it] } ? : returnReply(" [red]找不到配置项" .with ())
42- if (! hasPermission(permission + " ." + config.path))
43- returnReply(" [red]你没有权限修改配置项: {config}" .with (" config" to config.path))
44- when (arg.getOrNull(1 )?.lowercase()) {
45- null -> {
46- returnReply(
47- """
32+ })
33+ }
34+ if (arg[0 ].equals(" reload" , true )) {
35+ if (! hasPermission(" $permission .reload" ))
36+ replyNoPermission()
37+ ConfigBuilder .reloadFile()
38+ returnReply(" [green]重载成功" .with ())
39+ }
40+ val config = arg.firstOrNull()?.let { ConfigBuilder .all[it] } ? : returnReply(" [red]找不到配置项" .with ())
41+ if (! hasPermission(permission + " ." + config.path))
42+ returnReply(" [red]你没有权限修改配置项: {config}" .with (" config" to config.path))
43+ when (arg.getOrNull(1 )?.lowercase()) {
44+ null -> {
45+ returnReply(
46+ """
4847 |[yellow]==== [light_yellow]配置项: {name}[yellow] ====
4948 |[purple]{desc:${" \n " } }
5049 |[cyan]当前值: [yellow]{value}
5150 |[cyan]默认值: [yellow]{default}
5251 |[yellow]使用/sa config help查看可用操作
5352 """ .trimMargin().with (
54- " name" to config.path, " desc" to config.desc,
55- " value" to config.getString(), " default" to config.default,
56- )
53+ " name" to config.path, " desc" to config.desc,
54+ " value" to config.getString(), " default" to config.default,
5755 )
58- }
56+ )
57+ }
5958
60- " reset" -> {
61- config.reset()
62- returnReply(" [green]重置成功,当前:[yellow]{value}" .with (" value" to config.getString()))
63- }
59+ " reset" -> {
60+ config.reset()
61+ returnReply(" [green]重置成功,当前:[yellow]{value}" .with (" value" to config.getString()))
62+ }
6463
65- " write" -> {
66- config.writeDefault()
67- reply(" [green]写入文件成功" .with ())
68- }
64+ " write" -> {
65+ config.writeDefault()
66+ reply(" [green]写入文件成功" .with ())
67+ }
6968
70- " set" -> {
71- if (arg.size <= 2 ) returnReply(" [red]请输入值" .with ())
72- val value = arg.subList(2 , arg.size).joinToString(" " )
73- returnReply(" [green]设置成功,当前:[yellow]{value}" .with (" value" to config.setString(value)))
74- }
69+ " set" -> {
70+ if (arg.size <= 2 ) returnReply(" [red]请输入值" .with ())
71+ val value = arg.subList(2 , arg.size).joinToString(" " )
72+ returnReply(" [green]设置成功,当前:[yellow]{value}" .with (" value" to config.setString(value)))
73+ }
7574
76- else -> {
77- returnReply(" [red]未知操作,请查阅help帮助" .with ())
78- }
75+ else -> {
76+ returnReply(" [red]未知操作,请查阅help帮助" .with ())
7977 }
8078 }
8179 }
0 commit comments