EventEmitter

Manages subscriptions to specific Events and notifies those subscribers when such an event is being emitted. Subscribers can be simple function types in Kotlin or EventListener implementations in Java. There are also reified versions of the EventEmitter API to allow for convenient usage from Kotlin.

Usage from Kotlin:

// Adding a new subscriber for an event
player.on(PlayerEvent.Active::class) { println("Player is active") }
player.on<PlayerEvent.Active> { println("Player is active") }

// Adding a subscriber for an event and removing it later
val onPlayerActive: (PlayerEvent.Active) -> Unit = { println("Player is active") }

player.on(onPlayerActive)
player.off(onPlayerActive)

// Adding a subscriber only for the next occurrence of an event
player.next(PlayerEvent.Active::class) { println("Player is active") }
player.next<PlayerEvent.Active> { println("Player is active") }

Usage from Java:

// Adding a new event listener for an event
player.on(PlayerEvent.Active.class, event -> System.out.println("Player is active"))

// Adding an event listener for an event and removing it later
EventListener<PlayerEvent.Active> onPlayerActive = event -> System.out.println("Player is active");

player.on(PlayerEvent.Active.class, onPlayerActive)
player.off(PlayerEvent.Active.class, onPlayerActive)

// Adding an event listener only for the next occurrence of an event
player.next(PlayerEvent.Active.class, event -> System.out.println("Player is active"))

Inheritors

Functions

Link copied to clipboard
open override fun <E : T> next(eventClass: Class<E>, eventListener: EventListener<in E>)

Subscribes the eventListener to be executed when the next event of type E is emitted. The eventListener will then be automatically unsubscribed.

abstract fun <E : T> next(eventClass: KClass<E>, action: (E) -> Unit)

Subscribes the action to be executed when the next event of type E is emitted. The action will then be automatically unsubscribed.

Link copied to clipboard
inline fun <E : Event> EventEmitter<Event>.next(noinline action: (E) -> Unit)
@JvmName(name = "nextOfflineEvent")
inline fun <E : OfflineEvent> EventEmitter<OfflineEvent>.next(noinline action: (E) -> Unit)
@JvmName(name = "nextPlayerEvent")
inline fun <E : PlayerEvent> EventEmitter<PlayerEvent>.next(noinline action: (E) -> Unit)
@JvmName(name = "nextSourceEvent")
inline fun <E : SourceEvent> EventEmitter<SourceEvent>.next(noinline action: (E) -> Unit)
Link copied to clipboard
open override fun <E : T> off(eventListener: EventListener<in E>)

Unsubscribes the eventListener for all events.

abstract fun <E : T> off(action: (E) -> Unit)

Unsubscribes the action for all events.

open override fun <E : T> off(eventClass: Class<E>, eventListener: EventListener<in E>)

Unsubscribes the eventListener for the specified event.

abstract fun <E : T> off(eventClass: KClass<E>, action: (E) -> Unit)

Unsubscribes the action for the specified event.

Link copied to clipboard
open override fun <E : T> on(eventClass: Class<E>, eventListener: EventListener<in E>)

Subscribes the eventListener to be executed when an event of type E is emitted. Provides the same functionality as EventEmitter.on with a more convenient style when used from Java.

abstract fun <E : T> on(eventClass: KClass<E>, action: (E) -> Unit)

Subscribes the action to be executed when an event of type E is emitted.

Link copied to clipboard
inline fun <E : Event> EventEmitter<Event>.on(noinline action: (E) -> Unit)
@JvmName(name = "onOfflineEvent")
inline fun <E : OfflineEvent> EventEmitter<OfflineEvent>.on(noinline action: (E) -> Unit)
@JvmName(name = "onPlayerEvent")
inline fun <E : PlayerEvent> EventEmitter<PlayerEvent>.on(noinline action: (E) -> Unit)
@JvmName(name = "onSourceEvent")
inline fun <E : SourceEvent> EventEmitter<SourceEvent>.on(noinline action: (E) -> Unit)