Skip to content

Commit da1b2cf

Browse files
author
BuildTools
committed
Try to fix the remaining issues.
1 parent 83a3a93 commit da1b2cf

File tree

23 files changed

+135
-359
lines changed

23 files changed

+135
-359
lines changed

common/build.gradle.kts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,10 @@ dependencies {
1717
compileOnly("com.google.code.gson:gson:2.8.6")
1818
compileOnly("org.slf4j:slf4j-log4j12:1.7.30")
1919
implementation("commons-io:commons-io:2.7")
20-
implementation("me.scoretwo:commons-syntaxes:2.0-SNAPSHOT")
21-
implementation("me.scoretwo:commons-command:2.0-SNAPSHOT")
22-
implementation("me.scoretwo:commons-bukkit-configuration:2.0-SNAPSHOT")
20+
implementation("me.scoretwo:commons-syntaxes:2.0.1-SNAPSHOT")
21+
implementation("me.scoretwo:commons-command:2.0.1-SNAPSHOT")
22+
implementation("me.scoretwo:commons-server:2.0.1-SNAPSHOT")
23+
implementation("me.scoretwo:commons-bukkit-configuration:2.0.1-SNAPSHOT")
2324
}
2425

2526
configure<PublishingExtension> {
Lines changed: 23 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,40 @@
11
package me.scoretwo.fastscript
22

3-
import me.scoretwo.fastscript.api.plugin.FastScriptPlugin
3+
import me.scoretwo.fastscript.api.plugin.ScriptPlugin
44
import me.scoretwo.fastscript.script.ScriptManager
55
import me.scoretwo.fastscript.commands.CommandManager
66
import me.scoretwo.fastscript.config.SettingConfig
77
import me.scoretwo.fastscript.utils.Utils
88
import me.scoretwo.utils.bukkit.configuration.yaml.patchs.getLowerCaseNode
9-
import me.scoretwo.utils.command.GlobalSender
9+
import me.scoretwo.utils.sender.GlobalPlayer
10+
import me.scoretwo.utils.sender.GlobalSender
11+
import me.scoretwo.utils.syntaxes.StreamUtils
12+
import net.md_5.bungee.api.ChatColor
1013
import java.io.File
11-
import java.io.IOException
12-
import java.io.InputStream
13-
import java.net.URL
1414

15-
class FastScript(plugin: FastScriptPlugin) {
16-
17-
private val plugin: FastScriptPlugin = plugin
18-
19-
val dataFolder: File
20-
val classLoader: ClassLoader
15+
class FastScript(val plugin: ScriptPlugin) {
2116

2217
val scriptManager: ScriptManager
2318
val commandManager: CommandManager
2419

25-
fun setPlaceholder(player: Any, string: String) = plugin.setPlaceholder(player, string)
26-
fun translateStringColors(string: String): String = plugin.translateStringColors(string)
20+
fun setPlaceholder(player: GlobalPlayer, string: String) = plugin.setPlaceholder(player, string)
2721

2822
init {
2923
instance = this
30-
console = plugin.console
3124
printLogo()
32-
println("[FastScript | INIT] 正在初始化...")
3325

34-
dataFolder = plugin.getDataFolder()
35-
classLoader = plugin.getPluginClassLoader()
26+
plugin.server.console.sendMessage(FormatHeader.INFO, "Initializing...")
27+
3628
scriptManager = ScriptManager()
3729
commandManager = CommandManager()
3830

39-
if (!dataFolder.exists()) {
40-
dataFolder.mkdirs()
31+
if (!plugin.dataFolder.exists()) {
32+
plugin.dataFolder.mkdirs()
4133
}
4234

4335
SettingConfig.init()
4436
}
4537

46-
fun getResource(filename: String): InputStream? {
47-
return try {
48-
val url: URL = classLoader.getResource(filename) ?: return null
49-
val connection = url.openConnection()
50-
connection.useCaches = false
51-
connection.getInputStream()
52-
} catch (ex: IOException) {
53-
null
54-
}
55-
}
56-
5738
/**
5839
* 初始化内置脚本
5940
* 暂时弃坑
@@ -63,15 +44,15 @@ class FastScript(plugin: FastScriptPlugin) {
6344
}
6445

6546
fun initLanguageFiles() {
66-
Utils.saveDefaultResource(File("${dataFolder}/languages", "en_US.yml"), getResource("lang/en_US.yml")!!)
67-
Utils.saveDefaultResource(File("${dataFolder}/languages", "zh_CN.yml"), getResource("lang/zh_CN.yml")!!)
47+
Utils.saveDefaultResource(File("${plugin.dataFolder}/languages", "en_US.yml"), StreamUtils.getResource("lang/en_US.yml")!!)
48+
Utils.saveDefaultResource(File("${plugin.dataFolder}/languages", "zh_CN.yml"), StreamUtils.getResource("lang/zh_CN.yml")!!)
6849
}
6950

7051
fun onReload() {
71-
if (!dataFolder.exists()) {
72-
dataFolder.mkdirs()
52+
if (!plugin.dataFolder.exists()) {
53+
plugin.dataFolder.mkdirs()
7354
}
74-
plugin.onReload()
55+
plugin.reload()
7556
initLanguageFiles()
7657
initInternalScripts()
7758
scriptManager.loadScripts()
@@ -103,88 +84,19 @@ class FastScript(plugin: FastScriptPlugin) {
10384
it[index] = String(line).replaceFirst(replace, "§${arrayOf('a', 'b', '2').random()}$replace§8")
10485
}
10586
}
106-
console.sendMessage(it)
87+
plugin.server.console.sendMessage(it)
10788
}
10889

10990
companion object {
11091
lateinit var instance: FastScript
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-
}
11792

118-
fun setBootstrap(plugin: FastScriptPlugin) {
119-
/*if (initialized) {
93+
fun setBootstrap(plugin: ScriptPlugin) {
94+
if (::instance.isInitialized) {
12095
throw UnsupportedOperationException("Cannot redefine instance")
121-
}*/
122-
FastScript(plugin)
123-
}
124-
/*
125-
@JvmStatic
126-
fun main(args: Array<out String>) {
127-
128-
val main = object : FastScriptMain {
129-
override val console: Any = this
130-
131-
override fun getDataFolder(): File {
132-
return File("FastScript")
133-
}
134-
135-
override fun getPluginClassLoader(): ClassLoader {
136-
return javaClass.classLoader
137-
}
138-
139-
override fun setPlaceholder(player: Any, string: String): String {
140-
return string
141-
}
142-
143-
override fun onReload() {}
144-
145-
override fun sendMessage(sender: Any, string: String, colorIndex: Boolean) {
146-
printColors(if (colorIndex) string.replace("§", "&") else string)
147-
}
14896
}
149-
150-
instance = FastScript(main)
151-
152-
instance.printLogo()
153-
}
154-
155-
fun printColors(list: MutableList<String>) {
156-
list.forEach { printColors(it) }
97+
FastScript(plugin)
15798
}
15899

159-
fun printColors(string: String) {
160-
for (s in string.split("§")) {
161-
if (s.isEmpty()) continue
162-
val index = s.substring(0,1)
163-
val rawMessage = s.substring(1)
164-
165-
when(index) {
166-
"a"-> print(rawMessage.lightGreen())
167-
"b"-> print(rawMessage.lightCyan())
168-
"c"-> print(rawMessage.lightRed())
169-
"d"-> print(rawMessage.lightMagenta())
170-
"e"-> print(rawMessage.lightYellow())
171-
"f"-> print(rawMessage.lightWhite())
172-
"0"-> print(rawMessage.black())
173-
"1"-> print(rawMessage.blue())
174-
"2"-> print(rawMessage.green())
175-
"3"-> print(rawMessage.cyan())
176-
"4"-> print(rawMessage.red())
177-
"5"-> print(rawMessage.magenta())
178-
"6"-> print(rawMessage.yellow())
179-
"7"-> print(rawMessage.lightGray())
180-
"8"-> print(rawMessage.lightGray())
181-
"9"-> print(rawMessage.lightBlue())
182-
else-> print(rawMessage.lightGray())
183-
}
184-
}
185-
println()
186-
}
187-
*/
188100
}
189101

190102
}
@@ -201,9 +113,9 @@ fun GlobalSender.sendMessage(formatHeader: FormatHeader, string: String, colorIn
201113
if (colorIndex)
202114
this.sendMessage("${SettingConfig.instance.defaultLanguage.getString(SettingConfig.instance.defaultLanguage.getLowerCaseNode("format-header.${formatHeader.name.toLowerCase()}"))}${string}")
203115
else
204-
this.sendMessage(FastScript.instance.translateStringColors("${SettingConfig.instance.defaultLanguage.getString(SettingConfig.instance.defaultLanguage.getLowerCaseNode("format-header.${formatHeader.name.toLowerCase()}"))}${string}"))
116+
this.sendMessage(ChatColor.translateAlternateColorCodes('&',"${SettingConfig.instance.defaultLanguage.getString(SettingConfig.instance.defaultLanguage.getLowerCaseNode("format-header.${formatHeader.name.toLowerCase()}"))}${string}"))
205117
}
206118

207-
fun String.setPlaceholder(sender: Any): String {
208-
return FastScript.instance.setPlaceholder(sender, this)
119+
fun String.setPlaceholder(player: GlobalPlayer): String {
120+
return FastScript.instance.setPlaceholder(player, this)
209121
}

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

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package me.scoretwo.fastscript.api.plugin
2+
3+
import me.scoretwo.utils.plugin.GlobalPlugin
4+
import me.scoretwo.utils.plugin.PluginDescription
5+
import me.scoretwo.utils.plugin.logging.GlobalLogger
6+
import me.scoretwo.utils.sender.GlobalPlayer
7+
import me.scoretwo.utils.server.GlobalServer
8+
import java.io.File
9+
10+
abstract class ScriptPlugin(plugin: GlobalPlugin): GlobalPlugin {
11+
12+
abstract fun setPlaceholder(player: GlobalPlayer, string: String): String
13+
14+
open fun load() {}
15+
open fun reload() {}
16+
open fun enable() {}
17+
open fun disable() {}
18+
19+
override val dataFolder: File = plugin.dataFolder
20+
override val description: PluginDescription = plugin.description
21+
override val logger: GlobalLogger = plugin.logger
22+
override val pluginClassLoader: ClassLoader = plugin.pluginClassLoader
23+
override val server: GlobalServer = plugin.server
24+
25+
}

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

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

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

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

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

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

common/src/main/kotlin/me/scoretwo/fastscript/api/script/Script.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import me.scoretwo.fastscript.script.options.ScriptOption
66
import me.scoretwo.fastscript.script.options.imports.ScriptImportType.*
77
import me.scoretwo.fastscript.config.SettingConfig
88
import me.scoretwo.fastscript.sendMessage
9-
import me.scoretwo.fastscript.utils.StreamUtils
109
import me.scoretwo.fastscript.utils.Utils
1110
import java.io.File
1211
import java.io.FileInputStream

0 commit comments

Comments
 (0)