Interface Extension
- All Known Implementing Classes:
GuiceExtension
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:
-
providedImplementations()
: By implementing this method and returning a collection ofImplementation
s, you can for example provide an own implementation ofInteractionControllerInstantiator
orDescriptor
. These implementations will override the default ones. -
If the
Extension
needs additional configuration data, implementations have to provide an own implementation ofExtension.Data
that the user has to register in the builder by callingJDACBuilder.extensionData(Data...)
.
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 {}
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Implementations of this interface are providing additional configuration to implementations ofExtension
. -
Method Summary
Modifier and TypeMethodDescriptiondefault @NotNull Class
<?> dataType()
void
init
(@Nullable Extension.Data data) Initialises theExtension
with the providedExtension.Data
.default @NotNull Collection
<@NotNull Implementation<?>> Gets a collection ofImplementation
s thisExtension
provides.
-
Method Details
-
init
Initialises theExtension
with the providedExtension.Data
. Will be called right after jda-commands loaded the Extension.- Parameters:
data
- The custom implementation ofExtension.Data
if given by the User. This can be safely cast to the type returned bydataType()
.
-
providedImplementations
Gets a collection ofImplementation
s thisExtension
provides.- Returns:
- a collection of
Implementation
s - 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
- Returns:
- the
Class
of the customExtension.Data
implementation
-