Skip to main content
Version: 0.7.0

Initializers

Sometimes your extension needs to do some initialization before it can be used. For example, you might need to add a hook to a plugin to make it work with your extension.

Declaring an Initializer

To declare an initializer, you need to create a object that implements the Initializable interface. And add the @Initializer annotation to the class.

ExampleInitializer.kt
import com.typewritermc.core.extension.Initializable
import com.typewritermc.core.extension.annotations.Initializer

@Initializer
object ExampleInitializer : Initializable {
override fun initialize() {
// Do something when the extension is initialized
}

override fun shutdown() {
// Do something when the extension is shutdown
}
}
 Ensure Cleanup

The shutdown method is called when the extension is unloaded. You should make sure that no resources are leaked when the extension is unloaded.

Typewriter will automatically register and call the control flow methods when the extension is loaded and unloaded.