Interface Extension<T extends Extension.Data>
- All Known Implementing Classes:
GuiceExtension
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 JDACPropertyProviders, you can
for example provide an own implementation of Instantiator
or Descriptor. These implementations will override the default ones.
It's important to know, that you can only return JDACPropertyProviders of JDACPropertys
with Property.source() set to Property.Source.EXTENSION!
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...).
On Framework Start
At the time that framework is fully initialized and started (practically at the end of JDACBuilder.start()),
the onStart(JDACommands) method of all extensions will be called.
This allows further configuration, e.g. through the Introspection API by using JDACommands.introspection().
Example
This example extension provides an own implementation of Instantiator.
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<JDACPropertyProvider<?>> properties() {
return List.of(new JDACPropertyProvider(
JDACProperty.INSTANTIATOR,
Priority.of(2000),
DiExtension.class
_ -> new CustomInteractionClassProvider(this))
);
}
@Override
public void onStart(JDACommands framework) {
Introspection introspection = framework.introspection();
introspection.subscribe(Listener.create(RuntimeCloseEvent.class, (event, _) -> ...));
}
@Override
public Class<DIExtensionData> dataType() {
return DIExtensionData.class;
}
}
public record DIExtensionData(Injector providedInjector) implements Extension.Data {}
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceImplementations of this interface are providing additional configuration to implementations ofExtension. -
Method Summary
Modifier and TypeMethodDescriptiondataType()voidInitializes theExtensionwith the providedExtension.Data.default voidonStart(JDACommands framework) This method will be called after the framework was fully started, practically at the end ofJDACBuilder.start().default Collection<JDACPropertyProvider<?>> Gets a collection ofJDACPropertyProviders thisExtensionprovides.
-
Method Details
-
init
Initializes theExtensionwith the providedExtension.Data. Will be called right after jda-commands loaded the Extension.- Parameters:
data- The custom implementation ofExtension.Dataif given by the User. This can be safely cast to the type returned bydataType().
-
properties
Gets a collection of
JDACPropertyProviders thisExtensionprovides.The
JDACPropertys provided by these providers must have [Property#source()()] set toProperty.Source.EXTENSION!- Returns:
- a collection of
JDACPropertyProviders
-
onStart
This method will be called after the framework was fully started, practically at the end ofJDACBuilder.start().- Parameters:
framework- the fully initializedJDACommandsinstance.
-
dataType
- Returns:
- the
Classof the customExtension.Dataimplementation or null if the extension doesn't support additional configuration
-