diff --git a/src/main/java/com/github/kaktushose/jda/commands/annotations/Produces.java b/src/main/java/com/github/kaktushose/jda/commands/annotations/Produces.java index a1a067f5..63383d2f 100644 --- a/src/main/java/com/github/kaktushose/jda/commands/annotations/Produces.java +++ b/src/main/java/com/github/kaktushose/jda/commands/annotations/Produces.java @@ -29,4 +29,14 @@ @Retention(RetentionPolicy.RUNTIME) public @interface Produces { + /** + * Whether jda-commands should ignore this method at indexing during startup. Useful if you wish to register your + * dependency providers manually by calling + * {@link com.github.kaktushose.jda.commands.dependency.DependencyInjector#registerProvider(Object) + * DependencyInjector#registerProvider(Object)} + * + * @return Whether jda-commands should ignore this method, default {@code true} + */ + boolean skipIndexing() default false; + } diff --git a/src/main/java/com/github/kaktushose/jda/commands/dependency/DependencyInjector.java b/src/main/java/com/github/kaktushose/jda/commands/dependency/DependencyInjector.java index 6788636a..4d868180 100644 --- a/src/main/java/com/github/kaktushose/jda/commands/dependency/DependencyInjector.java +++ b/src/main/java/com/github/kaktushose/jda/commands/dependency/DependencyInjector.java @@ -63,6 +63,13 @@ public void index(@NotNull Class clazz, @NotNull String... packages) { Set methods = reflections.getMethodsAnnotatedWith(Produces.class); for (Method method : methods) { log.debug("Found producer {}", method.getName()); + + Produces produces = method.getAnnotation(Produces.class); + if (produces.skipIndexing()) { + log.debug("Method is marked as indexIgnore. Skipping Producer {}", method); + return; + } + if (method.getParameterTypes().length != 0) { log.error("An error has occurred! Skipping Producer {}", method, new IllegalArgumentException("Producer method must not have parameters!"));