Skip to content

Commit 6cbf0be

Browse files
committed
Fixed bugs.
1 parent 358a7db commit 6cbf0be

File tree

16 files changed

+207
-167
lines changed

16 files changed

+207
-167
lines changed

FastScript-common/src/main/kotlin/me/scoretwo/fastscript/FastScript.kt

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,8 @@ class FastScript(val plugin: ScriptPlugin) {
4343
}
4444

4545
settings = SettingConfig()
46-
settings.reload()
47-
4846
languages = LanguageManager()
49-
languages.current = languages.languages[settings.getString("Options.Language")] ?: languages.defaultLanguage.also {
50-
plugin.server.console.sendMessage(FormatHeader.ERROR, "Language loading failed. The file may not exist. The default language will be used: en_US")
51-
}
47+
reload("config")
5248

5349
commandNexus = FSCommandNexus()
5450
scriptManager = ScriptManager()
@@ -57,6 +53,12 @@ class FastScript(val plugin: ScriptPlugin) {
5753
}
5854
}
5955

56+
fun reloadLanguage() {
57+
languages.current = languages.languages[settings.getString("Options.Language")] ?: languages.defaultLanguage.also {
58+
plugin.server.console.sendMessage(FormatHeader.ERROR, "Language loading failed. The file may not exist. The default language will be used: en_US")
59+
}
60+
}
61+
6062
/**
6163
* 初始化内置脚本
6264
* 暂时弃坑
@@ -65,14 +67,27 @@ class FastScript(val plugin: ScriptPlugin) {
6567

6668
}
6769

68-
fun onReload() {
70+
fun reloadAll() = reload("config", "script", "plugin")
71+
72+
fun reload(vararg modes: String) {
6973
if (!plugin.dataFolder.exists()) {
7074
plugin.dataFolder.mkdirs()
7175
}
72-
settings.reload()
73-
plugin.reload()
74-
initInternalScripts()
75-
scriptManager.loadScripts()
76+
modes.forEach {mode ->
77+
when (mode) {
78+
"config" -> {
79+
settings.reload()
80+
reloadLanguage()
81+
}
82+
"script" -> {
83+
initInternalScripts()
84+
scriptManager.loadScripts()
85+
}
86+
"plugin" ->{
87+
plugin.reload()
88+
}
89+
}
90+
}
7691
}
7792

7893
companion object {
@@ -121,8 +136,9 @@ fun GlobalSender.sendMessage(format: FormatHeader, text: String, placeholders: M
121136
fun GlobalSender.sendMessage(text: String, placeholders: Map<String, String>) {
122137
var rawText = text
123138
placeholders.forEach {
124-
rawText = rawText.replace(it.key, it.value)
139+
rawText = rawText.replace("{${it.key}}", it.value)
125140
}
141+
this.sendMessage(text)
126142
}
127143

128144
fun String.setPlaceholder(player: GlobalPlayer) = FastScript.instance.setPlaceholder(player, this)
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
package me.scoretwo.fastscript.command
22

33
import me.scoretwo.fastscript.FastScript
4+
import me.scoretwo.fastscript.command.commands.ReloadCommand
5+
import me.scoretwo.fastscript.command.commands.ScriptCommand
46
import me.scoretwo.fastscript.languages
57
import me.scoretwo.utils.command.CommandBuilder
68
import me.scoretwo.utils.command.CommandNexus
9+
import me.scoretwo.utils.command.executor.Executors
710
import me.scoretwo.utils.command.helper.HelpGenerator
811
import me.scoretwo.utils.command.language.CommandLanguage
12+
import me.scoretwo.utils.sender.GlobalSender
913
import net.md_5.bungee.api.chat.TextComponent
1014

1115
class FSCommandNexus: CommandNexus(FastScript.instance.plugin, arrayOf("FastScript", "script", "fs")) {
1216

17+
init {
18+
register(ReloadCommand())
19+
register(ScriptCommand())
20+
}
21+
1322
override var language = object : CommandLanguage {
1423
override val COMMAND_NO_PERMISSION = languages["COMMAND-TIPS.COMMAND_NO_PERMISSION"]
1524
override val COMMAND_ONLY_CONSOLE = languages["COMMAND-TIPS.COMMAND_ONLY_CONSOLE"]
1625
override val COMMAND_ONLY_PLAYER = languages["COMMAND-TIPS.COMMAND_ONLY_PLAYER"]
1726
override val COMMAND_UNKNOWN_USAGE = languages["COMMAND-TIPS.COMMAND_UNKNOWN_USAGE"]
1827
}
19-
28+
/*
2029
override var helpGenerator = object : HelpGenerator {
21-
override val description: HelpGenerator.Companion.Description
22-
get() = TODO("Not yet implemented")
2330
2431
override fun translateTexts(parents: MutableList<String>, args: MutableList<String>): MutableList<MutableList<TextComponent>> {
25-
TODO("Not yet implemented")
32+
return mutableListOf()
2633
}
2734
28-
}
29-
30-
init {
31-
registerBuilder()
32-
.alias("reload")
33-
}
35+
}*/
3436

3537
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package me.scoretwo.fastscript.command
2+
3+
import me.scoretwo.fastscript.plugin
4+
import me.scoretwo.utils.command.SendLimit
5+
import me.scoretwo.utils.command.SubCommand
6+
7+
/**
8+
* @author Score2
9+
* @date 2021/2/6 14:51
10+
*
11+
* @project FastScript
12+
*/
13+
abstract class SimpleCommand(alias: Array<String>, limit: SendLimit = SendLimit.ALL): SubCommand(plugin, alias, limit) {
14+
15+
16+
17+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package me.scoretwo.fastscript.command.commands
2+
3+
import me.scoretwo.fastscript.sendMessage
4+
import me.scoretwo.fastscript.FastScript
5+
import me.scoretwo.fastscript.api.format.FormatHeader
6+
import me.scoretwo.fastscript.command.SimpleCommand
7+
import me.scoretwo.utils.sender.GlobalSender
8+
9+
/**
10+
* @author Score2
11+
* @date 2021/2/6 14:50
12+
*
13+
* @project FastScript
14+
*/
15+
class ReloadCommand: SimpleCommand(arrayOf("reload")) {
16+
17+
override fun execute(sender: GlobalSender, parents: Array<String>, args: Array<String>): Boolean {
18+
var mode = "all"
19+
if (args.isNotEmpty()) {
20+
mode = args[0].toLowerCase()
21+
}
22+
23+
if (mode == "all") {
24+
FastScript.instance.reloadAll()
25+
sender.sendMessage(FormatHeader.INFO, "成功载入所有设置.")
26+
return true
27+
}
28+
FastScript.instance.reload(mode)
29+
sender.sendMessage(FormatHeader.INFO, "成功载入部分设置.")
30+
return true
31+
}
32+
33+
override fun tabComplete(sender: GlobalSender, parents: Array<String>, args: Array<String>) = mutableListOf("config", "script", "plugin", "all")
34+
35+
36+
}

FastScript-common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ScriptCommand.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
package me.scoretwo.fastscript.command.commands
22

3+
import me.scoretwo.fastscript.command.SimpleCommand
34
import me.scoretwo.fastscript.plugin
45
import me.scoretwo.utils.command.SubCommand
56
import me.scoretwo.utils.sender.GlobalSender
67

7-
class ScriptCommand: SubCommand(plugin, arrayOf("script")) {
8+
class ScriptCommand: SimpleCommand(arrayOf("script")) {
89

9-
init {
10-
11-
}
12-
13-
override fun executed(sender: GlobalSender, parents: MutableList<String>, args: MutableList<String>): Boolean {
10+
override fun execute(sender: GlobalSender, parents: Array<String>, args: Array<String>): Boolean {
1411
if (args.isEmpty()) {
1512
// list script
1613
return true

FastScript-plugin/build.gradle.kts

Lines changed: 0 additions & 110 deletions
This file was deleted.

0 commit comments

Comments
 (0)