|
1 | 1 | package me.scoretwo.fastscript |
2 | 2 |
|
3 | | -import me.scoretwo.fastscript.api.plugin.FastScriptMain |
| 3 | +import me.scoretwo.fastscript.api.plugin.FastScriptPlugin |
4 | 4 | import me.scoretwo.fastscript.script.ScriptManager |
5 | 5 | import me.scoretwo.fastscript.commands.CommandManager |
6 | 6 | import me.scoretwo.fastscript.config.SettingConfig |
7 | 7 | import me.scoretwo.fastscript.utils.Utils |
8 | 8 | import me.scoretwo.utils.bukkit.configuration.yaml.patchs.getLowerCaseNode |
| 9 | +import me.scoretwo.utils.command.GlobalSender |
9 | 10 | import java.io.File |
10 | 11 | import java.io.IOException |
11 | 12 | import java.io.InputStream |
12 | 13 | import java.net.URL |
13 | 14 |
|
14 | | -class FastScript(main: FastScriptMain) { |
| 15 | +class FastScript(plugin: FastScriptPlugin) { |
15 | 16 |
|
16 | | - private val main: FastScriptMain = main |
| 17 | + private val plugin: FastScriptPlugin = plugin |
17 | 18 |
|
18 | 19 | val dataFolder: File |
19 | 20 | val classLoader: ClassLoader |
20 | 21 |
|
21 | 22 | val scriptManager: ScriptManager |
22 | 23 | val commandManager: CommandManager |
23 | 24 |
|
24 | | - fun hasPermission(sender: Any, string: String) = main.hasPermission(sender, string) |
25 | | - fun setPlaceholder(player: Any, string: String) = main.setPlaceholder(player, string) |
26 | | - fun sendMessage(sender: Any, string: String, colorIndex: Boolean) = main.sendMessage(sender, string, colorIndex) |
27 | | - fun translateStringColors(string: String): String = main.translateStringColors(string) |
| 25 | + fun setPlaceholder(player: Any, string: String) = plugin.setPlaceholder(player, string) |
| 26 | + fun translateStringColors(string: String): String = plugin.translateStringColors(string) |
28 | 27 |
|
29 | 28 | init { |
30 | 29 | instance = this |
31 | | - console = main.console |
| 30 | + console = plugin.console |
32 | 31 | printLogo() |
33 | 32 | println("[FastScript | INIT] 正在初始化...") |
34 | 33 |
|
35 | | - dataFolder = main.getDataFolder() |
36 | | - classLoader = main.getPluginClassLoader() |
| 34 | + dataFolder = plugin.getDataFolder() |
| 35 | + classLoader = plugin.getPluginClassLoader() |
37 | 36 | scriptManager = ScriptManager() |
38 | 37 | commandManager = CommandManager() |
39 | 38 |
|
@@ -72,7 +71,7 @@ class FastScript(main: FastScriptMain) { |
72 | 71 | if (!dataFolder.exists()) { |
73 | 72 | dataFolder.mkdirs() |
74 | 73 | } |
75 | | - main.onReload() |
| 74 | + plugin.onReload() |
76 | 75 | initLanguageFiles() |
77 | 76 | initInternalScripts() |
78 | 77 | scriptManager.loadScripts() |
@@ -109,13 +108,18 @@ class FastScript(main: FastScriptMain) { |
109 | 108 |
|
110 | 109 | companion object { |
111 | 110 | lateinit var instance: FastScript |
112 | | - var console = Any() |
| 111 | + var console = object : GlobalSender { |
| 112 | + override val name = "console" |
| 113 | + override fun hasPermission(name: String) = true |
| 114 | + override fun sendMessage(messages: Array<String>) = println(messages) |
| 115 | + override fun sendMessage(message: String) = println(message) |
| 116 | + } |
113 | 117 |
|
114 | | - fun setBootstrap(main: FastScriptMain) { |
| 118 | + fun setBootstrap(plugin: FastScriptPlugin) { |
115 | 119 | /*if (initialized) { |
116 | 120 | throw UnsupportedOperationException("Cannot redefine instance") |
117 | 121 | }*/ |
118 | | - FastScript(main) |
| 122 | + FastScript(plugin) |
119 | 123 | } |
120 | 124 | /* |
121 | 125 | @JvmStatic |
@@ -187,31 +191,17 @@ class FastScript(main: FastScriptMain) { |
187 | 191 |
|
188 | 192 | enum class FormatHeader { INFO, WARN, ERROR, TIPS, HOOKED, DEBUG } |
189 | 193 |
|
190 | | -fun Any.hasPermission(string: String): Boolean { |
191 | | - return FastScript.instance.hasPermission(this, string) |
192 | | -} |
193 | | - |
194 | | - |
195 | | -fun Any.sendMessage(formatHeader: FormatHeader, strings: Array<String>, colorIndex: Boolean = true) { |
| 194 | +fun GlobalSender.sendMessage(formatHeader: FormatHeader, strings: Array<String>, colorIndex: Boolean = true) { |
196 | 195 | strings.forEach { |
197 | 196 | this.sendMessage(formatHeader, it, colorIndex) |
198 | 197 | } |
199 | 198 | } |
200 | 199 |
|
201 | | -fun Any.sendMessage(formatHeader: FormatHeader, string: String, colorIndex: Boolean = true) { |
202 | | - this.sendMessage( |
203 | | - "${SettingConfig.instance.defaultLanguage.getString(SettingConfig.instance.defaultLanguage.getLowerCaseNode("format-header.${formatHeader.name.toLowerCase()}"))}${string}", colorIndex |
204 | | - ) |
205 | | -} |
206 | | - |
207 | | -fun Any.sendMessage(string: String, colorIndex: Boolean = true) { |
208 | | - FastScript.instance.sendMessage(this, string, colorIndex) |
209 | | -} |
210 | | - |
211 | | -fun Any.sendMessage(strings: Array<String>, colorIndex: Boolean = true) { |
212 | | - strings.forEach { |
213 | | - this.sendMessage(it, colorIndex) |
214 | | - } |
| 200 | +fun GlobalSender.sendMessage(formatHeader: FormatHeader, string: String, colorIndex: Boolean = true) { |
| 201 | + if (colorIndex) |
| 202 | + this.sendMessage("${SettingConfig.instance.defaultLanguage.getString(SettingConfig.instance.defaultLanguage.getLowerCaseNode("format-header.${formatHeader.name.toLowerCase()}"))}${string}") |
| 203 | + else |
| 204 | + this.sendMessage(FastScript.instance.translateStringColors("${SettingConfig.instance.defaultLanguage.getString(SettingConfig.instance.defaultLanguage.getLowerCaseNode("format-header.${formatHeader.name.toLowerCase()}"))}${string}")) |
215 | 205 | } |
216 | 206 |
|
217 | 207 | fun String.setPlaceholder(sender: Any): String { |
|
0 commit comments