From 6bb1ebe1a1a6d2c2c7adbdd864b40f720ea44db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Tue, 17 Jan 2023 09:45:12 +0100 Subject: [PATCH] add some simple command creation logic --- .../commands/PlotSquaredCommandManager.java | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Core/src/main/java/com/plotsquared/core/commands/PlotSquaredCommandManager.java b/Core/src/main/java/com/plotsquared/core/commands/PlotSquaredCommandManager.java index c7d877641..644ab0bf4 100644 --- a/Core/src/main/java/com/plotsquared/core/commands/PlotSquaredCommandManager.java +++ b/Core/src/main/java/com/plotsquared/core/commands/PlotSquaredCommandManager.java @@ -22,19 +22,25 @@ import cloud.commandframework.CommandManager; import cloud.commandframework.annotations.AnnotationParser; import cloud.commandframework.meta.SimpleCommandMeta; import com.google.inject.Inject; +import com.google.inject.Injector; import com.plotsquared.core.player.PlotPlayer; import io.leangen.geantyref.TypeToken; import org.checkerframework.checker.nullness.qual.NonNull; +import java.util.stream.Stream; + public class PlotSquaredCommandManager { + private final Injector injector; private final CommandManager> commandManager; private final AnnotationParser> annotationParser; @Inject public PlotSquaredCommandManager( + final @NonNull Injector injector, final @NonNull CommandManager> commandManager ) { + this.injector = injector; this.commandManager = commandManager; this.annotationParser = new AnnotationParser>( this.commandManager, @@ -45,11 +51,20 @@ public class PlotSquaredCommandManager { } /** - * Scans the given {@link Class class} for commands, and registers them. + * Scans the given {@code instance} for commands, and registers them. * - * @param clazz the class to scan. + * @param instance the instance to scan */ - public void scanClass(final @NonNull Class clazz) { - this.annotationParser.parse(clazz); + public void scanClass(final @NonNull Object instance) { + this.annotationParser.parse(instance); + } + + /** + * Initializes all the known commands. + */ + public void initializeCommands() { + final Stream> commandClasses = Stream.of( + ); + commandClasses.map(injector::getInstance).forEach(this::scanClass); } }