Skip to content

Commit 4bfcbb2

Browse files
committed
Update.
1 parent ca4c906 commit 4bfcbb2

File tree

16 files changed

+206
-64
lines changed

16 files changed

+206
-64
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
![](http://mc3.roselle.vip:602/FastScript/big_logo.gif)
2+
<font color=#8E8E8E size=3>The idea of the LOGO comes from @Arasple's TrMenu.</font>
23
***
34
### About
45
FastScript is a Spigot plugin, which can run JavaScript-based scripts more efficiently.

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

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,32 @@ import me.scoretwo.fastscript.api.plugin.FastScriptMain
55
import me.scoretwo.fastscript.api.script.ScriptManager
66
import java.io.File
77

8-
class FastScript(val dataFolder: File, private val classLoader: ClassLoader) {
8+
class FastScript(main: FastScriptMain) {
9+
10+
private val main: FastScriptMain = main
911

1012
val scriptManager = ScriptManager()
1113

14+
val dataFolder = main.getDataFolder()
15+
val classLoader = main.getPluginClassLoader()
16+
fun setPlaceholder(player: Any, string: String) = main.setPlaceholder(player, string)
17+
fun sendMessage(sender: Any, string: String, colorIndex: Boolean) = main.sendMessage(sender, string, colorIndex)
18+
19+
init {
20+
CONSOLE = main.CONSOLE
21+
}
22+
1223
fun initInternalScripts() {
1324

1425
}
1526

1627
fun onReload() {
28+
main.onReload()
1729
initInternalScripts()
1830
}
1931

2032
/**
33+
* 用于随机点亮 FastScript 的 Logo
2134
* 该创意来源于 TrMenu
2235
* @author Arasple
2336
*/
@@ -47,12 +60,14 @@ class FastScript(val dataFolder: File, private val classLoader: ClassLoader) {
4760

4861
companion object {
4962
lateinit var instance: FastScript
50-
lateinit var main: FastScriptMain
63+
var CONSOLE = Any()
5164

5265
@JvmStatic
5366
fun main(args: Array<out String>) {
5467

55-
main = object : FastScriptMain {
68+
val main = object : FastScriptMain {
69+
override val CONSOLE: Any = this
70+
5671
override fun getDataFolder(): File {
5772
return File("FastScript")
5873
}
@@ -67,16 +82,12 @@ class FastScript(val dataFolder: File, private val classLoader: ClassLoader) {
6782

6883
override fun onReload() {}
6984

70-
override fun sendConsoleMessage(message: String) {
71-
println(message.yellow())
72-
}
73-
74-
override fun sendMessage(sender: Any, string: String) {
75-
println(string.yellow())
85+
override fun sendMessage(sender: Any, string: String, colorIndex: Boolean) {
86+
printColors(if (colorIndex) string.replace("§", "&") else string)
7687
}
7788
}
7889

79-
instance = FastScript(main.getDataFolder(), main.getPluginClassLoader())
90+
instance = FastScript(main)
8091

8192
instance.printLogo()
8293
}
@@ -114,13 +125,16 @@ class FastScript(val dataFolder: File, private val classLoader: ClassLoader) {
114125
println()
115126
}
116127

128+
fun sendMessage(sender: Any, string: String, colorIndex: Boolean = false) {
129+
instance.sendMessage(sender, string, colorIndex)
130+
}
131+
117132
fun setBootstrap(main: FastScriptMain) {
118133
if (instance != null) {
119134
throw UnsupportedOperationException("Cannot redefine instance")
120135
}
121136

122-
this.main = main
123-
instance = FastScript(main.getDataFolder(), main.getPluginClassLoader())
137+
instance = FastScript(main)
124138
}
125139

126140

src/main/kotlin/me/scoretwo/fastscript/api/config/ScriptImport.kt

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

src/main/kotlin/me/scoretwo/fastscript/api/config/ScriptOption.kt

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

src/main/kotlin/me/scoretwo/fastscript/api/plugin/FastScriptMain.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import java.io.InputStream
77

88
interface FastScriptMain {
99

10+
val CONSOLE: Any
11+
1012
fun getDataFolder(): File
1113

1214
fun getPluginClassLoader(): ClassLoader
@@ -15,9 +17,7 @@ interface FastScriptMain {
1517

1618
fun onReload()
1719

18-
fun sendConsoleMessage(message: String)
19-
20-
fun sendMessage(sender: Any, string: String)
20+
fun sendMessage(sender: Any, string: String, colorIndex: Boolean)
2121

2222

2323
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package me.scoretwo.fastscript.api.script
2+
3+
import me.scoretwo.fastscript.config.YAMLObject
4+
5+
class ScriptImport(val name: String, val TYPE: TYPE, val obj: Object?, val met: Method?) {
6+
7+
8+
9+
companion object {
10+
enum class TYPE { INIT, OBJECT, STATIC, IMPORT, ERROR }
11+
class Object(val clazz: String, val args: Array<Any?> = arrayOf())
12+
class Method(val name: String, val args: Array<Any?> = arrayOf())
13+
14+
fun fromConfigSection(name: String, yamlObject: YAMLObject): ScriptImport {
15+
val obj: Object?
16+
val met: Method?
17+
val type = when {
18+
yamlObject.containsLowerCaseKey("init") -> {
19+
val init = yamlObject.getLowerCaseYAMLObject("init")
20+
obj = Object(init.getLowerCaseString("class")!!)
21+
met = null
22+
TYPE.INIT
23+
}
24+
yamlObject.containsLowerCaseKey("object") -> {
25+
val object0 = yamlObject.getLowerCaseYAMLObject("object")
26+
val method = yamlObject.getLowerCaseYAMLObject("method")
27+
obj = Object(object0.getLowerCaseString("class")!!, object0.getLowerCaseYAMLArray("args").toArray())
28+
met = Method(method.getLowerCaseString("name")!!, method.getLowerCaseYAMLArray("args").toArray())
29+
TYPE.OBJECT
30+
}
31+
yamlObject.containsLowerCaseKey("static") -> {
32+
val static = yamlObject.getLowerCaseYAMLObject("static")
33+
val method = yamlObject.getLowerCaseYAMLObject("method")
34+
obj = Object(static.getLowerCaseString("class")!!)
35+
met = Method(method.getLowerCaseString("name")!!, method.getLowerCaseYAMLArray("args").toArray())
36+
TYPE.STATIC
37+
}
38+
/*
39+
暂不支持
40+
jsonObject.containsKey("import") -> {
41+
TYPE.IMPORT
42+
}
43+
*/
44+
else -> {
45+
obj = null
46+
met = null
47+
TYPE.ERROR
48+
}
49+
}
50+
51+
52+
return ScriptImport(name, type, obj, met)
53+
}
54+
55+
}
56+
57+
}

src/main/kotlin/me/scoretwo/fastscript/api/script/ScriptOption.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package me.scoretwo.fastscript.api.script
22

3-
class ScriptOption {
3+
class ScriptOption(engine: String, import: MutableList<ScriptImport>, main: String? = null) {
4+
45

56

67

src/main/kotlin/me/scoretwo/fastscript/bukkit/BukkitSection.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import me.scoretwo.fastscript.FastScript
44
import me.scoretwo.fastscript.api.plugin.FastScriptMain
55
import me.scoretwo.fastscript.bukkit.hooks.PlaceholderAPIHook
66
import net.md_5.bungee.api.ChatColor
7+
import net.md_5.bungee.api.ChatMessageType
8+
import net.md_5.bungee.api.chat.TextComponent
79
import org.bukkit.Bukkit
810
import org.bukkit.command.Command
911
import org.bukkit.command.CommandMap
@@ -28,6 +30,8 @@ class BukkitSection: JavaPlugin(), FastScriptMain {
2830
})
2931
}
3032

33+
override val CONSOLE: Any = Bukkit.getConsoleSender()
34+
3135
override fun getPluginClassLoader(): ClassLoader {
3236
return super.getClassLoader()
3337
}
@@ -41,17 +45,15 @@ class BukkitSection: JavaPlugin(), FastScriptMain {
4145
return text
4246
}
4347

44-
override fun sendConsoleMessage(message: String) = Bukkit.getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', message))
45-
46-
override fun sendMessage(sender: Any, string: String) {
47-
(sender as? CommandSender)?.sendMessage(string)
48+
override fun sendMessage(sender: Any, string: String, colorIndex: Boolean) {
49+
(sender as? CommandSender)?.sendMessage(if (colorIndex) ChatColor.translateAlternateColorCodes('&', string) else string)
4850
}
4951

5052
override fun onReload() {
5153
if (PAPIHook == null) {
5254
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
5355
PAPIHook = PlaceholderAPIHook(this)
54-
sendConsoleMessage("&7[&2Fast&aScript&7] &6HOOKED &8| &2成功挂钩 PlaceholderAPI!")
56+
FastScript.sendMessage(CONSOLE,"&7[&2Fast&aScript&7] &6HOOKED &8| &2成功挂钩 PlaceholderAPI!")
5557
}
5658
}
5759
}

src/main/kotlin/me/scoretwo/fastscript/bungee/BungeeSection.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class BungeeSection: Plugin(), FastScriptMain {
1717
FastScript.instance.onReload()
1818
}
1919

20+
override val CONSOLE: Any = ProxyServer.getInstance().console
21+
2022
override fun getPluginClassLoader(): ClassLoader {
2123
return javaClass.classLoader
2224
}
@@ -25,12 +27,8 @@ class BungeeSection: Plugin(), FastScriptMain {
2527
return string
2628
}
2729

28-
override fun sendConsoleMessage(message: String) {
29-
ProxyServer.getInstance().console.sendMessage(ChatColor.translateAlternateColorCodes('&', message))
30-
}
31-
32-
override fun sendMessage(sender: Any, string: String) {
33-
(sender as? CommandSender)?.sendMessage(string)
30+
override fun sendMessage(sender: Any, string: String, colorIndex: Boolean) {
31+
(sender as? org.bukkit.command.CommandSender)?.sendMessage(if (colorIndex) ChatColor.translateAlternateColorCodes('&', string) else string)
3432
}
3533

3634
override fun onReload() {

src/main/kotlin/me/scoretwo/fastscript/commands/CommandHandle.kt renamed to src/main/kotlin/me/scoretwo/fastscript/commands/SubCommand.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
package me.scoretwo.fastscript.commands
22

3-
abstract class CommandHandle {
3+
abstract class SubCommand {
44
}

0 commit comments

Comments
 (0)