Rename event bus
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
package moe.nea.firmament.events
|
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
|
* 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.
|
* Cancels this is event.
|
||||||
*
|
*
|
||||||
@@ -9,7 +9,7 @@ import moe.nea.firmament.Firmament
|
|||||||
* [subscribe] to events [publish]ed on this event bus.
|
* [subscribe] to events [publish]ed on this event bus.
|
||||||
* Subscriptions may not necessarily be delivered in the order or registering.
|
* 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)
|
data class Handler<T>(val invocation: (T) -> Unit, val receivesCancelled: Boolean)
|
||||||
|
|
||||||
private val toHandle: MutableList<Handler<T>> = CopyOnWriteArrayList()
|
private val toHandle: MutableList<Handler<T>> = CopyOnWriteArrayList()
|
||||||
@@ -23,7 +23,7 @@ open class NEUEventBus<T : NEUEvent> {
|
|||||||
|
|
||||||
fun publish(event: T): T {
|
fun publish(event: T): T {
|
||||||
for (function in toHandle) {
|
for (function in toHandle) {
|
||||||
if (function.receivesCancelled || event !is NEUEvent.Cancellable || !event.cancelled) {
|
if (function.receivesCancelled || event !is FirmamentEvent.Cancellable || !event.cancelled) {
|
||||||
try {
|
try {
|
||||||
function.invocation(event)
|
function.invocation(event)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
@@ -8,6 +8,6 @@ data class ParticleSpawnEvent(
|
|||||||
val position: Vec3d,
|
val position: Vec3d,
|
||||||
val offset: Vec3d,
|
val offset: Vec3d,
|
||||||
val longDistance: Boolean,
|
val longDistance: Boolean,
|
||||||
) : NEUEvent() {
|
) : FirmamentEvent() {
|
||||||
companion object : NEUEventBus<ParticleSpawnEvent>()
|
companion object : FirmamentEventBus<ParticleSpawnEvent>()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,6 @@ package moe.nea.firmament.events
|
|||||||
|
|
||||||
import net.minecraft.client.gui.screen.Screen
|
import net.minecraft.client.gui.screen.Screen
|
||||||
|
|
||||||
data class ScreenOpenEvent(val old: Screen?, val new: Screen?) : NEUEvent.Cancellable() {
|
data class ScreenOpenEvent(val old: Screen?, val new: Screen?) : FirmamentEvent.Cancellable() {
|
||||||
companion object : NEUEventBus<ScreenOpenEvent>()
|
companion object : FirmamentEventBus<ScreenOpenEvent>()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import moe.nea.firmament.util.unformattedString
|
|||||||
/**
|
/**
|
||||||
* This event gets published whenever the client receives a chat message from the server.
|
* This event gets published whenever the client receives a chat message from the server.
|
||||||
*/
|
*/
|
||||||
data class ServerChatLineReceivedEvent(val text: Text) : NEUEvent.Cancellable() {
|
data class ServerChatLineReceivedEvent(val text: Text) : FirmamentEvent.Cancellable() {
|
||||||
companion object : NEUEventBus<ServerChatLineReceivedEvent>()
|
companion object : FirmamentEventBus<ServerChatLineReceivedEvent>()
|
||||||
|
|
||||||
val unformattedString = text.unformattedString
|
val unformattedString = text.unformattedString
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
* **N.B.:** This event may get fired multiple times while on the server (for example, first to null, then to the
|
||||||
* correct location).
|
* correct location).
|
||||||
*/
|
*/
|
||||||
data class SkyblockServerUpdateEvent(val oldLocraw: Locraw?, val newLocraw: Locraw?) : NEUEvent() {
|
data class SkyblockServerUpdateEvent(val oldLocraw: Locraw?, val newLocraw: Locraw?) : FirmamentEvent() {
|
||||||
companion object : NEUEventBus<SkyblockServerUpdateEvent>()
|
companion object : FirmamentEventBus<SkyblockServerUpdateEvent>()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package moe.nea.firmament.events
|
package moe.nea.firmament.events
|
||||||
|
|
||||||
class WorldReadyEvent : NEUEvent() {
|
class WorldReadyEvent : FirmamentEvent() {
|
||||||
companion object : NEUEventBus<WorldReadyEvent>()
|
companion object : FirmamentEventBus<WorldReadyEvent>()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ data class WorldRenderLastEvent(
|
|||||||
val gameRenderer: GameRenderer,
|
val gameRenderer: GameRenderer,
|
||||||
val lightmapTextureManager: LightmapTextureManager,
|
val lightmapTextureManager: LightmapTextureManager,
|
||||||
val positionMatrix: Matrix4f,
|
val positionMatrix: Matrix4f,
|
||||||
) : NEUEvent() {
|
) : FirmamentEvent() {
|
||||||
companion object : NEUEventBus<WorldRenderLastEvent>()
|
companion object : FirmamentEventBus<WorldRenderLastEvent>()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user