Skip to content

Commit 7a92afe

Browse files
committed
添加部分框架, 与完善部分接口
1 parent d37957b commit 7a92afe

File tree

14 files changed

+248
-19
lines changed

14 files changed

+248
-19
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,24 @@ class FastScript(val dataFolder: File, private val classLoader: ClassLoader) {
1212

1313
}
1414

15+
fun onReload() {
16+
initInternalScripts()
17+
}
18+
1519
companion object {
1620
var instance: FastScript? = null
21+
lateinit var main: FastScriptMain
1722

1823
fun setBootstrap(main: FastScriptMain) {
1924
if (instance != null) {
2025
throw UnsupportedOperationException("Cannot redefine instance")
2126
}
2227

28+
this.main = main
2329
instance = FastScript(main.getDataFolder(), main.getPluginClassLoader())
2430
}
31+
32+
2533
}
2634

2735
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package me.scoretwo.fastscript.api.config
2+
3+
class ScriptOption {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package me.scoretwo.fastscript.api.exception
2+
3+
class ScriptException: Exception() {
4+
}

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@ interface FastScriptMain {
1111

1212
fun getPluginClassLoader(): ClassLoader
1313

14-
fun saveDefaultResource(target: File, inputStream: InputStream) {
15-
if (target.exists()) {
16-
saveResource(target, inputStream)
17-
}
18-
}
19-
20-
fun saveResource(target: File, inputStream: InputStream) {
21-
FileUtils.save(target, inputStream)
22-
}
14+
fun setPlaceholder(player: Any, string: String): String
15+
16+
fun onReload()
17+
18+
fun sendConsoleMessage(message: String)
19+
20+
fun sendMessage(sender: Any, string: String)
21+
2322

2423
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package me.scoretwo.fastscript.api.script
2+
3+
class ImportObject {
4+
5+
6+
7+
}
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
package me.scoretwo.fastscript.api.script
22

3+
import me.scoretwo.fastscript.utils.Utils
34
import java.io.File
5+
import java.io.FileInputStream
6+
import java.io.InputStream
47

5-
abstract class Script(val file: File) {
8+
abstract class Script {
9+
10+
val name: String
11+
var file: File? = null
12+
var inputStream: InputStream
13+
14+
constructor(file: File): this(file.name.substring(0, file.name.indexOf(".") - 1), FileInputStream(file)) {
15+
this.file = file
16+
}
17+
18+
constructor(name: String, inputStream: InputStream) {
19+
this.inputStream = inputStream
20+
this.name = name
21+
}
22+
23+
fun onReload() {
24+
if (file == null) return
25+
Utils.saveDefaultResource(file!!, inputStream)
26+
this.inputStream = FileInputStream(file!!)
27+
}
628

729
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,65 @@
11
package me.scoretwo.fastscript.bukkit
22

3+
import me.scoretwo.fastscript.FastScript
34
import me.scoretwo.fastscript.api.plugin.FastScriptMain
5+
import me.scoretwo.fastscript.bukkit.hooks.PlaceholderAPIHook
6+
import net.md_5.bungee.api.ChatColor
7+
import org.bukkit.Bukkit
8+
import org.bukkit.command.Command
9+
import org.bukkit.command.CommandMap
10+
import org.bukkit.command.CommandSender
11+
import org.bukkit.command.SimpleCommandMap
12+
import org.bukkit.entity.Player
413
import org.bukkit.plugin.java.JavaPlugin
514

615
class BukkitSection: JavaPlugin(), FastScriptMain {
716

17+
override fun onLoad() {
18+
FastScript.setBootstrap(this)
19+
}
20+
821
override fun onEnable() {
22+
FastScript.instance?.onReload()
923

24+
commandMap.register(description.name, object : Command(description.name, "", "/" + description.name, listOf("script","bukkitScript")) {
25+
override fun execute(sender: CommandSender, label: String, args: Array<out String>): Boolean {
26+
return true
27+
}
28+
})
1029
}
1130

1231
override fun getPluginClassLoader(): ClassLoader {
1332
return super.getClassLoader()
1433
}
34+
35+
override fun setPlaceholder(player: Any, string: String): String {
36+
var text: String = string
37+
if (PAPIHook != null) {
38+
text = PlaceholderAPIHook.setPlaceholder(player as? Player, string)
39+
}
40+
41+
return text
42+
}
43+
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+
}
49+
50+
override fun onReload() {
51+
if (PAPIHook == null) {
52+
if (Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI")) {
53+
PAPIHook = PlaceholderAPIHook(this)
54+
sendConsoleMessage("&7[&2Fast&aScript&7] &6HOOKED &8| &2成功挂钩 PlaceholderAPI!")
55+
}
56+
}
57+
}
58+
59+
companion object {
60+
private var PAPIHook: PlaceholderAPIHook? = null
61+
62+
val commandMap: CommandMap = Bukkit.getServer().javaClass.getDeclaredMethod("getCommandMap").invoke(Bukkit.getServer()) as SimpleCommandMap
63+
}
64+
1565
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package me.scoretwo.fastscript.bukkit.hooks
2+
3+
import me.clip.placeholderapi.PlaceholderAPI
4+
import me.clip.placeholderapi.expansion.PlaceholderExpansion
5+
import org.bukkit.entity.Player
6+
import org.bukkit.plugin.java.JavaPlugin
7+
8+
class PlaceholderAPIHook(val javaPlugin: JavaPlugin): PlaceholderExpansion() {
9+
10+
override fun persist(): Boolean {
11+
return true
12+
}
13+
14+
override fun getIdentifier(): String {
15+
return javaPlugin.description.name.toLowerCase()
16+
}
17+
18+
override fun getAuthor(): String {
19+
return javaPlugin.description.authors.toString()
20+
}
21+
22+
override fun getVersion(): String {
23+
return javaPlugin.description.version
24+
}
25+
26+
override fun onPlaceholderRequest(player: Player, params: String): String {
27+
TODO()
28+
}
29+
30+
companion object {
31+
32+
fun setPlaceholder(player: Player?, string: String): String = PlaceholderAPI.setPlaceholders(player, string)
33+
}
34+
}
Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,40 @@
11
package me.scoretwo.fastscript.bungee
22

3+
import me.scoretwo.fastscript.FastScript
34
import me.scoretwo.fastscript.api.plugin.FastScriptMain
5+
import net.md_5.bungee.api.ChatColor
6+
import net.md_5.bungee.api.CommandSender
7+
import net.md_5.bungee.api.ProxyServer
48
import net.md_5.bungee.api.plugin.Plugin
59

610
class BungeeSection: Plugin(), FastScriptMain {
711

8-
override fun onEnable() {
12+
override fun onLoad() {
13+
FastScript.setBootstrap(this)
14+
}
915

16+
override fun onEnable() {
17+
FastScript.instance?.onReload()
1018
}
1119

1220
override fun getPluginClassLoader(): ClassLoader {
1321
return javaClass.classLoader
1422
}
1523

24+
override fun setPlaceholder(player: Any, string: String): String {
25+
return string
26+
}
27+
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)
34+
}
35+
36+
override fun onReload() {
37+
38+
}
39+
1640
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package me.scoretwo.fastscript.commands
2+
3+
abstract class CommandHandle {
4+
}

0 commit comments

Comments
 (0)