Interface Extension<T extends Extension.Data>


public interface Extension<T extends Extension.Data>

Extensions

Implementations of this interface, that are registered by Javas service provider interface, will be called in JDACBuilder to configure the framework.

This interface provides ways to extend the framework with own functionality:

Properties

By implementing properties() and returning a collection of PropertyProviders, you can for example provide an own implementation of InteractionControllerInstantiator or Descriptor. These implementations will override the default ones.

It's important to know, that you can only return PropertyProviders of Propertys with Property.category() set to Property.Category.LOADABLE!

Extension configuration (Extension.Data)

If the Extension needs additional configuration data, implementations have to provide an own implementation of Extension.Data that the user has to register in the builder by calling JDACBuilder.extensionData(Data...).

Example

This example extension provides an own implementation of InteractionControllerInstantiator.

public class DIExtension implements Extension<DIExtensionData> {

    private Injector injector;

    @Override
    public void init(@Nullable DIExtensionData data) {
        this.injector = data != null
                ? data.providedInjector()
                : DI.createInjector();
    }

    @Override
    public Collection<PropertyProvider<?>> properties() {
        return List.of(PropertyProvider.create(
                Property.INTERACTION_CONTROLLER_INSTANTIATOR,
                2000,
                _ -> new CustomInteractionClassProvider(this))
        );
    }

    @Override
    public Class<DIExtensionData> dataType() {
        return DIExtensionData.class;
    }
}

public record DIExtensionData(Injector providedInjector) implements Extension.Data {}