Skip to content

Creating & registering content

Registrables in UnderscoreEnchants are what powers the enchantment - triggers, actions, placeholders, etc.

Creating registrables

There is a separate guide for each registrable type. Please note that the guides are Kotlin-only and if you plan on using Java, you will have to convert the code to Java yourselves.

Registering

To register a registrable, providers are used. The simple reason behind this decision is to be able to easily reload the registry when reloading the plugin. When registering a provider, it gets stored in the registry, and when the plugin gets reloaded and the registry gets cleared, it goes through all providers, verifies their validity again (for a provider to be valid, its backing plugin must be enabled) and registers the provided content.

When enchantments get registered the first time and they use content that is not bundled with UnderscoreEnchants, the content that they use is unrecognized (e.g. enchantment uses a trigger from plugin X, but UnderscoreEnchants loads before plugin X, so the enchantment does not properly recognize the trigger). Internally, such trigger gets saved as an UndiscoveredTrigger. Afterwards, whenever the registry accepts a provider, it goes through all enchantments that have any undiscovered content, and tries to load the content again. Thus, when plugin X sends a provider to the registry, it will reload the enchantment and it will discover the trigger and load properly.

While you can provide content at any time, you are encouraged to not do it dynamically while the plugin is running, but immediately when it loads for the reason outlined above.

ueApi.registry.provide(object : RegistrablesProvider {
    override fun getAssociatedPlugin() = pluginInstance
    override fun getProvidedRegistrables() = listOf(reg1, reg2)
})
ueApi.getRegistry.provide(new RegistrablesProvider {
    @Override
    public JavaPlugin getAssociatedPlugin() {
        return pluginInstance;
    }

    @Override
    public List<Registrable> getProvidedRegistrables() {
        return List.of(reg1, reg2);
    }
});