@@ -3,10 +3,13 @@ package me.scoretwo.fastscript
33import me.scoretwo.fastscript.api.plugin.FastScriptMain
44import me.scoretwo.fastscript.api.script.ScriptManager
55import me.scoretwo.fastscript.commands.CommandManager
6- import me.scoretwo.fastscript.config.MessageConfig
76import me.scoretwo.fastscript.config.SettingConfig
7+ import me.scoretwo.fastscript.utils.Utils
88import me.scoretwo.utils.configuration.patchs.getLowerCaseNode
99import java.io.File
10+ import java.io.IOException
11+ import java.io.InputStream
12+ import java.net.URL
1013
1114class FastScript (main : FastScriptMain ) {
1215
@@ -27,6 +30,7 @@ class FastScript(main: FastScriptMain) {
2730 instance = this
2831 CONSOLE = main.CONSOLE
2932 printLogo()
33+ println (" FastScript 正在初始化..." )
3034
3135 dataFolder = main.getDataFolder()
3236 classLoader = main.getPluginClassLoader()
@@ -40,48 +44,64 @@ class FastScript(main: FastScriptMain) {
4044 SettingConfig .init ()
4145 }
4246
43- /* *
47+ fun getResource (filename : String ): InputStream ? {
48+ return try {
49+ val url: URL = classLoader.getResource(filename) ? : return null
50+ val connection = url.openConnection()
51+ connection.useCaches = false
52+ connection.getInputStream()
53+ } catch (ex: IOException ) {
54+ null
55+ }
56+ }
57+
58+ /* *
4459 * 初始化内置脚本
4560 * 暂时弃坑
4661 */
4762 fun initInternalScripts () {
4863
4964 }
5065
66+ fun initLanguageFiles () {
67+ Utils .saveDefaultResource(File (" ${dataFolder} /languages" , " en_US.yml" ), getResource(" lang/en_US.yml" )!! )
68+ Utils .saveDefaultResource(File (" ${dataFolder} /languages" , " zh_CN.yml" ), getResource(" lang/zh_CN.yml" )!! )
69+ }
70+
5171 fun onReload () {
5272 if (! dataFolder.exists()) {
5373 dataFolder.mkdirs()
5474 }
5575 main.onReload()
76+ initLanguageFiles()
5677 initInternalScripts()
5778 scriptManager.loadScripts()
5879 commandManager.initCommands()
5980 }
6081
61- /* *
82+ /* *
6283 * 用于随机点亮 FastScript 的 Logo.
6384 * 该创意来源于 TrMenu
6485 * @author Arasple
6586 */
66-
6787 fun printLogo () = arrayOf(
68- " ___________ __ _________ .__ __ " ,
69- " \\ _ _____/____ _______/ |_/ _____/ ___________|__|______/ |_ " ,
70- " | __) \\ __ \\ / ___/\\ __\\ _____ \\ _/ ___\\ _ __ \\ \\ ____ \\ __\\ " ,
71- " | \\ / __ \\ _\\ ___ \\ | | / \\ \\ ___| | \\ / | |_> > | " ,
72- " \\ ___ / (____ /____ > |__|/_______ /\\ ___ >__| |__| __/|__| " ,
73- " \\ / \\ / \\ / \\ / \\ / |__| "
74- ).let {
88+ " ___________ __ _________ .__ __ " ,
89+ " \\ _ _____/____ _______/ |_/ _____/ ___________|__|______/ |_ " ,
90+ " | __) \\ __ \\ / ___/\\ __\\ _____ \\ _/ ___\\ _ __ \\ \\ ____ \\ __\\ " ,
91+ " | \\ / __ \\ _\\ ___ \\ | | / \\ \\ ___| | \\ / | |_> > | " ,
92+ " \\ ___ / (____ /____ > |__|/_______ /\\ ___ >__| |__| __/|__| " ,
93+ " \\ / \\ / \\ / \\ / \\ / |__| "
94+ ).let {
7595 it.forEachIndexed { index, raw ->
7696 if (raw.isNotBlank()) {
7797 val line = raw.toCharArray()
78- val width = (2 .. 6 ).random()
98+ val width = (2 .. 8 ).random()
7999 var randomIndex: Int
80100 do {
81101 randomIndex = (2 .. line.size - width).random()
82102 } while (String (line.copyOfRange(randomIndex, randomIndex + width)).isBlank())
83103 val replace = String (line.copyOfRange(randomIndex, randomIndex + width))
84- it[index] = String (line).replaceFirst(replace, " §${arrayOf(' 9 ' , ' b' , ' 3 ' ).random()}$replace §8" )
104+ it[index] = String (line).replaceFirst(replace, " §${arrayOf(' a ' , ' b' , ' 2 ' ).random()}$replace §8" )
85105 }
86106 }
87107 CONSOLE .sendMessage(it)
@@ -172,23 +192,23 @@ fun Any.hasPermission(string: String): Boolean {
172192}
173193
174194
175- fun Any.sendMessage (formatHeader : FormatHeader , strings : Array <String >, colorIndex : Boolean = false ) {
195+ fun Any.sendMessage (formatHeader : FormatHeader , strings : Array <String >, colorIndex : Boolean = true ) {
176196 strings.forEach {
177197 this .sendMessage(formatHeader, it, colorIndex)
178198 }
179199}
180200
181- fun Any.sendMessage (formatHeader : FormatHeader , string : String , colorIndex : Boolean = false ) {
182- this .sendMessage(" ${
183- SettingConfig .instance.defaultLanguage.getString(SettingConfig .instance.defaultLanguage.getLowerCaseNode(" format-header.${formatHeader.name.toLowerCase()} " ))
184- }${string} " , colorIndex )
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+ )
185205}
186206
187- fun Any.sendMessage (string : String , colorIndex : Boolean = false ) {
207+ fun Any.sendMessage (string : String , colorIndex : Boolean = true ) {
188208 FastScript .instance.sendMessage(this , string, colorIndex)
189209}
190210
191- fun Any.sendMessage (strings : Array <String >, colorIndex : Boolean = false ) {
211+ fun Any.sendMessage (strings : Array <String >, colorIndex : Boolean = true ) {
192212 strings.forEach {
193213 this .sendMessage(it, colorIndex)
194214 }
0 commit comments