diff --git a/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt b/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt
index ffd861b..d48601a 100644
--- a/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt
+++ b/base/src/main/kotlin/de/staropensource/engine/base/Engine.kt
@@ -19,8 +19,10 @@
package de.staropensource.engine.base
+import de.staropensource.engine.base.Engine.Companion.bootstrap
import de.staropensource.engine.base.exception.EngineInitializationFailureException
import de.staropensource.engine.base.implementable.Subsystem
+import de.staropensource.engine.base.implementation.event.*
import de.staropensource.engine.base.logging.Logger
import de.staropensource.engine.base.utility.Environment
import de.staropensource.engine.base.utility.FileAccess
@@ -58,7 +60,10 @@ class Engine private constructor() {
* @since v1-alpha10
*/
var state: State = State.UNINITIALIZED
- internal set
+ internal set(value: State) {
+ field = value
+ EngineStateChangeEvent.instance.emit(value)
+ }
/**
* Contains if the engine is currently
@@ -155,9 +160,10 @@ class Engine private constructor() {
/**
* Bootstraps the engine.
*
- * This method initializes static variables
- * and generally performs actions which
- * should only be executed once.
+ * This method initializes static
+ * variables and generally performs
+ * actions which should only be
+ * performed once.
*
* @return `true` if bootstrapping was performed successfully, `false` if failed
* @throws Throwable on initialization error
@@ -193,6 +199,9 @@ class Engine private constructor() {
)
}
+ // Emit EngineBootstrapEvent
+ EngineBootstrapEvent.instance.emit()
+
bootstrapping = false
return true
} catch (exception: Exception) {
@@ -250,6 +259,9 @@ class Engine private constructor() {
)
}
+ // Emit EngineInitializationEvent
+ EngineInitializationEvent.instance.emit()
+
state = State.INITIALIZED
// Print initialization message
@@ -307,6 +319,9 @@ class Engine private constructor() {
fatal = true
)
}
+
+ // Emit EngineReloadEvent
+ EngineReloadEvent.instance.emit()
}
/**
@@ -376,11 +391,11 @@ class Engine private constructor() {
/**
* Shuts the engine down.
*
- * This performs the actual shutdown,
- * just without the bloat.
+ * This method performs
+ * the actual shutdown.
*
- * @param final whether this is the last time the engine shuts down. Doesn't actually shut the application down, just changes some messages and does other things
- * @param crashed enables super careful mode to prevent further breakage
+ * @param final whether this is the last time the engine shuts down. Note that enabling this flag does not kill the process by itself
+ * @param crashed whether to enable super careful mode to prevent further breakage
* @since v1-alpha10
*/
@JvmStatic
@@ -411,6 +426,9 @@ class Engine private constructor() {
}
}
+ // Emit EngineShutdownEvent
+ EngineShutdownEvent.instance.emit(final, crashed)
+
// Print shutdown message
if (final)
logger.info("""
diff --git a/base/src/main/kotlin/de/staropensource/engine/base/implementable/Event.kt b/base/src/main/kotlin/de/staropensource/engine/base/implementable/Event.kt
new file mode 100644
index 0000000..f65267b
--- /dev/null
+++ b/base/src/main/kotlin/de/staropensource/engine/base/implementable/Event.kt
@@ -0,0 +1,136 @@
+/*
+ * STAROPENSOURCE ENGINE SOURCE FILE
+ * Copyright (c) 2024 The StarOpenSource Engine Authors
+ * Licensed under the GNU General Public License v3.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see .
+ */
+
+package de.staropensource.engine.base.implementable
+
+import de.staropensource.engine.base.Engine.Companion.logger
+import de.staropensource.engine.base.utility.misc.StackTraceUtils
+
+/**
+ * An event.
+ *
+ * It's highly recommended that
+ * the implementing class provides
+ * a global instance of itself.
+ *
+ * @constructor Initializes this event
+ * @since v1-alpha10
+ */
+abstract class Event {
+ /**
+ * Contains all registered listeners.
+ *
+ * @since v1-alpha10
+ */
+ private val listeners: MutableSet