Skip to content
Jonathan edited this page Sep 25, 2017 · 1 revision

Currently, Sandstone uses EventSys to generate, manage and dispatch events. Sandstone events implementation and factory are generated at runtime, but we recommned you to use Event Adapters when same event with same purpose exists in the platform.

EventAdapters

Event adapters are used in the cases that the same event exists in platform with the same purpose, example Sandstone InitializationEvent have same purpose as GameInitializationEvent of Sponge, so in this case, Event Adapter is used instead of generated event:

import com.github.jonathanxd.adapterhelper.Adapter
import com.github.jonathanxd.adapterhelper.implgen.Additional
import com.github.projectsandstone.api.event.init.InitializationEvent
import com.github.projectsandstone.eventsys.add.EventSysAdditionalHandler
import com.github.projectsandstone.sponge.util.alias.SpongeGameInitializationEvent

@Additional(EventSysAdditionalHandler::class)
interface GameInitAdapter : Adapter<SpongeGameInitializationEvent>, InitializationEvent

But it is not enough, you need to register the class in both systems, AdapterHelper System and Event System. In EventSys you need to register only to avoid the system from generating event class and use GameInitAdapter instead:

adapters.register(AdapterSpecification.createFromInterface(GameInitAdapter::class.java, 
        InitializationEvent::class.java, SpongeGameInitializationEvent::class.java))

Sandstone.eventManager.eventGenerator.registerEventImplementation(
        EventClassSpecification(TypeInfo.of(InitializationEvent::class.java), emptyList(), emptyList()),
        GameInitAdapter::class.java as Class<InitializationEvent>
)
Clone this wiki locally