11package me.scoretwo.fastscript.api.expansion
22
3- import me.scoretwo.fastscript.FastScript
3+ import me.scoretwo.fastscript.*
44import me.scoretwo.fastscript.api.format.FormatHeader
55import me.scoretwo.fastscript.api.plugin.ScriptPluginState
66import me.scoretwo.fastscript.api.utils.ExecType
77import me.scoretwo.fastscript.api.utils.process.ProcessResult
88import me.scoretwo.fastscript.api.utils.process.ProcessResultType
99import me.scoretwo.fastscript.expansion.javascript.JavaScriptExpansion
10- import me.scoretwo.fastscript.plugin
11- import me.scoretwo.fastscript.sendMessage
1210import me.scoretwo.utils.bukkit.configuration.yaml.file.YamlConfiguration
1311import java.io.File
1412import java.net.URL
@@ -74,14 +72,24 @@ class ExpansionManager {
7472 try {
7573 expansions.add(rawExpansion.second!! .reload())
7674 success++
77- } catch (e: Exception ) {
75+ } catch (e: Throwable ) {
7876 fail++
79- plugin.server.console.sendMessage(FormatHeader .ERROR , " An exception occurred when loading extended ${file.name} , reason:\n §8${e.stackTraceToString()} " )
77+ // plugin.server.console.sendMessage(FormatHeader.ERROR, "An exception occurred while loading expansion ${file.name}, reason:\n§8${e.stackTraceToString()}")
8078 }
8179 }
8280 val format = if (FastScript .stats == ScriptPluginState .RUNNING ) FormatHeader .INFO else FormatHeader .TREE
8381
84- plugin.server.console.sendMessage(format, " Loaded §b$total §7expansions, §a$success §7successes${if (fail == 0 ) " " else " , §c$fail §7failures" } .§8(${System .currentTimeMillis() - startTime} ms)" )
82+ val placeholders = mapOf (
83+ " id" to " expansions" ,
84+ " total" to " $total " ,
85+ " success" to " $success " ,
86+ " fail" to " $fail " ,
87+ " millisecond" to " ${System .currentTimeMillis() - startTime} "
88+ )
89+ if (fail == 0 )
90+ plugin.server.console.sendMessage(format, languages[" LOADED-COUNTS-PROCESS-SUCCESS" ].setPlaceholder(placeholders))
91+ else
92+ plugin.server.console.sendMessage(format, languages[" LOADED-COUNTS-PROCESS-HAS-FAILED" ].setPlaceholder(placeholders))
8593 }
8694
8795 private fun fromFileExpansion (file : File ): Pair <ProcessResult , FastScriptExpansion ?> {
@@ -95,32 +103,59 @@ class ExpansionManager {
95103 val jarFile = JarFile (file)
96104 description = try {
97105 ExpansionDescription .readConfig(YamlConfiguration ().also { it.load(jarFile.getInputStream(jarFile.getJarEntry(" expansion.yml" )).reader()) })
98- } catch (e: Exception ) {
99- plugin.server.console.sendMessage(FormatHeader .ERROR , " An error occurred while loading the expansion '${file.name} ' description file, reason:\n §8${e.stackTraceToString()} " )
106+ } catch (e: Throwable ) {
107+ plugin.server.console.sendMessage(FormatHeader .ERROR , languages[" EXPANSION.ERROR-BY-CAUSE.LOAD-DESCRIPTION-FILE-ERROR" ].setPlaceholder(
108+ mapOf (
109+ " file_name" to file.name,
110+ " reason" to e.stackTraceToString()
111+ )
112+ ))
100113 return Pair (ProcessResult (ProcessResultType .FAILED ), null )
101114 }
102115 val clazz = try {
103116 Class .forName(description.main)
104- } catch (e: Exception ) {
105- plugin.server.console.sendMessage(FormatHeader .ERROR , " An error occurred while loading the main class ${description.main} of expansion '${file.name} ', reason:\n §8${e.stackTraceToString()} " )
117+ } catch (e: Throwable ) {
118+ plugin.server.console.sendMessage(FormatHeader .ERROR , languages[" EXPANSION.ERROR-BY-CAUSE.LOAD-MAIN-CLASS-ERROR" ].setPlaceholder(
119+ mapOf (
120+ " file_name" to file.name,
121+ " description_main" to description.main,
122+ " reason" to e.stackTraceToString()
123+ )
124+ ))
106125 return Pair (ProcessResult (ProcessResultType .FAILED ), null )
107126 }
108127
109128 val instance = try {
110129 clazz.newInstance()
111- } catch (e: Exception ) {
112- plugin.server.console.sendMessage(FormatHeader .ERROR , " An error occurred while loading the main class ${description.main} of expansion '${file.name} ', reason:\n §8${e.stackTraceToString()} " )
130+ } catch (e: Throwable ) {
131+ plugin.server.console.sendMessage(FormatHeader .ERROR , languages[" EXPANSION.ERROR-BY-CAUSE.LOAD-MAIN-CLASS-ERROR" ].setPlaceholder(
132+ mapOf (
133+ " file_name" to file.name,
134+ " description_main" to description.main,
135+ " reason" to e.stackTraceToString()
136+ )
137+ ))
113138 return Pair (ProcessResult (ProcessResultType .FAILED ), null )
114139 }
115140
116141 if (instance !is FastScriptExpansion ) {
117- plugin.server.console.sendMessage(FormatHeader .ERROR , " An error occurred while loading the main class ${description.main} of expansion '${file.name} ', reason: §cThe main class does not depend on FastScriptExpansion." )
142+ plugin.server.console.sendMessage(FormatHeader .ERROR , languages[" EXPANSION.ERROR-BY-CAUSE.LOAD-MAIN-CLASS-MAIN-NOT-DEPEND" ].setPlaceholder(
143+ mapOf (
144+ " file_name" to file.name,
145+ " description_main" to description.main
146+ )
147+ ))
118148 return Pair (ProcessResult (ProcessResultType .FAILED ), null )
119149 }
120150
121151 clazz.asSubclass(FastScriptExpansion ::class .java)
122- } catch (e: Exception ) {
123- plugin.server.console.sendMessage(FormatHeader .ERROR , " An exception occurred when loading extended '${file.name} ', reason:\n §8${e.stackTraceToString()} " )
152+ } catch (e: Throwable ) {
153+ plugin.server.console.sendMessage(FormatHeader .ERROR , languages[" EXPANSION.ERROR-BY-CAUSE.LOAD-ERROR" ].setPlaceholder(
154+ mapOf (
155+ " file_name" to file.name,
156+ " reason" to e.stackTraceToString()
157+ )
158+ ))
124159 return Pair (ProcessResult (ProcessResultType .FAILED ), null )
125160 }
126161
0 commit comments