add some simple command creation logic

This commit is contained in:
Alexander Söderberg 2023-01-17 09:45:12 +01:00
parent ab64836fc0
commit 6bb1ebe1a1

View File

@ -22,19 +22,25 @@ import cloud.commandframework.CommandManager;
import cloud.commandframework.annotations.AnnotationParser; import cloud.commandframework.annotations.AnnotationParser;
import cloud.commandframework.meta.SimpleCommandMeta; import cloud.commandframework.meta.SimpleCommandMeta;
import com.google.inject.Inject; import com.google.inject.Inject;
import com.google.inject.Injector;
import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.player.PlotPlayer;
import io.leangen.geantyref.TypeToken; import io.leangen.geantyref.TypeToken;
import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.stream.Stream;
public class PlotSquaredCommandManager { public class PlotSquaredCommandManager {
private final Injector injector;
private final CommandManager<PlotPlayer<?>> commandManager; private final CommandManager<PlotPlayer<?>> commandManager;
private final AnnotationParser<PlotPlayer<?>> annotationParser; private final AnnotationParser<PlotPlayer<?>> annotationParser;
@Inject @Inject
public PlotSquaredCommandManager( public PlotSquaredCommandManager(
final @NonNull Injector injector,
final @NonNull CommandManager<PlotPlayer<?>> commandManager final @NonNull CommandManager<PlotPlayer<?>> commandManager
) { ) {
this.injector = injector;
this.commandManager = commandManager; this.commandManager = commandManager;
this.annotationParser = new AnnotationParser<PlotPlayer<?>>( this.annotationParser = new AnnotationParser<PlotPlayer<?>>(
this.commandManager, 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) { public void scanClass(final @NonNull Object instance) {
this.annotationParser.parse(clazz); this.annotationParser.parse(instance);
}
/**
* Initializes all the known commands.
*/
public void initializeCommands() {
final Stream<Class<?>> commandClasses = Stream.of(
);
commandClasses.map(injector::getInstance).forEach(this::scanClass);
} }
} }