diff --git a/api/src/main/java/com/clubobsidian/dynamicgui/api/command/CommandRegistrar.java b/api/src/main/java/com/clubobsidian/dynamicgui/api/command/CommandRegistrar.java index 0e7ac5e1f..15ac77035 100644 --- a/api/src/main/java/com/clubobsidian/dynamicgui/api/command/CommandRegistrar.java +++ b/api/src/main/java/com/clubobsidian/dynamicgui/api/command/CommandRegistrar.java @@ -16,7 +16,7 @@ package com.clubobsidian.dynamicgui.api.command; -import cloud.commandframework.arguments.CommandArgument; +import org.incendo.cloud.component.CommandComponent; import org.jetbrains.annotations.NotNull; import java.util.Collection; @@ -38,7 +38,7 @@ public interface CommandRegistrar { */ void registerGuiAliasCommand(@NotNull String guiName, @NotNull String alias, - @NotNull Collection arguments); + @NotNull Collection arguments); /** * Unregisters a command diff --git a/api/src/main/java/com/clubobsidian/dynamicgui/api/command/cloud/CloudArgument.java b/api/src/main/java/com/clubobsidian/dynamicgui/api/command/cloud/CloudArgument.java index e0074d4e2..b036802c4 100644 --- a/api/src/main/java/com/clubobsidian/dynamicgui/api/command/cloud/CloudArgument.java +++ b/api/src/main/java/com/clubobsidian/dynamicgui/api/command/cloud/CloudArgument.java @@ -16,8 +16,10 @@ package com.clubobsidian.dynamicgui.api.command.cloud; -import cloud.commandframework.arguments.CommandArgument; -import cloud.commandframework.arguments.standard.*; +import org.incendo.cloud.component.CommandComponent; +import org.incendo.cloud.component.TypedCommandComponent; +import org.incendo.cloud.parser.ArgumentParser; +import org.incendo.cloud.parser.standard.*; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Field; @@ -28,16 +30,16 @@ public final class CloudArgument { public static final String PLAYER_ARG_NAME = "player"; - public static final CloudArgument BOOLEAN = create(name -> BooleanArgument.builder(name)); - public static final CloudArgument BYTE = create(name -> ByteArgument.builder(name)); - public static final CloudArgument CHAR = create(name -> CharArgument.builder(name)); - public static final CloudArgument DOUBLE = create(name -> DoubleArgument.builder(name)); - public static final CloudArgument FLOAT = create(name -> FloatArgument.builder(name)); - public static final CloudArgument INTEGER = create(name -> IntegerArgument.builder(name)); - public static final CloudArgument LONG = create(name -> LongArgument.builder(name)); - public static final CloudArgument SHORT = create(name -> ShortArgument.builder(name)); - public static final CloudArgument STRING = create(name -> StringArgument.builder(name)); - public static final CloudArgument UUID = create(name -> UUIDArgument.builder(name)); + public static final CloudArgument BOOLEAN = create(name -> BooleanParser.booleanComponent().name(name)); + public static final CloudArgument BYTE = create(name -> ByteParser.byteComponent().name(name)); + public static final CloudArgument CHAR = create(name -> CharacterParser.characterComponent().name(name)); + public static final CloudArgument DOUBLE = create(name -> DoubleParser.doubleComponent().name(name)); + public static final CloudArgument FLOAT = create(name -> FloatParser.floatComponent().name(name)); + public static final CloudArgument INTEGER = create(name -> IntegerParser.integerComponent().name(name)); + public static final CloudArgument LONG = create(name -> LongParser.longComponent().name(name)); + public static final CloudArgument SHORT = create(name -> ShortParser.shortComponent().name(name)); + public static final CloudArgument STRING = create(name -> StringParser.stringComponent().name(name)); + public static final CloudArgument UUID = create(name -> UUIDParser.uuidComponent().name(name)); private static final Map TYPES = new HashMap<>(); @@ -53,13 +55,13 @@ public final class CloudArgument { } } - public static CloudArgument create(@NotNull Function func) { + public static CloudArgument create(@NotNull Function func) { return new CloudArgument((d) -> { - CommandArgument.Builder builder = func.apply(d.getArgumentName()); + CommandComponent.Builder builder = func.apply(d.getArgumentName()); if (d.isOptional()) { - builder.asOptional(); + builder.optional(); } else { - builder.asRequired(); + builder.required(); } return builder.build(); }); @@ -87,17 +89,17 @@ public static Optional fromType(@NotNull String type) { return Optional.ofNullable(TYPES.get(type)); } - private final Function function; + private final Function function; - public CloudArgument(@NotNull Function function) { + public CloudArgument(@NotNull Function function) { this.function = Objects.requireNonNull(function); } - public T argument(@NotNull String argName) { + public T argument(@NotNull String argName) { return this.argument(argName, false); } - public T argument(@NotNull String argName, boolean optional) { + public T argument(@NotNull String argName, boolean optional) { Objects.requireNonNull(argName); return (T) this.function.apply(new CloudData(argName, optional)); } diff --git a/api/src/main/java/com/clubobsidian/dynamicgui/api/parser/gui/GuiToken.java b/api/src/main/java/com/clubobsidian/dynamicgui/api/parser/gui/GuiToken.java index d7d1edbb4..8678a95e0 100644 --- a/api/src/main/java/com/clubobsidian/dynamicgui/api/parser/gui/GuiToken.java +++ b/api/src/main/java/com/clubobsidian/dynamicgui/api/parser/gui/GuiToken.java @@ -16,11 +16,11 @@ package com.clubobsidian.dynamicgui.api.parser.gui; -import cloud.commandframework.arguments.CommandArgument; import com.clubobsidian.dynamicgui.api.gui.GuiBuildType; import com.clubobsidian.dynamicgui.api.parser.function.tree.FunctionTree; import com.clubobsidian.dynamicgui.api.parser.macro.MacroParser; import com.clubobsidian.dynamicgui.api.parser.slot.SlotToken; +import org.incendo.cloud.component.CommandComponent; import java.io.Serializable; import java.util.Collection; @@ -48,7 +48,7 @@ default String parseType(String type) { List getAlias(); - Collection getCommandArguments(); + Collection getCommandArguments(); List getLocations(); diff --git a/build.gradle b/build.gradle index ed900e386..83f2a75e1 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ allprojects { version projectVersion ext { junitVersion = '5.9.1' - cloudVersion = '1.8.0' + cloudVersion = '2.0.0-rc.2' wrappyVersion = "3.0.1" langVersion = "3.12.0" guiceVersion = "5.1.0" @@ -103,18 +103,18 @@ subprojects { } repositories { - maven { url "https://hub.spigotmc.org/nexus/content/repositories/snapshots"} + maven { url = "https://hub.spigotmc.org/nexus/content/repositories/snapshots" } maven { url = "https://oss.sonatype.org/content/repositories/snapshots" } mavenCentral() - maven { url 'https://jitpack.io' } + maven { url = "https://jitpack.io" } } dependencies { testImplementation "org.junit.jupiter:junit-jupiter-api:$junitVersion" testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junitVersion" testImplementation 'org.mockito:mockito-core:4.8.0' - compileOnly("cloud.commandframework:cloud-core:$cloudVersion") - testRuntimeOnly("cloud.commandframework:cloud-core:$cloudVersion") + compileOnly("org.incendo:cloud-core:$cloudVersion") + testRuntimeOnly("org.incendo:cloud-core:$cloudVersion") compileOnly("org.jetbrains:annotations:23.0.0") compileOnly("org.apache.commons:commons-lang3:$langVersion") testImplementation("org.apache.commons:commons-lang3:$langVersion") diff --git a/bukkit/build.gradle b/bukkit/build.gradle index 0f1cfe8b6..46026c6ab 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -23,5 +23,5 @@ dependencies { compileOnly 'com.github.clubobsidian:foundry:3.0.0' compileOnly 'org.spigotmc:spigot-api:1.8.8-R0.1-SNAPSHOT' compileOnly 'net.md-5:bungeecord-api:1.8-SNAPSHOT' - implementation "cloud.commandframework:cloud-paper:$cloudVersion" + implementation "org.incendo:cloud-paper:2.0.0-beta.8" } \ No newline at end of file diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/cloud/DynamicGuiPaperCommandManager.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/cloud/DynamicGuiPaperCommandManager.java index ee8151ec3..eb7a2ab71 100644 --- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/cloud/DynamicGuiPaperCommandManager.java +++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/cloud/DynamicGuiPaperCommandManager.java @@ -16,32 +16,31 @@ package com.clubobsidian.dynamicgui.bukkit.cloud; -import cloud.commandframework.CloudCapability; -import cloud.commandframework.CommandManager; -import cloud.commandframework.CommandTree; -import cloud.commandframework.bukkit.CloudBukkitCapabilities; -import cloud.commandframework.execution.CommandExecutionCoordinator; -import cloud.commandframework.paper.PaperCommandManager; import com.clubobsidian.dynamicgui.core.util.ReflectionUtil; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; import org.checkerframework.checker.nullness.qual.NonNull; +import org.incendo.cloud.CloudCapability; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.SenderMapper; +import org.incendo.cloud.bukkit.CloudBukkitCapabilities; +import org.incendo.cloud.execution.ExecutionCoordinator; +import org.incendo.cloud.paper.LegacyPaperCommandManager; +import org.incendo.cloud.paper.PaperCommandManager; import java.util.Set; import java.util.function.Function; -public class DynamicGuiPaperCommandManager extends PaperCommandManager { +public class DynamicGuiPaperCommandManager extends LegacyPaperCommandManager { //A hack for not updating the command map for each player every time a new command is registered private final Set capabilities; - public DynamicGuiPaperCommandManager(@NonNull Plugin owningPlugin, - @NonNull Function, - CommandExecutionCoordinator> commandExecutionCoordinator, - @NonNull Function commandSenderMapper, - @NonNull Function backwardsCommandSenderMapper) throws Exception { - super(owningPlugin, commandExecutionCoordinator, commandSenderMapper, backwardsCommandSenderMapper); + public DynamicGuiPaperCommandManager(final @NonNull Plugin owningPlugin, + final @NonNull ExecutionCoordinator commandExecutionCoordinator, + final @NonNull SenderMapper senderMapper) throws Exception { + super(owningPlugin, commandExecutionCoordinator, senderMapper); this.capabilities = (Set) ReflectionUtil .getFieldByName(CommandManager.class, "capabilities") .get(this); diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inject/BukkitPluginModule.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inject/BukkitPluginModule.java index 0dfd09824..9d0172bb2 100644 --- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inject/BukkitPluginModule.java +++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/inject/BukkitPluginModule.java @@ -16,7 +16,6 @@ package com.clubobsidian.dynamicgui.bukkit.inject; -import cloud.commandframework.CommandManager; import com.clubobsidian.dynamicgui.api.command.GuiCommandSender; import com.clubobsidian.dynamicgui.api.economy.Economy; import com.clubobsidian.dynamicgui.api.logger.LoggerWrapper; @@ -36,6 +35,7 @@ import com.clubobsidian.dynamicgui.bukkit.manager.world.BukkitLocationManager; import com.clubobsidian.dynamicgui.core.inject.module.PluginModule; import com.clubobsidian.dynamicgui.core.manager.cloud.CloudManager; +import org.incendo.cloud.CommandManager; public class BukkitPluginModule extends PluginModule { diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/cloud/BukkitCloudManager.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/cloud/BukkitCloudManager.java index c3066e7c8..1a52d6da8 100644 --- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/cloud/BukkitCloudManager.java +++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/manager/cloud/BukkitCloudManager.java @@ -16,15 +16,14 @@ package com.clubobsidian.dynamicgui.bukkit.manager.cloud; -import cloud.commandframework.bukkit.parsers.PlayerArgument; import com.clubobsidian.dynamicgui.api.command.cloud.CloudArgument; import com.clubobsidian.dynamicgui.core.manager.cloud.CloudManager; -import org.bukkit.entity.Player; +import org.incendo.cloud.bukkit.parser.PlayerParser; public class BukkitCloudManager implements CloudManager { @Override public CloudArgument createPlayerArg() { - return CloudArgument.create(name -> PlayerArgument.builder(name)); + return CloudArgument.create(name -> PlayerParser.playerComponent().name(name)); } } \ No newline at end of file diff --git a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/plugin/DynamicGuiBukkitPlugin.java b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/plugin/DynamicGuiBukkitPlugin.java index f136fc1c4..db61ce56a 100644 --- a/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/plugin/DynamicGuiBukkitPlugin.java +++ b/bukkit/src/main/java/com/clubobsidian/dynamicgui/bukkit/plugin/DynamicGuiBukkitPlugin.java @@ -16,10 +16,6 @@ package com.clubobsidian.dynamicgui.bukkit.plugin; -import cloud.commandframework.CommandManager; -import cloud.commandframework.bukkit.CloudBukkitCapabilities; -import cloud.commandframework.execution.CommandExecutionCoordinator; -import cloud.commandframework.paper.PaperCommandManager; import com.clubobsidian.dynamicgui.api.DynamicGui; import com.clubobsidian.dynamicgui.api.command.GuiCommandSender; import com.clubobsidian.dynamicgui.api.economy.Economy; @@ -44,9 +40,20 @@ import com.clubobsidian.dynamicgui.core.economy.NoOpEconomy; import com.clubobsidian.dynamicgui.core.logger.JavaLoggerWrapper; import com.clubobsidian.dynamicgui.core.permission.NoOpPermission; +import org.bukkit.command.CommandSender; import org.bukkit.event.Listener; import org.bukkit.plugin.PluginManager; import org.bukkit.plugin.java.JavaPlugin; +import org.checkerframework.checker.nullness.qual.NonNull; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.SenderMapper; +import org.incendo.cloud.brigadier.BrigadierSetting; +import org.incendo.cloud.bukkit.CloudBukkitCapabilities; +import org.incendo.cloud.bukkit.internal.BukkitBackwardsBrigadierSenderMapper; +import org.incendo.cloud.execution.ExecutionCoordinator; +import org.incendo.cloud.paper.LegacyPaperCommandManager; +import org.incendo.cloud.paper.PaperCommandManager; +import org.incendo.cloud.setting.ManagerSetting; import java.util.logging.Level; @@ -116,20 +123,30 @@ private void registerListener(Listener listener) { private CommandManager createCommandSender() { try { - PaperCommandManager commandManager = new DynamicGuiPaperCommandManager<>(this, - CommandExecutionCoordinator.simpleCoordinator(), - BukkitGuiCommandSender::new, - wrappedSender -> wrappedSender.getNativeSender() + LegacyPaperCommandManager commandManager = new DynamicGuiPaperCommandManager<>( + this, + ExecutionCoordinator.simpleCoordinator(), + new SenderMapper<>() { + @Override + public @NonNull GuiCommandSender map(@NonNull CommandSender base) { + return new BukkitGuiCommandSender(base); + } + + @Override + public @NonNull CommandSender reverse(@NonNull GuiCommandSender mapped) { + return mapped.getNativeSender(); + } + } ); //Unfortunately is tied to bukkit so there is no way to do this in core - if (commandManager.hasCapability(CloudBukkitCapabilities.BRIGADIER)) { - commandManager.registerBrigadier(); + if (commandManager.hasBrigadierManager()) { + commandManager.brigadierManager().settings().set(BrigadierSetting.FORCE_EXECUTABLE, true); } if (commandManager.hasCapability(CloudBukkitCapabilities.ASYNCHRONOUS_COMPLETION)) { commandManager.registerAsynchronousCompletions(); } - commandManager.setSetting(CommandManager.ManagerSettings.ALLOW_UNSAFE_REGISTRATION, true); - commandManager.setSetting(CommandManager.ManagerSettings.OVERRIDE_EXISTING_COMMANDS, true); + commandManager.settings().set(ManagerSetting.ALLOW_UNSAFE_REGISTRATION, true); + commandManager.settings().set(ManagerSetting.OVERRIDE_EXISTING_COMMANDS, true); return commandManager; } catch (Exception e) { e.printStackTrace(); diff --git a/core/build.gradle b/core/build.gradle index 90bb48f0d..c13cb9eeb 100644 --- a/core/build.gradle +++ b/core/build.gradle @@ -21,7 +21,7 @@ dependencies { api 'org.apache.commons:commons-lang3:3.12.0' api "com.github.clubobsidian:wrappy:$wrappyVersion" api 'com.github.ben-manes.caffeine:caffeine:3.1.1' - testImplementation "cloud.commandframework:cloud-core:$cloudVersion" - api "cloud.commandframework:cloud-annotations:$cloudVersion" + testImplementation "org.incendo:cloud-core:$cloudVersion" + api "org.incendo:cloud-annotations:$cloudVersion" api "io.github.classgraph:classgraph:4.8.149" } \ No newline at end of file diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/CommandRegistrarImpl.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/CommandRegistrarImpl.java index 798a43225..82770a890 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/CommandRegistrarImpl.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/CommandRegistrarImpl.java @@ -16,11 +16,6 @@ package com.clubobsidian.dynamicgui.core.command; -import cloud.commandframework.Command; -import cloud.commandframework.CommandManager; -import cloud.commandframework.annotations.AnnotationParser; -import cloud.commandframework.arguments.CommandArgument; -import cloud.commandframework.meta.SimpleCommandMeta; import com.clubobsidian.dynamicgui.api.DynamicGui; import com.clubobsidian.dynamicgui.api.command.CommandRegistrar; import com.clubobsidian.dynamicgui.api.command.GuiCommandSender; @@ -31,6 +26,12 @@ import com.clubobsidian.dynamicgui.api.manager.gui.GuiManager; import com.google.inject.Injector; import org.checkerframework.checker.nullness.qual.NonNull; +import org.incendo.cloud.Command; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.annotations.AnnotationParser; +import org.incendo.cloud.component.CommandComponent; +import org.incendo.cloud.meta.SimpleCommandMeta; +import org.incendo.cloud.setting.ManagerSetting; import org.jetbrains.annotations.NotNull; import javax.inject.Inject; @@ -55,8 +56,8 @@ private CommandRegistrarImpl(CommandManager commandManager, this.commandParser = new AnnotationParser<>(this.commandManager, GuiCommandSender.class, parserParameters -> SimpleCommandMeta.empty()); - this.commandManager.setSetting(CommandManager.ManagerSettings.ALLOW_UNSAFE_REGISTRATION, true); - this.commandManager.setSetting(CommandManager.ManagerSettings.OVERRIDE_EXISTING_COMMANDS, true); + this.commandManager.settings().set(ManagerSetting.ALLOW_UNSAFE_REGISTRATION, true); + this.commandManager.settings().set(ManagerSetting.OVERRIDE_EXISTING_COMMANDS, true); } @Override @@ -68,20 +69,20 @@ public void registerCommand(@NotNull Class command) @Override public void registerGuiAliasCommand(@NotNull String guiName, @NotNull String alias, - @NotNull Collection arguments) { + @NotNull Collection arguments) { Objects.requireNonNull(guiName); Objects.requireNonNull(alias); Objects.requireNonNull(arguments); this.unregisterCommand(alias); Command.@NonNull Builder builder = this.commandManager.commandBuilder(alias); builder = builder.handler(context -> { - context.getSender().getPlayer() + context.sender().getPlayer() .ifPresent(playerWrapper -> { Map metadata = new HashMap<>(); - for (CommandArgument arg : arguments) { - String argName = arg.getName(); + for (CommandComponent arg : arguments) { + String argName = arg.name(); String metaKey = "command_" + argName; - context.getOptional(argName).ifPresent(value -> { + context.optional(argName).ifPresent(value -> { String metadataValue = EntityManager.get().isPlayer(value) ? EntityManager.get().createPlayerWrapper(value).getName() : String.valueOf(value); @@ -91,7 +92,7 @@ public void registerGuiAliasCommand(@NotNull String guiName, GuiManager.get().openGui(playerWrapper, guiName, metadata); }); }); - for (CommandArgument arg : arguments) { + for (CommandComponent arg : arguments) { builder = builder.argument(arg); } this.commandManager.command(builder.build()); diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/DynamicGuiCommand.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/DynamicGuiCommand.java index 7c75c90b8..7ea497d82 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/DynamicGuiCommand.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/DynamicGuiCommand.java @@ -16,9 +16,6 @@ package com.clubobsidian.dynamicgui.core.command; -import cloud.commandframework.annotations.Argument; -import cloud.commandframework.annotations.CommandMethod; -import cloud.commandframework.annotations.CommandPermission; import com.clubobsidian.dynamicgui.api.command.GuiCommandSender; import com.clubobsidian.dynamicgui.api.command.RegisteredCommand; import com.clubobsidian.dynamicgui.api.entity.PlayerWrapper; @@ -29,6 +26,9 @@ import com.clubobsidian.dynamicgui.core.event.plugin.DynamicGuiReloadEvent; import com.clubobsidian.dynamicgui.core.util.ChatColor; import com.clubobsidian.trident.EventBus; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.Permission; import javax.inject.Inject; import java.util.Iterator; @@ -49,25 +49,25 @@ private DynamicGuiCommand(Platform platform, EventBus eventBus) { } - @CommandMethod("dynamicgui|dyngui reload") - @CommandPermission(Constant.RELOAD_COMMAND_PERMISSION) - private void reload(GuiCommandSender sender) { + @Command("dynamicgui|dyngui reload") + @Permission(Constant.RELOAD_COMMAND_PERMISSION) + public void reload(GuiCommandSender sender) { sender.sendMessage("Guis have been reloaded"); GuiManager.get().reloadGuis(false); this.eventBus.callEvent(new DynamicGuiReloadEvent()); } - @CommandMethod("dynamicgui|dyngui forcereload") - @CommandPermission(Constant.RELOAD_COMMAND_PERMISSION) - private void forceReload(GuiCommandSender sender) { + @Command("dynamicgui|dyngui forcereload") + @Permission(Constant.RELOAD_COMMAND_PERMISSION) + public void forceReload(GuiCommandSender sender) { sender.sendMessage("Guis have been force reloaded"); GuiManager.get().reloadGuis(true); this.eventBus.callEvent(new DynamicGuiReloadEvent()); } - @CommandMethod("dynamicgui|dyngui close all [guiName]") - @CommandPermission(Constant.CLOSE_COMMAND_PERMISSION) - private void closeAll(GuiCommandSender sender, @Argument("guiName") String guiName) { + @Command("dynamicgui|dyngui close all [guiName]") + @Permission(Constant.CLOSE_COMMAND_PERMISSION) + public void closeAll(GuiCommandSender sender, @Argument("guiName") String guiName) { if (guiName == null) { sender.sendMessage("All open DynamicGui guis have been closed"); for (UUID uuid : GuiManager.get().getPlayerGuis().keySet()) { @@ -95,9 +95,9 @@ private void closeAll(GuiCommandSender sender, @Argument("guiName") String guiNa } } - @CommandMethod("dynamicgui|dyngui close ") - @CommandPermission(Constant.CLOSE_COMMAND_PERMISSION) - private void closePlayer(GuiCommandSender sender, @Argument("playerName") String playerName) { + @Command("dynamicgui|dyngui close ") + @Permission(Constant.CLOSE_COMMAND_PERMISSION) + public void closePlayer(GuiCommandSender sender, @Argument("playerName") String playerName) { PlayerWrapper player = this.platform.getPlayer(playerName); if (player == null) { sender.sendMessage("That player is not online, so their gui cannot be closed"); @@ -111,9 +111,9 @@ private void closePlayer(GuiCommandSender sender, @Argument("playerName") String } } - @CommandMethod("dynamicgui|dyngui list") - @CommandPermission(Constant.LIST_COMMAND_PERMISSION) - private void guiList(GuiCommandSender sender) { + @Command("dynamicgui|dyngui list") + @Permission(Constant.LIST_COMMAND_PERMISSION) + public void guiList(GuiCommandSender sender) { List guiNames = GuiManager .get() .getGuis() diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/GuiCommand.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/GuiCommand.java index d905160d1..0fa2ed20d 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/command/GuiCommand.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/command/GuiCommand.java @@ -16,11 +16,6 @@ package com.clubobsidian.dynamicgui.core.command; -import cloud.commandframework.annotations.Argument; -import cloud.commandframework.annotations.CommandMethod; -import cloud.commandframework.annotations.CommandPermission; -import cloud.commandframework.annotations.suggestions.Suggestions; -import cloud.commandframework.context.CommandContext; import com.clubobsidian.dynamicgui.api.DynamicGui; import com.clubobsidian.dynamicgui.api.command.GuiCommandSender; import com.clubobsidian.dynamicgui.api.command.RegisteredCommand; @@ -28,14 +23,19 @@ import com.clubobsidian.dynamicgui.api.gui.Gui; import com.clubobsidian.dynamicgui.api.manager.gui.GuiManager; import com.clubobsidian.dynamicgui.core.Constant; +import org.incendo.cloud.annotations.Argument; +import org.incendo.cloud.annotations.Command; +import org.incendo.cloud.annotations.Permission; +import org.incendo.cloud.annotations.suggestion.Suggestions; +import org.incendo.cloud.context.CommandContext; import java.util.ArrayList; import java.util.List; public class GuiCommand implements RegisteredCommand { - @CommandMethod("gui ") - @CommandPermission(Constant.GUI_BASE_PERMISSION) + @Command("gui ") + @Permission(Constant.GUI_BASE_PERMISSION) private void gui(GuiCommandSender sender, @Argument(value = "guiName", suggestions = "guiName") String guiName) { PlayerWrapper player = sender.getPlayer().orElse(null); if (player != null) { diff --git a/core/src/main/java/com/clubobsidian/dynamicgui/core/inject/module/PluginModule.java b/core/src/main/java/com/clubobsidian/dynamicgui/core/inject/module/PluginModule.java index fe18c8057..536cedf5c 100644 --- a/core/src/main/java/com/clubobsidian/dynamicgui/core/inject/module/PluginModule.java +++ b/core/src/main/java/com/clubobsidian/dynamicgui/core/inject/module/PluginModule.java @@ -16,7 +16,6 @@ package com.clubobsidian.dynamicgui.core.inject.module; -import cloud.commandframework.CommandManager; import com.clubobsidian.dynamicgui.api.DynamicGui; import com.clubobsidian.dynamicgui.api.command.CommandRegistrar; import com.clubobsidian.dynamicgui.api.command.GuiCommandSender; @@ -65,6 +64,7 @@ import com.google.inject.Guice; import com.google.inject.Module; import com.google.inject.TypeLiteral; +import org.incendo.cloud.CommandManager; public abstract class PluginModule implements Module { diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/command/CloudArgumentTest.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/command/CloudArgumentTest.java deleted file mode 100644 index 9e7e14a8b..000000000 --- a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/command/CloudArgumentTest.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright 2018-2023 virustotalop - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.clubobsidian.dynamicgui.core.test.command; - -import cloud.commandframework.arguments.CommandArgument; -import com.clubobsidian.dynamicgui.api.command.cloud.CloudArgument; -import org.junit.jupiter.api.Test; - -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -public class CloudArgumentTest { - - private String getName(CommandArgument arg) { - return arg.getValueType().getType().getTypeName(); - } - - @Test - public void testFromTypeText() { - assertEquals(CloudArgument.STRING, CloudArgument.fromType("text").get()); - } - - @Test - public void testFromTypeNumber() { - assertEquals(CloudArgument.INTEGER, CloudArgument.fromType("number").get()); - } - - @Test - public void testBooleanArgument() { - assertEquals(Boolean.class.getName(), this.getName(CloudArgument.BOOLEAN.argument("test"))); - } - - @Test - public void testByteArgument() { - assertEquals(Byte.class.getName(), this.getName(CloudArgument.BYTE.argument("test"))); - } - - @Test - public void testCharArgument() { - assertEquals(Character.class.getName(), this.getName(CloudArgument.CHAR.argument("test"))); - } - - @Test - public void testDoubleArgument() { - assertEquals(Double.class.getName(), this.getName(CloudArgument.DOUBLE.argument("test"))); - } - - @Test - public void testFloatArgument() { - assertEquals(Float.class.getName(), this.getName(CloudArgument.FLOAT.argument("test"))); - } - - @Test - public void testIntegerArgument() { - assertEquals(Integer.class.getName(), this.getName(CloudArgument.INTEGER.argument("test"))); - } - - @Test - public void testLongArgument() { - assertEquals(Long.class.getName(), this.getName(CloudArgument.LONG.argument("test"))); - } - - @Test - public void testShortArgument() { - assertEquals(Short.class.getName(), this.getName(CloudArgument.SHORT.argument("test"))); - } - - @Test - public void testStringArgument() { - assertEquals(String.class.getName(), this.getName(CloudArgument.STRING.argument("test"))); - } - - @Test - public void testUUIDArgument() { - assertEquals(UUID.class.getName(), this.getName(CloudArgument.UUID.argument("test"))); - } -} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/MockFactory.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/MockFactory.java index bea29f3e1..e2e0871fc 100644 --- a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/MockFactory.java +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/MockFactory.java @@ -16,7 +16,6 @@ package com.clubobsidian.dynamicgui.core.test.mock; -import cloud.commandframework.CommandManager; import com.clubobsidian.dynamicgui.api.DynamicGui; import com.clubobsidian.dynamicgui.api.command.GuiCommandSender; import com.clubobsidian.dynamicgui.api.economy.Economy; @@ -49,6 +48,7 @@ import com.clubobsidian.dynamicgui.mock.logger.MockLogger; import com.clubobsidian.dynamicgui.mock.logger.MockLoggerWrapper; import com.clubobsidian.dynamicgui.parser.function.tree.SimpleFunctionTree; +import org.incendo.cloud.CommandManager; import org.mockito.Mockito; import java.io.File; @@ -193,7 +193,7 @@ public MockFactory inject(Economy economy, Permission permission) { } Platform platform = new MockPlatform(); LoggerWrapper logger = new MockLoggerWrapper(new MockLogger()); - CommandManager commandManager = new MockCommandManager(); + CommandManager commandManager = new MockCommandManager<>(); MockPluginModule module = new MockPluginModule( plugin, platform, logger, commandManager, diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockCommandManager.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockCommandManager.java index 13064a455..917a6964e 100644 --- a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockCommandManager.java +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockCommandManager.java @@ -16,48 +16,22 @@ package com.clubobsidian.dynamicgui.core.test.mock.command; -import cloud.commandframework.CommandManager; -import cloud.commandframework.CommandTree; -import cloud.commandframework.execution.AsynchronousCommandExecutionCoordinator; -import cloud.commandframework.execution.CommandExecutionCoordinator; -import cloud.commandframework.internal.CommandRegistrationHandler; -import cloud.commandframework.meta.CommandMeta; import org.checkerframework.checker.nullness.qual.NonNull; - -import java.util.function.Function; +import org.incendo.cloud.CommandManager; +import org.incendo.cloud.execution.ExecutionCoordinator; +import org.incendo.cloud.internal.CommandRegistrationHandler; public class MockCommandManager extends CommandManager { public MockCommandManager() { - this(CommandExecutionCoordinator.simpleCoordinator(), - CommandRegistrationHandler.nullCommandRegistrationHandler()); - } - - /** - * Create a new command manager instance - * - * @param commandExecutionCoordinator Execution coordinator instance. The coordinator is in charge of executing incoming - * commands. Some considerations must be made when picking a suitable execution coordinator - * for your platform. For example, an entirely asynchronous coordinator is not suitable - * when the parsers used in that particular platform are not thread safe. If you have - * commands that perform blocking operations, however, it might not be a good idea to - * use a synchronous execution coordinator. In most cases you will want to pick between - * {@link CommandExecutionCoordinator#simpleCoordinator()} and - * {@link AsynchronousCommandExecutionCoordinator} - * @param commandRegistrationHandler Command registration handler. This will get called every time a new command is - * registered to the command manager. This may be used to forward command registration - */ - protected MockCommandManager(@NonNull Function<@NonNull CommandTree, @NonNull CommandExecutionCoordinator> commandExecutionCoordinator, @NonNull CommandRegistrationHandler commandRegistrationHandler) { - super(commandExecutionCoordinator, commandRegistrationHandler); + super( + ExecutionCoordinator.simpleCoordinator(), + CommandRegistrationHandler.nullCommandRegistrationHandler() + ); } @Override public boolean hasPermission(@NonNull C sender, @NonNull String permission) { return false; } - - @Override - public @NonNull CommandMeta createDefaultCommandMeta() { - return null; - } -} +} \ No newline at end of file diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockPlayerArgument.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockPlayerArgument.java deleted file mode 100644 index 1f9ee5647..000000000 --- a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockPlayerArgument.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2018-2023 virustotalop - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.clubobsidian.dynamicgui.core.test.mock.command; - -import cloud.commandframework.ArgumentDescription; -import cloud.commandframework.arguments.CommandArgument; -import cloud.commandframework.arguments.parser.ArgumentParser; -import cloud.commandframework.arguments.standard.BooleanArgument; -import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayer; -import io.leangen.geantyref.TypeToken; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; - -import java.util.Collection; -import java.util.function.BiFunction; - -public class MockPlayerArgument extends CommandArgument { - public MockPlayerArgument(boolean required, @NonNull String name, @NonNull ArgumentParser parser, @NonNull String defaultValue, @NonNull TypeToken valueType, @Nullable BiFunction suggestionsProvider, @NonNull ArgumentDescription defaultDescription, @NonNull Collection argumentPreprocessors) { - super(required, name, parser, defaultValue, valueType, suggestionsProvider, defaultDescription, argumentPreprocessors); - } - - public static MockPlayerArgument.Builder builder(final @NonNull String name) { - return new MockPlayerArgument.Builder<>(name); - } - - public static class Builder extends CommandArgument.Builder { - - protected Builder(@NonNull String name) { - super(TypeToken.get(MockPlayer.class), name); - } - } -} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockPlayerArgumentParser.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockPlayerArgumentParser.java new file mode 100644 index 000000000..d60fb469a --- /dev/null +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/command/MockPlayerArgumentParser.java @@ -0,0 +1,47 @@ +/* + * Copyright 2018-2023 virustotalop + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.clubobsidian.dynamicgui.core.test.mock.command; + +import com.clubobsidian.dynamicgui.api.command.cloud.CloudArgument; +import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayer; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.incendo.cloud.component.CommandComponent; +import org.incendo.cloud.context.CommandContext; +import org.incendo.cloud.context.CommandInput; +import org.incendo.cloud.parser.ArgumentParseResult; +import org.incendo.cloud.parser.ArgumentParser; +import org.incendo.cloud.parser.ParserDescriptor; + +public class MockPlayerArgumentParser implements ArgumentParser { + + public static @NonNull ParserDescriptor playerParser() { + return ParserDescriptor.of(new MockPlayerArgumentParser<>(), MockPlayer.class); + } + + + public static CommandComponent.@NonNull Builder playerComponent() { + return CommandComponent.builder(CloudArgument.PLAYER_ARG_NAME, playerParser()); + } + + + @Override + public @NonNull ArgumentParseResult<@NonNull MockPlayer> parse(@NonNull CommandContext<@NonNull C> commandContext, + @NonNull CommandInput commandInput) { + return ArgumentParseResult.success(new MockPlayer()); + } +} diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inject/MockPluginModule.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inject/MockPluginModule.java index 6f1a9f55c..6247d1186 100644 --- a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inject/MockPluginModule.java +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/inject/MockPluginModule.java @@ -16,7 +16,6 @@ package com.clubobsidian.dynamicgui.core.test.mock.inject; -import cloud.commandframework.CommandManager; import com.clubobsidian.dynamicgui.api.command.GuiCommandSender; import com.clubobsidian.dynamicgui.api.economy.Economy; import com.clubobsidian.dynamicgui.api.logger.LoggerWrapper; @@ -31,6 +30,7 @@ import com.clubobsidian.dynamicgui.core.inject.module.PluginModule; import com.clubobsidian.dynamicgui.core.manager.cloud.CloudManager; import com.clubobsidian.dynamicgui.core.test.mock.manager.*; +import org.incendo.cloud.CommandManager; public class MockPluginModule extends PluginModule { diff --git a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockCloudManager.java b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockCloudManager.java index 7a2dbf467..2aa74accf 100644 --- a/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockCloudManager.java +++ b/core/src/test/java/com/clubobsidian/dynamicgui/core/test/mock/manager/MockCloudManager.java @@ -18,12 +18,11 @@ import com.clubobsidian.dynamicgui.api.command.cloud.CloudArgument; import com.clubobsidian.dynamicgui.core.manager.cloud.CloudManager; -import com.clubobsidian.dynamicgui.core.test.mock.command.MockPlayerArgument; -import com.clubobsidian.dynamicgui.core.test.mock.entity.player.MockPlayer; +import com.clubobsidian.dynamicgui.core.test.mock.command.MockPlayerArgumentParser; public class MockCloudManager implements CloudManager { @Override public CloudArgument createPlayerArg() { - return CloudArgument.create(name -> MockPlayerArgument.builder(name)); + return CloudArgument.create(name -> MockPlayerArgumentParser.playerComponent()); } } diff --git a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/SimpleGuiToken.java b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/SimpleGuiToken.java index e8e411073..757d58f20 100644 --- a/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/SimpleGuiToken.java +++ b/parser/src/main/java/com/clubobsidian/dynamicgui/parser/gui/SimpleGuiToken.java @@ -16,7 +16,6 @@ package com.clubobsidian.dynamicgui.parser.gui; -import cloud.commandframework.arguments.CommandArgument; import com.clubobsidian.dynamicgui.api.DynamicGui; import com.clubobsidian.dynamicgui.api.command.cloud.CloudArgument; import com.clubobsidian.dynamicgui.api.gui.GuiBuildType; @@ -31,6 +30,7 @@ import com.clubobsidian.dynamicgui.parser.macro.SimpleMacroToken; import com.clubobsidian.dynamicgui.parser.slot.SimpleSlotToken; import com.clubobsidian.wrappy.ConfigurationSection; +import org.incendo.cloud.component.CommandComponent; import java.util.*; @@ -47,7 +47,7 @@ public class SimpleGuiToken implements GuiToken { private final GuiBuildType mode; private final Boolean closed; //This should be boxed private final List alias; - private final List commandArguments; + private final List commandArguments; private final List locations; private final Map> npcs; private final Map slots; @@ -93,8 +93,8 @@ public SimpleGuiToken(ConfigurationSection section, List macroTokens this.section = section; } - private List loadCommandArguments(ConfigurationSection section) { - List args = new ArrayList<>(); + private List loadCommandArguments(ConfigurationSection section) { + List args = new ArrayList<>(); for (Object key : section.getKeys()) { String keyName = String.valueOf(key); ConfigurationSection keySec = section.getConfigurationSection(key); @@ -215,7 +215,7 @@ public List getAlias() { } @Override - public Collection getCommandArguments() { + public Collection getCommandArguments() { return this.commandArguments; }