Skip to content

Commit e3d4fad

Browse files
committed
Moved try/catch handling to ScriptablePluginEngine.loadMainScript
Added ScriptablePluginEngine.getStartupErrors() to get startup errors inside the script engine.
1 parent 2275c53 commit e3d4fad

5 files changed

Lines changed: 56 additions & 55 deletions

File tree

ScriptableMC-Engine-Core/src/main/kotlin/com/pixlfox/scriptablemc/ScriptEngineConfig.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ abstract class ScriptEngineConfig(private val config: FileConfiguration) {
2222
val debugger: ScriptEngineDebuggerConfig
2323
get() = ScriptEngineDebuggerConfig(this)
2424

25+
@JvmOverloads
2526
fun readConfigString(path: String, def: String = ""): String {
2627
val input = config.getString(path, def).orEmpty()
2728
val regex = Regex("\\\$\\{(.*)}")
@@ -32,6 +33,7 @@ abstract class ScriptEngineConfig(private val config: FileConfiguration) {
3233
}
3334
}
3435

36+
@JvmOverloads
3537
fun readConfigStringList(path: String, def: List<String> = listOf()): List<String> {
3638
val inputList = config.getStringList(path)
3739
val regex = Regex("\\\$\\{(.*)}")
@@ -50,6 +52,7 @@ abstract class ScriptEngineConfig(private val config: FileConfiguration) {
5052
return inputList
5153
}
5254

55+
@JvmOverloads
5356
fun readConfigBoolean(path: String, def: Boolean = false): Boolean {
5457
return readConfigString(path, def.toString()).equals("true", true)
5558
}

ScriptableMC-Engine-Core/src/main/kotlin/com/pixlfox/scriptablemc/core/ScriptablePluginEngine.kt

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ abstract class ScriptablePluginEngine {
3232
var enabledAllPlugins: Boolean = false
3333
internal set
3434

35-
private val _startupErrors = mutableListOf<Exception>()
36-
val startupErrors: Array<Exception>
37-
get() = _startupErrors.toTypedArray()
35+
val startupErrors: MutableList<Exception> = mutableListOf()
3836

3937
open fun start() {
4038
inventoryManager.init()
@@ -43,12 +41,7 @@ abstract class ScriptablePluginEngine {
4341
loadAllHelperClasses()
4442

4543
for(mainScriptFile in config.mainScriptFiles) {
46-
try {
47-
loadMainScript(mainScriptFile)
48-
}
49-
catch(ex: Exception) {
50-
_startupErrors.add(ex)
51-
}
44+
loadMainScript(mainScriptFile)
5245
}
5346

5447
if(!enabledAllPlugins && config.autoEnablePlugins) {

ScriptableMC-Engine-JS/src/main/kotlin/com/pixlfox/scriptablemc/core/JavaScriptPluginEngine.kt

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -93,29 +93,34 @@ class JavaScriptPluginEngine(override val bootstrapPlugin: ScriptEngineMain, ove
9393
}
9494

9595
override fun loadMainScript(path: String) {
96-
val mainScriptFile = File(path)
97-
if(!mainScriptFile.parentFile.exists()) {
98-
mainScriptFile.parentFile.mkdirs()
99-
}
96+
try {
97+
val mainScriptFile = File(path)
98+
if(!mainScriptFile.parentFile.exists()) {
99+
mainScriptFile.parentFile.mkdirs()
100+
}
100101

101-
if(mainScriptFile.exists()) {
102-
val mainReturn = eval(
103-
Source.newBuilder(languageName, mainScriptFile)
104-
.name(mainScriptFile.name)
105-
.mimeType(config.scriptMimeType)
106-
.interactive(false)
107-
.build()
108-
)
109-
110-
// Load all plugin types returned as an array
111-
if(mainReturn.hasArrayElements()) {
112-
for (i in 0 until mainReturn.arraySize) {
113-
this.loadPlugin(mainReturn.getArrayElement(i))
102+
if(mainScriptFile.exists()) {
103+
val mainReturn = eval(
104+
Source.newBuilder(languageName, mainScriptFile)
105+
.name(mainScriptFile.name)
106+
.mimeType(config.scriptMimeType)
107+
.interactive(false)
108+
.build()
109+
)
110+
111+
// Load all plugin types returned as an array
112+
if(mainReturn.hasArrayElements()) {
113+
for (i in 0 until mainReturn.arraySize) {
114+
this.loadPlugin(mainReturn.getArrayElement(i))
115+
}
114116
}
115117
}
118+
else {
119+
throw ScriptNotFoundException(mainScriptFile)
120+
}
116121
}
117-
else {
118-
throw ScriptNotFoundException(mainScriptFile)
122+
catch(ex: Exception) {
123+
startupErrors.add(ex)
119124
}
120125
}
121126

ScriptableMC-Engine-JS/src/main/resources/config.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,10 @@ common_js:
6767

6868
# CommonJS globals file name
6969
# The CommonJS globals file used to define global CommonJS values
70-
# Relative to the `common_js.modules_path` value
70+
# Relative to the `common_js.modules_path` folder
7171
# Default: globals.js
7272
globals_file: 'globals.js'
7373

74-
java_libraries:
75-
- path: ""
76-
preload_classes:
77-
- ""
78-
7974
# Chrome debugger settings
8075
# **WARNING** THE DEBUGGER SHOULD NEVER BE ENABLED ON A PUBLIC SERVER
8176
# IT IS INTENDED ONLY FOR DEBUGGING THE SCRIPT ENGINE AND CAN BREAK/FREEZE YOUR WHOLE SERVER

ScriptableMC-Engine-PY/src/main/kotlin/com/pixlfox/scriptablemc/core/PythonPluginEngine.kt

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,38 @@ class PythonPluginEngine(override val bootstrapPlugin: ScriptEngineMain, overrid
5454
}
5555

5656
override fun loadMainScript(path: String) {
57-
val mainScriptFile = File(path)
58-
if(!mainScriptFile.parentFile.exists()) {
59-
mainScriptFile.parentFile.mkdirs()
60-
}
57+
try {
58+
val mainScriptFile = File(path)
59+
if(!mainScriptFile.parentFile.exists()) {
60+
mainScriptFile.parentFile.mkdirs()
61+
}
6162

62-
if(mainScriptFile.exists()) {
63-
val mainReturn = eval(
64-
Source.newBuilder(languageName, mainScriptFile)
65-
.name(mainScriptFile.name)
66-
.interactive(false)
67-
.build()
68-
)
63+
if(mainScriptFile.exists()) {
64+
val mainReturn = eval(
65+
Source.newBuilder(languageName, mainScriptFile)
66+
.name(mainScriptFile.name)
67+
.interactive(false)
68+
.build()
69+
)
6970

70-
// Load all plugin types returned as an array
71-
if(mainReturn.hasArrayElements()) {
72-
for (i in 0 until mainReturn.arraySize) {
73-
this.loadPlugin(mainReturn.getArrayElement(i))
74-
}
71+
// Load all plugin types returned as an array
72+
if(mainReturn.hasArrayElements()) {
73+
for (i in 0 until mainReturn.arraySize) {
74+
this.loadPlugin(mainReturn.getArrayElement(i))
75+
}
7576

76-
// Enable all plugins if not already enabled
77-
if(!enabledAllPlugins) {
78-
enableAllPlugins()
77+
// Enable all plugins if not already enabled
78+
if(!enabledAllPlugins) {
79+
enableAllPlugins()
80+
}
7981
}
8082
}
83+
else {
84+
throw ScriptNotFoundException(mainScriptFile)
85+
}
8186
}
82-
else {
83-
throw ScriptNotFoundException(mainScriptFile)
87+
catch(ex: Exception) {
88+
startupErrors.add(ex)
8489
}
8590
}
8691

0 commit comments

Comments
 (0)