Skip to content

Commit 6df92d5

Browse files
committed
Fixed bugs.
1 parent 6b4808f commit 6df92d5

File tree

18 files changed

+314
-106
lines changed

18 files changed

+314
-106
lines changed

build.gradle.kts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ plugins {
88
}
99

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

1414
defaultTasks = mutableListOf("ShadowJar", "publishToMavenLocal")
@@ -23,6 +23,7 @@ allprojects {
2323
jcenter()
2424
mavenCentral()
2525
mavenLocal()
26+
maven("https://maven.aliyun.com/nexus/content/groups/public/")
2627
maven("http://repo.iroselle.com/snapshots/")
2728
maven("http://repo.iroselle.com/public/")
2829
maven("https://nexus.velocitypowered.com/repository/velocity-artifacts-snapshots/")
@@ -55,13 +56,13 @@ dependencies {
5556
implementation("me.scoretwo:commons-bukkit-plugin:${rootProject.extra.get("commonsVersion")}")
5657
implementation("me.scoretwo:commons-velocity-plugin:${rootProject.extra.get("commonsVersion")}")
5758

58-
implementation("net.md-5:bungeecord-chat:1.16-R0.4-SNAPSHOT")
5959
implementation("org.bstats:bstats-bukkit:1.8")
6060
implementation("com.iroselle:cstats-bukkit:1.7")
6161
implementation("org.bstats:bstats-bungeecord:1.8")
6262
implementation("com.iroselle:cstats-bungeecord:1.7")
63-
implementation("commons-io:commons-io:2.7")
63+
implementation("commons-io:commons-io:2.8.0")
6464
implementation("commons-lang:commons-lang:2.6")
65+
implementation("net.md-5:bungeecord-chat:1.16-R0.5-SNAPSHOT")
6566

6667
implementation("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}")
6768
implementation("me.scoretwo:commons-server:${rootProject.extra.get("commonsVersion")}")
@@ -84,13 +85,13 @@ tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
8485
include(dependency("me.scoretwo:commons-bungee-plugin:${rootProject.extra.get("commonsVersion")}"))
8586
include(dependency("me.scoretwo:commons-bukkit-plugin:${rootProject.extra.get("commonsVersion")}"))
8687

87-
include(dependency("net.md-5:bungeecord-chat:1.16-R0.4-SNAPSHOT"))
8888
include(dependency("org.bstats:bstats-bukkit:1.8"))
8989
include(dependency("com.iroselle:cstats-bukkit:1.7"))
9090
include(dependency("org.bstats:bstats-bungeecord:1.8"))
9191
include(dependency("com.iroselle:cstats-bungeecord:1.7"))
9292

93-
include(dependency("commons-io:commons-io:2.7"))
93+
include(dependency("net.md-5:bungeecord-chat:1.16-R0.5-SNAPSHOT"))
94+
include(dependency("commons-io:commons-io:2.8.0"))
9495
include(dependency("commons-lang:commons-lang:2.6"))
9596

9697
include(dependency("me.scoretwo:commons-syntaxes:${rootProject.extra.get("commonsVersion")}"))

common/build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ dependencies {
1212
compileOnly("org.slf4j:slf4j-log4j12:1.7.30")
1313
compileOnly("net.md-5:bungeecord-chat:1.16-R0.5-SNAPSHOT")
1414

15+
compileOnly("org.openjdk.nashorn:nashorn-core:15.2")
16+
compileOnly("org.scala-lang:scala-compiler:2.12.9")
1517
compileOnly("commons-lang:commons-lang:2.6")
16-
compileOnly("commons-io:commons-io:2.7")
18+
compileOnly("commons-io:commons-io:2.8.0")
1719
compileOnly("me.scoretwo:commons-bukkit-configuration:${rootProject.extra.get("commonsVersion")}")
1820
compileOnly("org.jetbrains.kotlin:kotlin-script-util:${rootProject.extra.get("kotlinVersion")}")
1921
compileOnly("org.jetbrains.kotlin:kotlin-compiler:${rootProject.extra.get("kotlinVersion")}")
@@ -26,7 +28,7 @@ tasks.withType<com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar> {
2628
exclude(dependency("org.jetbrains.kotlin:kotlin-stdlib"))
2729
exclude(dependency("org.jetbrains.kotlin:kotlin-stdlib-common"))
2830

29-
exclude(dependency("commons-io:commons-io:2.7"))
31+
exclude(dependency("commons-io:commons-io:2.8.0"))
3032
exclude(dependency("commons-lang:commons-lang:2.6"))
3133

3234
exclude(dependency("me.scoretwo:commons-bukkit-configuration:${rootProject.extra.get("commonsVersion")}"))

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

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import me.scoretwo.fastscript.config.SettingConfig
1010
import me.scoretwo.fastscript.api.script.ScriptManager
1111
import me.scoretwo.fastscript.api.utils.ExecType
1212
import me.scoretwo.fastscript.api.utils.ExecUtils
13+
import me.scoretwo.fastscript.api.utils.maven.MavenArtifact
14+
import me.scoretwo.fastscript.api.utils.process.ProcessResultType
1315
import me.scoretwo.fastscript.command.commands.ScriptCommand
1416
import me.scoretwo.fastscript.utils.Assist
1517
import me.scoretwo.fastscript.utils.assist
@@ -25,6 +27,20 @@ class FastScript(val plugin: ScriptPlugin) {
2527

2628
fun setPlaceholder(player: GlobalPlayer, string: String) = plugin.setPlaceholder(player, string)
2729

30+
private val libs = arrayOf(
31+
MavenArtifact("org.openjdk.nashorn:nashorn-core:15.2"),
32+
MavenArtifact("org.ow2.asm:asm-commons:7.3.1"),
33+
MavenArtifact("org.ow2.asm:asm-analysis:7.3.1"),
34+
MavenArtifact("org.ow2.asm:asm:7.3.1"),
35+
MavenArtifact("org.ow2.asm:asm-util:7.3.1"),
36+
MavenArtifact("org.ow2.asm:asm-tree:7.3.1"),
37+
38+
MavenArtifact("org.scala-lang:scala-compiler:2.12.9"),
39+
MavenArtifact("org.scala-lang:scala-library:2.12.9"),
40+
MavenArtifact("org.scala-lang:scala-reflect:2.12.9"),
41+
MavenArtifact("org.scala-lang.modules:scala-xml_2.12:1.1.0"),
42+
)
43+
2844
init {
2945
instance = this
3046
me.scoretwo.fastscript.plugin = plugin
@@ -51,9 +67,29 @@ class FastScript(val plugin: ScriptPlugin) {
5167
languages = LanguageManager()
5268
plugin.server.console.sendMessage(FormatHeader.TREE, "Loaded config and language system.§8(${System.currentTimeMillis() - startTime}ms)")
5369

54-
ExecUtils.execPeriod(ExecType.Loaded, "configs") {
70+
ExecUtils.execPeriod(ExecType.Loaded, languages["EXEC-ID.CONFIGS"]) {
5571
reload("config")
5672
}
73+
74+
ExecUtils.execPeriod(ExecType.Loaded, languages["EXEC-ID.LIBS"]) {
75+
fun download(artifact: MavenArtifact) {
76+
val start = System.currentTimeMillis()
77+
val processResult = artifact.download()
78+
if (processResult.type == ProcessResultType.FAILED) {
79+
plugin.server.console.sendMessage(FormatHeader.ERROR, languages["DOWNLOAD-LIBS-FAILED"])
80+
throw Throwable(languages["DOWNLOAD-LIBS-FAILED"])
81+
}
82+
if (processResult.type == ProcessResultType.SUCCESS) {
83+
plugin.server.console.sendMessage(FormatHeader.INFO, languages["DOWNLOADED-LIB"].setPlaceholder(mapOf(
84+
"lib_name" to "${artifact.artifactId}-${artifact.version}.jar",
85+
"millisecond" to "${System.currentTimeMillis() - start}"
86+
)))
87+
}
88+
}
89+
libs.forEach { download(it) }
90+
plugin.libs.forEach { download(it) }
91+
}
92+
5793
ExecUtils.execPeriod(ExecType.Initialized, "script manager") {
5894
scriptManager = ScriptManager()
5995
}
@@ -98,6 +134,10 @@ class FastScript(val plugin: ScriptPlugin) {
98134
"script" -> {
99135
initInternalScripts()
100136
scriptManager.loadScripts()
137+
// Try to Fix Mohist and CatServer
138+
if (::commandNexus.isInitialized) {
139+
commandNexus = FSCommandNexus()
140+
}
101141
commandNexus.findSubCommand("script")?.also { (it as ScriptCommand).reload() }
102142
}
103143
"plugin" ->{

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ package me.scoretwo.fastscript.api.expansion
33
import me.scoretwo.fastscript.*
44
import me.scoretwo.fastscript.api.format.FormatHeader
55
import me.scoretwo.fastscript.api.plugin.ScriptPluginState
6-
import me.scoretwo.fastscript.api.utils.ExecType
76
import me.scoretwo.fastscript.api.utils.process.ProcessResult
87
import me.scoretwo.fastscript.api.utils.process.ProcessResultType
98
import me.scoretwo.fastscript.expansion.javascript.JavaScriptExpansion
9+
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
1112
import java.io.File
1213
import java.net.URL
1314
import java.net.URLClassLoader
@@ -55,12 +56,15 @@ class ExpansionManager {
5556
var fail = 0
5657
var total = 1
5758
try {
58-
register(JavaScriptExpansion().reload())
59+
if (settings.getBoolean(settings.getLowerCaseNode("Options.Internal-Expansions.JavaScript")))
60+
register(JavaScriptExpansion().reload())
61+
if (settings.getBoolean(settings.getLowerCaseNode("Options.Internal-Expansions.Scala")))
62+
register(ScalaExpansion().reload())
5963
} catch (t: Throwable) {
6064
fail++
6165
plugin.server.console.sendMessage(FormatHeader.ERROR, languages["EXPANSION.ERROR-BY-CAUSE.LOAD-ERROR"].setPlaceholder(
6266
mapOf(
63-
"file_name" to "JavaScript",
67+
"file_name" to "InternalExpansion",
6468
"reason" to t.stackTraceToString()
6569
)
6670
))

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ abstract class FastScriptExpansion {
1313

1414
abstract fun reload(): FastScriptExpansion
1515

16-
abstract fun eval(text: String, sender: GlobalSender, args: Array<Any?> = arrayOf(), otherBindings: MutableMap<String, Any?> = mutableMapOf()): Any?
17-
abstract fun eval(script: Script, sender: GlobalSender, args: Array<Any?> = arrayOf(), otherBindings: MutableMap<String, Any?> = mutableMapOf()): Any?
18-
abstract fun execute(script: Script, sender: GlobalSender, main: String = script.option.main, args: Array<Any?> = arrayOf(), otherBindings: MutableMap<String, Any?> = mutableMapOf()): Any?
19-
abstract fun execute(text: String, sender: GlobalSender, main: String = "main", args: Array<Any?> = arrayOf(), otherBindings: MutableMap<String, Any?> = mutableMapOf()): Any?
16+
abstract fun eval(text: String, sender: GlobalSender, args: Array<Any?> = arrayOf(), otherBindings: Map<String, Any?> = mutableMapOf()): Any?
17+
abstract fun eval(script: Script, sender: GlobalSender, args: Array<Any?> = arrayOf(), otherBindings: Map<String, Any?> = mutableMapOf()): Any?
18+
abstract fun execute(script: Script, sender: GlobalSender, main: String = script.option.main, args: Array<Any?> = arrayOf(), otherBindings: Map<String, Any?> = mutableMapOf()): Any?
19+
abstract fun execute(text: String, sender: GlobalSender, main: String = "main", args: Array<Any?> = arrayOf(), otherBindings: Map<String, Any?> = mutableMapOf()): Any?
2020

2121
// abstract fun eval(script: Script, sender: GlobalSender): Any?
2222

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ class Language(val version: String, val name: String = "en_US") {
2727
it["USAGE"] = "usage"
2828
it["EVALUATED"] = "evaluated"
2929
}
30+
it["EXEC-ID"] = YamlConfiguration().also {
31+
it["CONFIGS"] = "configs"
32+
it["LIBS"] = "libs"
33+
it["SCRIPT-MANAGER"] = "script manager"
34+
it["EXPANSION-MANAGER"] = "expansion manager"
35+
it["COMMAND-NEXUS"] = "CommandNexus"
36+
}
37+
it["DOWNLOADED-LIB"] = "Downloaded &b{lib_name}&7...&8({millisecond}ms)"
38+
it["DOWNLOAD-LIBS-FAILED"] = "&cFailed to download the pre-library file, please check your network, FastScript failed to start."
3039
it["HOOKED-PLUGIN"] = "Hook to the plugin &e{plugin_name} &7successfully, now you can use the relevant functions of this plugin!"
3140
it["COMMAND-NEXUS"] = YamlConfiguration().also {
3241
it["TIPS"] = YamlConfiguration().also {

common/src/main/kotlin/me/scoretwo/fastscript/api/plugin/ScriptPlugin.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package me.scoretwo.fastscript.api.plugin
22

3+
import me.scoretwo.fastscript.api.utils.maven.MavenArtifact
34
import me.scoretwo.utils.plugin.GlobalPlugin
45
import me.scoretwo.utils.plugin.PluginDescription
56
import me.scoretwo.utils.plugin.logging.GlobalLogger
@@ -12,6 +13,8 @@ abstract class ScriptPlugin(plugin: GlobalPlugin): GlobalPlugin {
1213

1314
abstract fun setPlaceholder(player: GlobalPlayer, string: String): String
1415

16+
open val libs: MutableList<MavenArtifact> = mutableListOf()
17+
1518
val scriptKits = mutableMapOf<String, Any?>()
1619

1720
abstract fun toOriginalSender(sender: GlobalSender): Any?

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ object ExecUtils {
2626
plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.ASYNC-SUCCESS"].setPlaceholder(placeholders))
2727
else
2828
plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.ASYNC-SUCCESS-HAS-DESCRIPTION"].setPlaceholder(placeholders))
29-
} catch (t: Throwable) {
30-
plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.ASYNC-FAILED"].setPlaceholder(placeholders.also { it["reason"] = t.stackTraceToString() }))
31-
t.printStackTrace()
29+
} catch (e: Exception) {
30+
plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.ASYNC-FAILED"].setPlaceholder(placeholders.also { it["reason"] = e.stackTraceToString() }))
3231
}
3332
})
3433
return ProcessResult(ProcessResultType.SUCCESS)
@@ -46,8 +45,8 @@ object ExecUtils {
4645
else
4746
plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.SUCCESS-HAS-DESCRIPTION"].setPlaceholder(placeholders))
4847
ProcessResult(ProcessResultType.SUCCESS)
49-
} catch (t: Throwable) {
50-
plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.FAILED"].setPlaceholder(placeholders.also { it["reason"] = t.stackTraceToString() }))
48+
} catch (e: Exception) {
49+
plugin.server.console.sendMessage(FormatHeader.TREE, languages["INVOKE.FAILED"].setPlaceholder(placeholders.also { it["reason"] = e.stackTraceToString() }))
5150
ProcessResult(ProcessResultType.FAILED)
5251
}
5352
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package me.scoretwo.fastscript.api.utils.maven
2+
3+
import me.scoretwo.fastscript.api.utils.process.ProcessResult
4+
import me.scoretwo.fastscript.api.utils.process.ProcessResultType
5+
import me.scoretwo.fastscript.plugin
6+
import java.io.File
7+
import java.io.InputStream
8+
import java.io.FileOutputStream
9+
import java.lang.StringBuilder
10+
import java.net.HttpURLConnection
11+
import java.net.URL
12+
import java.net.URLClassLoader
13+
14+
15+
/**
16+
* @author Score2
17+
* @date 2021/2/25 19:05
18+
*
19+
* @project FastScript
20+
*/
21+
class MavenArtifact {
22+
23+
val groupId: String
24+
val artifactId: String
25+
val version: String
26+
27+
constructor(groupId: String, artifactId: String, version: String, vararg repositories: String) {
28+
this.groupId = groupId
29+
this.artifactId = artifactId
30+
this.version = version
31+
this.repositories = arrayOf(*repositories, "https://maven.aliyun.com/nexus/content/groups/public/")
32+
}
33+
34+
constructor(combined: String, vararg repositories: String) {
35+
val split = combined.split(":")
36+
this.groupId = split[0]
37+
this.artifactId = split[1]
38+
this.version = split[2]
39+
this.repositories = arrayOf(*repositories, "https://maven.aliyun.com/nexus/content/groups/public/")
40+
}
41+
42+
val repositories: Array<String>
43+
44+
fun toURL(repository: String) = StringBuilder(repository).also {
45+
if (repository.last() != '/') it.append("/")
46+
it.append("${groupId.replace(".", "/")}/")
47+
it.append("$artifactId/")
48+
it.append("$version/")
49+
it.append("$artifactId-$version.jar")
50+
}.toString()
51+
52+
fun download(): ProcessResult {
53+
repositories.forEach {
54+
if (downLoad(it).type == ProcessResultType.FAILED) return@forEach
55+
return ProcessResult(ProcessResultType.SUCCESS)
56+
}
57+
return ProcessResult(ProcessResultType.FAILED)
58+
}
59+
60+
private fun downLoad(repository: String): ProcessResult {
61+
try {
62+
val url = toURL(repository)
63+
val folder = File(plugin.dataFolder, "lib")
64+
val target = File(folder, url.substringAfterLast("/"))
65+
if (target.exists()) {
66+
return ProcessResult(ProcessResultType.OTHER, "exists")
67+
}
68+
69+
val httpURLConnection = (URL(url).openConnection() as HttpURLConnection).also {
70+
it.connectTimeout = 20 * 1000
71+
it.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)")
72+
}
73+
74+
val inputStream: InputStream = httpURLConnection.inputStream
75+
val bytes: ByteArray = inputStream.readBytes()
76+
77+
if (!folder.exists()) {
78+
folder.mkdir()
79+
}
80+
81+
val fileOutputStream = FileOutputStream(target)
82+
fileOutputStream.write(bytes)
83+
fileOutputStream.close()
84+
inputStream.close()
85+
86+
val method = URLClassLoader::class.java.getDeclaredMethod("addURL", URL::class.java)
87+
method.isAccessible = true
88+
method.invoke(plugin.pluginClassLoader, target.toURI().toURL())
89+
return ProcessResult(ProcessResultType.SUCCESS)
90+
} catch (e: Throwable) {
91+
e.printStackTrace()
92+
return ProcessResult(ProcessResultType.FAILED)
93+
}
94+
}
95+
96+
override fun toString() = "$groupId:$artifactId:$version"
97+
98+
}

0 commit comments

Comments
 (0)