diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/AreaShop.java b/AreaShop/src/main/java/me/wiefferink/areashop/AreaShop.java index 62f1e078..586bad10 100644 --- a/AreaShop/src/main/java/me/wiefferink/areashop/AreaShop.java +++ b/AreaShop/src/main/java/me/wiefferink/areashop/AreaShop.java @@ -9,6 +9,7 @@ import io.papermc.lib.PaperLib; import me.wiefferink.areashop.adapters.platform.MinecraftPlatform; import me.wiefferink.areashop.adapters.platform.paper.PaperPlatform; +import me.wiefferink.areashop.commands.cloud.AreashopCloudCommands; import me.wiefferink.areashop.extensions.AreashopExtension; import me.wiefferink.areashop.features.signs.SignManager; import me.wiefferink.areashop.interfaces.AreaShopInterface; @@ -307,9 +308,9 @@ public void onEnable() { setupTasks(); - // Startup the CommandManager (registers itself for the command) - commandManager = injector.getInstance(CommandManager.class); - managers.add(commandManager); + // Register commands + AreashopCloudCommands commands = injector.getInstance(AreashopCloudCommands.class); + commands.registerCommands(); // Create a signLinkerManager signLinkerManager = injector.getInstance(SignLinkerManager.class); diff --git a/AreaShop/src/main/java/me/wiefferink/areashop/commands/cloud/AreashopCloudCommands.java b/AreaShop/src/main/java/me/wiefferink/areashop/commands/cloud/AreashopCloudCommands.java new file mode 100644 index 00000000..f099dde7 --- /dev/null +++ b/AreaShop/src/main/java/me/wiefferink/areashop/commands/cloud/AreashopCloudCommands.java @@ -0,0 +1,56 @@ +package me.wiefferink.areashop.commands.cloud; + +import com.google.inject.Inject; +import com.google.inject.Injector; +import com.google.inject.Singleton; +import me.wiefferink.areashop.commands.CloudCommandBean; +import org.bukkit.command.CommandSender; +import org.bukkit.plugin.Plugin; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.incendo.cloud.SenderMapper; +import org.incendo.cloud.bukkit.CloudBukkitCapabilities; +import org.incendo.cloud.execution.ExecutionCoordinator; +import org.incendo.cloud.paper.PaperCommandManager; + +import java.util.List; +import java.util.function.Function; + +@Singleton +public class AreashopCloudCommands { + + private static final List> COMMAND_CLASSES = List.of( + AddCommandCloud.class, + AddFriendCloudCommand.class, + AddSignCloudCommand.class + ); + + private final Injector injector; + private final PaperCommandManager commandManager; + + @Inject + AreashopCloudCommands(@NonNull Injector injector, @NonNull Plugin plugin) { + this.injector = injector; + this.commandManager = new PaperCommandManager<>( + plugin, + ExecutionCoordinator.simpleCoordinator(), + SenderMapper.identity() + ); + } + + public void registerCommands() { + initCommandManager(this.commandManager); + for (Class commandClass : COMMAND_CLASSES) { + CloudCommandBean commandBean = injector.getInstance(commandClass); + commandManager.command(commandBean); + } + } + + private static void initCommandManager(PaperCommandManager commandManager) { + if (commandManager.hasCapability(CloudBukkitCapabilities.NATIVE_BRIGADIER)) { + commandManager.registerBrigadier(); + } + } + + + +}