Interface Extension

All Known Implementing Classes:
GuiceExtension

public interface Extension

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:

Example

This example extension provides an own implementation of InteractionControllerInstantiator.

public class DIExtension implements Extension {

    private Injector injector;

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

    @Override
    public @NotNull Collection<Implementation<?>> providedImplementations() {
        return List.of(new Implementation<>(
                InteractionClassProvider.class,
                _ -> new CustomInteractionClassProvider(this))
        );
    }

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

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

    • init

      void init(@Nullable @Nullable Extension.Data data)
      Initialises the Extension with the provided Extension.Data. Will be called right after jda-commands loaded the Extension.
      Parameters:
      data - The custom implementation of Extension.Data if given by the User. This can be safely cast to the type returned by dataType().
    • providedImplementations

      @NotNull default @NotNull Collection<@NotNull Implementation<?>> providedImplementations()
      Gets a collection of Implementations this Extension provides.
      Returns:
      a collection of Implementations
      Implementation Note:
      Please note that this method is called multiple times during framework creation. If the identity of the implementations is important, you should always return the same instance.
    • dataType

      @NotNull default @NotNull Class<?> dataType()
      Returns:
      the Class of the custom Extension.Data implementation