OneConfig V1
  • Welcome
  • Documentation license
  • Introduction
    • Getting started
  • Configuration
    • Creating your config
      • Option dependencies & hiding options
      • Listening for option changes
    • Available options
      • Boolean options
        • Switch option
        • Checkbox option
      • Number options
        • Slider option
        • Number option
      • Selector options
        • Dropdown option
        • Radio button option
      • Text option
      • Color option
      • Keybind option
      • Buttons
      • Accordions
      • Decorations
    • Creating your own options
  • Commands
    • Annotation-based commands
    • Tree-based commands
  • Events
    • Using the events system
      • Callback events
      • Subscriber events
  • Utilities Module
    • Hypixel utilities
    • IO utilities
    • Networking utilities
    • JSON utilities
    • Multithreading
    • Platform-specific utilities
  • Migration
    • Temporary V0 -> V1 migration guide
    • Migrating your configs from Vigilance
Powered by GitBook
On this page
  • Registering a listener & listening for events
  • Kotlin DSL
Export as PDF
  1. Events
  2. Using the events system

Callback events

Getting started with OneConfig's callback-based events system is familiar, easy to learn and fast. If you've worked with FabricMC or QuiltMC before, you'll already be familiar with how these function.

Registering a listener & listening for events

Registering a listener is as simple as defining the class of the event you'd like to listen to, and providing a callback to be executed whenever that event is dispatched. This can be done via OneConfig's EventManager, like so:

public void setupEvents() {
    EventManager.register(TickEvent.Start.class, event -> System.out.println("Tick tick tick!"));
}
fun setupEvents() {
    EventManager.register(TickEvent.Start::class.java) { event ->
        println("Tick tick tick!")
    }
}

And that's it! Now, from this example, you'll be listening to the TickEvent.Start event, and every time a new game tick starts, it will print "Tick tick tick!" so long as our setupEvents method/function is executed at least once in it's lifetime.

Kotlin DSL

There is also a Kotlin DSL for an improved developer experience with event listeners:

eventHandler { event: TickEvent.Start ->
    println("Tick tick tick!")
}.register()
PreviousUsing the events systemNextSubscriber events

Last updated 5 months ago