Skip to content

Commit 3a0c9d9

Browse files
committed
Start version 1.1.0
Fixed bindExpansion invalid. Added FileListener. Added nukkit support. Added new language "zh_CN". Code is more standardized.
1 parent 69fd56b commit 3a0c9d9

File tree

39 files changed

+660
-135
lines changed

39 files changed

+660
-135
lines changed

build.gradle.kts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ plugins {
88
}
99

1010
group = "me.scoretwo"
11-
version = "1.0.4-SNAPSHOT"
11+
version = "1.1.0-SNAPSHOT"
1212
description = "FastScript is a Spigot plugin, which can run JavaScript-based scripts more efficiently."
1313

1414
defaultTasks = mutableListOf("ShadowJar", "publishToMavenLocal")
1515

1616
extra.apply {
17-
set("commonsVersion", "2.0.11-SNAPSHOT")
17+
set("commonsVersion", "2.0.12-SNAPSHOT")
1818
set("kotlinVersion", "1.4.30")
1919
}
2020

@@ -33,6 +33,7 @@ allprojects {
3333
maven("https://repo.codemc.io/repository/maven-snapshots/")
3434
maven("https://repo.codemc.io/repository/maven-public/")
3535
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
36+
maven("https://repo.opencollab.dev/maven-snapshots/")
3637
}
3738

3839
group = rootProject.group
@@ -50,11 +51,13 @@ dependencies {
5051
implementation(project(":version-control:FastScript-bungee"))
5152
implementation(project(":version-control:FastScript-sponge"))
5253
implementation(project(":version-control:FastScript-velocity"))
54+
implementation(project(":version-control:FastScript-nukkit"))
5355

5456
implementation("me.scoretwo:commons-sponge-plugin:${rootProject.extra.get("commonsVersion")}")
5557
implementation("me.scoretwo:commons-bungee-plugin:${rootProject.extra.get("commonsVersion")}")
5658
implementation("me.scoretwo:commons-bukkit-plugin:${rootProject.extra.get("commonsVersion")}")
5759
implementation("me.scoretwo:commons-velocity-plugin:${rootProject.extra.get("commonsVersion")}")
60+
implementation("me.scoretwo:commons-nukkit-plugin:${rootProject.extra.get("commonsVersion")}")
5861

5962
implementation("org.bstats:bstats-bukkit:1.8")
6063
implementation("com.iroselle:cstats-bukkit:1.7")
@@ -79,11 +82,13 @@ tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
7982
include(dependency(":FastScript-bungee"))
8083
include(dependency(":FastScript-sponge"))
8184
include(dependency(":FastScript-velocity"))
85+
include(dependency(":FastScript-nukkit"))
8286

8387
include(dependency("me.scoretwo:commons-velocity-plugin:${rootProject.extra.get("commonsVersion")}"))
8488
include(dependency("me.scoretwo:commons-sponge-plugin:${rootProject.extra.get("commonsVersion")}"))
8589
include(dependency("me.scoretwo:commons-bungee-plugin:${rootProject.extra.get("commonsVersion")}"))
8690
include(dependency("me.scoretwo:commons-bukkit-plugin:${rootProject.extra.get("commonsVersion")}"))
91+
include(dependency("me.scoretwo:commons-nukkit-plugin:${rootProject.extra.get("commonsVersion")}"))
8792

8893
include(dependency("org.bstats:bstats-bukkit:1.8"))
8994
include(dependency("com.iroselle:cstats-bukkit:1.7"))
@@ -148,4 +153,14 @@ tasks.processResources {
148153
"description" to project.description
149154
))
150155
}
156+
from("src/main/resources") {
157+
include("nukkit.yml")
158+
expand(mapOf(
159+
"id" to rootProject.name.toLowerCase(),
160+
"name" to rootProject.name,
161+
"version" to project.version,
162+
"main" to "${rootProject.group}.${rootProject.name.toLowerCase()}.nukkit.NukkitBootStrap",
163+
"description" to project.description
164+
))
165+
}
151166
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import me.scoretwo.fastscript.api.utils.process.ProcessResultType
1515
import me.scoretwo.fastscript.command.commands.ScriptCommand
1616
import me.scoretwo.fastscript.utils.Assist
1717
import me.scoretwo.fastscript.utils.assist
18+
import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
1819
import me.scoretwo.utils.sender.GlobalPlayer
1920
import me.scoretwo.utils.sender.GlobalSender
2021
import net.md_5.bungee.api.ChatColor
@@ -135,6 +136,10 @@ class FastScript(val plugin: ScriptPlugin) {
135136
when (mode) {
136137
"config" -> {
137138
settings.reload()
139+
if (settings.getBoolean(settings.ignoreCase("options.debug")))
140+
plugin.server.dispatchCommand(plugin.server.console, "fs ::enable_debug")
141+
else
142+
plugin.server.dispatchCommand(plugin.server.console, "fs ::disable_debug")
138143
reloadLanguage()
139144
}
140145
"script" -> {

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import me.scoretwo.fastscript.api.utils.process.ProcessResultType
88
import me.scoretwo.fastscript.expansion.javascript.JavaScriptExpansion
99
import me.scoretwo.fastscript.expansion.scala.ScalaExpansion
1010
import me.scoretwo.utils.bukkit.configuration.yaml.file.YamlConfiguration
11-
import me.scoretwo.utils.bukkit.configuration.yaml.patchs.getLowerCaseNode
11+
import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
1212
import java.io.File
1313
import java.net.URL
1414
import java.net.URLClassLoader
@@ -56,9 +56,9 @@ class ExpansionManager {
5656
var fail = 0
5757
var total = 1
5858
try {
59-
if (settings.getBoolean(settings.getLowerCaseNode("Options.Internal-Expansions.JavaScript")))
59+
if (settings.getBoolean(settings.ignoreCase("Options.Internal-Expansions.JavaScript")))
6060
register(JavaScriptExpansion().reload())
61-
if (settings.getBoolean(settings.getLowerCaseNode("Options.Internal-Expansions.Scala")))
61+
if (settings.getBoolean(settings.ignoreCase("Options.Internal-Expansions.Scala")))
6262
register(ScalaExpansion().reload())
6363
} catch (t: Throwable) {
6464
fail++
@@ -86,9 +86,9 @@ class ExpansionManager {
8686
try {
8787
expansions.add(rawExpansion.second!!.reload())
8888
success++
89-
} catch (e: Throwable) {
89+
} catch (t: Throwable) {
9090
fail++
91-
// plugin.server.console.sendMessage(FormatHeader.ERROR, "An exception occurred while loading expansion ${file.name}, reason:\n§8${e.stackTraceToString()}")
91+
// plugin.server.console.sendMessage(FormatHeader.ERROR, "An exception occurred while loading expansion ${file.name}, reason:\n§8${t.stackTraceToString()}")
9292
}
9393
}
9494
val format = if (FastScript.stats == ScriptPluginState.RUNNING) FormatHeader.INFO else FormatHeader.TREE
@@ -117,36 +117,36 @@ class ExpansionManager {
117117
val jarFile = JarFile(file)
118118
description = try {
119119
ExpansionDescription.readConfig(YamlConfiguration().also { it.load(jarFile.getInputStream(jarFile.getJarEntry("expansion.yml")).reader()) })
120-
} catch (e: Throwable) {
120+
} catch (t: Throwable) {
121121
plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-DESCRIPTION-FILE-ERROR"].setPlaceholder(
122122
mapOf(
123123
"file_name" to file.name,
124-
"reason" to e.stackTraceToString()
124+
"reason" to t.stackTraceToString()
125125
)
126126
))
127127
return Pair(ProcessResult(ProcessResultType.FAILED), null)
128128
}
129129
val clazz = try {
130130
Class.forName(description.main)
131-
} catch (e: Throwable) {
131+
} catch (t: Throwable) {
132132
plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-MAIN-CLASS-ERROR"].setPlaceholder(
133133
mapOf(
134134
"file_name" to file.name,
135135
"description_main" to description.main,
136-
"reason" to e.stackTraceToString()
136+
"reason" to t.stackTraceToString()
137137
)
138138
))
139139
return Pair(ProcessResult(ProcessResultType.FAILED), null)
140140
}
141141

142142
val instance = try {
143143
clazz.newInstance()
144-
} catch (e: Throwable) {
144+
} catch (t: Throwable) {
145145
plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-MAIN-CLASS-ERROR"].setPlaceholder(
146146
mapOf(
147147
"file_name" to file.name,
148148
"description_main" to description.main,
149-
"reason" to e.stackTraceToString()
149+
"reason" to t.stackTraceToString()
150150
)
151151
))
152152
return Pair(ProcessResult(ProcessResultType.FAILED), null)
@@ -163,11 +163,11 @@ class ExpansionManager {
163163
}
164164

165165
clazz.asSubclass(FastScriptExpansion::class.java)
166-
} catch (e: Throwable) {
166+
} catch (t: Throwable) {
167167
plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-ERROR"].setPlaceholder(
168168
mapOf(
169169
"file_name" to file.name,
170-
"reason" to e.stackTraceToString()
170+
"reason" to t.stackTraceToString()
171171
)
172172
))
173173
return Pair(ProcessResult(ProcessResultType.FAILED), null)

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ abstract class FastScriptExpansion {
99
abstract val sign: String
1010
abstract val fileSuffix: String
1111

12+
@Deprecated("已不需要该 boolean 进行判断, 脚本不应该在每次 execute 时进行 evaluate")
1213
abstract val needEval: Boolean
1314

1415
abstract fun reload(): FastScriptExpansion

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

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package me.scoretwo.fastscript.api.language
33
import me.scoretwo.fastscript.languages
44
import me.scoretwo.fastscript.plugin
55
import me.scoretwo.utils.bukkit.configuration.yaml.file.YamlConfiguration
6-
import me.scoretwo.utils.bukkit.configuration.yaml.patchs.getLowerCaseNode
6+
import me.scoretwo.utils.bukkit.configuration.yaml.patchs.ignoreCase
77
import me.scoretwo.utils.bukkit.configuration.yaml.patchs.saveConfiguration
88
import me.scoretwo.utils.server.task.TaskType
99
import java.io.File
@@ -71,7 +71,7 @@ class Language(val version: String, val name: String = "en_US") {
7171
" &3&l* &7File suffix: &a{expansion_file_suffix}",
7272
" &3&l* &7Bind scripts: &f{expansion_bind_scripts}",
7373
"",
74-
" &7About expansions &6{expansion_name} &7more help, please enter:&8(Bad grammar)"
74+
" &7About expansions &6{expansion_name} &7more help, please enter:"
7575

7676
)
7777
}
@@ -101,7 +101,7 @@ class Language(val version: String, val name: String = "en_US") {
101101
}
102102

103103
it["INFO"] = YamlConfiguration().also {
104-
it["DESCRIPTION"] = "View the information of this expansion."
104+
it["DESCRIPTION"] = "View the information of this script."
105105
it["TITLE"] = "Script &b{script_name}&7's information."
106106
it["TEXTS"] = mutableListOf(
107107
" &3&l* &7Version: &2{script_version}",
@@ -110,7 +110,7 @@ class Language(val version: String, val name: String = "en_US") {
110110
" &3&l* &7Main: &f{script_main}",
111111
" &3&l* &7Bind expansions: &6{script_bind_expansions}",
112112
"",
113-
" &7About script &6{script_name} &7more help, please enter:&8(Bad grammar)"
113+
" &7About script &6{script_name} &7more help, please enter:"
114114

115115
)
116116
}
@@ -128,6 +128,11 @@ class Language(val version: String, val name: String = "en_US") {
128128
it["LOADED-CONFIG"] = "Loaded configuration file successful."
129129
it["LOADED-SCRIPT"] = "Loaded script file successful."
130130
it["LOADED-PLUGIN"] = "Loaded plugin settings successful."
131+
132+
it["ASYNC-LOADED-ALL"] = "Async loaded all settings successful."
133+
it["ASYNC-LOADED-CONFIG"] = "Async loaded configuration file successful."
134+
it["ASYNC-LOADED-SCRIPT"] = "Async loaded script file successful."
135+
it["ASYNC-LOADED-PLUGIN"] = "Async loaded plugin settings successful."
131136
}
132137
it["TOOLS"] = YamlConfiguration().also {
133138
it["DESCRIPTION"] = "Some useful tool libraries."
@@ -139,7 +144,7 @@ class Language(val version: String, val name: String = "en_US") {
139144
it["BUKKIT"] = YamlConfiguration().also {
140145
it["SOUNDS"] = YamlConfiguration().also {
141146
it["DESCRIPTION"] = "Play Sound to the player."
142-
it["NOT-FOUND-SOUND"] = "Sound {sound_name} not found."
147+
it["NOT-FOUND-SOUND"] = "Sound &8{sound_name} &7not found."
143148
}
144149
}
145150
}
@@ -150,21 +155,20 @@ class Language(val version: String, val name: String = "en_US") {
150155
}
151156
it["EXPANSION"] = YamlConfiguration().also {
152157
it["TYPE-ENGINE"] = YamlConfiguration().also {
153-
it["EVALUATE-SCRIPT-ERROR"] = "An error occurred during script {script_name} evaluation, please check the script format.\n&8{reason}"
154-
it["EVALUATE-TEMP-SCRIPT-ERROR"] = "An error occurred during temp script evaluation, please check the script format.\n&8{reason}"
155-
it["EXECUTE-SCRIPT-ERROR"] = "An error occurred when the script {script_name} executes the function {execute_main}, please check the script format.\n&8{reason}"
156-
it["EXECUTE-SCRIPT-FUNCTION-NOT-FOUND-ERROR"] = "An error occurred when the script {script_name} executes the function {execute_main}, this function not found!"
157-
it["EXECUTE-TEMP-SCRIPT-ERROR"] = "An error occurred when the temp script executes the function {execute_main}, please check the script format, reason:\n&8{reason}"
158-
it["EXECUTE-SCRIPT-FUNCTION-NOT-FOUND-ERROR"] = "An error occurred when the temp script executes the function {execute_main}, this function not found!"
158+
it["EVALUATE-SCRIPT-ERROR"] = "An error occurred during script {script_name} evaluation, please check the script format. reason: \n&8{reason}"
159+
it["EVALUATE-TEMP-SCRIPT-ERROR"] = "An error occurred during temp script evaluation, please check the script format. reason: \n&8{reason}"
160+
it["EXECUTE-SCRIPT-ERROR"] = "An error occurred when the script {script_name} executes the function {execute_main}, please check the script format. reason: \n&8{reason}"
161+
it["EXECUTE-SCRIPT-FUNCTION-NOT-FOUND-ERROR"] = "An error occurred when the script {script_name} executes the function {execute_main}, reason: &8this function not found!"
162+
it["EXECUTE-TEMP-SCRIPT-ERROR"] = "An error occurred when the temp script executes the function {execute_main}, please check the script format, reason: \n&8{reason}"
163+
it["EXECUTE-SCRIPT-FUNCTION-NOT-FOUND-ERROR"] = "An error occurred when the temp script executes the function {execute_main}, reason: &8this function not found!"
159164
}
160165
it["ERROR-BY-CAUSE"] = YamlConfiguration().also {
161-
it["LOAD-ERROR"] = "An exception occurred while loading expansion {file_name}, reason:\n&8{reason}"
162-
it["LOAD-DESCRIPTION-FILE-ERROR"] = "An error occurred while loading the expansion '{file_name}' description file, reason:\n&8{reason}"
163-
it["LOAD-MAIN-CLASS-ERROR"] = "An error occurred while loading the main class {description_main} of expansion '{file_name}', reason:\n&8{reason}"
166+
it["LOAD-ERROR"] = "An exception occurred while loading expansion {file_name}, reason: \n&8{reason}"
167+
it["LOAD-DESCRIPTION-FILE-ERROR"] = "An error occurred while loading the expansion '{file_name}' description file, reason: \n&8{reason}"
168+
it["LOAD-MAIN-CLASS-ERROR"] = "An error occurred while loading the main class {description_main} of expansion '{file_name}', reason: \n&8{reason}"
164169
it["LOAD-MAIN-CLASS-MAIN-NOT-DEPEND"] = "An error occurred while loading the main class {description_main} of expansion '{file_name}', reason: &cThe main class does not depend on FastScriptExpansion."
165170
it["CAN-NOT-LOAD-MAIN-CLASS"] = "Unable to load the extension '{file_name}' because it has no FastScriptExpansion class available!"
166171
}
167-
168172
}
169173
it["SCRIPT"] = YamlConfiguration().also {
170174
it["PROCESS-RESULT"] = YamlConfiguration().also {
@@ -188,6 +192,12 @@ class Language(val version: String, val name: String = "en_US") {
188192
it["FAILED"] = "&cFailed to invoke {exec_name}, reason:\n&8{reason}"
189193
}
190194

195+
it["FILE-LISTENER"] = YamlConfiguration().also {
196+
it["SCRIPT"] = YamlConfiguration().also {
197+
it["LOADED"] = "Detected file &6{file_name} &7changes, successfully reloaded script &b{script_name}&7.&8({millisecond}ms)"
198+
}
199+
}
200+
191201
it["VERSION"] = version
192202

193203
}
@@ -205,7 +215,7 @@ class Language(val version: String, val name: String = "en_US") {
205215
file.saveConfiguration(defaultConfig)
206216
} else {
207217
config.load(file)
208-
val configVersion = config.getString(config.getLowerCaseNode("version"))
218+
val configVersion = config.getString(config.ignoreCase("version"))
209219

210220
if (configVersion == null || version != configVersion) {
211221
defaultConfig.getKeys(true).forEach { if (!config.contains(it)) { config.set(it, defaultConfig[it]) } }

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ import net.md_5.bungee.api.ChatColor
55
import java.io.File
66

77
class LanguageManager {
8-
val version = "1"
8+
val version = Companion.version
99
val defaultLanguage = Language(version).reload()
1010
val languages = mutableMapOf<String, Language>().also {
11+
File(plugin.dataFolder, "language/zh_CN.yml").also {
12+
if (!it.exists()) zh_CN.save(it)
13+
}
14+
1115
it["en_US"] = defaultLanguage
16+
it["zh_CN"] = Language(version, "zh_CN")
1217
}
1318

1419
init {
@@ -26,4 +31,8 @@ class LanguageManager {
2631

2732
fun getList(node: String) = current.getList(node).also { it.toMutableList().forEachIndexed { i, s -> it[i] = ChatColor.translateAlternateColorCodes('&', s) } }
2833

34+
companion object {
35+
const val version = "2"
36+
}
37+
2938
}

0 commit comments

Comments
 (0)