EventEmitter

interface EventEmitter<T : Event> : JavaEventEmitter<T>

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"))

Functions

next
Link copied to clipboard
open override fun <E : T> next(eventClass: Class<E>, eventListener: EventListener<E>)
Subscribes the eventListener to be executed when the next event of type E is emitted.
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.
off
Link copied to clipboard
open override fun <E : T> off(eventListener: EventListener<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<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.
on
Link copied to clipboard
open override fun <E : T> on(eventClass: Class<E>, eventListener: EventListener<E>)
Subscribes the eventListener to be executed when an event of type E is emitted.
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.

Inheritors

PlayerView
Link copied to clipboard
Source
Link copied to clipboard
Player
Link copied to clipboard

Extensions

next
Link copied to clipboard
inline fun <E : Event> EventEmitter<Event>.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)
on
Link copied to clipboard
inline fun <E : Event> EventEmitter<Event>.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)