Rename event bus

This commit is contained in:
nea
2023-05-16 03:42:06 +02:00
parent fbe8bc680b
commit 01f3981959
8 changed files with 18 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
package moe.nea.firmament.events
/**
* An event that can be fired by a [NEUEventBus].
* An event that can be fired by a [FirmamentEventBus].
*
* Typically, that event bus is implemented as a companion object
*
@@ -11,11 +11,11 @@ package moe.nea.firmament.events
* }
* ```
*/
abstract class NEUEvent {
abstract class FirmamentEvent {
/**
* A [NEUEvent] that can be [cancelled]
* A [FirmamentEvent] that can be [cancelled]
*/
abstract class Cancellable : NEUEvent() {
abstract class Cancellable : FirmamentEvent() {
/**
* Cancels this is event.
*

View File

@@ -9,7 +9,7 @@ import moe.nea.firmament.Firmament
* [subscribe] to events [publish]ed on this event bus.
* Subscriptions may not necessarily be delivered in the order or registering.
*/
open class NEUEventBus<T : NEUEvent> {
open class FirmamentEventBus<T : FirmamentEvent> {
data class Handler<T>(val invocation: (T) -> Unit, val receivesCancelled: Boolean)
private val toHandle: MutableList<Handler<T>> = CopyOnWriteArrayList()
@@ -23,7 +23,7 @@ open class NEUEventBus<T : NEUEvent> {
fun publish(event: T): T {
for (function in toHandle) {
if (function.receivesCancelled || event !is NEUEvent.Cancellable || !event.cancelled) {
if (function.receivesCancelled || event !is FirmamentEvent.Cancellable || !event.cancelled) {
try {
function.invocation(event)
} catch (e: Exception) {

View File

@@ -8,6 +8,6 @@ data class ParticleSpawnEvent(
val position: Vec3d,
val offset: Vec3d,
val longDistance: Boolean,
) : NEUEvent() {
companion object : NEUEventBus<ParticleSpawnEvent>()
) : FirmamentEvent() {
companion object : FirmamentEventBus<ParticleSpawnEvent>()
}

View File

@@ -2,6 +2,6 @@ package moe.nea.firmament.events
import net.minecraft.client.gui.screen.Screen
data class ScreenOpenEvent(val old: Screen?, val new: Screen?) : NEUEvent.Cancellable() {
companion object : NEUEventBus<ScreenOpenEvent>()
data class ScreenOpenEvent(val old: Screen?, val new: Screen?) : FirmamentEvent.Cancellable() {
companion object : FirmamentEventBus<ScreenOpenEvent>()
}

View File

@@ -6,8 +6,8 @@ import moe.nea.firmament.util.unformattedString
/**
* This event gets published whenever the client receives a chat message from the server.
*/
data class ServerChatLineReceivedEvent(val text: Text) : NEUEvent.Cancellable() {
companion object : NEUEventBus<ServerChatLineReceivedEvent>()
data class ServerChatLineReceivedEvent(val text: Text) : FirmamentEvent.Cancellable() {
companion object : FirmamentEventBus<ServerChatLineReceivedEvent>()
val unformattedString = text.unformattedString
}

View File

@@ -8,6 +8,6 @@ import moe.nea.firmament.util.Locraw
* **N.B.:** This event may get fired multiple times while on the server (for example, first to null, then to the
* correct location).
*/
data class SkyblockServerUpdateEvent(val oldLocraw: Locraw?, val newLocraw: Locraw?) : NEUEvent() {
companion object : NEUEventBus<SkyblockServerUpdateEvent>()
data class SkyblockServerUpdateEvent(val oldLocraw: Locraw?, val newLocraw: Locraw?) : FirmamentEvent() {
companion object : FirmamentEventBus<SkyblockServerUpdateEvent>()
}

View File

@@ -1,5 +1,5 @@
package moe.nea.firmament.events
class WorldReadyEvent : NEUEvent() {
companion object : NEUEventBus<WorldReadyEvent>()
class WorldReadyEvent : FirmamentEvent() {
companion object : FirmamentEventBus<WorldReadyEvent>()
}

View File

@@ -17,6 +17,6 @@ data class WorldRenderLastEvent(
val gameRenderer: GameRenderer,
val lightmapTextureManager: LightmapTextureManager,
val positionMatrix: Matrix4f,
) : NEUEvent() {
companion object : NEUEventBus<WorldRenderLastEvent>()
) : FirmamentEvent() {
companion object : FirmamentEventBus<WorldRenderLastEvent>()
}