Skip to content

Commit 4df8b67

Browse files
committed
Fixed bugs.
1 parent 3eedbc1 commit 4df8b67

File tree

20 files changed

+171
-55
lines changed

20 files changed

+171
-55
lines changed

build.gradle.kts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ dependencies {
6464
implementation("commons-lang:commons-lang:2.6")
6565

6666
implementation("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}")
67-
implementation("me.scoretwo:commons-command:${rootProject.extra.get("commonsVersion")}")
6867
implementation("me.scoretwo:commons-server:${rootProject.extra.get("commonsVersion")}")
6968
implementation("me.scoretwo:commons-bukkit-configuration:${rootProject.extra.get("commonsVersion")}")
7069
}
@@ -95,7 +94,6 @@ tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
9594
include(dependency("commons-lang:commons-lang:2.6"))
9695

9796
include(dependency("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}"))
98-
include(dependency("me.scoretwo:commons-command:${rootProject.extra.get("commonsVersion")}"))
9997
include(dependency("me.scoretwo:commons-server:${rootProject.extra.get("commonsVersion")}"))
10098
include(dependency("me.scoretwo:commons-bukkit-configuration:${rootProject.extra.get("commonsVersion")}"))
10199
}

common/build.gradle.kts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ plugins {
1010
dependencies {
1111
compileOnly("com.google.code.gson:gson:2.8.6")
1212
compileOnly("org.slf4j:slf4j-log4j12:1.7.30")
13+
compileOnly("net.md-5:bungeecord-chat:1.16-R0.5-SNAPSHOT")
1314

1415
implementation("org.jetbrains.kotlin:kotlin-script-util:${rootProject.extra.get("kotlinVersion")}")
1516
implementation("org.jetbrains.kotlin:kotlin-compiler:${rootProject.extra.get("kotlinVersion")}")
1617

1718
implementation("commons-lang:commons-lang:2.6")
1819
implementation("commons-io:commons-io:2.7")
1920
implementation("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}")
20-
implementation("me.scoretwo:commons-command:${rootProject.extra.get("commonsVersion")}")
2121
implementation("me.scoretwo:commons-server:${rootProject.extra.get("commonsVersion")}")
2222
implementation("me.scoretwo:commons-bukkit-configuration:${rootProject.extra.get("commonsVersion")}")
2323
}
@@ -31,7 +31,6 @@ tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
3131
include(dependency("commons-lang:commons-lang:2.6"))
3232

3333
include(dependency("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}"))
34-
include(dependency("me.scoretwo:commons-command:${rootProject.extra.get("commonsVersion")}"))
3534
include(dependency("me.scoretwo:commons-server:${rootProject.extra.get("commonsVersion")}"))
3635
include(dependency("me.scoretwo:commons-bukkit-configuration:${rootProject.extra.get("commonsVersion")}"))
3736
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import me.scoretwo.fastscript.api.script.ScriptManager
1111
import me.scoretwo.fastscript.api.utils.ExecType
1212
import me.scoretwo.fastscript.api.utils.ExecUtils
1313
import me.scoretwo.fastscript.command.commands.ScriptCommand
14+
import me.scoretwo.fastscript.utils.Assist
15+
import me.scoretwo.fastscript.utils.assist
1416
import me.scoretwo.utils.sender.GlobalPlayer
1517
import me.scoretwo.utils.sender.GlobalSender
1618
import net.md_5.bungee.api.ChatColor
@@ -64,6 +66,7 @@ class FastScript(val plugin: ScriptPlugin) {
6466
ExecUtils.execPeriod(ExecType.Initialized, "CommandNexus") {
6567
commandNexus = FSCommandNexus()
6668
}
69+
assist = Assist()
6770
}
6871

6972
fun reloadLanguage() {

common/src/main/kotlin/me/scoretwo/fastscript/api/expansion/ExpansionManager.kt

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,24 @@ class ExpansionManager {
5151
fun reload() {
5252
val startTime = System.currentTimeMillis()
5353
expansions.clear()
54-
register(JavaScriptExpansion().reload())
54+
var success = 1
55+
var fail = 0
56+
var total = 1
57+
try {
58+
register(JavaScriptExpansion().reload())
59+
} catch (t: Throwable) {
60+
fail++
61+
plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-ERROR"].setPlaceholder(
62+
mapOf(
63+
"file_name" to "JavaScript",
64+
"reason" to t.stackTraceToString()
65+
)
66+
))
67+
}
5568

5669
if (!expansionFolder.exists())
5770
expansionFolder.mkdirs()
5871

59-
var success = 1
60-
var fail = 0
61-
var total = 1
6272

6373
for (file in expansionFolder.listFiles() ?: arrayOf()) {
6474
total++

common/src/main/kotlin/me/scoretwo/fastscript/api/language/Language.kt

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,12 @@ class Language(val version: String, val name: String = "en_US") {
2727
it["USAGE"] = "usage"
2828
it["EVALUATED"] = "evaluated"
2929
}
30+
it["HOOKED-PLUGIN"] = "Hook to the plugin &e{plugin_name} &7successfully, now you can use the relevant functions of this plugin!"
3031
it["COMMAND-NEXUS"] = YamlConfiguration().also {
3132
it["TIPS"] = YamlConfiguration().also {
32-
it["ONLY-CONSOLE"] = "This command can only be executed on the console."
33-
it["ONLY-PLAYER"] = "This command can only be executed by the player."
34-
it["NO-PERMISSION"] = "You do not have permission to execute the command."
33+
it["ONLY-CONSOLE"] = "&cThis command can only be executed on the console."
34+
it["ONLY-PLAYER"] = "&cThis command can only be executed by the player."
35+
it["NO-PERMISSION"] = "&cYou do not have permission to execute the command."
3536
it["UNKNOWN-USAGE"] = "&cUsage &e{usage_error} &cis incorrect, you may want to use &e{usage_guess}&c."
3637
}
3738
it["HELPER"] = YamlConfiguration().also {
@@ -41,6 +42,12 @@ class Language(val version: String, val name: String = "en_US") {
4142
it["PLAYER-IS-OFFLINE"] = "&7Player &a{player_name} &7is not online"
4243
}
4344
it["COMMANDS"] = YamlConfiguration().also {
45+
it["MIGRATE"] = YamlConfiguration().also {
46+
it["DESCRIPTION"] = "Migrate from other plugins."
47+
48+
it["UNKNOWN-ACTION"] = "No action found {action_name}"
49+
}
50+
4451
it["EXPANSION"] = YamlConfiguration().also {
4552
it["NOT-FOUND-NAME-OR-SIGN"] = "Cannot find the extension name or sign &c{expansion_name}&7! Please check the name."
4653
it["LOADED-EXPANSIONS"] = "Currently available extensions: &6{expansions}"
@@ -123,6 +130,7 @@ class Language(val version: String, val name: String = "en_US") {
123130
it["BUKKIT"] = YamlConfiguration().also {
124131
it["SOUNDS"] = YamlConfiguration().also {
125132
it["DESCRIPTION"] = "Play Sound to the player."
133+
it["NOT-FOUND-SOUND"] = "Sound {sound_name} not found."
126134
}
127135
}
128136
}
@@ -155,7 +163,7 @@ class Language(val version: String, val name: String = "en_US") {
155163
it["SCRIPT-TYPE-NOT-SUPPORTED"] = "The script file extension is not supported!"
156164
it["SCRIPT-FILE-NAME-CANNOT-SPACES"] = "File name cannot contain spaces!"
157165
}
158-
it["SCRIPT-FAILED-LOAD-BY-PROCESS-RESULT"] = "An error occurred while loading script {file_name}, reason:&8{reason}"
166+
it["SCRIPT-FAILED-LOAD-BY-PROCESS-RESULT"] = "An error occurred while loading script &3{file_name}&7, reason: &8{reason}"
159167
}
160168
it["LOADED-COUNTS-PROCESS-SUCCESS"] = "Loaded &b{total} &7{id}, &a{success} &7successes.&8({millisecond}ms)"
161169
it["LOADED-COUNTS-PROCESS-SUCCESS-HAS-FAILED"] = "Loaded &b{total} &7{id}, &a{success} &7successes, &c{fail} &7failures.&8({millisecond}ms)"

common/src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptManager.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ScriptManager {
4747
val scriptName = scriptFile.name.substringBeforeLast(".")
4848
scriptFile.parentFile.listFiles()?.forEach {
4949
if (it.name == "$scriptName.yml") {
50-
return Pair(null, ProcessResult(ProcessResultType.OTHER, languages["SCRIPT.PROCESS-RESULT.SCRIPT-OPTION-FILE-NOT-EXISTS"]))
50+
return Pair(null, ProcessResult(ProcessResultType.OTHER, languages["SCRIPT.PROCESS-RESULT.SCRIPT-OPTION-FILE-NOT-EXISTS"], "file" to scriptFile.name))
5151
}
5252
}
5353

@@ -58,7 +58,7 @@ class ScriptManager {
5858

5959
return@let scriptFile
6060
}
61-
return Pair(null, ProcessResult(ProcessResultType.FAILED, languages["SCRIPT.PROCESS-RESULT.SCRIPT-TYPE-NOT-SUPPORTED"]))
61+
return Pair(null, ProcessResult(ProcessResultType.FAILED, languages["SCRIPT.PROCESS-RESULT.SCRIPT-TYPE-NOT-SUPPORTED"], "file" to scriptFile.name))
6262
}
6363
val script = CustomScript(
6464
object : ScriptDescription {
@@ -171,7 +171,7 @@ class ScriptManager {
171171
if (it.second.type == ProcessResultType.FAILED || it.first == null) {
172172
fail++
173173
plugin.server.console.sendMessage(FormatHeader.ERROR, languages["SCRIPT.SCRIPT-FAILED-LOAD-BY-PROCESS-RESULT"].setPlaceholder(
174-
mapOf("file_name" to file.name, "reason" to it.second.message)
174+
mapOf("file_name" to (it.second.infos["file"] ?: "Unknown"), "reason" to it.second.message)
175175
))
176176
}
177177
else if (it.second.type == ProcessResultType.SUCCESS)

common/src/main/kotlin/me/scoretwo/fastscript/api/utils/ExecUtils.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object ExecUtils {
1919
"exec_description" to (description ?: ""),
2020
"millisecond" to "${System.currentTimeMillis() - start}"
2121
)
22-
plugin.server.schedule.task(plugin, taskType) {
22+
plugin.server.schedule.task(plugin, taskType, Runnable {
2323
try {
2424
unit.invoke()
2525
if (description == null)
@@ -30,7 +30,7 @@ object ExecUtils {
3030
plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.ASYNC-FAILED"].setPlaceholder(placeholders.also { it["reason"] = t.stackTraceToString() }))
3131
t.printStackTrace()
3232
}
33-
}
33+
})
3434
return ProcessResult(ProcessResultType.SUCCESS)
3535
} else {
3636
val placeholders = mutableMapOf(
@@ -47,7 +47,7 @@ object ExecUtils {
4747
plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.SUCCESS-HAS-DESCRIPTION"].setPlaceholder(placeholders))
4848
ProcessResult(ProcessResultType.SUCCESS)
4949
} catch (t: Throwable) {
50-
plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.SUCCESS-FAILED"].setPlaceholder(placeholders.also { it["reason"] = t.stackTraceToString() }))
50+
plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.FAILED"].setPlaceholder(placeholders.also { it["reason"] = t.stackTraceToString() }))
5151
ProcessResult(ProcessResultType.FAILED)
5252
}
5353
}

common/src/main/kotlin/me/scoretwo/fastscript/api/utils/Utils.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import me.scoretwo.fastscript.api.format.FormatHeader
55
import me.scoretwo.fastscript.config.SettingConfig
66
import me.scoretwo.fastscript.plugin
77
import me.scoretwo.utils.bukkit.configuration.yaml.patchs.getLowerCaseNode
8+
import me.scoretwo.utils.command.CommandBuilder
9+
import me.scoretwo.utils.command.CommandNexus
810
import me.scoretwo.utils.sender.GlobalPlayer
911
import me.scoretwo.utils.sender.GlobalSender
1012
import me.scoretwo.utils.syntaxes.FileUtils
@@ -28,6 +30,16 @@ object Utils {
2830
}
2931

3032
}
33+
34+
class Assist {
35+
36+
fun createCommandNexus(vararg alias: String) = CommandNexus(plugin, arrayOf(*alias))
37+
38+
fun createCommandBuilder() = CommandBuilder()
39+
40+
}
41+
lateinit var assist: Assist
42+
3143
fun String.subStringWithEscape(from: Int, to: Int, escapes: List<Int>): String {
3244
val builder = StringBuilder()
3345
if (escapes.isEmpty())

common/src/main/kotlin/me/scoretwo/fastscript/api/utils/process/ProcessResult.kt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@ package me.scoretwo.fastscript.api.utils.process
22

33
import me.scoretwo.fastscript.api.exception.ProcessException
44

5-
class ProcessResult(val type: ProcessResultType, message: String? = null) {
5+
class ProcessResult(val type: ProcessResultType, message: String? = null, vararg infos: Pair<String, String>) {
66

77
var message: String = message ?: type.message
88

9+
val infos = mutableMapOf<String, String>()
10+
11+
init {
12+
infos.forEach {
13+
this.infos[it.first] = it.second
14+
}
15+
}
16+
917
fun throwException() {
1018
throw ProcessException(message)
1119
}

common/src/main/kotlin/me/scoretwo/fastscript/command/FSCommandNexus.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class FSCommandNexus: CommandNexus(FastScript.instance.plugin, arrayOf("FastScri
2121
init {
2222
register(ScriptCommand())
2323
register(ExpansionCommand())
24+
register(MigrateCommand())
2425
register(ToolsCommand())
2526
register(ReloadCommand())
2627
register(DebugCommand())
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package me.scoretwo.fastscript.command.commands
2+
3+
import me.scoretwo.fastscript.api.format.FormatHeader
4+
import me.scoretwo.fastscript.command.SimpleCommand
5+
import me.scoretwo.fastscript.languages
6+
import me.scoretwo.fastscript.sendMessage
7+
import me.scoretwo.fastscript.setPlaceholder
8+
import me.scoretwo.utils.sender.GlobalSender
9+
10+
/**
11+
* @author Score2
12+
* @date 2021/2/24 10:57
13+
*
14+
* @project FastScript
15+
*/
16+
class MigrateCommand: SimpleCommand(arrayOf("migrate")) {
17+
18+
override var description = languages["COMMAND-NEXUS.COMMANDS.MIGRATE.DESCRIPTION"]
19+
20+
override fun execute(sender: GlobalSender, parents: Array<String>, args: Array<String>): Boolean {
21+
if (args.isEmpty()) {
22+
return false
23+
}
24+
25+
when (args[0]) {
26+
"PlaceholderAPI:JavaScript" -> {
27+
sender.sendMessage(FormatHeader.ERROR, "Not currently supported.")
28+
}
29+
else -> {
30+
sender.sendMessage(FormatHeader.ERROR, languages["COMMAND-NEXUS.COMMANDS.MIGRATE.UNKNOWN-ACTION"].setPlaceholder("action_name" to args[0]))
31+
}
32+
}
33+
34+
return true
35+
}
36+
37+
override fun tabComplete(sender: GlobalSender, parents: Array<String>, args: Array<String>): MutableList<String>? {
38+
if (args.size < 2) {
39+
return mutableListOf("PlaceholderAPI:JavaScript")
40+
}
41+
return null
42+
}
43+
44+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class ScriptCommand: SimpleCommand(arrayOf("script")) {
154154
}
155155

156156
script.reload()
157-
sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.SCRIPT.RELOAD.RELOADED-SCRIPT"])
157+
sender.sendMessage(FormatHeader.INFO, languages["COMMAND-NEXUS.COMMANDS.SCRIPT.RELOAD.RELOADED-SCRIPT"].setPlaceholder("script_name" to script.name))
158158
return true
159159
}
160160
})

common/src/main/kotlin/me/scoretwo/fastscript/command/commands/ToolsCommand.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ class ToolsCommand: SimpleCommand(arrayOf("tools", "tool", "utils", "util")) {
2727
if (args.isEmpty()) {
2828
return false
2929
}
30+
val command = args.sliceArray(1 until args.size).joinToString(" ")
31+
if (args[0].toLowerCase() == "@all") {
32+
plugin.server.getOnlinePlayers().forEach { plugin.server.dispatchCommand(it, command) }
33+
return true
34+
}
35+
3036
val target = if (args[0].toLowerCase() == "@console") plugin.server.console else plugin.server.getPlayer(args[0]).let {
3137
if (it.isPresent) {
3238
it.get()
@@ -35,13 +41,12 @@ class ToolsCommand: SimpleCommand(arrayOf("tools", "tool", "utils", "util")) {
3541
return true
3642
}
3743
}
38-
val command = args.sliceArray(1 until args.size).joinToString(" ")
3944
plugin.server.dispatchCommand(target, command)
4045
return true
4146
}
4247

4348
override fun tabComplete(sender: GlobalSender, parents: Array<String>, args: Array<String>) =
44-
mutableListOf("@CONSOLE").also { list -> plugin.server.getOnlinePlayers().forEach { list.add(it.name) } }
49+
mutableListOf("@CONSOLE", "@ALL").also { list -> plugin.server.getOnlinePlayers().forEach { list.add(it.name) } }
4550
})
4651
.build()
4752
)

common/src/main/kotlin/me/scoretwo/fastscript/expansion/javascript/JavaScriptExpansion.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ class JavaScriptExpansion: TypeEngineExpansion() {
77
override val name = "JavaScript"
88
override val sign = "nashorn"
99
override val fileSuffix = "js"
10-
override val engine: ScriptEngine = scriptEngineManager.getEngineByName("nashorn")
10+
override val engine: ScriptEngine = scriptEngineManager.getEngineByName("nashorn") ?: scriptEngineManager.getEngineByName("javascript")
11+
1112
}

0 commit comments

Comments
 (0)