Skip to main content
 Warning: Beta Version
Version: Beta ⚠️

EventEntry

The EventEntry is used as a starting point for any sequence. It can have external event listeners listening to events and trigger based on that.

Usage

ExampleEventEntry.kt
@Entry("example_event", "An example event entry.", Colors.YELLOW, "material-symbols:bigtop-updates")
class ExampleEventEntry(
override val id: String = "",
override val name: String = "",
override val triggers: List<Ref<TriggerableEntry>> = emptyList(),
) : EventEntry

To listen to an event, you must create a function that is annotated with @EntryListener. The great thing about kotlin, is that this can be done in the same file as the entry.

ExampleEventEntry.kt
@EntryListener(ExampleEventEntry::class)
fun onEvent(event: SomeBukkitEvent, query: Query<ExampleEventEntry>) {
// Do something
val entries = query.find() // Find all the entries of this type, for more information see the Query section
// Do something with the entries, for example trigger them
entries.triggerAllFor(event.player, context())
}

The function will automatically be registered as a listener for the event by Typewriter and be called when the Bukkit event is trigger. An optional Query parameter can be added to easily fetch all the different event entries.

Entry Context Variables

Sometimes you want to pass some information to the context so that subsequent entries can use it.

ExampleEventEntry.kt
@Entry("example_event_with_context_keys", "An example event entry with context keys.", Colors.YELLOW, "material-symbols:bigtop-updates")
// This tells Typewriter that this entry exposes some context
@ContextKeys(ExampleContextKeys::class)
class ExampleEventEntryWithContextKeys(
override val id: String = "",
override val name: String = "",
override val triggers: List<Ref<TriggerableEntry>> = emptyList(),
) : EventEntry

enum class ExampleContextKeys(override val klass: KClass<*>) : EntryContextKey {
// The two `String::class` have to be the same.
// The @KeyType is for the panel to know
@KeyType(String::class)
// The type here is for casting during runtime
TEXT(String::class),

@KeyType(Int::class)
NUMBER(Int::class),

// More complex types are also allowed.
@KeyType(Position::class)
POSITION(Position::class)
}

@EntryListener(ExampleEventEntryWithContextKeys::class)
fun onEventAddContext(event: SomeBukkitEvent, query: Query<ExampleEventEntryWithContextKeys>) {
val entries = query.find()
entries.triggerAllFor(event.player) {
// Make sure these values are drawn from the event.
// You MUST supply all the context keys.
ExampleContextKeys.TEXT withValue "Hello World"
ExampleContextKeys.NUMBER withValue 42
ExampleContextKeys.POSITION withValue Position.ORIGIN
}
}