From b802bc2fa57655d6946145841aa5840bb69930a6 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 6 Aug 2022 19:30:44 -0500 Subject: [PATCH 001/101] Yeet CLI --- cli/build.gradle.kts | 21 --- .../dev/triumphteam/cmds/cli/CliCommand.java | 166 ------------------ .../cmds/cli/CliCommandManager.java | 138 --------------- .../cmds/cli/CliCommandProcessor.java | 46 ----- .../cmds/cli/CliCommandSender.java | 9 - .../cmds/cli/CliSenderValidator.java | 34 ---- .../triumphteam/cmds/cli/CliSubCommand.java | 39 ---- .../cmds/cli/CliSubCommandProcessor.java | 46 ----- .../cmds/cli/sender/CliSender.java | 7 - settings.gradle.kts | 3 +- 10 files changed, 1 insertion(+), 508 deletions(-) delete mode 100644 cli/build.gradle.kts delete mode 100644 cli/src/main/java/dev/triumphteam/cmds/cli/CliCommand.java delete mode 100644 cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandManager.java delete mode 100644 cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandProcessor.java delete mode 100644 cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandSender.java delete mode 100644 cli/src/main/java/dev/triumphteam/cmds/cli/CliSenderValidator.java delete mode 100644 cli/src/main/java/dev/triumphteam/cmds/cli/CliSubCommand.java delete mode 100644 cli/src/main/java/dev/triumphteam/cmds/cli/CliSubCommandProcessor.java delete mode 100644 cli/src/main/java/dev/triumphteam/cmds/cli/sender/CliSender.java diff --git a/cli/build.gradle.kts b/cli/build.gradle.kts deleted file mode 100644 index e9bee019..00000000 --- a/cli/build.gradle.kts +++ /dev/null @@ -1,21 +0,0 @@ -plugins { - id("cmds.base-conventions") - id("cmds.library-conventions") -} - -dependencies { - api(project(":triumph-cmd-core")) - - testImplementation(kotlin("stdlib")) - testImplementation(libs.junit.api) - testImplementation(libs.junit.engine) - testImplementation(libs.assertj) - - api(libs.guava) -} - -tasks { - test { - useJUnitPlatform() - } -} \ No newline at end of file diff --git a/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommand.java b/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommand.java deleted file mode 100644 index b61817e4..00000000 --- a/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommand.java +++ /dev/null @@ -1,166 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmds.cli; - -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.SubCommand; -import dev.triumphteam.cmd.core.annotation.Default; -import dev.triumphteam.cmd.core.argument.ArgumentRegistry; -import dev.triumphteam.cmd.core.argument.named.NamedArgumentRegistry; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; -import dev.triumphteam.cmd.core.registry.Registry; -import dev.triumphteam.cmd.core.requirement.RequirementRegistry; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmds.cli.sender.CliSender; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public final class CliCommand implements Command { - - private final String name; - - private final Map, Registry> registries; - private final MessageRegistry messageRegistry; - - private final SenderMapper senderMapper; - private final SenderValidator senderValidator; - - private final ExecutionProvider syncExecutionProvider; - private final ExecutionProvider asyncExecutionProvider; - - private final Map> subCommands = new HashMap<>(); - private final Map> subCommandAliases = new HashMap<>(); - - @SuppressWarnings("unchecked") - public CliCommand( - @NotNull final CliCommandProcessor processor, - @NotNull final ExecutionProvider syncExecutionProvider, - @NotNull final ExecutionProvider asyncExecutionProvider - ) { - this.name = processor.getName(); - - this.senderMapper = processor.getSenderMapper(); - this.senderValidator = processor.getSenderValidator(); - this.registries = processor.getRegistries(); - this.messageRegistry = (MessageRegistry) registries.get(MessageRegistry.class); - this.syncExecutionProvider = syncExecutionProvider; - this.asyncExecutionProvider = asyncExecutionProvider; - } - - /** - * adds SubCommands from the Command. - * - * @param baseCommand The {@link BaseCommand} to get the sub commands from. - */ - @Override - public void addSubCommands(@NotNull final BaseCommand baseCommand) { - for (final Method method : baseCommand.getClass().getDeclaredMethods()) { - if (Modifier.isPrivate(method.getModifiers())) continue; - - final CliSubCommandProcessor processor = new CliSubCommandProcessor<>( - baseCommand, - name, - method, - registries, - senderValidator - ); - - final String subCommandName = processor.getName(); - if (subCommandName == null) continue; - - final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider; - final CliSubCommand subCommand = subCommands.computeIfAbsent(subCommandName, it -> new CliSubCommand<>(processor, name, executionProvider)); - processor.getAlias().forEach(alias -> subCommandAliases.putIfAbsent(alias, subCommand)); - } - } - - // TODO: Comments - public void execute( - @NotNull final CliSender sender, - @NotNull final String[] args - ) { - CliSubCommand subCommand = getDefaultSubCommand(); - - String subCommandName = ""; - if (args.length > 0) subCommandName = args[0].toLowerCase(); - if (subCommand == null || subCommandExists(subCommandName)) { - subCommand = getSubCommand(subCommandName); - } - - final S mappedSender = senderMapper.map(sender); - - if (subCommand == null) { - messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, mappedSender, new DefaultMessageContext(name, subCommandName)); - return; - } - - final List commandArgs = Arrays.asList(!subCommand.isDefault() ? Arrays.copyOfRange(args, 1, args.length) : args); - subCommand.execute(mappedSender, commandArgs); - } - - /** - * Gets a default command if present. - * - * @return A default SubCommand. - */ - @Nullable - private CliSubCommand getDefaultSubCommand() { - return subCommands.get(Default.DEFAULT_CMD_NAME); - } - - /** - * Used in order to search for the given {@link SubCommand} in the {@link #subCommandAliases} - * - * @param key the String to look for the {@link SubCommand} - * @return the {@link SubCommand} for the particular key or NULL - */ - @Nullable - private CliSubCommand getSubCommand(@NotNull final String key) { - final CliSubCommand subCommand = subCommands.get(key); - if (subCommand != null) return subCommand; - return subCommandAliases.get(key); - } - - /** - * Checks if a SubCommand with the specified key exists. - * - * @param key the Key to check for - * @return whether a SubCommand with that key exists - */ - private boolean subCommandExists(@NotNull final String key) { - return subCommands.containsKey(key) || subCommandAliases.containsKey(key); - } -} diff --git a/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandManager.java b/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandManager.java deleted file mode 100644 index 921d55c1..00000000 --- a/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandManager.java +++ /dev/null @@ -1,138 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmds.cli; - -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.CommandManager; -import dev.triumphteam.cmd.core.execution.AsyncExecutionProvider; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.execution.SyncExecutionProvider; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmds.cli.sender.CliSender; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; -import java.util.Scanner; - -public final class CliCommandManager extends CommandManager { - - private final Map> commands = new HashMap<>(); - - private final ExecutionProvider syncExecutionProvider = new SyncExecutionProvider(); - private final ExecutionProvider asyncExecutionProvider = new AsyncExecutionProvider(); - - private CliCommandManager( - @NotNull final SenderMapper senderMapper, - @NotNull final SenderValidator senderValidator - ) { - super(senderMapper, senderValidator); - } - - - @NotNull - @Contract(" -> new") - public static CliCommandManager create() { - final CliCommandManager commandManager = new CliCommandManager<>( - SenderMapper.defaultMapper(), - new CliSenderValidator() - ); - setUpDefaults(commandManager); - return commandManager; - } - - @NotNull - @Contract("_, _ -> new") - public static CliCommandManager create( - @NotNull final SenderMapper senderMapper, - @NotNull final SenderValidator senderValidator - ) { - return new CliCommandManager<>(senderMapper, senderValidator); - } - - @Override - public void registerCommand(@NotNull final BaseCommand baseCommand) { - final CliCommandProcessor processor = new CliCommandProcessor<>( - baseCommand, - getRegistries(), - getSenderMapper(), - getSenderValidator() - ); - - final String name = processor.getName(); - - final CliCommand command = commands.computeIfAbsent( - name, - ignored -> new CliCommand<>(processor, syncExecutionProvider, asyncExecutionProvider) - ); - - command.addSubCommands(baseCommand); - } - - @Override - public void unregisterCommand(@NotNull final BaseCommand command) { - // TODO add a remove functionality - } - - public void startManager() { - final Scanner scanner = new Scanner(System.in); - while (true) { - final String line = scanner.nextLine(); - if (line.isEmpty()) continue; - final String[] args = line.split(" "); - if (args.length == 0) continue; - final String commandName = args[0]; - - final CliCommand command = commands.get(commandName); - if (command == null) { - // TODO: Change this to a logger - System.out.println("Command not found"); - continue; - } - - command.execute(new CliCommandSender(), Arrays.copyOfRange(args, 1, args.length)); - } - } - - private static void setUpDefaults(@NotNull final CliCommandManager manager) { - /*manager.registerMessage(MessageKey.UNKNOWN_COMMAND, (sender, context) -> sender.sendMessage("Unknown command: `" + context.getCommand() + "`.")); - manager.registerMessage(MessageKey.TOO_MANY_ARGUMENTS, (sender, context) -> sender.sendMessage("Invalid usage.")); - manager.registerMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, (sender, context) -> sender.sendMessage("Invalid usage.")); - manager.registerMessage(MessageKey.INVALID_ARGUMENT, (sender, context) -> sender.sendMessage("Invalid argument `" + context.getTypedArgument() + "` for type `" + context.getArgumentType().getSimpleName() + "`.")); - manager.registerMessage(MessageKey.MISSING_REQUIRED_FLAG, (sender, context) -> sender.sendMessage("Command is missing required flags.")); - manager.registerMessage(MessageKey.MISSING_REQUIRED_FLAG_ARGUMENT, (sender, context) -> sender.sendMessage("Command is missing required flags argument.")); - manager.registerMessage(MessageKey.INVALID_FLAG_ARGUMENT, (sender, context) -> sender.sendMessage("Invalid flag argument `" + context.getTypedArgument() + "` for type `" + context.getArgumentType().getSimpleName() + "`.")); - - manager.registerMessage(BukkitMessageKey.NO_PERMISSION, (sender, context) -> sender.sendMessage("You do not have permission to perform this command. Permission needed: `" + context.getPermission() + "`.")); - manager.registerMessage(BukkitMessageKey.PLAYER_ONLY, (sender, context) -> sender.sendMessage("This command can only be used by players.")); - manager.registerMessage(BukkitMessageKey.CONSOLE_ONLY, (sender, context) -> sender.sendMessage("This command can only be used by the console.")); - - manager.registerArgument(Material.class, (sender, arg) -> Material.matchMaterial(arg)); - manager.registerArgument(Player.class, (sender, arg) -> Bukkit.getPlayer(arg)); - manager.registerArgument(World.class, (sender, arg) -> Bukkit.getWorld(arg));*/ - } -} diff --git a/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandProcessor.java b/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandProcessor.java deleted file mode 100644 index cfd5ec98..00000000 --- a/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandProcessor.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmds.cli; - -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.processor.AbstractCommandProcessor; -import dev.triumphteam.cmd.core.registry.Registry; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmds.cli.sender.CliSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; - -public final class CliCommandProcessor extends AbstractCommandProcessor { - - public CliCommandProcessor( - @NotNull final BaseCommand baseCommand, - @NotNull final Map, Registry> registries, - @NotNull final SenderMapper senderMapper, - @NotNull final SenderValidator senderValidator - ) { - super(baseCommand, registries, senderMapper, senderValidator); - } -} diff --git a/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandSender.java b/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandSender.java deleted file mode 100644 index c291c11d..00000000 --- a/cli/src/main/java/dev/triumphteam/cmds/cli/CliCommandSender.java +++ /dev/null @@ -1,9 +0,0 @@ -package dev.triumphteam.cmds.cli; - -import dev.triumphteam.cmds.cli.sender.CliSender; - -final class CliCommandSender implements CliSender { - - - -} diff --git a/cli/src/main/java/dev/triumphteam/cmds/cli/CliSenderValidator.java b/cli/src/main/java/dev/triumphteam/cmds/cli/CliSenderValidator.java deleted file mode 100644 index 6e84b4a8..00000000 --- a/cli/src/main/java/dev/triumphteam/cmds/cli/CliSenderValidator.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.triumphteam.cmds.cli; - -import com.google.common.collect.ImmutableSet; -import dev.triumphteam.cmd.core.SubCommand; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmds.cli.sender.CliSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Set; - -final class CliSenderValidator implements SenderValidator { - - /** - * {@inheritDoc} - */ - @NotNull - @Override - public Set> getAllowedSenders() { - return ImmutableSet.of(CliSender.class); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean validate( - @NotNull final MessageRegistry messageRegistry, - @NotNull final SubCommand subCommand, - @NotNull final CliSender sender - ) { - return true; - } -} diff --git a/cli/src/main/java/dev/triumphteam/cmds/cli/CliSubCommand.java b/cli/src/main/java/dev/triumphteam/cmds/cli/CliSubCommand.java deleted file mode 100644 index acf67f57..00000000 --- a/cli/src/main/java/dev/triumphteam/cmds/cli/CliSubCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmds.cli; - -import dev.triumphteam.cmd.core.AbstractSubCommand; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import org.jetbrains.annotations.NotNull; - -public final class CliSubCommand extends AbstractSubCommand { - - public CliSubCommand( - @NotNull final CliSubCommandProcessor processor, - @NotNull final String parentName, - @NotNull final ExecutionProvider executionProvider - ) { - super(processor, parentName, executionProvider); - } -} diff --git a/cli/src/main/java/dev/triumphteam/cmds/cli/CliSubCommandProcessor.java b/cli/src/main/java/dev/triumphteam/cmds/cli/CliSubCommandProcessor.java deleted file mode 100644 index d6648f1f..00000000 --- a/cli/src/main/java/dev/triumphteam/cmds/cli/CliSubCommandProcessor.java +++ /dev/null @@ -1,46 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmds.cli; - -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; -import dev.triumphteam.cmd.core.registry.Registry; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Method; -import java.util.Map; - -final class CliSubCommandProcessor extends AbstractSubCommandProcessor { - - public CliSubCommandProcessor( - @NotNull final BaseCommand baseCommand, - @NotNull final String parentName, - @NotNull final Method method, - @NotNull final Map, Registry> registries, - @NotNull final SenderValidator senderValidator - ) { - super(baseCommand, parentName, method, registries, senderValidator); - } -} diff --git a/cli/src/main/java/dev/triumphteam/cmds/cli/sender/CliSender.java b/cli/src/main/java/dev/triumphteam/cmds/cli/sender/CliSender.java deleted file mode 100644 index 1272daaf..00000000 --- a/cli/src/main/java/dev/triumphteam/cmds/cli/sender/CliSender.java +++ /dev/null @@ -1,7 +0,0 @@ -package dev.triumphteam.cmds.cli.sender; - -public interface CliSender { - - - -} diff --git a/settings.gradle.kts b/settings.gradle.kts index ff163ce7..5dff0bc3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -8,7 +8,6 @@ rootProject.name = "triumph-cmd" listOf( "core", "kotlin-extras", - // "cli" ).forEach(::includeProject) listOf( @@ -39,4 +38,4 @@ fun includeProject(name: String, folder: String) { fun include(name: String, block: ProjectDescriptor.() -> Unit) { include(name) project(":$name").apply(block) -} \ No newline at end of file +} From 47cec37d5dcd44d71c0b895caecfa41e668a0cc0 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 7 Aug 2022 16:42:21 -0500 Subject: [PATCH 002/101] Removed SubCommand interface and made abstract the main one --- core/build.gradle.kts | 2 +- .../cmd/core/AbstractSubCommand.java | 358 ------------------ .../dev/triumphteam/cmd/core/SubCommand.java | 309 ++++++++++++++- .../processor/AbstractCommandProcessor.java | 44 ++- .../cmd/prefixed/PrefixedCommand.java | 1 - .../cmd/prefixed/PrefixedSenderValidator.java | 1 - .../cmd/prefixed/PrefixedSubCommand.java | 4 +- .../cmd/slash/SlashCommandProcessor.java | 3 +- .../cmd/slash/SlashSubCommand.java | 4 +- .../triumphteam/cmd/bukkit/BukkitCommand.java | 1 - .../cmd/bukkit/BukkitSubCommand.java | 4 +- 11 files changed, 346 insertions(+), 385 deletions(-) delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/AbstractSubCommand.java diff --git a/core/build.gradle.kts b/core/build.gradle.kts index ff006b2e..f33c151d 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -16,4 +16,4 @@ tasks { test { useJUnitPlatform() } -} \ No newline at end of file +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/AbstractSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/AbstractSubCommand.java deleted file mode 100644 index 82f88ba2..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/AbstractSubCommand.java +++ /dev/null @@ -1,358 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core; - -import dev.triumphteam.cmd.core.annotation.Default; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; -import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; -import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; -import dev.triumphteam.cmd.core.requirement.Requirement; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * SubCommand implementation. - * Might be better to rename this to something different. - * - * @param The sender type. - */ -public abstract class AbstractSubCommand implements SubCommand { - - private final BaseCommand baseCommand; - private final Method method; - - private final String parentName; - private final String name; - private final List alias; - private final boolean isDefault; - - private final Class senderType; - - private final List> internalArguments; - private final Set> requirements; - - private final MessageRegistry messageRegistry; - private final ExecutionProvider executionProvider; - - private final SenderValidator senderValidator; - - private final boolean hasArguments; - private final boolean containsLimitless; - - public AbstractSubCommand( - @NotNull final AbstractSubCommandProcessor processor, - @NotNull final String parentName, - @NotNull final ExecutionProvider executionProvider - ) { - this.baseCommand = processor.getBaseCommand(); - this.method = processor.getMethod(); - this.name = processor.getName(); - this.alias = processor.getAlias(); - this.internalArguments = processor.getArguments(); - this.requirements = processor.getRequirements(); - this.messageRegistry = processor.getMessageRegistry(); - this.isDefault = processor.isDefault(); - this.senderValidator = processor.getSenderValidator(); - - this.senderType = processor.getSenderType(); - - this.parentName = parentName; - - this.executionProvider = executionProvider; - - this.hasArguments = !internalArguments.isEmpty(); - this.containsLimitless = internalArguments.stream().anyMatch(LimitlessInternalArgument.class::isInstance); - } - - /** - * Checks if the sub command is default. - * Can also just check if the name is {@link Default#DEFAULT_CMD_NAME}. - * - * @return Whether the sub command is default. - */ - @Override - public boolean isDefault() { - return isDefault; - } - - // TODO: 2/5/2022 comments - @NotNull - @Override - public Class getSenderType() { - return senderType; - } - - /** - * Gets the name of the parent command. - * - * @return The name of the parent command. - */ - @NotNull - @Override - public String getParentName() { - return parentName; - } - - /** - * Gets the name of the sub command. - * - * @return The name of the sub command. - */ - @NotNull - @Override - public String getName() { - return name; - } - - @Override - public boolean hasArguments() { - return hasArguments; - } - - /** - * Gets the message registry. - * - * @return The message registry. - */ - @NotNull - protected MessageRegistry getMessageRegistry() { - return messageRegistry; - } - - /** - * Executes the sub command. - * - * @param sender The sender. - * @param args The arguments to pass to the executor. - */ - @Override - public void execute(@NotNull final S sender, @NotNull final List args) { - if (!senderValidator.validate(messageRegistry, this, sender)) return; - if (!meetRequirements(sender)) return; - - // Creates the invoking arguments list - final List invokeArguments = new ArrayList<>(); - invokeArguments.add(sender); - - if (!validateAndCollectArguments(sender, invokeArguments, args)) { - return; - } - - if ((!containsLimitless) && args.size() >= invokeArguments.size()) { - messageRegistry.sendMessage(MessageKey.TOO_MANY_ARGUMENTS, sender, new DefaultMessageContext(parentName, name)); - return; - } - - executionProvider.execute(() -> { - try { - method.invoke(baseCommand, invokeArguments.toArray()); - } catch (IllegalAccessException | InvocationTargetException exception) { - throw new CommandExecutionException("An error occurred while executing the command", parentName, name) - .initCause(exception instanceof InvocationTargetException ? exception.getCause() : exception); - } - }); - } - - /** - * Gets the arguments of the sub command. - * - * @return The arguments of the sub command. - */ - @NotNull - protected List> getArguments() { - return internalArguments; - } - - @Nullable - protected InternalArgument getArgument(@NotNull final String name) { - final List> foundArgs = internalArguments.stream() - .filter(internalArgument -> internalArgument.getName().toLowerCase().startsWith(name)) - .collect(Collectors.toList()); - - if (foundArgs.size() != 1) return null; - return foundArgs.get(0); - } - - @Nullable - protected InternalArgument getArgument(final int index) { - final int size = internalArguments.size(); - if (size == 0) return null; - if (index >= size) { - final InternalArgument last = internalArguments.get(size - 1); - if (last instanceof LimitlessInternalArgument) return last; - return null; - } - - return internalArguments.get(index); - } - - // TODO: 2/1/2022 Comments - public List<@Nullable String> mapArguments(@NotNull final Map args) { - final List arguments = getArguments().stream().map(InternalArgument::getName).collect(Collectors.toList()); - return arguments.stream().map(it -> { - final String value = args.get(it); - return value == null ? "" : value; - }).collect(Collectors.toList()); - } - - /** - * Used for checking if the arguments are valid and adding them to the `invokeArguments`. - * - * @param sender The sender of the command. - * @param invokeArguments A list with the arguments that'll be used on the `invoke` of the command method. - * @param commandArgs The command arguments type. - * @return False if any internalArgument fails to pass. - */ - @SuppressWarnings("unchecked") - private boolean validateAndCollectArguments( - @NotNull final S sender, - @NotNull final List invokeArguments, - @NotNull final List commandArgs - ) { - for (int i = 0; i < internalArguments.size(); i++) { - final InternalArgument internalArgument = internalArguments.get(i); - - if (internalArgument instanceof LimitlessInternalArgument) { - final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument; - final List leftOvers = leftOvers(commandArgs, i); - - final Object result = limitlessArgument.resolve(sender, leftOvers); - - if (result == null) { - return false; - } - - invokeArguments.add(result); - return true; - } - - if (!(internalArgument instanceof StringInternalArgument)) { - throw new CommandExecutionException("Found unsupported internalArgument", parentName, name); - } - - final StringInternalArgument stringArgument = (StringInternalArgument) internalArgument; - final String arg = valueOrNull(commandArgs, i); - - if (arg == null || arg.isEmpty()) { - if (internalArgument.isOptional()) { - invokeArguments.add(null); - continue; - } - - messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new DefaultMessageContext(parentName, name)); - return false; - } - - final Object result = stringArgument.resolve(sender, arg); - if (result == null) { - messageRegistry.sendMessage( - MessageKey.INVALID_ARGUMENT, - sender, - new InvalidArgumentContext(parentName, name, arg, internalArgument.getName(), internalArgument.getType()) - ); - return false; - } - - invokeArguments.add(result); - } - - return true; - } - - /** - * Checks if the requirements to run the command are met. - * - * @param sender The sender of the command. - * @return Whether all requirements are met. - */ - private boolean meetRequirements(@NotNull final S sender) { - for (final Requirement requirement : requirements) { - if (!requirement.isMet(sender)) { - requirement.sendMessage(messageRegistry, sender, parentName, name); - return false; - } - } - - return true; - } - - /** - * Gets an internalArgument value or null. - * - * @param list The list to check from. - * @param index The current index of the internalArgument. - * @return The internalArgument name or null. - */ - @Nullable - private String valueOrNull(@NotNull final List list, final int index) { - if (index >= list.size()) return null; - return list.get(index); - } - - /** - * Gets the left over of the arguments. - * - * @param list The list with all the arguments. - * @param from The index from which should start removing. - * @return A list with the leftover arguments. - */ - @NotNull - private List leftOvers(@NotNull final List list, final int from) { - if (from > list.size()) return Collections.emptyList(); - return list.subList(from, list.size()); - } - - @NotNull - @Override - public String toString() { - return "SimpleSubCommand{" + - "baseCommand=" + baseCommand + - ", method=" + method + - ", name='" + name + '\'' + - ", alias=" + alias + - ", isDefault=" + isDefault + - ", arguments=" + internalArguments + - ", requirements=" + requirements + - ", messageRegistry=" + messageRegistry + - ", containsLimitlessArgument=" + containsLimitless + - '}'; - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java index dab51ae2..54cb4773 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java @@ -24,27 +24,83 @@ package dev.triumphteam.cmd.core; import dev.triumphteam.cmd.core.annotation.Default; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; +import dev.triumphteam.cmd.core.execution.ExecutionProvider; +import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; +import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; +import dev.triumphteam.cmd.core.requirement.Requirement; +import dev.triumphteam.cmd.core.sender.SenderValidator; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; /** - * Sub command holds its data and its execution. + * SubCommand implementation. + * Might be better to rename this to something different. * * @param The sender type. */ -public interface SubCommand { +public abstract class SubCommand { - @NotNull - String getName(); + private final BaseCommand baseCommand; + private final Method method; - @NotNull - String getParentName(); + private final String parentName; + private final String name; + private final List alias; + private final boolean isDefault; - @NotNull - Class getSenderType(); + private final Class senderType; + + private final List> internalArguments; + private final Set> requirements; + + private final MessageRegistry messageRegistry; + private final ExecutionProvider executionProvider; + + private final SenderValidator senderValidator; + + private final boolean hasArguments; + private final boolean containsLimitless; + + public SubCommand( + @NotNull final AbstractSubCommandProcessor processor, + @NotNull final String parentName, + @NotNull final ExecutionProvider executionProvider + ) { + this.baseCommand = processor.getBaseCommand(); + this.method = processor.getMethod(); + this.name = processor.getName(); + this.alias = processor.getAlias(); + this.internalArguments = processor.getArguments(); + this.requirements = processor.getRequirements(); + this.messageRegistry = processor.getMessageRegistry(); + this.isDefault = processor.isDefault(); + this.senderValidator = processor.getSenderValidator(); + + this.senderType = processor.getSenderType(); + + this.parentName = parentName; - boolean hasArguments(); + this.executionProvider = executionProvider; + + this.hasArguments = !internalArguments.isEmpty(); + this.containsLimitless = internalArguments.stream().anyMatch(LimitlessInternalArgument.class::isInstance); + } /** * Checks if the sub command is default. @@ -52,7 +108,49 @@ public interface SubCommand { * * @return Whether the sub command is default. */ - boolean isDefault(); + public boolean isDefault() { + return isDefault; + } + + // TODO: 2/5/2022 comments + @NotNull + public Class getSenderType() { + return senderType; + } + + /** + * Gets the name of the parent command. + * + * @return The name of the parent command. + */ + @NotNull + public String getParentName() { + return parentName; + } + + /** + * Gets the name of the sub command. + * + * @return The name of the sub command. + */ + @NotNull + public String getName() { + return name; + } + + public boolean hasArguments() { + return hasArguments; + } + + /** + * Gets the message registry. + * + * @return The message registry. + */ + @NotNull + protected MessageRegistry getMessageRegistry() { + return messageRegistry; + } /** * Executes the sub command. @@ -60,6 +158,195 @@ public interface SubCommand { * @param sender The sender. * @param args The arguments to pass to the executor. */ - void execute(@NotNull S sender, @NotNull final List args); + public void execute(@NotNull final S sender, @NotNull final List args) { + if (!senderValidator.validate(messageRegistry, this, sender)) return; + if (!meetRequirements(sender)) return; + + // Creates the invoking arguments list + final List invokeArguments = new ArrayList<>(); + invokeArguments.add(sender); + + if (!validateAndCollectArguments(sender, invokeArguments, args)) { + return; + } + + if ((!containsLimitless) && args.size() >= invokeArguments.size()) { + messageRegistry.sendMessage(MessageKey.TOO_MANY_ARGUMENTS, sender, new DefaultMessageContext(parentName, name)); + return; + } + + executionProvider.execute(() -> { + try { + method.invoke(baseCommand, invokeArguments.toArray()); + } catch (IllegalAccessException | InvocationTargetException exception) { + throw new CommandExecutionException("An error occurred while executing the command", parentName, name) + .initCause(exception instanceof InvocationTargetException ? exception.getCause() : exception); + } + }); + } + /** + * Gets the arguments of the sub command. + * + * @return The arguments of the sub command. + */ + @NotNull + protected List> getArguments() { + return internalArguments; + } + + @Nullable + protected InternalArgument getArgument(@NotNull final String name) { + final List> foundArgs = internalArguments.stream() + .filter(internalArgument -> internalArgument.getName().toLowerCase().startsWith(name)) + .collect(Collectors.toList()); + + if (foundArgs.size() != 1) return null; + return foundArgs.get(0); + } + + @Nullable + protected InternalArgument getArgument(final int index) { + final int size = internalArguments.size(); + if (size == 0) return null; + if (index >= size) { + final InternalArgument last = internalArguments.get(size - 1); + if (last instanceof LimitlessInternalArgument) return last; + return null; + } + + return internalArguments.get(index); + } + + // TODO: 2/1/2022 Comments + public List<@Nullable String> mapArguments(@NotNull final Map args) { + final List arguments = getArguments().stream().map(InternalArgument::getName).collect(Collectors.toList()); + return arguments.stream().map(it -> { + final String value = args.get(it); + return value == null ? "" : value; + }).collect(Collectors.toList()); + } + + /** + * Used for checking if the arguments are valid and adding them to the `invokeArguments`. + * + * @param sender The sender of the command. + * @param invokeArguments A list with the arguments that'll be used on the `invoke` of the command method. + * @param commandArgs The command arguments type. + * @return False if any internalArgument fails to pass. + */ + @SuppressWarnings("unchecked") + private boolean validateAndCollectArguments( + @NotNull final S sender, + @NotNull final List invokeArguments, + @NotNull final List commandArgs + ) { + for (int i = 0; i < internalArguments.size(); i++) { + final InternalArgument internalArgument = internalArguments.get(i); + + if (internalArgument instanceof LimitlessInternalArgument) { + final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument; + final List leftOvers = leftOvers(commandArgs, i); + + final Object result = limitlessArgument.resolve(sender, leftOvers); + + if (result == null) { + return false; + } + + invokeArguments.add(result); + return true; + } + + if (!(internalArgument instanceof StringInternalArgument)) { + throw new CommandExecutionException("Found unsupported internalArgument", parentName, name); + } + + final StringInternalArgument stringArgument = (StringInternalArgument) internalArgument; + final String arg = valueOrNull(commandArgs, i); + + if (arg == null || arg.isEmpty()) { + if (internalArgument.isOptional()) { + invokeArguments.add(null); + continue; + } + + messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new DefaultMessageContext(parentName, name)); + return false; + } + + final Object result = stringArgument.resolve(sender, arg); + if (result == null) { + messageRegistry.sendMessage( + MessageKey.INVALID_ARGUMENT, + sender, + new InvalidArgumentContext(parentName, name, arg, internalArgument.getName(), internalArgument.getType()) + ); + return false; + } + + invokeArguments.add(result); + } + + return true; + } + + /** + * Checks if the requirements to run the command are met. + * + * @param sender The sender of the command. + * @return Whether all requirements are met. + */ + private boolean meetRequirements(@NotNull final S sender) { + for (final Requirement requirement : requirements) { + if (!requirement.isMet(sender)) { + requirement.sendMessage(messageRegistry, sender, parentName, name); + return false; + } + } + + return true; + } + + /** + * Gets an internalArgument value or null. + * + * @param list The list to check from. + * @param index The current index of the internalArgument. + * @return The internalArgument name or null. + */ + @Nullable + private String valueOrNull(@NotNull final List list, final int index) { + if (index >= list.size()) return null; + return list.get(index); + } + + /** + * Gets the left over of the arguments. + * + * @param list The list with all the arguments. + * @param from The index from which should start removing. + * @return A list with the leftover arguments. + */ + @NotNull + private List leftOvers(@NotNull final List list, final int from) { + if (from > list.size()) return Collections.emptyList(); + return list.subList(from, list.size()); + } + + @NotNull + @Override + public String toString() { + return "SimpleSubCommand{" + + "baseCommand=" + baseCommand + + ", method=" + method + + ", name='" + name + '\'' + + ", alias=" + alias + + ", isDefault=" + isDefault + + ", arguments=" + internalArguments + + ", requirements=" + requirements + + ", messageRegistry=" + messageRegistry + + ", containsLimitlessArgument=" + containsLimitless + + '}'; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index d451db53..c6e4cc32 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -28,15 +28,19 @@ import dev.triumphteam.cmd.core.annotation.Command; import dev.triumphteam.cmd.core.annotation.Description; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; +import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -91,6 +95,7 @@ protected AbstractCommandProcessor( // TODO: Comments public void addSubCommands(@NotNull final dev.triumphteam.cmd.core.Command command) { + final Class baseCommandClass = baseCommand.getClass(); for (final Method method : baseCommand.getClass().getDeclaredMethods()) { if (Modifier.isPrivate(method.getModifiers())) continue; @@ -105,6 +110,37 @@ public void addSubCommands(@NotNull final dev.triumphteam.cmd.core.Command command.addSubCommandAlias(alias, subCommand)); } + + for (final Class klass : baseCommandClass.getDeclaredClasses()) { + try { + final List> constructors = Arrays.asList(klass.getDeclaredConstructors()); + + if (constructors.size() != 1) { + throw new SubCommandRegistrationException("TODO constructs", null, null); + } + + final Constructor constructor = constructors.get(0); + + final Object instance; + if (!Modifier.isStatic(klass.getModifiers())) { + if (constructor.getParameters().length != 1) { + throw new SubCommandRegistrationException("TODO params", null, null); + } + + instance = constructor.newInstance(baseCommand); + } else { + if (constructor.getParameters().length != 0) { + throw new SubCommandRegistrationException("TODO params", null, null); + } + + instance = constructor.newInstance(); + } + + System.out.println(instance); + } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } } @NotNull diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java index 8b79250b..a39828fc 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java @@ -24,7 +24,6 @@ package dev.triumphteam.cmd.prefixed; import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.SubCommand; import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.registry.RegistryContainer; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java index c38fb4b3..e00d199e 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java @@ -24,7 +24,6 @@ package dev.triumphteam.cmd.prefixed; import com.google.common.collect.ImmutableSet; -import dev.triumphteam.cmd.core.SubCommand; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.sender.SenderValidator; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java index 97505482..a4c16bbe 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java @@ -23,12 +23,12 @@ */ package dev.triumphteam.cmd.prefixed; -import dev.triumphteam.cmd.core.AbstractSubCommand; +import dev.triumphteam.cmd.core.SubCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; import org.jetbrains.annotations.NotNull; -final class PrefixedSubCommand extends AbstractSubCommand { +final class PrefixedSubCommand extends SubCommand { public PrefixedSubCommand( @NotNull final AbstractSubCommandProcessor processor, diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java index 829e59dc..391405a1 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java @@ -34,7 +34,6 @@ import dev.triumphteam.cmd.slash.sender.SlashSender; import net.dv8tion.jda.api.Permission; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.lang.reflect.Method; import java.util.ArrayList; @@ -114,7 +113,7 @@ protected SlashSubCommandProcessor createProcessor(@NotNull final Method meth ); } - @Nullable + @NotNull @Override protected SlashSubCommand createSubCommand( @NotNull final SlashSubCommandProcessor processor, diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java index da3d5f3d..8fddfa42 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.slash; -import dev.triumphteam.cmd.core.AbstractSubCommand; +import dev.triumphteam.cmd.core.SubCommand; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.slash.choices.Choice; @@ -38,7 +38,7 @@ import java.util.List; import java.util.stream.Collectors; -final class SlashSubCommand extends AbstractSubCommand { +final class SlashSubCommand extends SubCommand { private final String description; private final List choices; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index 148c4cde..27e9b4a2 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -26,7 +26,6 @@ import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; import dev.triumphteam.cmd.bukkit.message.NoPermissionMessageContext; import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.SubCommand; import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.MessageRegistry; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java index b5443741..884d77ea 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.bukkit; -import dev.triumphteam.cmd.core.AbstractSubCommand; +import dev.triumphteam.cmd.core.SubCommand; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.execution.ExecutionProvider; @@ -35,7 +35,7 @@ import static java.util.Collections.emptyList; -public final class BukkitSubCommand extends AbstractSubCommand { +public final class BukkitSubCommand extends SubCommand { private final CommandPermission permission; From aca96788c645028e3c651ac1c1a23ce656cc648e Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 24 Aug 2022 17:55:09 -0500 Subject: [PATCH 003/101] Uh yeah --- core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java | 4 +++- .../cmd/core/processor/AbstractSubCommandProcessor.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java index 54cb4773..2034b87d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java @@ -36,6 +36,7 @@ import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; import dev.triumphteam.cmd.core.requirement.Requirement; import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -54,7 +55,7 @@ * * @param The sender type. */ -public abstract class SubCommand { +public abstract class SubCommand extends LimitlessInternalArgument { private final BaseCommand baseCommand; private final Method method; @@ -82,6 +83,7 @@ public SubCommand( @NotNull final String parentName, @NotNull final ExecutionProvider executionProvider ) { + super(processor.getName(), processor.getDescription(), String.class, new EmptySuggestion<>(), 0, false); this.baseCommand = processor.getBaseCommand(); this.method = processor.getMethod(); this.name = processor.getName(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java index 3edfbcaa..95c11e8a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java @@ -201,7 +201,7 @@ protected void extractArguments(@NotNull final Method method) { * * @return The sub command name. */ - @Nullable + @NotNull public String getName() { return name; } From fc3d892372d5070028f831b0b255f09810831381 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 25 Aug 2022 17:28:13 -0500 Subject: [PATCH 004/101] Uh --- .../dev/triumphteam/cmd/core/Command.java | 1 + .../processor/AbstractCommandProcessor.java | 10 +++--- .../cmd/core/sender/SenderValidator.java | 2 +- .../cmd/core/{ => subcommand}/SubCommand.java | 3 +- .../core/subcommand/invoker/ClassInvoker.java | 35 +++++++++++++++++++ .../cmd/core/subcommand/invoker/Invoker.java | 15 ++++++++ .../subcommand/invoker/MethodInvoker.java | 24 +++++++++++++ .../cmd/prefixed/PrefixedSubCommand.java | 2 +- .../triumphteam/cmd/slash/SlashCommand.java | 2 +- .../cmd/slash/SlashSenderValidator.java | 2 +- .../cmd/slash/SlashSubCommand.java | 2 +- .../cmd/bukkit/BukkitSenderValidator.java | 2 +- .../cmd/bukkit/BukkitSubCommand.java | 2 +- 13 files changed, 88 insertions(+), 14 deletions(-) rename core/src/main/java/dev/triumphteam/cmd/core/{ => subcommand}/SubCommand.java (99%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/Command.java index 2b3d1373..74d71dc9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/Command.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import org.jetbrains.annotations.NotNull; /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index c6e4cc32..643d6ca2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.SubCommand; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.annotation.Command; import dev.triumphteam.cmd.core.annotation.Description; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; @@ -33,6 +33,7 @@ import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.subcommand.invoker.Invoker; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Constructor; @@ -121,22 +122,19 @@ public void addSubCommands(@NotNull final dev.triumphteam.cmd.core.Command constructor = constructors.get(0); - final Object instance; + final boolean isStatic = Modifier.isStatic(klass.getModifiers()); if (!Modifier.isStatic(klass.getModifiers())) { if (constructor.getParameters().length != 1) { throw new SubCommandRegistrationException("TODO params", null, null); } - instance = constructor.newInstance(baseCommand); } else { if (constructor.getParameters().length != 0) { throw new SubCommandRegistrationException("TODO params", null, null); } - - instance = constructor.newInstance(); } - System.out.println(instance); + System.out.println(invoker); } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java index dd63dea9..af46c09e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.sender; -import dev.triumphteam.cmd.core.SubCommand; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.message.MessageRegistry; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java similarity index 99% rename from core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java rename to core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java index 2034b87d..af8c4734 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java @@ -21,8 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core; +package dev.triumphteam.cmd.core.subcommand; +import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java new file mode 100644 index 00000000..17e63654 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java @@ -0,0 +1,35 @@ +package dev.triumphteam.cmd.core.subcommand.invoker; + +import dev.triumphteam.cmd.core.BaseCommand; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class ClassInvoker implements Invoker { + + private final BaseCommand parent; + private final Constructor constructor; + private final Method method; + private final boolean isStatic; + + public ClassInvoker( + @NotNull final BaseCommand parent, + @NotNull final Constructor constructor, + @NotNull final Method method, + final boolean isStatic + ) { + this.parent = parent; + this.constructor = constructor; + this.method = method; + this.isStatic = isStatic; + } + + @Override + public void invoke(final @Nullable Object arg, final @NotNull Object[] arguments) throws InvocationTargetException, InstantiationException, IllegalAccessException { + final Object instance = isStatic ? constructor.newInstance(arg) : constructor.newInstance(parent, arg); + method.invoke(instance, arguments); + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java new file mode 100644 index 00000000..9754afb6 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java @@ -0,0 +1,15 @@ +package dev.triumphteam.cmd.core.subcommand.invoker; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.InvocationTargetException; + +public interface Invoker { + + void invoke(@Nullable final Object arg, @NotNull final Object[] arguments) throws + InstantiationException, + IllegalAccessException, + IllegalArgumentException, + InvocationTargetException; +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java new file mode 100644 index 00000000..16779250 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java @@ -0,0 +1,24 @@ +package dev.triumphteam.cmd.core.subcommand.invoker; + +import dev.triumphteam.cmd.core.BaseCommand; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +public class MethodInvoker implements Invoker { + + private final BaseCommand baseCommand; + private final Method method; + + public MethodInvoker(@NotNull final BaseCommand baseCommand, @NotNull final Method method) { + this.baseCommand = baseCommand; + this.method = method; + } + + @Override + public void invoke(final @Nullable Object arg, final @NotNull Object[] arguments) throws InvocationTargetException, IllegalAccessException { + method.invoke(baseCommand, arguments); + } +} diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java index a4c16bbe..0c02d9c8 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.prefixed; -import dev.triumphteam.cmd.core.SubCommand; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; import org.jetbrains.annotations.NotNull; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java index 0f5614a5..0a6f832c 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.slash; import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.SubCommand; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.execution.ExecutionProvider; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java index b70178cd..6971644e 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.slash; import com.google.common.collect.ImmutableSet; -import dev.triumphteam.cmd.core.SubCommand; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.sender.SenderValidator; import dev.triumphteam.cmd.slash.sender.SlashSender; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java index 8fddfa42..ef761b7c 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.slash; -import dev.triumphteam.cmd.core.SubCommand; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.slash.choices.Choice; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java index a5440bcf..79e35b1c 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java @@ -25,7 +25,7 @@ import com.google.common.collect.ImmutableSet; import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; -import dev.triumphteam.cmd.core.SubCommand; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import dev.triumphteam.cmd.core.sender.SenderValidator; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java index 884d77ea..32374639 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.bukkit; -import dev.triumphteam.cmd.core.SubCommand; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.execution.ExecutionProvider; From 16d7372dc515c333b304108b5590b468890606eb Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 25 Aug 2022 21:06:28 -0500 Subject: [PATCH 005/101] Uh --- .../SubCommandRegistrationException.java | 6 +- .../cmd/core/flag/internal/FlagValidator.java | 14 ++-- .../processor/AbstractCommandProcessor.java | 73 ++++++++++++------- .../AbstractSubCommandProcessor.java | 67 ++++++++--------- .../cmd/core/subcommand/SubCommand.java | 12 +-- .../core/subcommand/invoker/ClassInvoker.java | 4 +- .../subcommand/invoker/MethodInvoker.java | 11 ++- .../cmd/bukkit/BukkitCommandProcessor.java | 4 +- .../cmd/bukkit/BukkitSubCommand.java | 5 ++ .../cmd/bukkit/BukkitSubCommandProcessor.java | 8 +- 10 files changed, 111 insertions(+), 93 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java index cd7f0ced..921f53a5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java @@ -26,7 +26,7 @@ import dev.triumphteam.cmd.core.BaseCommand; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Method; +import java.lang.reflect.AnnotatedElement; /** * Throws when sub command registration fails. @@ -35,10 +35,10 @@ public final class SubCommandRegistrationException extends RuntimeException { public SubCommandRegistrationException( @NotNull final String message, - @NotNull final Method method, + @NotNull final AnnotatedElement element, @NotNull final Class commandClass ) { - super(message + ". In Method \"" + method.getName() + "\" in Class \"" + commandClass.getName() + "\""); + super(message + ". In Method \"" + element + "\" in Class \"" + commandClass.getName() + "\""); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java index ad77e7fe..9dde1fed 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java @@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Method; +import java.lang.reflect.AnnotatedElement; /** * Modified from commons-cli. @@ -44,11 +44,11 @@ private FlagValidator() { * Checks whether the flag contains illegal characters. * * @param flag The {@link String} flag. - * @param method The method from the registration so that better error message can be thrown. + * @param annotatedElement The method from the registration so that better error message can be thrown. */ public static void validate( @Nullable final String flag, - @NotNull final Method method, + @NotNull final AnnotatedElement annotatedElement, @NotNull final BaseCommand baseCommand ) { if (flag == null) return; @@ -58,7 +58,11 @@ public static void validate( char character = flag.charAt(0); if (!isValidFlag(character)) { - throw new SubCommandRegistrationException("Illegal flag name \"" + character + "\"", method, baseCommand.getClass()); + throw new SubCommandRegistrationException( + "Illegal flag name \"" + character + "\"", + annotatedElement, + baseCommand.getClass() + ); } return; @@ -69,7 +73,7 @@ public static void validate( if (!isValidChar(character)) { throw new SubCommandRegistrationException( "The flag \"" + flag + "\" contains an illegal character \"" + character + "\"", - method, + annotatedElement, baseCommand.getClass() ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 643d6ca2..c400a300 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -24,7 +24,6 @@ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.annotation.Command; import dev.triumphteam.cmd.core.annotation.Description; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; @@ -33,11 +32,11 @@ import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.subcommand.invoker.Invoker; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -97,13 +96,24 @@ protected AbstractCommandProcessor( // TODO: Comments public void addSubCommands(@NotNull final dev.triumphteam.cmd.core.Command command) { final Class baseCommandClass = baseCommand.getClass(); + // Method sub commands for (final Method method : baseCommand.getClass().getDeclaredMethods()) { + // TODO: ALLOW PRIVATE if (Modifier.isPrivate(method.getModifiers())) continue; final P processor = createProcessor(method); final String subCommandName = processor.getName(); + // Not a command if (subCommandName == null) continue; + if (subCommandName.isEmpty()) { + throw new SubCommandRegistrationException( + "@" + dev.triumphteam.cmd.core.annotation.SubCommand.class.getSimpleName() + " name must not be empty", + method, + baseCommand.getClass() + ); + } + final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider; final SC subCommand = createSubCommand(processor, executionProvider); @@ -112,37 +122,44 @@ public void addSubCommands(@NotNull final dev.triumphteam.cmd.core.Command command.addSubCommandAlias(alias, subCommand)); } + // Classes sub commands for (final Class klass : baseCommandClass.getDeclaredClasses()) { - try { - final List> constructors = Arrays.asList(klass.getDeclaredConstructors()); - - if (constructors.size() != 1) { - throw new SubCommandRegistrationException("TODO constructs", null, null); - } - - final Constructor constructor = constructors.get(0); - - final boolean isStatic = Modifier.isStatic(klass.getModifiers()); - if (!Modifier.isStatic(klass.getModifiers())) { - if (constructor.getParameters().length != 1) { - throw new SubCommandRegistrationException("TODO params", null, null); - } - - } else { - if (constructor.getParameters().length != 0) { - throw new SubCommandRegistrationException("TODO params", null, null); - } - } - - System.out.println(invoker); - } catch (InstantiationException | IllegalAccessException | InvocationTargetException e) { - throw new RuntimeException(e); + final List> constructors = Arrays.asList(klass.getDeclaredConstructors()); + + if (constructors.size() != 1) { + throw new SubCommandRegistrationException("TODO constructs", null, null); } + + final Constructor constructor = constructors.get(0); + + final boolean isStatic = Modifier.isStatic(klass.getModifiers()); + final int argsSize = isStatic ? constructor.getParameterCount() : constructor.getParameterCount() - 1; + + if (argsSize > 1) { + throw new SubCommandRegistrationException("TODO params", null, null); + } + + final boolean hasArg = argsSize > 0; + + final P processor = createProcessor(klass); + final String subCommandName = processor.getName(); + // Not a command + if (subCommandName == null) continue; + // If the name is empty and there is no arguments + if (subCommandName.isEmpty() && !hasArg) { + throw new SubCommandRegistrationException( + "@" + dev.triumphteam.cmd.core.annotation.SubCommand.class.getSimpleName() + " name must not be empty on a class unless it has an argument.", + klass, + baseCommand.getClass() + ); + } + + } } @NotNull - protected abstract P createProcessor(@NotNull final Method method); + protected abstract P createProcessor(@NotNull final AnnotatedElement method); @NotNull protected abstract SC createSubCommand(@NotNull final P processor, @NotNull final ExecutionProvider executionProvider); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java index 95c11e8a..9edf38fb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java @@ -82,7 +82,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Method; +import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Parameter; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -115,7 +115,7 @@ public abstract class AbstractSubCommandProcessor { private final BaseCommand baseCommand; private final String parentName; - private final Method method; + private final AnnotatedElement annotatedElement; // Name is nullable to detect if the method should or not be considered a sub command. private String name = null; // TODO: 11/28/2021 Add better default description @@ -146,14 +146,14 @@ public abstract class AbstractSubCommandProcessor { protected AbstractSubCommandProcessor( @NotNull final BaseCommand baseCommand, @NotNull final String parentName, - @NotNull final Method method, + @NotNull final AnnotatedElement annotatedElement, @NotNull final RegistryContainer registryContainer, @NotNull final SenderValidator senderValidator ) { this.baseCommand = baseCommand; this.parentName = parentName; - this.method = method; + this.annotatedElement = annotatedElement; this.registryContainer = registryContainer; this.suggestionRegistry = registryContainer.getSuggestionRegistry(); @@ -163,7 +163,7 @@ protected AbstractSubCommandProcessor( this.messageRegistry = registryContainer.getMessageRegistry(); this.senderValidator = senderValidator; - this.isAsync = method.isAnnotationPresent(Async.class); + this.isAsync = annotatedElement.isAnnotationPresent(Async.class); extractSubCommandNames(); if (name == null) return; @@ -173,17 +173,17 @@ protected AbstractSubCommandProcessor( extractDescription(); extractArgDescriptions(); extractSuggestions(); - extractArguments(method); + extractArguments(annotatedElement); validateArguments(); } /** * Allows for customizing the internalArgument parsing, for example @Value and @Completion annotations. * - * @param method The method to search from. + * @param annotatedElement The method to search from. */ - protected void extractArguments(@NotNull final Method method) { - final Parameter[] parameters = method.getParameters(); + protected void extractArguments(@NotNull final AnnotatedElement annotatedElement) { + /*final Parameter[] parameters = annotatedElement.getParameters(); for (int i = 0; i < parameters.length; i++) { final Parameter parameter = parameters[i]; if (i == 0) { @@ -192,7 +192,7 @@ protected void extractArguments(@NotNull final Method method) { } createArgument(parameter, i - 1); - } + }*/ } /** @@ -201,7 +201,7 @@ protected void extractArguments(@NotNull final Method method) { * * @return The sub command name. */ - @NotNull + @Nullable public String getName() { return name; } @@ -260,14 +260,10 @@ public BaseCommand getBaseCommand() { return baseCommand; } - /** - * Gets the method. - * - * @return The method. - */ + // TODO comments @NotNull - public Method getMethod() { - return method; + public AnnotatedElement getAnnotatedElement() { + return annotatedElement; } /** @@ -310,7 +306,7 @@ public SenderValidator getSenderValidator() { @NotNull @Contract("_ -> new") protected SubCommandRegistrationException createException(@NotNull final String message) { - return new SubCommandRegistrationException(message, method, baseCommand.getClass()); + return new SubCommandRegistrationException(message, annotatedElement, baseCommand.getClass()); } /** @@ -436,7 +432,7 @@ protected void createArgument(@NotNull final Parameter parameter, final int posi // Handler for named arguments if (type == Arguments.class) { - final NamedArguments namedArguments = method.getAnnotation(NamedArguments.class); + final NamedArguments namedArguments = annotatedElement.getAnnotation(NamedArguments.class); if (namedArguments == null) { throw createException("TODO"); } @@ -610,8 +606,8 @@ private void addArgument(@NotNull final InternalArgument internalArgument) * Extracts the data from the method to retrieve the sub command name or the default name. */ private void extractSubCommandNames() { - final Default defaultAnnotation = method.getAnnotation(Default.class); - final dev.triumphteam.cmd.core.annotation.SubCommand subCommandAnnotation = method.getAnnotation(dev.triumphteam.cmd.core.annotation.SubCommand.class); + final Default defaultAnnotation = annotatedElement.getAnnotation(Default.class); + final dev.triumphteam.cmd.core.annotation.SubCommand subCommandAnnotation = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.SubCommand.class); if (defaultAnnotation == null && subCommandAnnotation == null) { return; @@ -626,10 +622,6 @@ private void extractSubCommandNames() { name = subCommandAnnotation.value().toLowerCase(); alias.addAll(Arrays.stream(subCommandAnnotation.alias()).map(String::toLowerCase).collect(Collectors.toList())); - - if (this.name.isEmpty()) { - throw createException("@" + dev.triumphteam.cmd.core.annotation.SubCommand.class.getSimpleName() + " name must not be empty"); - } } /** @@ -642,7 +634,7 @@ private void extractFlags() { for (final Flag flagAnnotation : flags) { String flag = flagAnnotation.flag(); if (flag.isEmpty()) flag = null; - FlagValidator.validate(flag, method, baseCommand); + FlagValidator.validate(flag, annotatedElement, baseCommand); String longFlag = flagAnnotation.longFlag(); if (longFlag.contains(" ")) { @@ -702,10 +694,10 @@ private void extractFlags() { * @return The list of flags. */ private List getFlagsFromAnnotations() { - final CommandFlags flags = method.getAnnotation(CommandFlags.class); + final CommandFlags flags = annotatedElement.getAnnotation(CommandFlags.class); if (flags != null) return Arrays.asList(flags.value()); - final Flag flag = method.getAnnotation(Flag.class); + final Flag flag = annotatedElement.getAnnotation(Flag.class); if (flag == null) return Collections.emptyList(); return Collections.singletonList(flag); } @@ -737,10 +729,10 @@ public void extractRequirements() { * @return The list of requirements. */ private List getRequirementsFromAnnotations() { - final Requirements requirements = method.getAnnotation(Requirements.class); + final Requirements requirements = annotatedElement.getAnnotation(Requirements.class); if (requirements != null) return Arrays.asList(requirements.value()); - final dev.triumphteam.cmd.core.annotation.Requirement requirement = method.getAnnotation(dev.triumphteam.cmd.core.annotation.Requirement.class); + final dev.triumphteam.cmd.core.annotation.Requirement requirement = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.Requirement.class); if (requirement == null) return Collections.emptyList(); return Collections.singletonList(requirement); } @@ -799,7 +791,7 @@ private void validateArguments() { * Extracts the {@link Description} Annotation from the Method. */ private void extractDescription() { - final Description description = method.getAnnotation(Description.class); + final Description description = annotatedElement.getAnnotation(Description.class); if (description == null) return; this.description = description.value(); } @@ -808,7 +800,7 @@ private void extractDescription() { * Extracts the {@link ArgDescriptions} Annotation from the Method. */ private void extractArgDescriptions() { - final ArgDescriptions argDescriptions = method.getAnnotation(ArgDescriptions.class); + final ArgDescriptions argDescriptions = annotatedElement.getAnnotation(ArgDescriptions.class); if (argDescriptions == null) return; this.argDescriptions.addAll(Arrays.asList(argDescriptions.value())); } @@ -841,7 +833,8 @@ public void extractSuggestions() { * Adds the suggestions to the passed list. */ private void extractSuggestionFromParams() { - final Parameter[] parameters = method.getParameters(); + // TODO SUGGESTIONS + /*final Parameter[] parameters = annotatedElement.getParameters(); for (int i = 1; i < parameters.length; i++) { final Parameter parameter = parameters[i]; @@ -851,7 +844,7 @@ private void extractSuggestionFromParams() { final Class type = getGenericType(parameter); final int addIndex = i - 1; setOrAddSuggestion(addIndex, createSuggestion(suggestionKey, type)); - } + }*/ } @NotNull @@ -897,10 +890,10 @@ private void setOrAddSuggestion(final int index, @Nullable final Suggestion s } private List getSuggestionsFromAnnotations() { - final Suggestions requirements = method.getAnnotation(Suggestions.class); + final Suggestions requirements = annotatedElement.getAnnotation(Suggestions.class); if (requirements != null) return Arrays.asList(requirements.value()); - final dev.triumphteam.cmd.core.annotation.Suggestion suggestion = method.getAnnotation(dev.triumphteam.cmd.core.annotation.Suggestion.class); + final dev.triumphteam.cmd.core.annotation.Suggestion suggestion = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.Suggestion.class); if (suggestion == null) return emptyList(); return singletonList(suggestion); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java index af8c4734..1942ebe6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java @@ -59,7 +59,7 @@ public abstract class SubCommand extends LimitlessInternalArgument { private final BaseCommand baseCommand; - private final Method method; + private final Method method = null; private final String parentName; private final String name; @@ -86,7 +86,7 @@ public SubCommand( ) { super(processor.getName(), processor.getDescription(), String.class, new EmptySuggestion<>(), 0, false); this.baseCommand = processor.getBaseCommand(); - this.method = processor.getMethod(); + // this.method = processor.getAnnotatedElement(); this.name = processor.getName(); this.alias = processor.getAlias(); this.internalArguments = processor.getArguments(); @@ -166,7 +166,7 @@ public void execute(@NotNull final S sender, @NotNull final List args) { if (!meetRequirements(sender)) return; // Creates the invoking arguments list - final List invokeArguments = new ArrayList<>(); + final List invokeArguments = new ArrayList<>(); invokeArguments.add(sender); if (!validateAndCollectArguments(sender, invokeArguments, args)) { @@ -241,7 +241,7 @@ public void execute(@NotNull final S sender, @NotNull final List args) { @SuppressWarnings("unchecked") private boolean validateAndCollectArguments( @NotNull final S sender, - @NotNull final List invokeArguments, + @NotNull final List invokeArguments, @NotNull final List commandArgs ) { for (int i = 0; i < internalArguments.size(); i++) { @@ -251,7 +251,7 @@ private boolean validateAndCollectArguments( final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument; final List leftOvers = leftOvers(commandArgs, i); - final Object result = limitlessArgument.resolve(sender, leftOvers); + final java.lang.Object result = limitlessArgument.resolve(sender, leftOvers); if (result == null) { return false; @@ -278,7 +278,7 @@ private boolean validateAndCollectArguments( return false; } - final Object result = stringArgument.resolve(sender, arg); + final java.lang.Object result = stringArgument.resolve(sender, arg); if (result == null) { messageRegistry.sendMessage( MessageKey.INVALID_ARGUMENT, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java index 17e63654..c9f895ad 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java @@ -28,8 +28,8 @@ public ClassInvoker( } @Override - public void invoke(final @Nullable Object arg, final @NotNull Object[] arguments) throws InvocationTargetException, InstantiationException, IllegalAccessException { - final Object instance = isStatic ? constructor.newInstance(arg) : constructor.newInstance(parent, arg); + public void invoke(final @Nullable java.lang.Object arg, final @NotNull java.lang.Object[] arguments) throws InvocationTargetException, InstantiationException, IllegalAccessException { + final java.lang.Object instance = isStatic ? constructor.newInstance(arg) : constructor.newInstance(parent, arg); method.invoke(instance, arguments); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java index 16779250..8a3beaad 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java @@ -1,6 +1,5 @@ package dev.triumphteam.cmd.core.subcommand.invoker; -import dev.triumphteam.cmd.core.BaseCommand; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -9,16 +8,16 @@ public class MethodInvoker implements Invoker { - private final BaseCommand baseCommand; + private final Object instance; private final Method method; - public MethodInvoker(@NotNull final BaseCommand baseCommand, @NotNull final Method method) { - this.baseCommand = baseCommand; + public MethodInvoker(@NotNull final Object instance, @NotNull final Method method) { + this.instance = instance; this.method = method; } @Override - public void invoke(final @Nullable Object arg, final @NotNull Object[] arguments) throws InvocationTargetException, IllegalAccessException { - method.invoke(baseCommand, arguments); + public void invoke(final @Nullable java.lang.Object arg, final @NotNull java.lang.Object[] arguments) throws InvocationTargetException, IllegalAccessException { + method.invoke(instance, arguments); } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java index 7dded638..d1aecb15 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java @@ -34,7 +34,7 @@ import org.bukkit.permissions.PermissionDefault; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.Method; +import java.lang.reflect.AnnotatedElement; final class BukkitCommandProcessor extends AbstractCommandProcessor, BukkitSubCommandProcessor> { @@ -67,7 +67,7 @@ public BukkitCommandProcessor( @NotNull @Override - protected BukkitSubCommandProcessor createProcessor(@NotNull final Method method) { + protected BukkitSubCommandProcessor createProcessor(@NotNull final AnnotatedElement method) { return new BukkitSubCommandProcessor<>( getBaseCommand(), getName(), diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java index 32374639..25c020b8 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java @@ -67,4 +67,9 @@ public List getSuggestions(@NotNull final S sender, @NotNull final List< public CommandPermission getPermission() { return permission; } + + @Override + public @Nullable Object resolve(@NotNull final S sender, final @NotNull List value) { + return null; + } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java index 65fd4832..cb0a9a7d 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java @@ -31,7 +31,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Method; +import java.lang.reflect.AnnotatedElement; final class BukkitSubCommandProcessor extends AbstractSubCommandProcessor { @@ -40,14 +40,14 @@ final class BukkitSubCommandProcessor extends AbstractSubCommandProcessor public BukkitSubCommandProcessor( @NotNull final BaseCommand baseCommand, @NotNull final String parentName, - @NotNull final Method method, + @NotNull final AnnotatedElement annotatedElement, @NotNull final RegistryContainer registryContainer, @NotNull final SenderValidator senderValidator, @Nullable final CommandPermission basePermission ) { - super(baseCommand, parentName, method, registryContainer, senderValidator); + super(baseCommand, parentName, annotatedElement, registryContainer, senderValidator); - final Permission annotation = method.getAnnotation(Permission.class); + final Permission annotation = annotatedElement.getAnnotation(Permission.class); if (annotation == null) { this.permission = basePermission; return; From b37e6ee67297c83fef0ac359ce5f26eaa3b66c4d Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 17 Sep 2022 15:12:13 +0100 Subject: [PATCH 006/101] merge conflicts --- .../triumphteam/cmd/prefixed/PrefixedCommand.java | 1 + .../cmd/prefixed/PrefixedCommandProcessor.java | 9 +++++---- .../cmd/prefixed/PrefixedSenderValidator.java | 1 + .../cmd/prefixed/PrefixedSubCommand.java | 9 +++++++++ .../cmd/slash/SlashCommandProcessor.java | 9 +++++---- .../dev/triumphteam/cmd/slash/SlashSubCommand.java | 7 +++++++ .../dev/triumphteam/cmds/simple/SimpleCommand.java | 2 +- .../cmds/simple/SimpleCommandProcessor.java | 11 ++++++----- .../triumphteam/cmds/simple/SimpleSubCommand.java | 13 +++++++++++-- 9 files changed, 46 insertions(+), 16 deletions(-) diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java index a39828fc..60c860ae 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java @@ -29,6 +29,7 @@ import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java index 2df42c3e..f0dbf369 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java @@ -33,6 +33,7 @@ import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; /** @@ -77,16 +78,16 @@ private String extractPrefix() { return prefixAnnotation == null ? "" : prefixAnnotation.value(); } - @NotNull @Override - protected PrefixedSubCommandProcessor createProcessor(@NotNull final Method method) { - return new PrefixedSubCommandProcessor<>( + protected @NotNull PrefixedSubCommandProcessor createProcessor(final @NotNull AnnotatedElement method) { + return null; + /*return new PrefixedSubCommandProcessor<>( getBaseCommand(), getName(), method, getRegistryContainer(), getSenderValidator() - ); + );*/ } @NotNull diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java index e00d199e..b9d3117d 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java @@ -26,6 +26,7 @@ import com.google.common.collect.ImmutableSet; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java index 0c02d9c8..3eb1508f 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java @@ -27,6 +27,9 @@ import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; final class PrefixedSubCommand extends SubCommand { @@ -37,4 +40,10 @@ public PrefixedSubCommand( ) { super(processor, parentName, executionProvider); } + + // TODO: + @Override + public @Nullable Object resolve(@NotNull final S sender, final @NotNull List value) { + return null; + } } diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java index a1e2dfa2..39ee08f5 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java @@ -35,6 +35,7 @@ import net.dv8tion.jda.api.Permission; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; @@ -101,16 +102,16 @@ private List getRolesFromAnnotations(@NotNull final Class klass) { return Collections.emptyList(); } - @NotNull @Override - protected SlashSubCommandProcessor createProcessor(@NotNull final Method method) { - return new SlashSubCommandProcessor<>( + protected @NotNull SlashSubCommandProcessor createProcessor(final @NotNull AnnotatedElement method) { + return null; + /*return new SlashSubCommandProcessor<>( getBaseCommand(), getName(), method, (SlashRegistryContainer) getRegistryContainer(), getSenderValidator() - ); + );*/ } @NotNull diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java index ef761b7c..76392002 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java @@ -33,6 +33,7 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.List; @@ -57,6 +58,12 @@ public String getDescription() { return description; } + // TODO + @Override + public @Nullable Object resolve(@NotNull final S sender, final @NotNull List value) { + return null; + } + public List getJdaOptions() { final List options = new ArrayList<>(); final List> internalArguments = getArguments(); diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index 8fb3bb93..2024bcbd 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -25,7 +25,7 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.SubCommand; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.message.MessageKey; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java index 9923fe3a..ce150a3b 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java @@ -31,6 +31,7 @@ import dev.triumphteam.cmd.core.sender.SenderValidator; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; public final class SimpleCommandProcessor extends AbstractCommandProcessor, SimpleSubCommandProcessor> { @@ -49,18 +50,18 @@ public SimpleCommandProcessor( /** * {@inheritDoc} */ - @NotNull @Override - protected SimpleSubCommandProcessor createProcessor(@NotNull Method method) { - return new SimpleSubCommandProcessor( + protected @NotNull SimpleSubCommandProcessor createProcessor(final @NotNull AnnotatedElement method) { + return null; + /*return new SimpleSubCommandProcessor( getBaseCommand(), method.getName(), method, getRegistryContainer(), getSenderValidator() - ); + );*/ } - + /** * {@inheritDoc} */ diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java index 3b76bd5d..27f73d95 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java @@ -23,11 +23,14 @@ */ package dev.triumphteam.cmds.simple; -import dev.triumphteam.cmd.core.AbstractSubCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public final class SimpleSubCommand extends AbstractSubCommand { +import java.util.List; + +public final class SimpleSubCommand extends SubCommand { public SimpleSubCommand( @NotNull final SimpleSubCommandProcessor processor, @@ -36,4 +39,10 @@ public SimpleSubCommand( ) { super(processor, parentName, executionProvider); } + + // TODO: + @Override + public @Nullable Object resolve(@NotNull final S sender, final @NotNull List value) { + return null; + } } From 6e1e9c3d9543c4c0712c7b161d693b2203b8196e Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 1 Oct 2022 21:42:15 +0200 Subject: [PATCH 007/101] Small rework of commands and subcommands --- .../dev/triumphteam/cmd/core/Command.java | 62 +++++++++++++++++- .../SubCommandRegistrationException.java | 3 +- .../processor/AbstractCommandProcessor.java | 65 ++++++++++++------- .../cmd/core/subcommand/SubCommand.java | 8 +-- .../cmd/core/subcommand/SubCommandHolder.java | 45 +++++++++++++ .../core/subcommand/invoker/ClassInvoker.java | 10 +-- .../cmd/core/subcommand/invoker/Invoker.java | 2 +- .../subcommand/invoker/MethodInvoker.java | 4 +- .../triumphteam/cmd/bukkit/BukkitCommand.java | 42 +++--------- .../cmds/simple/SimpleCommandProcessor.java | 6 +- 10 files changed, 169 insertions(+), 78 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/Command.java index 554bbdf3..e23c8d0a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/Command.java @@ -23,8 +23,16 @@ */ package dev.triumphteam.cmd.core; +import dev.triumphteam.cmd.core.annotation.Default; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import dev.triumphteam.cmd.core.subcommand.SubCommand; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Map; /** * Command interface which all platforms will implement. @@ -32,10 +40,62 @@ * @param The sender type. * @param The sub command type. */ -public interface Command> { +public interface Command> { + + @NotNull Map getSubCommands(); + @NotNull Map getSubCommandAlias(); void addSubCommand(final @NotNull String name, final @NotNull SC subCommand); void addSubCommandAlias(final @NotNull String alias, final @NotNull SC subCommand); + @NotNull String getName(); + + @NotNull MessageRegistry getMessageRegistry(); + + default @Nullable SC getSubCommand(final @NotNull List args, final @NotNull S mappedSender) { + SC subCommand = getDefaultSubCommand(); + + String subCommandName = ""; + if (args.size() > 0) subCommandName = args.get(0).toLowerCase(); + if (subCommand == null || subCommandExists(subCommandName)) { + subCommand = getSubCommand(subCommandName); + } + + if (subCommand == null || (args.size() > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { + getMessageRegistry().sendMessage( + MessageKey.UNKNOWN_COMMAND, + mappedSender, + new DefaultMessageContext(getName(), subCommandName) + ); + return null; + } + + return subCommand; + } + + /** + * Gets a default command if present. + * + * @return A default SubCommand. + */ + default @Nullable SC getDefaultSubCommand() { + return getSubCommands().get(Default.DEFAULT_CMD_NAME); + } + + default @Nullable SC getSubCommand(final @NotNull String key) { + final SC subCommand = getSubCommands().get(key); + if (subCommand != null) return subCommand; + return getSubCommandAlias().get(key); + } + + /** + * Checks if a SubCommand with the specified key exists. + * + * @param key the Key to check for + * @return whether a SubCommand with that key exists + */ + default boolean subCommandExists(final @NotNull String key) { + return getSubCommands().containsKey(key) || getSubCommandAlias().containsKey(key); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java index a2508f4d..1d516c4c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java @@ -23,7 +23,6 @@ */ package dev.triumphteam.cmd.core.exceptions; -import dev.triumphteam.cmd.core.BaseCommand; import org.jetbrains.annotations.NotNull; import java.lang.reflect.AnnotatedElement; @@ -36,7 +35,7 @@ public final class SubCommandRegistrationException extends RuntimeException { public SubCommandRegistrationException( final @NotNull String message, final @NotNull AnnotatedElement element, - final @NotNull Class commandClass + final @NotNull Class commandClass ) { super(message + ". In Method \"" + element + "\" in Class \"" + commandClass.getName() + "\""); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 892f5fd5..b3e095cb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -33,6 +33,9 @@ import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; import dev.triumphteam.cmd.core.subcommand.SubCommand; +import dev.triumphteam.cmd.core.subcommand.invoker.ClassInvoker; +import dev.triumphteam.cmd.core.subcommand.invoker.Invoker; +import dev.triumphteam.cmd.core.subcommand.invoker.MethodInvoker; import org.jetbrains.annotations.NotNull; import java.lang.reflect.AnnotatedElement; @@ -45,6 +48,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; /** * Abstracts most of the "extracting" from command annotations, allows for extending. @@ -95,30 +99,7 @@ public void addSubCommands(final @NotNull dev.triumphteam.cmd.core.Command baseCommandClass = baseCommand.getClass(); // Method sub commands - for (final Method method : baseCommandClass.getDeclaredMethods()) { - // TODO: ALLOW PRIVATE - if (Modifier.isPrivate(method.getModifiers())) continue; - - final P processor = createProcessor(method); - final String subCommandName = processor.getName(); - // Not a command - if (subCommandName == null) continue; - - if (subCommandName.isEmpty()) { - throw new SubCommandRegistrationException( - "@" + dev.triumphteam.cmd.core.annotation.SubCommand.class.getSimpleName() + " name must not be empty", - method, - baseCommandClass - ); - } - - final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider; - - final SC subCommand = createSubCommand(processor, executionProvider); - command.addSubCommand(subCommandName, subCommand); - - processor.getAlias().forEach(alias -> command.addSubCommandAlias(alias, subCommand)); - } + collectMethodSubCommands(command, baseCommandClass, method -> new MethodInvoker(baseCommand, method)); // Classes sub commands for (final Class klass : baseCommandClass.getDeclaredClasses()) { @@ -152,7 +133,41 @@ public void addSubCommands(final @NotNull dev.triumphteam.cmd.core.Command new ClassInvoker(baseCommand, constructor, method, isStatic)); + } + } + + private void collectMethodSubCommands( + final @NotNull dev.triumphteam.cmd.core.Command command, + final @NotNull Class klass, + final @NotNull Function invokerFunction + ) { + // Method sub commands + for (final Method method : klass.getDeclaredMethods()) { + // TODO: ALLOW PRIVATE + if (Modifier.isPrivate(method.getModifiers())) continue; + + final Invoker invoker = invokerFunction.apply(method); + + final P processor = createProcessor(method); + final String subCommandName = processor.getName(); + // Not a command + if (subCommandName == null) continue; + + if (subCommandName.isEmpty()) { + throw new SubCommandRegistrationException( + "@" + dev.triumphteam.cmd.core.annotation.SubCommand.class.getSimpleName() + " name must not be empty", + method, + klass + ); + } + + final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider; + + final SC subCommand = createSubCommand(processor, executionProvider); + command.addSubCommand(subCommandName, subCommand); + + processor.getAlias().forEach(alias -> command.addSubCommandAlias(alias, subCommand)); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java index 1942ebe6..031584f7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java @@ -26,10 +26,10 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; +import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; @@ -37,7 +37,6 @@ import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; import dev.triumphteam.cmd.core.requirement.Requirement; import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -56,7 +55,7 @@ * * @param The sender type. */ -public abstract class SubCommand extends LimitlessInternalArgument { +public abstract class SubCommand { private final BaseCommand baseCommand; private final Method method = null; @@ -84,7 +83,6 @@ public SubCommand( @NotNull final String parentName, @NotNull final ExecutionProvider executionProvider ) { - super(processor.getName(), processor.getDescription(), String.class, new EmptySuggestion<>(), 0, false); this.baseCommand = processor.getBaseCommand(); // this.method = processor.getAnnotatedElement(); this.name = processor.getName(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java new file mode 100644 index 00000000..a777a8e7 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java @@ -0,0 +1,45 @@ +package dev.triumphteam.cmd.core.subcommand; + +import dev.triumphteam.cmd.core.Command; +import dev.triumphteam.cmd.core.execution.ExecutionProvider; +import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; +import org.jetbrains.annotations.NotNull; + +import java.util.Map; + +public class SubCommandHolder extends SubCommand implements Command> { + + public SubCommandHolder( + final @NotNull AbstractSubCommandProcessor processor, + final @NotNull String parentName, + final @NotNull ExecutionProvider executionProvider + ) { + super(processor, parentName, executionProvider); + } + + @Override + public @NotNull Map> getSubCommands() { + return null; + } + + @Override + public @NotNull Map> getSubCommandAlias() { + return null; + } + + @Override + public @NotNull MessageRegistry getMessageRegistry() { + return null; + } + + @Override + public void addSubCommand(final @NotNull String name, final @NotNull SubCommand subCommand) { + + } + + @Override + public void addSubCommandAlias(final @NotNull String alias, final @NotNull SubCommand subCommand) { + + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java index c9f895ad..dde99bcb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java @@ -16,9 +16,9 @@ public class ClassInvoker implements Invoker { private final boolean isStatic; public ClassInvoker( - @NotNull final BaseCommand parent, - @NotNull final Constructor constructor, - @NotNull final Method method, + final @NotNull BaseCommand parent, + final @NotNull Constructor constructor, + final @NotNull Method method, final boolean isStatic ) { this.parent = parent; @@ -28,8 +28,8 @@ public ClassInvoker( } @Override - public void invoke(final @Nullable java.lang.Object arg, final @NotNull java.lang.Object[] arguments) throws InvocationTargetException, InstantiationException, IllegalAccessException { - final java.lang.Object instance = isStatic ? constructor.newInstance(arg) : constructor.newInstance(parent, arg); + public void invoke(final @Nullable Object arg, final @NotNull Object[] arguments) throws InvocationTargetException, InstantiationException, IllegalAccessException { + final Object instance = isStatic ? constructor.newInstance(arg) : constructor.newInstance(parent, arg); method.invoke(instance, arguments); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java index 9754afb6..650f5bc4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java @@ -7,7 +7,7 @@ public interface Invoker { - void invoke(@Nullable final Object arg, @NotNull final Object[] arguments) throws + void invoke(final @Nullable Object arg, final @NotNull Object[] arguments) throws InstantiationException, IllegalAccessException, IllegalArgumentException, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java index 8a3beaad..d4543639 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java @@ -11,13 +11,13 @@ public class MethodInvoker implements Invoker { private final Object instance; private final Method method; - public MethodInvoker(@NotNull final Object instance, @NotNull final Method method) { + public MethodInvoker(final @NotNull Object instance, final @NotNull Method method) { this.instance = instance; this.method = method; } @Override - public void invoke(final @Nullable java.lang.Object arg, final @NotNull java.lang.Object[] arguments) throws InvocationTargetException, IllegalAccessException { + public void invoke(final @Nullable Object arg, final @NotNull Object[] arguments) throws InvocationTargetException, IllegalAccessException { method.invoke(instance, arguments); } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index 0a3f230a..8153eef2 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -35,7 +35,10 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.*; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import static java.util.Collections.emptyList; @@ -71,7 +74,11 @@ public void addSubCommandAlias(final @NotNull String alias, final @NotNull Bukki * {@inheritDoc} */ @Override - public boolean execute(final @NotNull CommandSender sender, final @NotNull String commandLabel, final @NotNull String @NotNull [] args) { + public boolean execute( + final @NotNull CommandSender sender, + final @NotNull String commandLabel, + final @NotNull String @NotNull [] args + ) { BukkitSubCommand subCommand = getDefaultSubCommand(); String subCommandName = ""; @@ -130,35 +137,4 @@ public boolean execute(final @NotNull CommandSender sender, final @NotNull Strin final List commandArgs = Arrays.asList(args); return subCommand.getSuggestions(mappedSender, !subCommand.isDefault() ? commandArgs.subList(1, commandArgs.size()) : commandArgs); } - - /** - * Gets a default command if present. - * - * @return A default SubCommand. - */ - private @Nullable BukkitSubCommand getDefaultSubCommand() { - return subCommands.get(Default.DEFAULT_CMD_NAME); - } - - /** - * Used in order to search for the given {@link SubCommand} in the {@link #subCommandAliases} - * - * @param key the String to look for the {@link SubCommand} - * @return the {@link SubCommand} for the particular key or NULL - */ - private @Nullable BukkitSubCommand getSubCommand(final @NotNull String key) { - final BukkitSubCommand subCommand = subCommands.get(key); - if (subCommand != null) return subCommand; - return subCommandAliases.get(key); - } - - /** - * Checks if a SubCommand with the specified key exists. - * - * @param key the Key to check for - * @return whether a SubCommand with that key exists - */ - private boolean subCommandExists(final @NotNull String key) { - return subCommands.containsKey(key) || subCommandAliases.containsKey(key); - } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java index 05ad006d..80dd7eff 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java @@ -32,7 +32,6 @@ import org.jetbrains.annotations.NotNull; import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Method; public final class SimpleCommandProcessor extends AbstractCommandProcessor, SimpleSubCommandProcessor> { @@ -52,14 +51,13 @@ public SimpleCommandProcessor( */ @Override protected @NotNull SimpleSubCommandProcessor createProcessor(final @NotNull AnnotatedElement method) { - return null; - /*return new SimpleSubCommandProcessor( + return new SimpleSubCommandProcessor( getBaseCommand(), method.getName(), method, getRegistryContainer(), getSenderValidator() - );*/ + ); } /** From c039133157b0406e0332c3672c81e134ba31c4cd Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 2 Oct 2022 17:51:58 +0200 Subject: [PATCH 008/101] uh wtf --- .../java/org/jetbrains/annotations/UnknownNullability.java | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 core/src/main/java/org/jetbrains/annotations/UnknownNullability.java diff --git a/core/src/main/java/org/jetbrains/annotations/UnknownNullability.java b/core/src/main/java/org/jetbrains/annotations/UnknownNullability.java deleted file mode 100644 index 12aa5788..00000000 --- a/core/src/main/java/org/jetbrains/annotations/UnknownNullability.java +++ /dev/null @@ -1,4 +0,0 @@ -package org.jetbrains.annotations; - -public @interface UnknownNullability { -} From b96aaa7f6ae99daa57985274a08aee6b9dd74c4b Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 9 Oct 2022 20:17:17 -0500 Subject: [PATCH 009/101] Preparing for processor changes --- .../dev/triumphteam/cmd/core/Command.java | 14 ++--- .../cmd/core/annotation/Command.java | 15 +++-- .../core/message/context/MessageContext.java | 1 - .../processor/AbstractCommandProcessor.java | 55 +++++++------------ .../AbstractSubCommandProcessor.java | 1 - .../cmd/core/subcommand/SubCommand.java | 1 - .../subcommand/invoker/MethodInvoker.java | 10 ++-- .../cmd/prefixed/PrefixedCommand.java | 1 - .../prefixed/PrefixedCommandProcessor.java | 2 +- .../triumphteam/cmd/slash/SlashCommand.java | 1 - .../cmd/slash/SlashCommandListener.java | 1 - .../cmd/slash/SlashCommandProcessor.java | 2 +- .../triumphteam/cmd/bukkit/BukkitCommand.java | 2 - .../cmd/bukkit/BukkitCommandProcessor.java | 2 +- .../cmds/simple/SimpleCommand.java | 5 -- .../cmds/simple/SimpleCommandManager.java | 5 +- .../cmds/simple/SimpleCommandProcessor.java | 23 ++++---- 17 files changed, 59 insertions(+), 82 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/Command.java index e23c8d0a..9a62d408 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/Command.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,7 +23,6 @@ */ package dev.triumphteam.cmd.core; -import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; @@ -40,7 +39,7 @@ * @param The sender type. * @param The sub command type. */ -public interface Command> { +public interface Command> { @NotNull Map getSubCommands(); @@ -49,6 +48,7 @@ public interface Command> { void addSubCommand(final @NotNull String name, final @NotNull SC subCommand); void addSubCommandAlias(final @NotNull String alias, final @NotNull SC subCommand); + @NotNull String getName(); @NotNull MessageRegistry getMessageRegistry(); @@ -80,7 +80,7 @@ public interface Command> { * @return A default SubCommand. */ default @Nullable SC getDefaultSubCommand() { - return getSubCommands().get(Default.DEFAULT_CMD_NAME); + return getSubCommands().get(dev.triumphteam.cmd.core.annotation.Command.DEFAULT_CMD_NAME); } default @Nullable SC getSubCommand(final @NotNull String key) { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java index deeb2644..2587d030 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java @@ -32,21 +32,24 @@ import java.lang.annotation.Target; /** - * Command annotation, marks the class as a command class. + * Command annotation, marks the class or method as a command. */ @Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) +@Target({ElementType.TYPE, ElementType.METHOD}) @Inherited public @interface Command { + // Default commands use this name. + String DEFAULT_CMD_NAME = "TH_DEFAULT"; + /** - * Main command's name. - * Must be empty and have spaces. + * Command's name. + * Must not have spaces. * - * @return The command. + * @return The command name. */ @NotNull - String value(); + String value() default DEFAULT_CMD_NAME; /** * List with all command aliases. diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java index 3fc1758c..4aebe5a7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java @@ -23,7 +23,6 @@ */ package dev.triumphteam.cmd.core.message.context; -import dev.triumphteam.cmd.core.annotation.Default; import org.jetbrains.annotations.NotNull; /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index b3e095cb..12396076 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -33,7 +33,6 @@ import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; import dev.triumphteam.cmd.core.subcommand.SubCommand; -import dev.triumphteam.cmd.core.subcommand.invoker.ClassInvoker; import dev.triumphteam.cmd.core.subcommand.invoker.Invoker; import dev.triumphteam.cmd.core.subcommand.invoker.MethodInvoker; import org.jetbrains.annotations.NotNull; @@ -49,6 +48,7 @@ import java.util.List; import java.util.Map; import java.util.function.Function; +import java.util.function.Supplier; /** * Abstracts most of the "extracting" from command annotations, allows for extending. @@ -58,7 +58,7 @@ * * @param Sender type */ -public abstract class AbstractCommandProcessor, P extends AbstractSubCommandProcessor> { +public abstract class AbstractCommandProcessor, P extends AbstractSubCommandProcessor> { private String name; // TODO: 11/28/2021 Add better default description @@ -67,23 +67,26 @@ public abstract class AbstractCommandProcessor, private final Map subCommands = new HashMap<>(); private final Map subCommandsAlias = new HashMap<>(); - private final BaseCommand baseCommand; + private final Class commandClass; + private final Supplier instanceSupplier; private final RegistryContainer registryContainer; - private final SenderMapper senderMapper; + private final SenderMapper senderMapper; private final SenderValidator senderValidator; private final ExecutionProvider syncExecutionProvider; private final ExecutionProvider asyncExecutionProvider; protected AbstractCommandProcessor( - final @NotNull BaseCommand baseCommand, + final @NotNull Class commandClass, + final @NotNull Supplier instanceSupplier, final @NotNull RegistryContainer registryContainer, - final @NotNull SenderMapper senderMapper, + final @NotNull SenderMapper senderMapper, final @NotNull SenderValidator senderValidator, final @NotNull ExecutionProvider syncExecutionProvider, final @NotNull ExecutionProvider asyncExecutionProvider ) { - this.baseCommand = baseCommand; + this.commandClass = commandClass; + this.instanceSupplier = instanceSupplier; this.registryContainer = registryContainer; this.senderMapper = senderMapper; this.senderValidator = senderValidator; @@ -96,13 +99,11 @@ protected AbstractCommandProcessor( // TODO: Comments public void addSubCommands(final @NotNull dev.triumphteam.cmd.core.Command command) { - final Class baseCommandClass = baseCommand.getClass(); - // Method sub commands - collectMethodSubCommands(command, baseCommandClass, method -> new MethodInvoker(baseCommand, method)); + collectMethodSubCommands(command, commandClass, method -> new MethodInvoker(instanceSupplier, method)); // Classes sub commands - for (final Class klass : baseCommandClass.getDeclaredClasses()) { + for (final Class klass : commandClass.getDeclaredClasses()) { final List> constructors = Arrays.asList(klass.getDeclaredConstructors()); if (constructors.size() != 1) { @@ -120,20 +121,19 @@ public void addSubCommands(final @NotNull dev.triumphteam.cmd.core.Command 0; - final P processor = createProcessor(klass); + final P processor = createSubProcessor(klass); final String subCommandName = processor.getName(); // Not a command if (subCommandName == null) continue; // If the name is empty and there is no arguments if (subCommandName.isEmpty() && !hasArg) { throw new SubCommandRegistrationException( - "@" + dev.triumphteam.cmd.core.annotation.SubCommand.class.getSimpleName() + " name must not be empty on a class unless it has an argument.", + "@" + Command.class.getSimpleName() + " name must not be empty on a class unless it has an argument.", klass, - baseCommand.getClass() + commandClass ); } - collectMethodSubCommands(command, klass, method -> new ClassInvoker(baseCommand, constructor, method, isStatic)); } } @@ -149,7 +149,7 @@ private void collectMethodSubCommands( final Invoker invoker = invokerFunction.apply(method); - final P processor = createProcessor(method); + final P processor = createSubProcessor(method); final String subCommandName = processor.getName(); // Not a command if (subCommandName == null) continue; @@ -171,7 +171,7 @@ private void collectMethodSubCommands( } } - protected abstract @NotNull P createProcessor(final @NotNull AnnotatedElement method); + protected abstract @NotNull P createSubProcessor(final @NotNull AnnotatedElement method); protected abstract @NotNull SC createSubCommand(final @NotNull P processor, final @NotNull ExecutionProvider executionProvider); @@ -193,15 +193,6 @@ private void collectMethodSubCommands( return alias; } - /** - * Gets the {@link BaseCommand} which is needed to invoke the command later. - * - * @return The {@link BaseCommand}. - */ - public @NotNull BaseCommand getBaseCommand() { - return baseCommand; - } - // TODO: Comments public @NotNull RegistryContainer getRegistryContainer() { return registryContainer; @@ -212,7 +203,7 @@ private void collectMethodSubCommands( * * @return The {@link SenderMapper}. */ - public @NotNull SenderMapper getSenderMapper() { + public @NotNull SenderMapper getSenderMapper() { return senderMapper; } @@ -221,14 +212,6 @@ private void collectMethodSubCommands( return senderValidator; } - public @NotNull Map<@NotNull String, SC> getSubCommands() { - return subCommands; - } - - public @NotNull Map<@NotNull String, SC> getSubCommandsAlias() { - return subCommandsAlias; - } - public @NotNull ExecutionProvider getSyncExecutionProvider() { return syncExecutionProvider; } @@ -250,7 +233,7 @@ private void collectMethodSubCommands( * Helper method for getting the command names from the command annotation. */ private void extractCommandNames() { - final Command commandAnnotation = baseCommand.getClass().getAnnotation(Command.class); + final Command commandAnnotation = commandClass.getAnnotation(Command.class); if (commandAnnotation == null) { final String commandName = baseCommand.getCommand(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java index af55d0f6..430c3e07 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java @@ -30,7 +30,6 @@ import dev.triumphteam.cmd.core.annotation.ArgName; import dev.triumphteam.cmd.core.annotation.Async; import dev.triumphteam.cmd.core.annotation.CommandFlags; -import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.annotation.Description; import dev.triumphteam.cmd.core.annotation.Flag; import dev.triumphteam.cmd.core.annotation.Join; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java index 031584f7..2a10bca8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java @@ -24,7 +24,6 @@ package dev.triumphteam.cmd.core.subcommand; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.argument.StringInternalArgument; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java index d4543639..8c51a96b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java @@ -1,23 +1,25 @@ package dev.triumphteam.cmd.core.subcommand.invoker; +import dev.triumphteam.cmd.core.BaseCommand; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.function.Supplier; public class MethodInvoker implements Invoker { - private final Object instance; + private final Supplier instanceSupplier; private final Method method; - public MethodInvoker(final @NotNull Object instance, final @NotNull Method method) { - this.instance = instance; + public MethodInvoker(final @NotNull Supplier instanceSupplier, final @NotNull Method method) { + this.instanceSupplier = instanceSupplier; this.method = method; } @Override public void invoke(final @Nullable Object arg, final @NotNull Object[] arguments) throws InvocationTargetException, IllegalAccessException { - method.invoke(instance, arguments); + method.invoke(instanceSupplier.get(), arguments); } } diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java index adad623f..3bb6af1e 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java @@ -24,7 +24,6 @@ package dev.triumphteam.cmd.prefixed; import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java index 3f040f3e..fbd98783 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java @@ -78,7 +78,7 @@ public PrefixedCommandProcessor( } @Override - protected @NotNull PrefixedSubCommandProcessor createProcessor(final @NotNull AnnotatedElement method) { + protected @NotNull PrefixedSubCommandProcessor createSubProcessor(final @NotNull AnnotatedElement method) { return null; /*return new PrefixedSubCommandProcessor<>( getBaseCommand(), diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java index d6af4180..627ae11f 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java @@ -24,7 +24,6 @@ package dev.triumphteam.cmd.slash; import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.execution.ExecutionProvider; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java index 1c103fce..25dcf2c0 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java @@ -24,7 +24,6 @@ package dev.triumphteam.cmd.slash; import com.google.common.collect.Maps; -import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.slash.sender.SlashSender; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java index 48d41b15..a853c8f6 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java @@ -102,7 +102,7 @@ public SlashCommandProcessor( } @Override - protected @NotNull SlashSubCommandProcessor createProcessor(final @NotNull AnnotatedElement method) { + protected @NotNull SlashSubCommandProcessor createSubProcessor(final @NotNull AnnotatedElement method) { return null; /*return new SlashSubCommandProcessor<>( getBaseCommand(), diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index 772280e8..0f1078b9 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -26,7 +26,6 @@ import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; import dev.triumphteam.cmd.bukkit.message.NoPermissionMessageContext; import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.MessageRegistry; @@ -34,7 +33,6 @@ import dev.triumphteam.cmd.core.sender.SenderMapper; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.HashMap; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java index 78af9b2f..c7e23d95 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java @@ -70,7 +70,7 @@ public BukkitCommandProcessor( } @Override - protected @NotNull BukkitSubCommandProcessor createProcessor(final @NotNull AnnotatedElement method) { + protected @NotNull BukkitSubCommandProcessor createSubProcessor(final @NotNull AnnotatedElement method) { return new BukkitSubCommandProcessor<>( getBaseCommand(), getName(), diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index eb489167..80af847d 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -23,10 +23,8 @@ */ package dev.triumphteam.cmds.simple; -import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.Command; import dev.triumphteam.cmd.core.subcommand.SubCommand; -import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.message.MessageKey; @@ -38,9 +36,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index c533c497..da5e81de 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -36,11 +36,9 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Scanner; public final class SimpleCommandManager extends CommandManager { @@ -69,7 +67,8 @@ private SimpleCommandManager( @Override public void registerCommand(final @NotNull BaseCommand baseCommand) { final SimpleCommandProcessor processor = new SimpleCommandProcessor<>( - baseCommand, + baseCommand.getClass(), + () -> baseCommand, getRegistryContainer(), getSenderMapper(), getSenderValidator(), diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java index 80dd7eff..73cbfe55 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -32,29 +32,32 @@ import org.jetbrains.annotations.NotNull; import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Method; +import java.util.function.Supplier; public final class SimpleCommandProcessor extends AbstractCommandProcessor, SimpleSubCommandProcessor> { public SimpleCommandProcessor( - final @NotNull BaseCommand baseCommand, + final @NotNull Class commandClass, + final @NotNull Supplier instanceSupplier, final @NotNull RegistryContainer registries, final @NotNull SenderMapper senderMapper, final @NotNull SenderValidator senderValidator, final @NotNull ExecutionProvider syncExecutionProvider, final @NotNull ExecutionProvider asyncExecutionProvider ) { - super(baseCommand, registries, senderMapper, senderValidator, syncExecutionProvider, asyncExecutionProvider); + super(commandClass, instanceSupplier, registries, senderMapper, senderValidator, syncExecutionProvider, asyncExecutionProvider); } /** * {@inheritDoc} */ @Override - protected @NotNull SimpleSubCommandProcessor createProcessor(final @NotNull AnnotatedElement method) { + protected @NotNull SimpleSubCommandProcessor createSubProcessor(final @NotNull AnnotatedElement method) { return new SimpleSubCommandProcessor( getBaseCommand(), - method.getName(), - method, + "", + (Method) method, getRegistryContainer(), getSenderValidator() ); @@ -65,6 +68,6 @@ public SimpleCommandProcessor( */ @Override protected @NotNull SimpleSubCommand createSubCommand(final @NotNull SimpleSubCommandProcessor processor, final @NotNull ExecutionProvider executionProvider) { - return new SimpleSubCommand(processor, getName(), executionProvider); + return new SimpleSubCommand<>(processor, getName(), executionProvider); } } From 6034244d2619094074e58c5769851679324341fe Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 8 Nov 2022 22:15:27 +0000 Subject: [PATCH 010/101] pushing things to continue on the desktop --- .../triumphteam/cmd/core/CommandManager.java | 6 ++-- .../triumphteam/cmd/core/command/Command.java | 20 +++++++++++ .../cmd/core/command/SubCommand.java | 5 +++ .../argument/AbstractInternalArgument.java | 2 +- .../argument/ArgumentRegistry.java | 2 +- .../argument/ArgumentResolver.java | 2 +- .../argument/CollectionInternalArgument.java | 2 +- .../argument/EnumInternalArgument.java | 2 +- .../argument/FlagInternalArgument.java | 2 +- .../argument/InternalArgument.java | 2 +- .../JoinedStringInternalArgument.java | 2 +- .../argument/LimitlessInternalArgument.java | 2 +- .../argument/NamedInternalArgument.java | 8 ++--- .../argument/ResolverInternalArgument.java | 2 +- .../argument/SplitStringInternalArgument.java | 2 +- .../argument/StringInternalArgument.java | 2 +- .../named/AbstractArgumentBuilder.java | 2 +- .../argument/named/Argument.java | 2 +- .../argument/named/ArgumentBuilder.java | 2 +- .../argument/named/ArgumentKey.java | 2 +- .../argument/named/Arguments.java | 2 +- .../argument/named/ListArgument.java | 2 +- .../argument/named/ListArgumentBuilder.java | 2 +- .../argument/named/NamedArgumentParser.java | 2 +- .../argument/named/NamedArgumentRegistry.java | 2 +- .../argument/named/NamedArgumentResult.java | 2 +- .../argument/named/SimpleArgument.java | 2 +- .../cmd/core/flag/internal/ArgFlagValue.java | 2 +- .../cmd/core/flag/internal/FlagOptions.java | 2 +- .../AbstractSubCommandProcessor.java | 34 +++++++++---------- .../cmd/core/registry/RegistryContainer.java | 4 +-- .../cmd/core/subcommand/SubCommand.java | 6 ++-- .../cmd/slash/AttachmentArgument.java | 2 +- .../cmd/slash/SlashSubCommand.java | 2 +- .../cmd/slash/SlashSubCommandProcessor.java | 2 +- .../cmd/bukkit/BukkitSubCommand.java | 4 +-- 36 files changed, 84 insertions(+), 59 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/Command.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/AbstractInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/ArgumentRegistry.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/ArgumentResolver.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/CollectionInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/EnumInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/FlagInternalArgument.java (99%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/InternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/JoinedStringInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/LimitlessInternalArgument.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/NamedInternalArgument.java (95%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/ResolverInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/SplitStringInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/StringInternalArgument.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/named/AbstractArgumentBuilder.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/named/Argument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/named/ArgumentBuilder.java (95%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/named/ArgumentKey.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/named/Arguments.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/named/ListArgument.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/named/ListArgumentBuilder.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/named/NamedArgumentParser.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/named/NamedArgumentRegistry.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/named/NamedArgumentResult.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/argument/named/SimpleArgument.java (97%) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index 244f4bdd..ed6cc67c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -23,9 +23,9 @@ */ package dev.triumphteam.cmd.core; -import dev.triumphteam.cmd.core.argument.ArgumentResolver; -import dev.triumphteam.cmd.core.argument.named.Argument; -import dev.triumphteam.cmd.core.argument.named.ArgumentKey; +import dev.triumphteam.cmd.core.command.argument.ArgumentResolver; +import dev.triumphteam.cmd.core.command.argument.named.Argument; +import dev.triumphteam.cmd.core.command.argument.named.ArgumentKey; import dev.triumphteam.cmd.core.message.ContextualKey; import dev.triumphteam.cmd.core.message.MessageResolver; import dev.triumphteam.cmd.core.message.context.MessageContext; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java new file mode 100644 index 00000000..082b55a6 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -0,0 +1,20 @@ +package dev.triumphteam.cmd.core.command; + +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.Map; + +public class Command { + + private final String name; + private final Map> subCommands = new HashMap<>(); + + public Command(final @NotNull String name) { + this.name = name; + } + + public void addSubCommands() { + + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java new file mode 100644 index 00000000..1741c6ad --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -0,0 +1,5 @@ +package dev.triumphteam.cmd.core.command; + +public class SubCommand { + +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/AbstractInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/AbstractInternalArgument.java index e748e651..db837c59 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/AbstractInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentRegistry.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentRegistry.java index 73a9ae44..95c422d8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentRegistry.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import com.google.common.primitives.Doubles; import com.google.common.primitives.Floats; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentResolver.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentResolver.java index 1d77765d..24a7bd33 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentResolver.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/CollectionInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/CollectionInternalArgument.java index ae80b2a0..400da168 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/CollectionInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/EnumInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/EnumInternalArgument.java index 8dd5f61e..5c707eb5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/EnumInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/FlagInternalArgument.java similarity index 99% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/FlagInternalArgument.java index 971d5d0e..3ee63c71 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/FlagInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import dev.triumphteam.cmd.core.flag.Flags; import dev.triumphteam.cmd.core.flag.internal.FlagGroup; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/InternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/InternalArgument.java index aebc0051..94be826c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/InternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/JoinedStringInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/JoinedStringInternalArgument.java index aa7a4bed..963f2483 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/JoinedStringInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/LimitlessInternalArgument.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/LimitlessInternalArgument.java index 1fefb2ae..b3368be4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/LimitlessInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/NamedInternalArgument.java similarity index 95% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/NamedInternalArgument.java index 138b9438..408938c6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/NamedInternalArgument.java @@ -21,11 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; -import dev.triumphteam.cmd.core.argument.named.Arguments; -import dev.triumphteam.cmd.core.argument.named.NamedArgumentParser; -import dev.triumphteam.cmd.core.argument.named.NamedArgumentResult; +import dev.triumphteam.cmd.core.command.argument.named.Arguments; +import dev.triumphteam.cmd.core.command.argument.named.NamedArgumentParser; +import dev.triumphteam.cmd.core.command.argument.named.NamedArgumentResult; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ResolverInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/ResolverInternalArgument.java index e4082e50..7845c745 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ResolverInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/SplitStringInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/SplitStringInternalArgument.java index cfd1defc..fb81163f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/SplitStringInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/StringInternalArgument.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/StringInternalArgument.java index e174b5c7..1f199e28 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/StringInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/AbstractArgumentBuilder.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/AbstractArgumentBuilder.java index fc87a18a..0ac3c645 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/AbstractArgumentBuilder.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.command.argument.named; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Argument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Argument.java index 351e0508..142c244f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Argument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.command.argument.named; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentBuilder.java similarity index 95% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentBuilder.java index 4783756c..a76688d9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentBuilder.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.command.argument.named; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentKey.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentKey.java index 5e4e1df5..dff1c6c4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentKey.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.command.argument.named; import dev.triumphteam.cmd.core.registry.RegistryKey; import org.jetbrains.annotations.Contract; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Arguments.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Arguments.java index 5046e470..f874217b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Arguments.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.command.argument.named; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgument.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgument.java index 4d6952e4..d5d96c4a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.command.argument.named; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgumentBuilder.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgumentBuilder.java index c2c34cd8..bc32c1fd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgumentBuilder.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.command.argument.named; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentParser.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentParser.java index 663a7efc..f28d52e6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentParser.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.command.argument.named; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentRegistry.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentRegistry.java index fc5318a6..afba11b2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentRegistry.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.command.argument.named; import dev.triumphteam.cmd.core.registry.Registry; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentResult.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentResult.java index 09f0e347..25029996 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentResult.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.command.argument.named; import com.google.common.collect.ImmutableMap; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/SimpleArgument.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/SimpleArgument.java index ea6d4a7a..3d9653c7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/SimpleArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.command.argument.named; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java index 1b51a418..9dca1837 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.flag.internal; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.command.argument.StringInternalArgument; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java index f908c5d1..2b559d96 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.flag.internal; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.command.argument.StringInternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java index 430c3e07..a668d42d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java @@ -38,23 +38,23 @@ import dev.triumphteam.cmd.core.annotation.Requirements; import dev.triumphteam.cmd.core.annotation.Split; import dev.triumphteam.cmd.core.annotation.Suggestions; -import dev.triumphteam.cmd.core.argument.ArgumentRegistry; -import dev.triumphteam.cmd.core.argument.ArgumentResolver; -import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; -import dev.triumphteam.cmd.core.argument.EnumInternalArgument; -import dev.triumphteam.cmd.core.argument.FlagInternalArgument; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; -import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; -import dev.triumphteam.cmd.core.argument.NamedInternalArgument; -import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; -import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; -import dev.triumphteam.cmd.core.argument.named.Argument; -import dev.triumphteam.cmd.core.argument.named.ArgumentKey; -import dev.triumphteam.cmd.core.argument.named.Arguments; -import dev.triumphteam.cmd.core.argument.named.ListArgument; -import dev.triumphteam.cmd.core.argument.named.NamedArgumentRegistry; +import dev.triumphteam.cmd.core.command.argument.ArgumentRegistry; +import dev.triumphteam.cmd.core.command.argument.ArgumentResolver; +import dev.triumphteam.cmd.core.command.argument.CollectionInternalArgument; +import dev.triumphteam.cmd.core.command.argument.EnumInternalArgument; +import dev.triumphteam.cmd.core.command.argument.FlagInternalArgument; +import dev.triumphteam.cmd.core.command.argument.InternalArgument; +import dev.triumphteam.cmd.core.command.argument.JoinedStringInternalArgument; +import dev.triumphteam.cmd.core.command.argument.LimitlessInternalArgument; +import dev.triumphteam.cmd.core.command.argument.NamedInternalArgument; +import dev.triumphteam.cmd.core.command.argument.ResolverInternalArgument; +import dev.triumphteam.cmd.core.command.argument.SplitStringInternalArgument; +import dev.triumphteam.cmd.core.command.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.command.argument.named.Argument; +import dev.triumphteam.cmd.core.command.argument.named.ArgumentKey; +import dev.triumphteam.cmd.core.command.argument.named.Arguments; +import dev.triumphteam.cmd.core.command.argument.named.ListArgument; +import dev.triumphteam.cmd.core.command.argument.named.NamedArgumentRegistry; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.flag.Flags; import dev.triumphteam.cmd.core.flag.internal.FlagGroup; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java index 69468854..ac284dd9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java @@ -23,8 +23,8 @@ */ package dev.triumphteam.cmd.core.registry; -import dev.triumphteam.cmd.core.argument.ArgumentRegistry; -import dev.triumphteam.cmd.core.argument.named.NamedArgumentRegistry; +import dev.triumphteam.cmd.core.command.argument.ArgumentRegistry; +import dev.triumphteam.cmd.core.command.argument.named.NamedArgumentRegistry; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.requirement.RequirementRegistry; import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java index 2a10bca8..a6bbf47e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java @@ -24,9 +24,9 @@ package dev.triumphteam.cmd.core.subcommand; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.command.argument.InternalArgument; +import dev.triumphteam.cmd.core.command.argument.LimitlessInternalArgument; +import dev.triumphteam.cmd.core.command.argument.StringInternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.message.MessageKey; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java index b7289184..25303c46 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.slash; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.command.argument.StringInternalArgument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java index 5b2e971f..d3bb1e69 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.slash; import dev.triumphteam.cmd.core.subcommand.SubCommand; -import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.command.argument.InternalArgument; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.slash.choices.Choice; import dev.triumphteam.cmd.slash.choices.EmptyChoice; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java index 0e481020..d571c416 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.slash; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.command.argument.InternalArgument; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; import dev.triumphteam.cmd.core.sender.SenderValidator; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java index b8535794..a1e4d242 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java @@ -24,8 +24,8 @@ package dev.triumphteam.cmd.bukkit; import dev.triumphteam.cmd.core.subcommand.SubCommand; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; +import dev.triumphteam.cmd.core.command.argument.InternalArgument; +import dev.triumphteam.cmd.core.command.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; From d5f251abffdc0e1959ea207fb0cc39daa29e7234 Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Fri, 23 Dec 2022 01:30:11 +0000 Subject: [PATCH 011/101] feature: New command processing --- .../dev/triumphteam/cmd/core/BaseCommand.java | 62 ++-- .../dev/triumphteam/cmd/core/Command.java | 30 +- .../cmd/core/annotation/Description.java | 11 +- .../processor/AbstractCommandProcessor.java | 258 +---------------- .../cmd/core/processor/Commands.java | 70 +++++ .../OldAbstractCommandProcessor.java | 267 ++++++++++++++++++ ...va => OldAbstractSubCommandProcessor.java} | 5 +- .../cmd/core/subcommand/SubCommand.java | 4 +- .../cmd/core/subcommand/SubCommandHolder.java | 4 +- .../prefixed/PrefixedCommandProcessor.java | 5 +- .../cmd/prefixed/PrefixedSubCommand.java | 4 +- .../prefixed/PrefixedSubCommandProcessor.java | 4 +- .../cmd/slash/SlashCommandProcessor.java | 5 +- .../cmd/slash/SlashSubCommandProcessor.java | 4 +- .../triumphteam/cmd/bukkit/BukkitCommand.java | 99 +++---- .../cmd/bukkit/BukkitCommandManager.java | 44 +-- .../cmd/bukkit/BukkitCommandProcessor.java | 42 +-- .../cmd/bukkit/BukkitSubCommandProcessor.java | 5 +- .../cmd/bukkit/OldBukkitCommand.java | 145 ++++++++++ .../cmds/simple/SimpleCommand.java | 103 ++----- .../cmds/simple/SimpleCommandManager.java | 41 ++- .../cmds/simple/SimpleCommandProcessor.java | 36 +-- .../cmds/simple/SimpleSubCommand.java | 6 - .../simple/SimpleSubCommandProcessor.java | 4 +- 24 files changed, 676 insertions(+), 582 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java rename core/src/main/java/dev/triumphteam/cmd/core/processor/{AbstractSubCommandProcessor.java => OldAbstractSubCommandProcessor.java} (99%) create mode 100644 minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java index 49d0a2f0..c7741b0c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -37,61 +37,61 @@ public abstract class BaseCommand { private final String command; private final List alias = new ArrayList<>(); + private final String description; + - /** - * Normal constructor with no arguments for when using the {@link Command} annotation - */ public BaseCommand() { - this(null, null); + this(null, null, null); } - /** - * Constructor for alias only - * - * @param alias The alias {@link List} - */ public BaseCommand(final @Nullable List<@NotNull String> alias) { - this(null, alias); + this(null, alias, null); } - /** - * Constructor for command name only - * - * @param command The command name - */ public BaseCommand(final @Nullable String command) { - this(command, null); + this(command, null, null); } - /** - * Secondary constructor for when wanting a more customizable command, which isn't possible with annotations - * - * @param command The command name - * @param alias The aliases for the command - */ - public BaseCommand(final @Nullable String command, final @Nullable List<@NotNull String> alias) { + public BaseCommand(final @Nullable String command, final @Nullable String description) { + this(command, null, description); + } + + public BaseCommand( + final @Nullable String command, + final @Nullable List<@NotNull String> alias, + final @Nullable String description + ) { this.command = command; + this.description = description; if (alias != null) { this.alias.addAll(alias); } } /** - * Gets the command name + * Gets the command name. * - * @return The {@link #command} + * @return The {@link #command}. */ public @Nullable String getCommand() { return command; } /** - * Gets the list with the aliases for the command + * Gets the list with the aliases for the command. * - * @return The {@link #alias} + * @return The {@link #alias}. */ public @NotNull List<@NotNull String> getAlias() { return alias; } + /** + * Gets the description of the command. + * + * @return The {@link #description}. + */ + public @NotNull String getDescription() { + return description == null ? "" : description; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/Command.java index 9a62d408..635d5024 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/Command.java @@ -37,24 +37,15 @@ * Command interface which all platforms will implement. * * @param The sender type. - * @param The sub command type. */ -public interface Command> { +public interface Command { - @NotNull Map getSubCommands(); + @NotNull Map> getSubCommands(); - @NotNull Map getSubCommandAlias(); + @NotNull Map> getSubCommandAlias(); - void addSubCommand(final @NotNull String name, final @NotNull SC subCommand); - - void addSubCommandAlias(final @NotNull String alias, final @NotNull SC subCommand); - - @NotNull String getName(); - - @NotNull MessageRegistry getMessageRegistry(); - - default @Nullable SC getSubCommand(final @NotNull List args, final @NotNull S mappedSender) { - SC subCommand = getDefaultSubCommand(); + default @Nullable SubCommand getSubCommand(final @NotNull List args) { + SubCommand subCommand = getDefaultSubCommand(); String subCommandName = ""; if (args.size() > 0) subCommandName = args.get(0).toLowerCase(); @@ -63,11 +54,6 @@ public interface Command> { } if (subCommand == null || (args.size() > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { - getMessageRegistry().sendMessage( - MessageKey.UNKNOWN_COMMAND, - mappedSender, - new DefaultMessageContext(getName(), subCommandName) - ); return null; } @@ -79,12 +65,12 @@ public interface Command> { * * @return A default SubCommand. */ - default @Nullable SC getDefaultSubCommand() { + default @Nullable SubCommand getDefaultSubCommand() { return getSubCommands().get(dev.triumphteam.cmd.core.annotation.Command.DEFAULT_CMD_NAME); } - default @Nullable SC getSubCommand(final @NotNull String key) { - final SC subCommand = getSubCommands().get(key); + default @Nullable SubCommand getSubCommand(final @NotNull String key) { + final SubCommand subCommand = getSubCommands().get(key); if (subCommand != null) return subCommand; return getSubCommandAlias().get(key); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Description.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Description.java index a64fd936..04040e57 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Description.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Description.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -36,6 +36,5 @@ @Inherited public @interface Description { - @NotNull - String value(); + @NotNull String value(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 12396076..e5880664 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -1,267 +1,39 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.annotation.Command; -import dev.triumphteam.cmd.core.annotation.Description; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; -import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.subcommand.SubCommand; -import dev.triumphteam.cmd.core.subcommand.invoker.Invoker; -import dev.triumphteam.cmd.core.subcommand.invoker.MethodInvoker; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Constructor; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; import java.util.List; -import java.util.Map; -import java.util.function.Function; -import java.util.function.Supplier; -/** - * Abstracts most of the "extracting" from command annotations, allows for extending. - *
- * I know this could be done better, but couldn't think of a better way. - * If you do please PR or let me know on my discord! - * - * @param Sender type - */ -public abstract class AbstractCommandProcessor, P extends AbstractSubCommandProcessor> { +import static dev.triumphteam.cmd.core.processor.Commands.aliasOf; +import static dev.triumphteam.cmd.core.processor.Commands.descriptionOf; - private String name; - // TODO: 11/28/2021 Add better default description - private String description = "No description provided."; - private final List alias = new ArrayList<>(); - private final Map subCommands = new HashMap<>(); - private final Map subCommandsAlias = new HashMap<>(); +public abstract class AbstractCommandProcessor { - private final Class commandClass; - private final Supplier instanceSupplier; - private final RegistryContainer registryContainer; - private final SenderMapper senderMapper; - private final SenderValidator senderValidator; + private final String name; + private final List alias; + private final String description; - private final ExecutionProvider syncExecutionProvider; - private final ExecutionProvider asyncExecutionProvider; - - protected AbstractCommandProcessor( - final @NotNull Class commandClass, - final @NotNull Supplier instanceSupplier, - final @NotNull RegistryContainer registryContainer, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator, - final @NotNull ExecutionProvider syncExecutionProvider, - final @NotNull ExecutionProvider asyncExecutionProvider + public AbstractCommandProcessor( + final @NotNull String name, + final @NotNull BaseCommand baseCommand ) { - this.commandClass = commandClass; - this.instanceSupplier = instanceSupplier; - this.registryContainer = registryContainer; - this.senderMapper = senderMapper; - this.senderValidator = senderValidator; - this.syncExecutionProvider = syncExecutionProvider; - this.asyncExecutionProvider = asyncExecutionProvider; - - extractCommandNames(); - extractDescription(); - } - - // TODO: Comments - public void addSubCommands(final @NotNull dev.triumphteam.cmd.core.Command command) { - // Method sub commands - collectMethodSubCommands(command, commandClass, method -> new MethodInvoker(instanceSupplier, method)); - - // Classes sub commands - for (final Class klass : commandClass.getDeclaredClasses()) { - final List> constructors = Arrays.asList(klass.getDeclaredConstructors()); - - if (constructors.size() != 1) { - throw new SubCommandRegistrationException("TODO constructs", null, null); - } - - final Constructor constructor = constructors.get(0); - - final boolean isStatic = Modifier.isStatic(klass.getModifiers()); - final int argsSize = isStatic ? constructor.getParameterCount() : constructor.getParameterCount() - 1; - - if (argsSize > 1) { - throw new SubCommandRegistrationException("TODO params", null, null); - } - - final boolean hasArg = argsSize > 0; - - final P processor = createSubProcessor(klass); - final String subCommandName = processor.getName(); - // Not a command - if (subCommandName == null) continue; - // If the name is empty and there is no arguments - if (subCommandName.isEmpty() && !hasArg) { - throw new SubCommandRegistrationException( - "@" + Command.class.getSimpleName() + " name must not be empty on a class unless it has an argument.", - klass, - commandClass - ); - } - - } - } - - private void collectMethodSubCommands( - final @NotNull dev.triumphteam.cmd.core.Command command, - final @NotNull Class klass, - final @NotNull Function invokerFunction - ) { - // Method sub commands - for (final Method method : klass.getDeclaredMethods()) { - // TODO: ALLOW PRIVATE - if (Modifier.isPrivate(method.getModifiers())) continue; - - final Invoker invoker = invokerFunction.apply(method); - - final P processor = createSubProcessor(method); - final String subCommandName = processor.getName(); - // Not a command - if (subCommandName == null) continue; - - if (subCommandName.isEmpty()) { - throw new SubCommandRegistrationException( - "@" + dev.triumphteam.cmd.core.annotation.SubCommand.class.getSimpleName() + " name must not be empty", - method, - klass - ); - } - - final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider; - - final SC subCommand = createSubCommand(processor, executionProvider); - command.addSubCommand(subCommandName, subCommand); - - processor.getAlias().forEach(alias -> command.addSubCommandAlias(alias, subCommand)); - } + this.name = name; + this.alias = aliasOf(baseCommand); + this.description = descriptionOf(baseCommand); } - protected abstract @NotNull P createSubProcessor(final @NotNull AnnotatedElement method); - - protected abstract @NotNull SC createSubCommand(final @NotNull P processor, final @NotNull ExecutionProvider executionProvider); - - /** - * Used for the child processors to get the command name. - * - * @return The command name. - */ - public @NotNull String getName() { + public String getName() { return name; } - /** - * Used for the child processors to get a {@link List} with the command's alias. - * - * @return The command alias. - */ - public @NotNull List<@NotNull String> getAlias() { + public List getAlias() { return alias; } - // TODO: Comments - public @NotNull RegistryContainer getRegistryContainer() { - return registryContainer; - } - - /** - * Gets the {@link SenderMapper}. - * - * @return The {@link SenderMapper}. - */ - public @NotNull SenderMapper getSenderMapper() { - return senderMapper; - } - - // TODO: 2/4/2022 comments - public @NotNull SenderValidator getSenderValidator() { - return senderValidator; - } - - public @NotNull ExecutionProvider getSyncExecutionProvider() { - return syncExecutionProvider; - } - - public @NotNull ExecutionProvider getAsyncExecutionProvider() { - return asyncExecutionProvider; - } - - /** - * gets the Description of the SubCommand. - * - * @return either the extracted Description or the default one. - */ - public @NotNull String getDescription() { + public String getDescription() { return description; } - - /** - * Helper method for getting the command names from the command annotation. - */ - private void extractCommandNames() { - final Command commandAnnotation = commandClass.getAnnotation(Command.class); - - if (commandAnnotation == null) { - final String commandName = baseCommand.getCommand(); - if (commandName == null) { - throw new CommandRegistrationException("Command name or \"@" + Command.class.getSimpleName() + "\" annotation missing", baseCommand.getClass()); - } - - name = commandName; - alias.addAll(baseCommand.getAlias()); - } else { - name = commandAnnotation.value(); - Collections.addAll(alias, commandAnnotation.alias()); - } - - alias.addAll(baseCommand.getAlias()); - - if (name.isEmpty()) { - throw new CommandRegistrationException("Command name must not be empty", baseCommand.getClass()); - } - } - - /** - * Extracts the {@link Description} Annotation from the annotatedClass. - */ - private void extractDescription() { - final Description description = baseCommand.getClass().getAnnotation(Description.class); - if (description == null) return; - this.description = description.value(); - } - } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java new file mode 100644 index 00000000..b027a22c --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java @@ -0,0 +1,70 @@ +package dev.triumphteam.cmd.core.processor; + +import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.annotation.Command; +import dev.triumphteam.cmd.core.annotation.Description; +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +public final class Commands { + + private Commands() { + throw new AssertionError("Class cannot be instantiated."); + } + + /** + * Gets the name of the given {@link BaseCommand}. + * + * @param baseCommand The instance of the {@link BaseCommand}. + * @return The name of the command. + */ + public static @NotNull String nameOf(final @NotNull BaseCommand baseCommand) { + final Class commandClass = baseCommand.getClass(); + final Command commandAnnotation = commandClass.getAnnotation(Command.class); + + final String name; + if (commandAnnotation == null) { + final String commandName = baseCommand.getCommand(); + if (commandName == null) { + throw new CommandRegistrationException("Command name or \"@" + Command.class.getSimpleName() + "\" annotation missing", baseCommand.getClass()); + } + + name = commandName; + } else { + name = commandAnnotation.value(); + } + + if (name.isEmpty()) { + throw new CommandRegistrationException("Command name must not be empty", baseCommand.getClass()); + } + + return name; + } + + /** + * Gets the alias of the given {@link BaseCommand}. + * + * @param baseCommand The instance of the {@link BaseCommand}. + * @return The alias of the command. + */ + public static @NotNull List aliasOf(final @NotNull BaseCommand baseCommand) { + final Command commandAnnotation = baseCommand.getClass().getAnnotation(Command.class); + return commandAnnotation == null ? baseCommand.getAlias() : Arrays.asList(commandAnnotation.alias()); + } + + /** + * Gets the alias of the given {@link BaseCommand}. + * + * @param baseCommand The instance of the {@link BaseCommand}. + * @return The alias of the command. + */ + public static @NotNull String descriptionOf(final @NotNull BaseCommand baseCommand) { + final Description commandAnnotation = baseCommand.getClass().getAnnotation(Description.class); + return commandAnnotation == null ? baseCommand.getDescription() : commandAnnotation.value(); + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java new file mode 100644 index 00000000..8ed5224e --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java @@ -0,0 +1,267 @@ +/** + * MIT License + *

+ * Copyright (c) 2019-2021 Matt + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.processor; + +import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.annotation.Command; +import dev.triumphteam.cmd.core.annotation.Description; +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; +import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; +import dev.triumphteam.cmd.core.execution.ExecutionProvider; +import dev.triumphteam.cmd.core.registry.RegistryContainer; +import dev.triumphteam.cmd.core.sender.SenderMapper; +import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.subcommand.SubCommand; +import dev.triumphteam.cmd.core.subcommand.invoker.Invoker; +import dev.triumphteam.cmd.core.subcommand.invoker.MethodInvoker; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Supplier; + +/** + * Abstracts most of the "extracting" from command annotations, allows for extending. + *
+ * I know this could be done better, but couldn't think of a better way. + * If you do please PR or let me know on my discord! + * + * @param Sender type + */ +public abstract class OldAbstractCommandProcessor, P extends OldAbstractSubCommandProcessor> { + + private String name; + // TODO: 11/28/2021 Add better default description + private String description = "No description provided."; + private final List alias = new ArrayList<>(); + private final Map subCommands = new HashMap<>(); + private final Map subCommandsAlias = new HashMap<>(); + + private final Class commandClass; + private final Supplier instanceSupplier; + private final RegistryContainer registryContainer; + private final SenderMapper senderMapper; + private final SenderValidator senderValidator; + + private final ExecutionProvider syncExecutionProvider; + private final ExecutionProvider asyncExecutionProvider; + + protected OldAbstractCommandProcessor( + final @NotNull Class commandClass, + final @NotNull Supplier instanceSupplier, + final @NotNull RegistryContainer registryContainer, + final @NotNull SenderMapper senderMapper, + final @NotNull SenderValidator senderValidator, + final @NotNull ExecutionProvider syncExecutionProvider, + final @NotNull ExecutionProvider asyncExecutionProvider + ) { + this.commandClass = commandClass; + this.instanceSupplier = instanceSupplier; + this.registryContainer = registryContainer; + this.senderMapper = senderMapper; + this.senderValidator = senderValidator; + this.syncExecutionProvider = syncExecutionProvider; + this.asyncExecutionProvider = asyncExecutionProvider; + + extractCommandNames(); + extractDescription(); + } + + // TODO: Comments + public void addSubCommands(final @NotNull dev.triumphteam.cmd.core.Command command) { + // Method sub commands + collectMethodSubCommands(command, commandClass, method -> new MethodInvoker(instanceSupplier, method)); + + // Classes sub commands + for (final Class klass : commandClass.getDeclaredClasses()) { + final List> constructors = Arrays.asList(klass.getDeclaredConstructors()); + + if (constructors.size() != 1) { + throw new SubCommandRegistrationException("TODO constructs", null, null); + } + + final Constructor constructor = constructors.get(0); + + final boolean isStatic = Modifier.isStatic(klass.getModifiers()); + final int argsSize = isStatic ? constructor.getParameterCount() : constructor.getParameterCount() - 1; + + if (argsSize > 1) { + throw new SubCommandRegistrationException("TODO params", null, null); + } + + final boolean hasArg = argsSize > 0; + + final P processor = createSubProcessor(klass); + final String subCommandName = processor.getName(); + // Not a command + if (subCommandName == null) continue; + // If the name is empty and there is no arguments + if (subCommandName.isEmpty() && !hasArg) { + throw new SubCommandRegistrationException( + "@" + Command.class.getSimpleName() + " name must not be empty on a class unless it has an argument.", + klass, + commandClass + ); + } + + } + } + + private void collectMethodSubCommands( + final @NotNull dev.triumphteam.cmd.core.Command command, + final @NotNull Class klass, + final @NotNull Function invokerFunction + ) { + // Method sub commands + for (final Method method : klass.getDeclaredMethods()) { + // TODO: ALLOW PRIVATE + if (Modifier.isPrivate(method.getModifiers())) continue; + + final Invoker invoker = invokerFunction.apply(method); + + final P processor = createSubProcessor(method); + final String subCommandName = processor.getName(); + // Not a command + if (subCommandName == null) continue; + + if (subCommandName.isEmpty()) { + throw new SubCommandRegistrationException( + "@" + dev.triumphteam.cmd.core.annotation.SubCommand.class.getSimpleName() + " name must not be empty", + method, + klass + ); + } + + final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider; + + final SC subCommand = createSubCommand(processor, executionProvider); + command.addSubCommand(subCommandName, subCommand); + + processor.getAlias().forEach(alias -> command.addSubCommandAlias(alias, subCommand)); + } + } + + protected abstract @NotNull P createSubProcessor(final @NotNull AnnotatedElement method); + + protected abstract @NotNull SC createSubCommand(final @NotNull P processor, final @NotNull ExecutionProvider executionProvider); + + /** + * Used for the child processors to get the command name. + * + * @return The command name. + */ + public @NotNull String getName() { + return name; + } + + /** + * Used for the child processors to get a {@link List} with the command's alias. + * + * @return The command alias. + */ + public @NotNull List<@NotNull String> getAlias() { + return alias; + } + + // TODO: Comments + public @NotNull RegistryContainer getRegistryContainer() { + return registryContainer; + } + + /** + * Gets the {@link SenderMapper}. + * + * @return The {@link SenderMapper}. + */ + public @NotNull SenderMapper getSenderMapper() { + return senderMapper; + } + + // TODO: 2/4/2022 comments + public @NotNull SenderValidator getSenderValidator() { + return senderValidator; + } + + public @NotNull ExecutionProvider getSyncExecutionProvider() { + return syncExecutionProvider; + } + + public @NotNull ExecutionProvider getAsyncExecutionProvider() { + return asyncExecutionProvider; + } + + /** + * gets the Description of the SubCommand. + * + * @return either the extracted Description or the default one. + */ + public @NotNull String getDescription() { + return description; + } + + /** + * Helper method for getting the command names from the command annotation. + */ + private void extractCommandNames() { + final Command commandAnnotation = commandClass.getAnnotation(Command.class); + + if (commandAnnotation == null) { + final String commandName = baseCommand.getCommand(); + if (commandName == null) { + throw new CommandRegistrationException("Command name or \"@" + Command.class.getSimpleName() + "\" annotation missing", baseCommand.getClass()); + } + + name = commandName; + alias.addAll(baseCommand.getAlias()); + } else { + name = commandAnnotation.value(); + Collections.addAll(alias, commandAnnotation.alias()); + } + + alias.addAll(baseCommand.getAlias()); + + if (name.isEmpty()) { + throw new CommandRegistrationException("Command name must not be empty", baseCommand.getClass()); + } + } + + /** + * Extracts the {@link Description} Annotation from the annotatedClass. + */ + private void extractDescription() { + final Description description = baseCommand.getClass().getAnnotation(Description.class); + if (description == null) return; + this.description = description.value(); + } + +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java similarity index 99% rename from core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java rename to core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java index a668d42d..814ab5fe 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java @@ -30,6 +30,7 @@ import dev.triumphteam.cmd.core.annotation.ArgName; import dev.triumphteam.cmd.core.annotation.Async; import dev.triumphteam.cmd.core.annotation.CommandFlags; +import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.annotation.Description; import dev.triumphteam.cmd.core.annotation.Flag; import dev.triumphteam.cmd.core.annotation.Join; @@ -109,7 +110,7 @@ * @param The sender type. */ @SuppressWarnings("unchecked") -public abstract class AbstractSubCommandProcessor { +public abstract class OldAbstractSubCommandProcessor { private final BaseCommand baseCommand; private final String parentName; @@ -142,7 +143,7 @@ public abstract class AbstractSubCommandProcessor { private static final Set> COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); - protected AbstractSubCommandProcessor( + protected OldAbstractSubCommandProcessor( final @NotNull BaseCommand baseCommand, final @NotNull String parentName, final @NotNull AnnotatedElement annotatedElement, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java index a6bbf47e..987a1fec 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java @@ -33,7 +33,7 @@ import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; -import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; +import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; import dev.triumphteam.cmd.core.requirement.Requirement; import dev.triumphteam.cmd.core.sender.SenderValidator; import org.jetbrains.annotations.NotNull; @@ -78,7 +78,7 @@ public abstract class SubCommand { private final boolean containsLimitless; public SubCommand( - @NotNull final AbstractSubCommandProcessor processor, + @NotNull final OldAbstractSubCommandProcessor processor, @NotNull final String parentName, @NotNull final ExecutionProvider executionProvider ) { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java index a777a8e7..3241800d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java @@ -3,7 +3,7 @@ import dev.triumphteam.cmd.core.Command; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; +import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; import org.jetbrains.annotations.NotNull; import java.util.Map; @@ -11,7 +11,7 @@ public class SubCommandHolder extends SubCommand implements Command> { public SubCommandHolder( - final @NotNull AbstractSubCommandProcessor processor, + final @NotNull OldAbstractSubCommandProcessor processor, final @NotNull String parentName, final @NotNull ExecutionProvider executionProvider ) { diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java index fbd98783..7b15cc47 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java @@ -25,7 +25,7 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.processor.AbstractCommandProcessor; +import dev.triumphteam.cmd.core.processor.OldAbstractCommandProcessor; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; @@ -34,14 +34,13 @@ import org.jetbrains.annotations.NotNull; import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Method; /** * Processor for Prefixed JDA platform specific code. * * @param The sender type. */ -final class PrefixedCommandProcessor extends AbstractCommandProcessor, PrefixedSubCommandProcessor> { +final class PrefixedCommandProcessor extends OldAbstractCommandProcessor, PrefixedSubCommandProcessor> { private final String prefix; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java index f41f9da8..80f1d997 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java @@ -25,7 +25,7 @@ import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; +import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,7 +34,7 @@ final class PrefixedSubCommand extends SubCommand { public PrefixedSubCommand( - final @NotNull AbstractSubCommandProcessor processor, + final @NotNull OldAbstractSubCommandProcessor processor, final @NotNull String parentName, final @NotNull ExecutionProvider executionProvider ) { diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java index 5004ea9d..1a36ae02 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.prefixed; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; +import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderValidator; import org.jetbrains.annotations.NotNull; @@ -36,7 +36,7 @@ * * @param The sender type. */ -final class PrefixedSubCommandProcessor extends AbstractSubCommandProcessor { +final class PrefixedSubCommandProcessor extends OldAbstractSubCommandProcessor { public PrefixedSubCommandProcessor( final @NotNull BaseCommand baseCommand, diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java index a853c8f6..f71c9328 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java @@ -25,7 +25,7 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.processor.AbstractCommandProcessor; +import dev.triumphteam.cmd.core.processor.OldAbstractCommandProcessor; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; import dev.triumphteam.cmd.jda.annotation.Privileges; @@ -37,7 +37,6 @@ import org.jetbrains.annotations.Nullable; import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -49,7 +48,7 @@ * @param The sender type. */ final class SlashCommandProcessor - extends AbstractCommandProcessor, SlashSubCommandProcessor> { + extends OldAbstractCommandProcessor, SlashSubCommandProcessor> { private final ChoiceRegistry choiceRegistry; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java index d571c416..c6350f9e 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java @@ -26,7 +26,7 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.command.argument.InternalArgument; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; +import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; import dev.triumphteam.cmd.core.sender.SenderValidator; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.slash.annotation.Choices; @@ -57,7 +57,7 @@ * * @param The sender type. */ -final class SlashSubCommandProcessor extends AbstractSubCommandProcessor { +final class SlashSubCommandProcessor extends OldAbstractSubCommandProcessor { private final ChoiceRegistry choiceRegistry; private final AttachmentRegistry attachmentRegistry; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index fd091a52..da7aba52 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -31,6 +31,7 @@ import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import dev.triumphteam.cmd.core.sender.SenderMapper; +import dev.triumphteam.cmd.core.subcommand.SubCommand; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; @@ -42,35 +43,26 @@ import static java.util.Collections.emptyList; -public final class BukkitCommand extends org.bukkit.command.Command implements Command> { - - private final MessageRegistry messageRegistry; +public final class BukkitCommand extends org.bukkit.command.Command implements Command { private final SenderMapper senderMapper; + private final MessageRegistry messageRegistry; - private final Map> subCommands = new HashMap<>(); - private final Map> subCommandAliases = new HashMap<>(); - - public BukkitCommand(final @NotNull String name, final @NotNull BukkitCommandProcessor processor) { - super(name); + public BukkitCommand( + final @NotNull BukkitCommandProcessor processor, + final @NotNull SenderMapper senderMapper, + final @NotNull MessageRegistry messageRegistry + ) { + super(processor.getName()); this.description = processor.getDescription(); - this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); - this.senderMapper = processor.getSenderMapper(); - } - - @Override - public void addSubCommand(final @NotNull String name, final @NotNull BukkitSubCommand subCommand) { - subCommands.putIfAbsent(name, subCommand); - } - - @Override - public void addSubCommandAlias(final @NotNull String alias, final @NotNull BukkitSubCommand subCommand) { - subCommandAliases.putIfAbsent(alias, subCommand); + this.senderMapper = senderMapper; + this.messageRegistry = messageRegistry; } /** * {@inheritDoc} + * * @throws CommandExecutionException If the sender mapper returns null. */ @Override @@ -79,67 +71,40 @@ public boolean execute( final @NotNull String commandLabel, final @NotNull String @NotNull [] args ) { - BukkitSubCommand subCommand = getDefaultSubCommand(); + final List arguments = Arrays.asList(args); + final int argumentSize = arguments.size(); - String subCommandName = ""; - if (args.length > 0) subCommandName = args[0].toLowerCase(); - if (subCommand == null || subCommandExists(subCommandName)) { - subCommand = getSubCommand(subCommandName); - } + final SubCommand subCommand = getSubCommand(arguments); final S mappedSender = senderMapper.map(sender); if (mappedSender == null) { throw new CommandExecutionException("Invalid sender. Sender mapper returned null"); } - if (subCommand == null || (args.length > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { - messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, mappedSender, new DefaultMessageContext(getName(), subCommandName)); + if (subCommand == null || (argumentSize > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { + final String name = argumentSize == 0 ? dev.triumphteam.cmd.core.annotation.Command.DEFAULT_CMD_NAME : arguments.get(0); + messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, mappedSender, new DefaultMessageContext(getName(), name)); return true; } - final CommandPermission permission = subCommand.getPermission(); + // TODO: Better command check that is more abstracted + /*final CommandPermission permission = subCommand.getPermission(); if (!CommandPermission.hasPermission(sender, permission)) { messageRegistry.sendMessage(BukkitMessageKey.NO_PERMISSION, mappedSender, new NoPermissionMessageContext(getName(), subCommand.getName(), permission)); return true; - } + }*/ - final List commandArgs = Arrays.asList(!subCommand.isDefault() ? Arrays.copyOfRange(args, 1, args.length) : args); - - subCommand.execute(mappedSender, commandArgs); + subCommand.execute(mappedSender, !subCommand.isDefault() ? arguments.subList(1, argumentSize) : arguments); return true; } @Override - public @NotNull List<@NotNull String> tabComplete(final @NotNull CommandSender sender, final @NotNull String alias, final @NotNull String @NotNull [] args) throws IllegalArgumentException { - if (args.length == 0) return emptyList(); - BukkitSubCommand subCommand = getDefaultSubCommand(); - - final String arg = args[0].toLowerCase(); - - if (args.length == 1 && (subCommand == null || !subCommand.hasArguments())) { - return subCommands.entrySet().stream() - .filter(it -> !it.getValue().isDefault()) - .filter(it -> it.getKey().startsWith(arg)) - .filter(it -> { - final CommandPermission permission = it.getValue().getPermission(); - return CommandPermission.hasPermission(sender, permission); - }) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); - } - - if (subCommandExists(arg)) subCommand = getSubCommand(arg); - if (subCommand == null) return emptyList(); - - final CommandPermission permission = subCommand.getPermission(); - if (!CommandPermission.hasPermission(sender, permission)) return emptyList(); - - final S mappedSender = senderMapper.map(sender); - if (mappedSender == null) { - return emptyList(); - } + public @NotNull Map> getSubCommands() { + return null; + } - final List commandArgs = Arrays.asList(args); - return subCommand.getSuggestions(mappedSender, !subCommand.isDefault() ? commandArgs.subList(1, commandArgs.size()) : commandArgs); + @Override + public @NotNull Map> getSubCommandAlias() { + return null; } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index 6cade5eb..0c89fb60 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -51,6 +51,8 @@ import java.util.*; import java.util.stream.Collectors; +import static dev.triumphteam.cmd.core.processor.Commands.nameOf; + public final class BukkitCommandManager extends CommandManager { private final Plugin plugin; @@ -125,24 +127,26 @@ private BukkitCommandManager( @Override public void registerCommand(final @NotNull BaseCommand baseCommand) { - final BukkitCommandProcessor processor = new BukkitCommandProcessor<>( - baseCommand, - registryContainer, - getSenderMapper(), - getSenderValidator(), - syncExecutionProvider, - asyncExecutionProvider, - basePermission - ); + final String name = nameOf(baseCommand); + + final BukkitCommand command = commands.get(name); + if (command != null) { + // TODO: Command exists, only care about adding subs + return; + } + + // Command does not exist, proceed to add new! + + final BukkitCommandProcessor processor = new BukkitCommandProcessor<>(name, baseCommand, basePermission); + + final BukkitCommand newCommand = commands.computeIfAbsent(processor.getName(), it -> createAndRegisterCommand(it, processor)); - final BukkitCommand command = commands.computeIfAbsent(processor.getName(), ignored -> createAndRegisterCommand(processor.getName(), processor)); - // Adding sub commands. - processor.addSubCommands(command); + // TODO: ADD SUBCOMMANDS processor.getAlias().forEach(it -> { final BukkitCommand aliasCommand = commands.computeIfAbsent(it, ignored -> createAndRegisterCommand(it, processor)); // Adding sub commands. - processor.addSubCommands(aliasCommand); + // TODO: ADD SUBCOMMANDS }); } @@ -165,7 +169,7 @@ public void unregisterCommand(final @NotNull BaseCommand command) { oldCommand.unregister(commandMap); } - final BukkitCommand newCommand = new BukkitCommand<>(name, processor); + final BukkitCommand newCommand = new BukkitCommand<>(processor, getSenderMapper(), registryContainer.getMessageRegistry()); commandMap.register(plugin.getName(), newCommand); return newCommand; } @@ -191,7 +195,7 @@ private static void setUpDefaults(final @NotNull BukkitCommandManager getBukkitCommands(final @NotNull CommandMap commandMap) { + private static @NotNull Map<@NotNull String, org.bukkit.command.@NotNull Command> getBukkitCommands(final @NotNull CommandMap commandMap) { try { final Field bukkitCommands = SimpleCommandMap.class.getDeclaredField("knownCommands"); bukkitCommands.setAccessible(true); diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java index c7e23d95..ea2fc2fd 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -27,6 +27,7 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.processor.AbstractCommandProcessor; +import dev.triumphteam.cmd.core.processor.OldAbstractCommandProcessor; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; @@ -35,27 +36,22 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Method; import java.util.*; import java.util.stream.Collectors; import java.lang.reflect.AnnotatedElement; -final class BukkitCommandProcessor extends AbstractCommandProcessor, BukkitSubCommandProcessor> { +final class BukkitCommandProcessor extends AbstractCommandProcessor { private final CommandPermission basePermission; public BukkitCommandProcessor( + final @NotNull String name, final @NotNull BaseCommand baseCommand, - final @NotNull RegistryContainer registryContainer, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator, - final @NotNull ExecutionProvider syncExecutionProvider, - final @NotNull ExecutionProvider asyncExecutionProvider, final @Nullable CommandPermission globalBasePermission ) { - super(baseCommand, registryContainer, senderMapper, senderValidator, syncExecutionProvider, asyncExecutionProvider); + super(name, baseCommand); - final Permission annotation = getBaseCommand().getClass().getAnnotation(Permission.class); + final Permission annotation = baseCommand.getClass().getAnnotation(Permission.class); if (annotation == null) { this.basePermission = null; return; @@ -69,24 +65,8 @@ public BukkitCommandProcessor( ); } - @Override - protected @NotNull BukkitSubCommandProcessor createSubProcessor(final @NotNull AnnotatedElement method) { - return new BukkitSubCommandProcessor<>( - getBaseCommand(), - getName(), - method, - getRegistryContainer(), - getSenderValidator(), - basePermission - ); - } - - @Override - protected @NotNull BukkitSubCommand createSubCommand( - final @NotNull BukkitSubCommandProcessor processor, - final @NotNull ExecutionProvider executionProvider - ) { - return new BukkitSubCommand<>(processor, getName(), executionProvider); + public CommandPermission getBasePermission() { + return basePermission; } static CommandPermission createPermission( diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java index 4deff682..5df1d74a 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java @@ -25,18 +25,17 @@ import dev.triumphteam.cmd.bukkit.annotation.Permission; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; +import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderValidator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Method; import java.util.Arrays; import java.util.stream.Collectors; import java.lang.reflect.AnnotatedElement; -final class BukkitSubCommandProcessor extends AbstractSubCommandProcessor { +final class BukkitSubCommandProcessor extends OldAbstractSubCommandProcessor { private final CommandPermission permission; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java new file mode 100644 index 00000000..89d0ba87 --- /dev/null +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java @@ -0,0 +1,145 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.bukkit; + +import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; +import dev.triumphteam.cmd.bukkit.message.NoPermissionMessageContext; +import dev.triumphteam.cmd.core.Command; +import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; +import dev.triumphteam.cmd.core.sender.SenderMapper; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static java.util.Collections.emptyList; + +public final class OldBukkitCommand extends org.bukkit.command.Command implements Command> { + + private final MessageRegistry messageRegistry; + + private final SenderMapper senderMapper; + + private final Map> subCommands = new HashMap<>(); + private final Map> subCommandAliases = new HashMap<>(); + + public OldBukkitCommand(final @NotNull String name, final @NotNull BukkitCommandProcessor processor) { + super(name); + + this.description = processor.getDescription(); + this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); + this.senderMapper = processor.getSenderMapper(); + } + + @Override + public void addSubCommand(final @NotNull String name, final @NotNull BukkitSubCommand subCommand) { + subCommands.putIfAbsent(name, subCommand); + } + + @Override + public void addSubCommandAlias(final @NotNull String alias, final @NotNull BukkitSubCommand subCommand) { + subCommandAliases.putIfAbsent(alias, subCommand); + } + + /** + * {@inheritDoc} + * @throws CommandExecutionException If the sender mapper returns null. + */ + @Override + public boolean execute( + final @NotNull CommandSender sender, + final @NotNull String commandLabel, + final @NotNull String @NotNull [] args + ) { + BukkitSubCommand subCommand = getDefaultSubCommand(); + + String subCommandName = ""; + if (args.length > 0) subCommandName = args[0].toLowerCase(); + if (subCommand == null || subCommandExists(subCommandName)) { + subCommand = getSubCommand(subCommandName); + } + + final S mappedSender = senderMapper.map(sender); + if (mappedSender == null) { + throw new CommandExecutionException("Invalid sender. Sender mapper returned null"); + } + + if (subCommand == null || (args.length > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { + messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, mappedSender, new DefaultMessageContext(getName(), subCommandName)); + return true; + } + + final CommandPermission permission = subCommand.getPermission(); + if (!CommandPermission.hasPermission(sender, permission)) { + messageRegistry.sendMessage(BukkitMessageKey.NO_PERMISSION, mappedSender, new NoPermissionMessageContext(getName(), subCommand.getName(), permission)); + return true; + } + + final List commandArgs = Arrays.asList(!subCommand.isDefault() ? Arrays.copyOfRange(args, 1, args.length) : args); + + subCommand.execute(mappedSender, commandArgs); + return true; + } + + @Override + public @NotNull List<@NotNull String> tabComplete(final @NotNull CommandSender sender, final @NotNull String alias, final @NotNull String @NotNull [] args) throws IllegalArgumentException { + if (args.length == 0) return emptyList(); + BukkitSubCommand subCommand = getDefaultSubCommand(); + + final String arg = args[0].toLowerCase(); + + if (args.length == 1 && (subCommand == null || !subCommand.hasArguments())) { + return subCommands.entrySet().stream() + .filter(it -> !it.getValue().isDefault()) + .filter(it -> it.getKey().startsWith(arg)) + .filter(it -> { + final CommandPermission permission = it.getValue().getPermission(); + return CommandPermission.hasPermission(sender, permission); + }) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + } + + if (subCommandExists(arg)) subCommand = getSubCommand(arg); + if (subCommand == null) return emptyList(); + + final CommandPermission permission = subCommand.getPermission(); + if (!CommandPermission.hasPermission(sender, permission)) return emptyList(); + + final S mappedSender = senderMapper.map(sender); + if (mappedSender == null) { + return emptyList(); + } + + final List commandArgs = Arrays.asList(args); + return subCommand.getSuggestions(mappedSender, !subCommand.isDefault() ? commandArgs.subList(1, commandArgs.size()) : commandArgs); + } +} diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index 80af847d..7dac8fc8 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,6 +24,7 @@ package dev.triumphteam.cmds.simple; import dev.triumphteam.cmd.core.Command; +import dev.triumphteam.cmd.core.annotation.Default; import dev.triumphteam.cmd.core.subcommand.SubCommand; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.execution.ExecutionProvider; @@ -36,113 +37,55 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; -public final class SimpleCommand implements Command> { +public final class SimpleCommand implements Command { private final String name; - private final RegistryContainer registries; private final MessageRegistry messageRegistry; - private final SenderMapper senderMapper; - private final SenderValidator senderValidator; - - private final ExecutionProvider syncExecutionProvider; - private final ExecutionProvider asyncExecutionProvider; - - private final Map> subCommands = new HashMap<>(); - private final Map> subCommandAliases = new HashMap<>(); + private final Map> subCommands = new HashMap<>(); + private final Map> subCommandAliases = new HashMap<>(); @SuppressWarnings("unchecked") public SimpleCommand( - final @NotNull SimpleCommandProcessor processor, - final @NotNull ExecutionProvider syncExecutionProvider, - final @NotNull ExecutionProvider asyncExecutionProvider + final @NotNull SimpleCommandProcessor processor, + final @NotNull MessageRegistry messageRegistry ) { this.name = processor.getName(); - this.senderMapper = processor.getSenderMapper(); - this.senderValidator = processor.getSenderValidator(); - this.registries = processor.getRegistryContainer(); - this.messageRegistry = registries.getMessageRegistry(); - this.syncExecutionProvider = syncExecutionProvider; - this.asyncExecutionProvider = asyncExecutionProvider; + this.messageRegistry = messageRegistry; } // TODO: Comments public void execute( final @NotNull S sender, - final @NotNull List<@NotNull String> args + final @NotNull List<@NotNull String> arguments ) { - SimpleSubCommand subCommand = getDefaultSubCommand(); - - String subCommandName = ""; - if (args.size() > 0) subCommandName = args.get(0).toLowerCase(); - if (subCommand == null || subCommandExists(subCommandName)) { - subCommand = getSubCommand(subCommandName); - } + final int argumentSize = arguments.size(); - final S mappedSender = senderMapper.map(sender); - if (mappedSender == null) { - throw new CommandExecutionException("Invalid sender. Sender mapper returned null"); - } + final SubCommand subCommand = getSubCommand(arguments); - if (subCommand == null) { - messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, mappedSender, new DefaultMessageContext(name, subCommandName)); + if (subCommand == null || (argumentSize > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { + final String name = argumentSize == 0 ? dev.triumphteam.cmd.core.annotation.Command.DEFAULT_CMD_NAME : arguments.get(0); + messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new DefaultMessageContext(this.name, name)); return; } - final List commandArgs = !subCommand.isDefault() ? args.subList(1, args.size()) : args; - subCommand.execute(mappedSender, commandArgs); - } - - /** - * Gets a default command if present. - * - * @return A default SubCommand. - */ - private @Nullable SimpleSubCommand getDefaultSubCommand() { - return subCommands.get(Default.DEFAULT_CMD_NAME); - } - - /** - * Used in order to search for the given {@link SubCommand} in the {@link #subCommandAliases} - * - * @param key the String to look for the {@link SubCommand} - * @return the {@link SubCommand} for the particular key or NULL - */ - private @Nullable SimpleSubCommand getSubCommand(final @NotNull String key) { - final SimpleSubCommand subCommand = subCommands.get(key); - if (subCommand != null) return subCommand; - return subCommandAliases.get(key); - } - - /** - * Checks if a SubCommand with the specified key exists. - * - * @param key the Key to check for - * @return whether a SubCommand with that key exists - */ - private boolean subCommandExists(final @NotNull String key) { - return subCommands.containsKey(key) || subCommandAliases.containsKey(key); + subCommand.execute(sender, !subCommand.isDefault() ? arguments.subList(1, argumentSize) : arguments); } - /** - * {@inheritDoc} - */ @Override - public void addSubCommand(final @NotNull String name, final @NotNull SimpleSubCommand subCommand) { - this.subCommands.put(name, subCommand); + public @NotNull Map> getSubCommands() { + return subCommands; } - /** - * {@inheritDoc} - */ @Override - public void addSubCommandAlias(final @NotNull String alias, final @NotNull SimpleSubCommand subCommand) { - this.subCommandAliases.put(alias, subCommand); + public @NotNull Map> getSubCommandAlias() { + return subCommandAliases; } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index da5e81de..04330e59 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -40,6 +40,8 @@ import java.util.List; import java.util.Map; +import static dev.triumphteam.cmd.core.processor.Commands.nameOf; + public final class SimpleCommandManager extends CommandManager { private final Map> commands = new HashMap<>(); @@ -66,31 +68,26 @@ private SimpleCommandManager( @Override public void registerCommand(final @NotNull BaseCommand baseCommand) { - final SimpleCommandProcessor processor = new SimpleCommandProcessor<>( - baseCommand.getClass(), - () -> baseCommand, - getRegistryContainer(), - getSenderMapper(), - getSenderValidator(), - syncExecutionProvider, - asyncExecutionProvider - ); - - final String name = processor.getName(); - - final SimpleCommand command = commands.computeIfAbsent( - name, - ignored -> new SimpleCommand<>(processor, syncExecutionProvider, asyncExecutionProvider) - ); - processor.addSubCommands(command); + final String name = nameOf(baseCommand); + + final SimpleCommand command = commands.get(name); + if (command != null) { + // TODO: Command exists, only care about adding subs + return; + } + + // Command does not exist, proceed to add new! + + final SimpleCommandProcessor processor = new SimpleCommandProcessor(name, baseCommand); + + final SimpleCommand newCommand = commands.computeIfAbsent(processor.getName(), it -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); + + // TODO: ADD SUBCOMMANDS processor.getAlias().forEach(it -> { - final SimpleCommand aliasCommand = commands.computeIfAbsent( - it, - ignored -> new SimpleCommand<>(processor, syncExecutionProvider, asyncExecutionProvider) - ); + final SimpleCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); // Adding sub commands. - processor.addSubCommands(aliasCommand); + // TODO: ADD SUBCOMMANDS }); } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java index 73cbfe55..e1dc13eb 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java @@ -26,6 +26,7 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.processor.AbstractCommandProcessor; +import dev.triumphteam.cmd.core.processor.OldAbstractCommandProcessor; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; @@ -35,39 +36,12 @@ import java.lang.reflect.Method; import java.util.function.Supplier; -public final class SimpleCommandProcessor extends AbstractCommandProcessor, SimpleSubCommandProcessor> { +public final class SimpleCommandProcessor extends AbstractCommandProcessor { public SimpleCommandProcessor( - final @NotNull Class commandClass, - final @NotNull Supplier instanceSupplier, - final @NotNull RegistryContainer registries, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator, - final @NotNull ExecutionProvider syncExecutionProvider, - final @NotNull ExecutionProvider asyncExecutionProvider + final @NotNull String name, + final @NotNull BaseCommand baseCommand ) { - super(commandClass, instanceSupplier, registries, senderMapper, senderValidator, syncExecutionProvider, asyncExecutionProvider); - } - - /** - * {@inheritDoc} - */ - @Override - protected @NotNull SimpleSubCommandProcessor createSubProcessor(final @NotNull AnnotatedElement method) { - return new SimpleSubCommandProcessor( - getBaseCommand(), - "", - (Method) method, - getRegistryContainer(), - getSenderValidator() - ); - } - - /** - * {@inheritDoc} - */ - @Override - protected @NotNull SimpleSubCommand createSubCommand(final @NotNull SimpleSubCommandProcessor processor, final @NotNull ExecutionProvider executionProvider) { - return new SimpleSubCommand<>(processor, getName(), executionProvider); + super(name, baseCommand); } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java index 3acdc31f..b6da39e3 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java @@ -39,10 +39,4 @@ public SimpleSubCommand( ) { super(processor, parentName, executionProvider); } - - // TODO: - @Override - public @Nullable Object resolve(@NotNull final S sender, final @NotNull List value) { - return null; - } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java index 1a90a8b5..7cb67bd0 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java @@ -24,14 +24,14 @@ package dev.triumphteam.cmds.simple; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.processor.AbstractSubCommandProcessor; +import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderValidator; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Method; -final class SimpleSubCommandProcessor extends AbstractSubCommandProcessor { +final class SimpleSubCommandProcessor extends OldAbstractSubCommandProcessor { public SimpleSubCommandProcessor( final @NotNull BaseCommand baseCommand, From 90f5bc13531cc9fdf82d28ba66a7b0132f219de9 Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Fri, 23 Dec 2022 01:33:21 +0000 Subject: [PATCH 012/101] chore: Make core and simple compilable --- .../OldAbstractCommandProcessor.java | 18 ++++---- .../cmd/core/subcommand/SubCommandHolder.java | 45 ------------------- 2 files changed, 8 insertions(+), 55 deletions(-) delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java index 8ed5224e..8c808d32 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java @@ -98,7 +98,7 @@ protected OldAbstractCommandProcessor( } // TODO: Comments - public void addSubCommands(final @NotNull dev.triumphteam.cmd.core.Command command) { + public void addSubCommands(final @NotNull dev.triumphteam.cmd.core.Command command) { // Method sub commands collectMethodSubCommands(command, commandClass, method -> new MethodInvoker(instanceSupplier, method)); @@ -138,7 +138,7 @@ public void addSubCommands(final @NotNull dev.triumphteam.cmd.core.Command command, + final @NotNull dev.triumphteam.cmd.core.Command command, final @NotNull Class klass, final @NotNull Function invokerFunction ) { @@ -165,9 +165,9 @@ private void collectMethodSubCommands( final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider; final SC subCommand = createSubCommand(processor, executionProvider); - command.addSubCommand(subCommandName, subCommand); + // command.addSubCommand(subCommandName, subCommand); - processor.getAlias().forEach(alias -> command.addSubCommandAlias(alias, subCommand)); + // processor.getAlias().forEach(alias -> command.addSubCommandAlias(alias, subCommand)); } } @@ -235,7 +235,7 @@ private void collectMethodSubCommands( private void extractCommandNames() { final Command commandAnnotation = commandClass.getAnnotation(Command.class); - if (commandAnnotation == null) { + /*if (commandAnnotation == null) { final String commandName = baseCommand.getCommand(); if (commandName == null) { throw new CommandRegistrationException("Command name or \"@" + Command.class.getSimpleName() + "\" annotation missing", baseCommand.getClass()); @@ -248,10 +248,10 @@ private void extractCommandNames() { Collections.addAll(alias, commandAnnotation.alias()); } - alias.addAll(baseCommand.getAlias()); + alias.addAll(baseCommand.getAlias());*/ if (name.isEmpty()) { - throw new CommandRegistrationException("Command name must not be empty", baseCommand.getClass()); + throw new CommandRegistrationException("Command name must not be empty", BaseCommand.class); } } @@ -259,9 +259,7 @@ private void extractCommandNames() { * Extracts the {@link Description} Annotation from the annotatedClass. */ private void extractDescription() { - final Description description = baseCommand.getClass().getAnnotation(Description.class); - if (description == null) return; - this.description = description.value(); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java deleted file mode 100644 index 3241800d..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommandHolder.java +++ /dev/null @@ -1,45 +0,0 @@ -package dev.triumphteam.cmd.core.subcommand; - -import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; - -public class SubCommandHolder extends SubCommand implements Command> { - - public SubCommandHolder( - final @NotNull OldAbstractSubCommandProcessor processor, - final @NotNull String parentName, - final @NotNull ExecutionProvider executionProvider - ) { - super(processor, parentName, executionProvider); - } - - @Override - public @NotNull Map> getSubCommands() { - return null; - } - - @Override - public @NotNull Map> getSubCommandAlias() { - return null; - } - - @Override - public @NotNull MessageRegistry getMessageRegistry() { - return null; - } - - @Override - public void addSubCommand(final @NotNull String name, final @NotNull SubCommand subCommand) { - - } - - @Override - public void addSubCommandAlias(final @NotNull String alias, final @NotNull SubCommand subCommand) { - - } -} From 6246ec1c8cd61eb4fd09cb6e0a0be8bdf61d724f Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Fri, 23 Dec 2022 13:16:41 +0000 Subject: [PATCH 013/101] feature: Tests are back baby --- .../cmd/core/processor/Commands.java | 2 +- .../kotlin/dev/triumphteam/tests/Sender.kt | 24 +++++++++ .../fail/command registration fail test.kt | 52 +++++++++++++++++++ 3 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt create mode 100644 simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java index b027a22c..ea3be669 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java @@ -39,7 +39,7 @@ private Commands() { name = commandAnnotation.value(); } - if (name.isEmpty()) { + if (name.isEmpty() || name.equals(Command.DEFAULT_CMD_NAME)) { throw new CommandRegistrationException("Command name must not be empty", baseCommand.getClass()); } diff --git a/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt b/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt new file mode 100644 index 00000000..a56a1233 --- /dev/null +++ b/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt @@ -0,0 +1,24 @@ +package dev.triumphteam.tests + +import dev.triumphteam.cmd.core.message.MessageRegistry +import dev.triumphteam.cmd.core.sender.SenderMapper +import dev.triumphteam.cmd.core.sender.SenderValidator +import dev.triumphteam.cmd.core.subcommand.SubCommand + +class TestSender + +class TestSenderMapper : SenderMapper { + + override fun map(defaultSender: TestSender): TestSender = defaultSender +} + +class TestSenderValidator : SenderValidator { + + override fun getAllowedSenders(): Set> = setOf(TestSender::class.java) + + override fun validate( + messageRegistry: MessageRegistry, + subCommand: SubCommand, + sender: TestSender, + ): Boolean = true +} diff --git a/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt b/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt new file mode 100644 index 00000000..72e63cf9 --- /dev/null +++ b/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt @@ -0,0 +1,52 @@ +package dev.triumphteam.tests.fail + +import dev.triumphteam.cmd.core.BaseCommand +import dev.triumphteam.cmd.core.annotation.Command +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException +import dev.triumphteam.cmds.simple.SimpleCommandManager +import dev.triumphteam.tests.TestSender +import dev.triumphteam.tests.TestSenderMapper +import dev.triumphteam.tests.TestSenderValidator +import org.assertj.core.api.Assertions.assertThatThrownBy +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.TestInstance + +@Suppress("ClassName") +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class `command registration fail test` { + + private val commandManager: SimpleCommandManager = + SimpleCommandManager.create(TestSenderMapper(), TestSenderValidator()) + + @Test + fun `no command registration fail`() { + assertThatThrownBy { + commandManager.registerCommand(NoCommand()) + }.isInstanceOf(CommandRegistrationException::class.java) + .hasMessageContaining("Command name or \"@${Command::class.java.simpleName}\" annotation missing") + } + + @Test + fun `empty command registration fail`() { + assertThatThrownBy { + commandManager.registerCommand(EmptyCommandAnnotation()) + println("test") + }.isInstanceOf(CommandRegistrationException::class.java) + .hasMessageContaining("Command name must not be empty") + } + + @Test + fun `empty extend command registration fail`() { + assertThatThrownBy { + commandManager.registerCommand(EmptyCommandSuper()) + }.isInstanceOf(CommandRegistrationException::class.java) + .hasMessageContaining("Command name must not be empty") + } +} + +class NoCommand : BaseCommand() + +@Command +class EmptyCommandAnnotation : BaseCommand() + +class EmptyCommandSuper : BaseCommand("") From 3c697b031ff8c058801a4ada08983ced1fc785c9 Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Fri, 23 Dec 2022 17:22:14 +0000 Subject: [PATCH 014/101] chore: Refactor --- .../dev/triumphteam/cmd/core/Command.java | 54 +- .../triumphteam/cmd/core/CommandManager.java | 6 +- .../argument/AbstractInternalArgument.java | 2 +- .../argument/ArgumentRegistry.java | 2 +- .../argument/ArgumentResolver.java | 2 +- .../argument/CollectionInternalArgument.java | 2 +- .../argument/EnumInternalArgument.java | 2 +- .../argument/FlagInternalArgument.java | 2 +- .../argument/InternalArgument.java | 2 +- .../JoinedStringInternalArgument.java | 2 +- .../argument/LimitlessInternalArgument.java | 2 +- .../argument/NamedInternalArgument.java | 8 +- .../argument/ResolverInternalArgument.java | 2 +- .../argument/SplitStringInternalArgument.java | 2 +- .../argument/StringInternalArgument.java | 2 +- .../cmd/core/argument/SubCommand.java | 5 + .../named/AbstractArgumentBuilder.java | 2 +- .../argument/named/Argument.java | 2 +- .../argument/named/ArgumentBuilder.java | 2 +- .../argument/named/ArgumentKey.java | 2 +- .../argument/named/Arguments.java | 2 +- .../argument/named/ListArgument.java | 2 +- .../argument/named/ListArgumentBuilder.java | 2 +- .../argument/named/NamedArgumentParser.java | 2 +- .../argument/named/NamedArgumentRegistry.java | 2 +- .../argument/named/NamedArgumentResult.java | 2 +- .../argument/named/SimpleArgument.java | 2 +- .../triumphteam/cmd/core/command/Command.java | 20 - .../cmd/core/command/SubCommand.java | 5 - .../cmd/core/flag/internal/ArgFlagValue.java | 2 +- .../cmd/core/flag/internal/FlagOptions.java | 2 +- .../AbstractSubCommandProcessor.java | 898 ++++++++++++++++++ .../cmd/core/processor/Commands.java | 11 + .../OldAbstractCommandProcessor.java | 5 +- .../OldAbstractSubCommandProcessor.java | 34 +- .../cmd/core/registry/RegistryContainer.java | 4 +- .../cmd/core/sender/SenderValidator.java | 4 +- .../{SubCommand.java => OldSubCommand.java} | 11 +- .../cmd/prefixed/PrefixedCommand.java | 8 +- .../cmd/prefixed/PrefixedSenderValidator.java | 4 +- .../cmd/prefixed/PrefixedSubCommand.java | 4 +- .../cmd/slash/AttachmentArgument.java | 2 +- .../cmd/slash/SlashSenderValidator.java | 4 +- .../cmd/slash/SlashSubCommand.java | 6 +- .../cmd/slash/SlashSubCommandProcessor.java | 2 +- .../triumphteam/cmd/bukkit/BukkitCommand.java | 14 +- .../cmd/bukkit/BukkitSenderValidator.java | 4 +- .../cmd/bukkit/BukkitSubCommand.java | 8 +- .../cmds/simple/SimpleCommand.java | 20 +- .../cmds/simple/SimpleSubCommand.java | 7 +- .../kotlin/dev/triumphteam/tests/Sender.kt | 4 +- 51 files changed, 1042 insertions(+), 160 deletions(-) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/AbstractInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/ArgumentRegistry.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/ArgumentResolver.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/CollectionInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/EnumInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/FlagInternalArgument.java (99%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/InternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/JoinedStringInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/LimitlessInternalArgument.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/NamedInternalArgument.java (95%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/ResolverInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/SplitStringInternalArgument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/StringInternalArgument.java (97%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/named/AbstractArgumentBuilder.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/named/Argument.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/named/ArgumentBuilder.java (95%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/named/ArgumentKey.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/named/Arguments.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/named/ListArgument.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/named/ListArgumentBuilder.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/named/NamedArgumentParser.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/named/NamedArgumentRegistry.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/named/NamedArgumentResult.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{command => }/argument/named/SimpleArgument.java (97%) delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/Command.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java rename core/src/main/java/dev/triumphteam/cmd/core/subcommand/{SubCommand.java => OldSubCommand.java} (97%) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/Command.java index 635d5024..5493624f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/Command.java @@ -23,29 +23,50 @@ */ package dev.triumphteam.cmd.core; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; +import dev.triumphteam.cmd.core.processor.Commands; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.core.subcommand.SubCommand; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; import java.util.List; import java.util.Map; +import static dev.triumphteam.cmd.core.processor.Commands.nameOf; + /** * Command interface which all platforms will implement. * - * @param The sender type. + * @param The sender type. */ public interface Command { - @NotNull Map> getSubCommands(); + @NotNull Map> getSubCommands(); + + @NotNull Map> getSubCommandAlias(); + + void addSubCommand(final @NotNull SubCommand subCommand, final boolean isAlias); + + default void addCommandsFrom(final @NotNull BaseCommand baseCommand) { + final Class klass = baseCommand.getClass(); + for (final Method method : klass.getDeclaredMethods()) { + // Ignore non-public methods + if (Modifier.isPublic(method.getModifiers())) continue; + + final String name = nameOf(method); + // Not a command, ignore the method + if (name == null) continue; - @NotNull Map> getSubCommandAlias(); - default @Nullable SubCommand getSubCommand(final @NotNull List args) { - SubCommand subCommand = getDefaultSubCommand(); + } + + // TODO: CLASSES + } + + default @Nullable OldSubCommand getSubCommand(final @NotNull List args) { + OldSubCommand subCommand = getDefaultSubCommand(); String subCommandName = ""; if (args.size() > 0) subCommandName = args.get(0).toLowerCase(); @@ -60,27 +81,16 @@ public interface Command { return subCommand; } - /** - * Gets a default command if present. - * - * @return A default SubCommand. - */ - default @Nullable SubCommand getDefaultSubCommand() { + default @Nullable OldSubCommand getDefaultSubCommand() { return getSubCommands().get(dev.triumphteam.cmd.core.annotation.Command.DEFAULT_CMD_NAME); } - default @Nullable SubCommand getSubCommand(final @NotNull String key) { - final SubCommand subCommand = getSubCommands().get(key); + default @Nullable OldSubCommand getSubCommand(final @NotNull String key) { + final OldSubCommand subCommand = getSubCommands().get(key); if (subCommand != null) return subCommand; return getSubCommandAlias().get(key); } - /** - * Checks if a SubCommand with the specified key exists. - * - * @param key the Key to check for - * @return whether a SubCommand with that key exists - */ default boolean subCommandExists(final @NotNull String key) { return getSubCommands().containsKey(key) || getSubCommandAlias().containsKey(key); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index ed6cc67c..244f4bdd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -23,9 +23,9 @@ */ package dev.triumphteam.cmd.core; -import dev.triumphteam.cmd.core.command.argument.ArgumentResolver; -import dev.triumphteam.cmd.core.command.argument.named.Argument; -import dev.triumphteam.cmd.core.command.argument.named.ArgumentKey; +import dev.triumphteam.cmd.core.argument.ArgumentResolver; +import dev.triumphteam.cmd.core.argument.named.Argument; +import dev.triumphteam.cmd.core.argument.named.ArgumentKey; import dev.triumphteam.cmd.core.message.ContextualKey; import dev.triumphteam.cmd.core.message.MessageResolver; import dev.triumphteam.cmd.core.message.context.MessageContext; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/AbstractInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java index db837c59..e748e651 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentRegistry.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java index 95c422d8..73a9ae44 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import com.google.common.primitives.Doubles; import com.google.common.primitives.Floats; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentResolver.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java index 24a7bd33..1d77765d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ArgumentResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/CollectionInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/CollectionInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java index 400da168..ae80b2a0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/CollectionInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/EnumInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/EnumInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java index 5c707eb5..8dd5f61e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/EnumInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java similarity index 99% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/FlagInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java index 3ee63c71..971d5d0e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/FlagInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.flag.Flags; import dev.triumphteam.cmd.core.flag.internal.FlagGroup; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/InternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index 94be826c..aebc0051 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/JoinedStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/JoinedStringInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java index 963f2483..aa7a4bed 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/JoinedStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/LimitlessInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/LimitlessInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java index b3368be4..1fefb2ae 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/LimitlessInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/NamedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java similarity index 95% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/NamedInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java index 408938c6..138b9438 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/NamedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java @@ -21,11 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; -import dev.triumphteam.cmd.core.command.argument.named.Arguments; -import dev.triumphteam.cmd.core.command.argument.named.NamedArgumentParser; -import dev.triumphteam.cmd.core.command.argument.named.NamedArgumentResult; +import dev.triumphteam.cmd.core.argument.named.Arguments; +import dev.triumphteam.cmd.core.argument.named.NamedArgumentParser; +import dev.triumphteam.cmd.core.argument.named.NamedArgumentResult; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ResolverInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/ResolverInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java index 7845c745..e4082e50 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/ResolverInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/SplitStringInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java index fb81163f..cfd1defc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/StringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/StringInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java index 1f199e28..e174b5c7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/StringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument; +package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java new file mode 100644 index 00000000..a3b05475 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java @@ -0,0 +1,5 @@ +package dev.triumphteam.cmd.core.argument; + +public class SubCommand { + +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/AbstractArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/AbstractArgumentBuilder.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java index 0ac3c645..fc87a18a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/AbstractArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument.named; +package dev.triumphteam.cmd.core.argument.named; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Argument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Argument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java index 142c244f..351e0508 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Argument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument.named; +package dev.triumphteam.cmd.core.argument.named; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java similarity index 95% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentBuilder.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java index a76688d9..4783756c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument.named; +package dev.triumphteam.cmd.core.argument.named; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentKey.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentKey.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java index dff1c6c4..5e4e1df5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ArgumentKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument.named; +package dev.triumphteam.cmd.core.argument.named; import dev.triumphteam.cmd.core.registry.RegistryKey; import org.jetbrains.annotations.Contract; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Arguments.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Arguments.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java index f874217b..5046e470 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/Arguments.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument.named; +package dev.triumphteam.cmd.core.argument.named; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java index d5d96c4a..4d6952e4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument.named; +package dev.triumphteam.cmd.core.argument.named; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgumentBuilder.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java index bc32c1fd..c2c34cd8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/ListArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument.named; +package dev.triumphteam.cmd.core.argument.named; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentParser.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java index f28d52e6..663a7efc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument.named; +package dev.triumphteam.cmd.core.argument.named; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentRegistry.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java index afba11b2..fc5318a6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument.named; +package dev.triumphteam.cmd.core.argument.named; import dev.triumphteam.cmd.core.registry.Registry; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentResult.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentResult.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java index 25029996..09f0e347 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/NamedArgumentResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument.named; +package dev.triumphteam.cmd.core.argument.named; import com.google.common.collect.ImmutableMap; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/SimpleArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/SimpleArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java index 3d9653c7..ea6d4a7a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/argument/named/SimpleArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.command.argument.named; +package dev.triumphteam.cmd.core.argument.named; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java deleted file mode 100644 index 082b55a6..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.triumphteam.cmd.core.command; - -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Map; - -public class Command { - - private final String name; - private final Map> subCommands = new HashMap<>(); - - public Command(final @NotNull String name) { - this.name = name; - } - - public void addSubCommands() { - - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java deleted file mode 100644 index 1741c6ad..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ /dev/null @@ -1,5 +0,0 @@ -package dev.triumphteam.cmd.core.command; - -public class SubCommand { - -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java index 9dca1837..1b51a418 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.flag.internal; -import dev.triumphteam.cmd.core.command.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java index 2b559d96..f908c5d1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.flag.internal; -import dev.triumphteam.cmd.core.command.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java new file mode 100644 index 00000000..af55d0f6 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java @@ -0,0 +1,898 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.processor; + +import com.google.common.base.CaseFormat; +import com.google.common.collect.Maps; +import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.annotation.ArgDescriptions; +import dev.triumphteam.cmd.core.annotation.ArgName; +import dev.triumphteam.cmd.core.annotation.Async; +import dev.triumphteam.cmd.core.annotation.CommandFlags; +import dev.triumphteam.cmd.core.annotation.Default; +import dev.triumphteam.cmd.core.annotation.Description; +import dev.triumphteam.cmd.core.annotation.Flag; +import dev.triumphteam.cmd.core.annotation.Join; +import dev.triumphteam.cmd.core.annotation.NamedArguments; +import dev.triumphteam.cmd.core.annotation.Optional; +import dev.triumphteam.cmd.core.annotation.Requirements; +import dev.triumphteam.cmd.core.annotation.Split; +import dev.triumphteam.cmd.core.annotation.Suggestions; +import dev.triumphteam.cmd.core.argument.ArgumentRegistry; +import dev.triumphteam.cmd.core.argument.ArgumentResolver; +import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; +import dev.triumphteam.cmd.core.argument.EnumInternalArgument; +import dev.triumphteam.cmd.core.argument.FlagInternalArgument; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; +import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; +import dev.triumphteam.cmd.core.argument.NamedInternalArgument; +import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; +import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.argument.named.Argument; +import dev.triumphteam.cmd.core.argument.named.ArgumentKey; +import dev.triumphteam.cmd.core.argument.named.Arguments; +import dev.triumphteam.cmd.core.argument.named.ListArgument; +import dev.triumphteam.cmd.core.argument.named.NamedArgumentRegistry; +import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; +import dev.triumphteam.cmd.core.flag.Flags; +import dev.triumphteam.cmd.core.flag.internal.FlagGroup; +import dev.triumphteam.cmd.core.flag.internal.FlagOptions; +import dev.triumphteam.cmd.core.flag.internal.FlagValidator; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; +import dev.triumphteam.cmd.core.message.context.MessageContext; +import dev.triumphteam.cmd.core.registry.RegistryContainer; +import dev.triumphteam.cmd.core.requirement.Requirement; +import dev.triumphteam.cmd.core.requirement.RequirementKey; +import dev.triumphteam.cmd.core.requirement.RequirementRegistry; +import dev.triumphteam.cmd.core.requirement.RequirementResolver; +import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; +import dev.triumphteam.cmd.core.suggestion.EnumSuggestion; +import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; +import dev.triumphteam.cmd.core.suggestion.Suggestion; +import dev.triumphteam.cmd.core.suggestion.SuggestionKey; +import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; +import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Parameter; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.WildcardType; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.function.BiConsumer; +import java.util.stream.Collectors; + +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + +/** + * Abstracts most of the "extracting" from sub command annotations, allows for extending. + *
+ * I know this could be done better, but couldn't think of a better way. + * If you do please PR or let me know on my discord! + * + * @param The sender type. + */ +@SuppressWarnings("unchecked") +public abstract class AbstractSubCommandProcessor { + + private final BaseCommand baseCommand; + private final String parentName; + + private final AnnotatedElement annotatedElement; + // Name is nullable to detect if the method should or not be considered a sub command. + private String name = null; + // TODO: 11/28/2021 Add better default description + private String description = "No description provided."; + private final List argDescriptions = new ArrayList<>(); + private final List alias = new ArrayList<>(); + + private boolean isDefault = false; + private final boolean isAsync; + + private Class senderType; + + private final FlagGroup flagGroup = new FlagGroup<>(); + private final List> suggestionList = new ArrayList<>(); + private final List> internalArguments = new ArrayList<>(); + private final Set> requirements = new HashSet<>(); + + private final RegistryContainer registryContainer; + private final SuggestionRegistry suggestionRegistry; + private final ArgumentRegistry argumentRegistry; + private final NamedArgumentRegistry namedArgumentRegistry; + private final RequirementRegistry requirementRegistry; + private final MessageRegistry messageRegistry; + private final SenderValidator senderValidator; + + private static final Set> COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); + + protected AbstractSubCommandProcessor( + final @NotNull BaseCommand baseCommand, + final @NotNull String parentName, + final @NotNull AnnotatedElement annotatedElement, + final @NotNull RegistryContainer registryContainer, + final @NotNull SenderValidator senderValidator + ) { + this.baseCommand = baseCommand; + this.parentName = parentName; + + this.annotatedElement = annotatedElement; + + this.registryContainer = registryContainer; + this.suggestionRegistry = registryContainer.getSuggestionRegistry(); + this.argumentRegistry = registryContainer.getArgumentRegistry(); + this.namedArgumentRegistry = registryContainer.getNamedArgumentRegistry(); + this.requirementRegistry = registryContainer.getRequirementRegistry(); + this.messageRegistry = registryContainer.getMessageRegistry(); + this.senderValidator = senderValidator; + + this.isAsync = annotatedElement.isAnnotationPresent(Async.class); + + extractSubCommandNames(); + if (name == null) return; + + extractFlags(); + extractRequirements(); + extractDescription(); + extractArgDescriptions(); + extractSuggestions(); + extractArguments(annotatedElement); + validateArguments(); + } + + /** + * Allows for customizing the internalArgument parsing, for example @Value and @Completion annotations. + * + * @param annotatedElement The method to search from. + */ + protected void extractArguments(final @NotNull AnnotatedElement annotatedElement) { + /*final Parameter[] parameters = method.getParameters(); + for (int i = 0; i < parameters.length; i++) { + final Parameter parameter = parameters[i]; + if (i == 0) { + validateSender(parameter.getType()); + continue; + } + + createArgument(parameter, i - 1); + }*/ + } + + /** + * Used for the child factories to get the sub command name. + * It's nullable because a method might not have a {@link dev.triumphteam.cmd.core.annotation.SubCommand} or {@link Default} annotation. + * + * @return The sub command name. + */ + public @Nullable String getName() { + return name; + } + + /** + * gets the Description of the SubCommand. + * + * @return either the extracted Description or the default one. + */ + public @NotNull String getDescription() { + return description; + } + + public @NotNull Class getSenderType() { + if (senderType == null) throw createException("Sender type could not be found."); + return senderType; + } + + /** + * Used for the child factories to get a {@link List} with the sub command's alias. + * + * @return The sub command alias. + */ + public @NotNull List<@NotNull String> getAlias() { + return alias; + } + + /** + * Used for the child factories to get whether the sub command is default. + * + * @return Whether the command is default. + */ + public boolean isDefault() { + return isDefault; + } + + /** + * Gets whether the sub command is to be executed asynchronously. + * + * @return If the sub command is async. + */ + public boolean isAsync() { + return isAsync; + } + + /** + * Gets the {@link BaseCommand} instance, so it can be used later to invoke. + * + * @return The base command instance. + */ + public @NotNull BaseCommand getBaseCommand() { + return baseCommand; + } + + // TODO comments + public @NotNull AnnotatedElement getAnnotatedElement() { + return annotatedElement; + } + + /** + * Gets a set with the requirements. + * + * @return The requirements. + */ + public @NotNull Set<@NotNull Requirement> getRequirements() { + return requirements; + } + + /** + * Gets the message registry. + * + * @return The message registry. + */ + public @NotNull MessageRegistry getMessageRegistry() { + return messageRegistry; + } + + public @NotNull RegistryContainer getRegistryContainer() { + return registryContainer; + } + + // TODO: 2/4/2022 comments + public @NotNull SenderValidator getSenderValidator() { + return senderValidator; + } + + /** + * Simple utility method for creating a new exception using the method and base command class. + * + * @param message The main message to pass to the exception. + * @return A new {@link SubCommandRegistrationException}. + */ + @Contract("_ -> new") + protected @NotNull SubCommandRegistrationException createException(final @NotNull String message) { + return new SubCommandRegistrationException(message, annotatedElement, baseCommand.getClass()); + } + + /** + * Used for validating if the sender is valid or not. + * + * @param type The sender type. + */ + protected void validateSender(final @NotNull Class type) { + final Set> allowedSenders = senderValidator.getAllowedSenders(); + if (allowedSenders.contains(type)) { + senderType = (Class) type; + return; + } + + throw createException( + "\"" + type.getSimpleName() + "\" is not a valid sender. " + + "Sender must be one of the following: " + + allowedSenders + .stream() + .map(it -> "\"" + it.getSimpleName() + "\"") + .collect(Collectors.joining(", ")) + ); + } + + /** + * Gets the necessary arguments for the command. + * + * @return The arguments list. + */ + public @NotNull List<@NotNull InternalArgument> getArguments() { + return internalArguments; + } + + /** + * Creates and adds the internalArgument to the arguments list. + * + * @param parameter The current parameter to get data from. + */ + protected void createArgument(final @NotNull Parameter parameter, final int position) { + final Class type = parameter.getType(); + final String argumentName = getArgName(parameter); + final String argumentDescription = getArgumentDescription(parameter, position); + final boolean optional = parameter.isAnnotationPresent(Optional.class); + + // Handles collection internalArgument. + // TODO: Add more collection types. + if (COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { + final Class collectionType = getGenericType(parameter); + final InternalArgument internalArgument = createSimpleArgument( + collectionType, + argumentName, + argumentDescription, + suggestionList.get(position), + 0, + true + ); + + if (parameter.isAnnotationPresent(Split.class)) { + final Split splitAnnotation = parameter.getAnnotation(Split.class); + addArgument( + new SplitStringInternalArgument<>( + argumentName, + argumentDescription, + splitAnnotation.value(), + internalArgument, + type, + suggestionList.get(position), + position, + optional + ) + ); + return; + } + + addArgument( + new CollectionInternalArgument<>( + argumentName, + argumentDescription, + internalArgument, + type, + suggestionList.get(position), + position, + optional + ) + ); + return; + } + + // Handler for using String with `@Join`. + if (type == String.class && parameter.isAnnotationPresent(Join.class)) { + final Join joinAnnotation = parameter.getAnnotation(Join.class); + addArgument( + new JoinedStringInternalArgument<>( + argumentName, + argumentDescription, + joinAnnotation.value(), + suggestionList.get(position), + position, + optional + ) + ); + return; + } + + // Handler for flags. + if (type == Flags.class) { + if (flagGroup.isEmpty()) { + throw createException("Flags internalArgument detected but no flag annotation declared"); + } + + addArgument( + new FlagInternalArgument<>( + argumentName, + argumentDescription, + flagGroup, + position, + optional + ) + ); + return; + } + + // Handler for named arguments + if (type == Arguments.class) { + final NamedArguments namedArguments = annotatedElement.getAnnotation(NamedArguments.class); + if (namedArguments == null) { + throw createException("TODO"); + } + + addArgument( + new NamedInternalArgument<>( + argumentName, + argumentDescription, + collectNamedArgs(namedArguments.value()), + position, + optional + ) + ); + return; + } + + addArgument(createSimpleArgument(type, argumentName, argumentDescription, suggestionList.get(position), position, optional)); + } + + private @NotNull Map<@NotNull String, @NotNull InternalArgument> collectNamedArgs(final @NotNull String key) { + final List arguments = namedArgumentRegistry.getResolver(ArgumentKey.of(key)); + if (arguments == null || arguments.isEmpty()) { + throw createException("No registered named arguments found for key \"" + key + "\""); + } + + // TODO: Handle list + return arguments.stream().map(argument -> { + final Suggestion suggestion = createSuggestion(argument.getSuggestion(), argument.getType()); + + if (argument instanceof ListArgument) { + final ListArgument listArgument = (ListArgument) argument; + + final InternalArgument internalArgument = createSimpleArgument( + listArgument.getType(), + listArgument.getName(), + listArgument.getDescription(), + suggestion, + 0, + true + ); + + return Maps.immutableEntry( + listArgument.getName(), + new SplitStringInternalArgument<>( + listArgument.getName(), + listArgument.getDescription(), + listArgument.getSeparator(), + internalArgument, + listArgument.getType(), + suggestion, + 0, + true + ) + ); + } + + return Maps.immutableEntry( + argument.getName(), + createSimpleArgument( + argument.getType(), + argument.getName(), + argument.getDescription(), + suggestion, + 0, + true + ) + ); + }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + } + + /** + * Gets the internalArgument name, either from the parameter or from the annotation. + * If the parameter is not annotated, turn the name from Camel Case to "lower-hyphen". + * + * @param parameter The parameter to get data from. + * @return The final internalArgument name. + */ + private @NotNull String getArgName(final @NotNull Parameter parameter) { + if (parameter.isAnnotationPresent(ArgName.class)) { + return parameter.getAnnotation(ArgName.class).value(); + } + + return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, parameter.getName()); + } + + /** + * Gets the internalArgument description. + * + * @param parameter The parameter to get data from. + * @param index The index of the internalArgument. + * @return The final internalArgument description. + */ + private @NotNull String getArgumentDescription(final @NotNull Parameter parameter, final int index) { + final Description description = parameter.getAnnotation(Description.class); + if (description != null) { + return description.value(); + } + + if (index < argDescriptions.size()) return argDescriptions.get(index); + // TODO: 11/28/2021 Add better default description + return "No description provided."; + } + + /** + * Create a SimpleArgument. + * + * @param type The Type of this Argument. + * @param parameterName The Name to use for this Argument. + * @param argumentDescription the Description to use for this Argument. + * @param optional whether this Argument is optional. + * @return The created {@link InternalArgument}. + */ + protected @NotNull InternalArgument createSimpleArgument( + final @NotNull Class type, + final @NotNull String parameterName, + final @NotNull String argumentDescription, + final @NotNull Suggestion suggestion, + final int position, + final boolean optional + ) { + // All other types default to the resolver. + final ArgumentResolver resolver = argumentRegistry.getResolver(type); + if (resolver == null) { + // Handler for using any Enum. + if (Enum.class.isAssignableFrom(type)) { + //noinspection unchecked + return new EnumInternalArgument<>( + parameterName, + argumentDescription, + (Class>) type, + suggestion, + position, + optional + ); + } + + throw createException("No internalArgument of type \"" + type.getName() + "\" registered"); + } + return new ResolverInternalArgument<>( + parameterName, + argumentDescription, + type, + resolver, + suggestion, + position, + optional + ); + } + + /** + * Adds a required internalArgument to the list. + * + * @param requirement The requirement to add. + */ + protected void addRequirement(final @NotNull Requirement requirement) { + requirements.add(requirement); + } + + /** + * Utility to add the internalArgument to the list. + * + * @param internalArgument The created internalArgument. + */ + private void addArgument(final @NotNull InternalArgument internalArgument) { + internalArguments.add(internalArgument); + } + + /** + * Extracts the data from the method to retrieve the sub command name or the default name. + */ + private void extractSubCommandNames() { + final Default defaultAnnotation = annotatedElement.getAnnotation(Default.class); + final dev.triumphteam.cmd.core.annotation.SubCommand subCommandAnnotation = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.SubCommand.class); + + if (defaultAnnotation == null && subCommandAnnotation == null) { + return; + } + + if (defaultAnnotation != null) { + name = Default.DEFAULT_CMD_NAME; + alias.addAll(Arrays.stream(defaultAnnotation.alias()).map(String::toLowerCase).collect(Collectors.toList())); + isDefault = true; + return; + } + + name = subCommandAnnotation.value().toLowerCase(); + alias.addAll(Arrays.stream(subCommandAnnotation.alias()).map(String::toLowerCase).collect(Collectors.toList())); + } + + /** + * Extract all the flag data for the subcommand from the method. + */ + private void extractFlags() { + final List flags = getFlagsFromAnnotations(); + if (flags.isEmpty()) return; + + for (final Flag flagAnnotation : flags) { + String flag = flagAnnotation.flag(); + if (flag.isEmpty()) flag = null; + FlagValidator.validate(flag, annotatedElement, baseCommand); + + String longFlag = flagAnnotation.longFlag(); + if (longFlag.contains(" ")) { + throw createException("@" + Flag.class.getSimpleName() + "'s identifiers must not contain spaces"); + } + + if (longFlag.isEmpty()) longFlag = null; + + final Class argumentType = flagAnnotation.argument(); + + final SuggestionKey suggestionKey = flagAnnotation.suggestion().isEmpty() ? null : SuggestionKey.of(flagAnnotation.suggestion()); + final Suggestion suggestion = createSuggestion(suggestionKey, flagAnnotation.argument()); + + StringInternalArgument internalArgument = null; + if (argumentType != void.class) { + if (Enum.class.isAssignableFrom(argumentType)) { + //noinspection unchecked + internalArgument = new EnumInternalArgument<>( + argumentType.getName(), + "", + (Class>) argumentType, + suggestion, + 0, + false + ); + } else { + final ArgumentResolver resolver = argumentRegistry.getResolver(argumentType); + if (resolver == null) { + throw createException("@" + Flag.class.getSimpleName() + "'s internalArgument contains unregistered type \"" + argumentType.getName() + "\""); + } + + internalArgument = new ResolverInternalArgument<>( + argumentType.getName(), + "", + argumentType, + resolver, + suggestion, + 0, + false + ); + } + } + + flagGroup.addFlag( + new FlagOptions<>( + flag, + longFlag, + internalArgument + ) + ); + } + } + + /** + * Gets the flags from the annotations. + * + * @return The list of flags. + */ + private @NotNull List<@NotNull Flag> getFlagsFromAnnotations() { + final CommandFlags flags = annotatedElement.getAnnotation(CommandFlags.class); + if (flags != null) return Arrays.asList(flags.value()); + + final Flag flag = annotatedElement.getAnnotation(Flag.class); + if (flag == null) return Collections.emptyList(); + return Collections.singletonList(flag); + } + + /** + * Extract all the requirement data for the sub command from the method. + */ + public void extractRequirements() { + for (final dev.triumphteam.cmd.core.annotation.Requirement requirementAnnotation : getRequirementsFromAnnotations()) { + final RequirementKey requirementKey = RequirementKey.of(requirementAnnotation.value()); + final String messageKeyValue = requirementAnnotation.messageKey(); + + final MessageKey messageKey; + if (messageKeyValue.isEmpty()) messageKey = null; + else messageKey = MessageKey.of(messageKeyValue, MessageContext.class); + + final RequirementResolver resolver = requirementRegistry.getRequirement(requirementKey); + if (resolver == null) { + throw createException("Could not find Requirement Key \"" + requirementKey.getKey() + "\""); + } + + addRequirement(new Requirement<>(resolver, messageKey, DefaultMessageContext::new, requirementAnnotation.invert())); + } + } + + /** + * Gets the requirements from the annotations. + * + * @return The list of requirements. + */ + private @NotNull List getRequirementsFromAnnotations() { + final Requirements requirements = annotatedElement.getAnnotation(Requirements.class); + if (requirements != null) return Arrays.asList(requirements.value()); + + final dev.triumphteam.cmd.core.annotation.Requirement requirement = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.Requirement.class); + if (requirement == null) return Collections.emptyList(); + return Collections.singletonList(requirement); + } + + /** + * Gets a list of all the arg validations for the platform. + * Defaults to just optional and limitless. + * This is likely to change. + * + * @return A list of BiConsumers with checks. + */ + protected @NotNull List<@NotNull BiConsumer<@NotNull Boolean, @NotNull InternalArgument>> getArgValidations() { + return Arrays.asList(validateOptionals(), validateLimitless()); + } + + /** + * Argument validation makes sure some arguments are placed in the correct place. + * For example a limitless arguments and optional arguments are only allowed at the end of the command. + */ + private void validateArguments() { + final List>> validations = getArgValidations(); + final Iterator> iterator = internalArguments.iterator(); + while (iterator.hasNext()) { + final InternalArgument internalArgument = iterator.next(); + validations.forEach(consumer -> consumer.accept(iterator.hasNext(), internalArgument)); + } + } + + /** + * Validation function for optionals. + * + * @return Returns a BiConsumer with an is optional check. + */ + protected @NotNull BiConsumer<@NotNull Boolean, @NotNull InternalArgument> validateOptionals() { + return (hasNext, internalArgument) -> { + if (hasNext && internalArgument.isOptional()) { + throw createException("Optional internalArgument is only allowed as the last internalArgument"); + } + }; + } + + /** + * Validation function for limitless position. + * + * @return Returns a BiConsumer with an instance of check. + */ + protected @NotNull BiConsumer<@NotNull Boolean, @NotNull InternalArgument> validateLimitless() { + return (hasNext, internalArgument) -> { + if (hasNext && internalArgument instanceof LimitlessInternalArgument) { + throw createException("Limitless internalArgument is only allowed as the last internalArgument"); + } + }; + } + + /** + * Extracts the {@link Description} Annotation from the Method. + */ + private void extractDescription() { + final Description description = annotatedElement.getAnnotation(Description.class); + if (description == null) return; + this.description = description.value(); + } + + /** + * Extracts the {@link ArgDescriptions} Annotation from the Method. + */ + private void extractArgDescriptions() { + final ArgDescriptions argDescriptions = annotatedElement.getAnnotation(ArgDescriptions.class); + if (argDescriptions == null) return; + this.argDescriptions.addAll(Arrays.asList(argDescriptions.value())); + } + + /** + * Extract all suggestions from the method and parameters. + */ + public void extractSuggestions() { + for (final dev.triumphteam.cmd.core.annotation.Suggestion suggestion : getSuggestionsFromAnnotations()) { + final String key = suggestion.value(); + if (key.isEmpty()) { + suggestionList.add(new EmptySuggestion<>()); + continue; + } + + final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(SuggestionKey.of(key)); + + if (resolver == null) { + throw createException("Cannot find the suggestion key `" + key + "`"); + } + + suggestionList.add(new SimpleSuggestion<>(resolver)); + } + + extractSuggestionFromParams(); + } + + /** + * Extract all suggestions from the parameters. + * Adds the suggestions to the passed list. + */ + private void extractSuggestionFromParams() { + // TODO SUGGESTIONS + /*final Parameter[] parameters = annotatedElement.getParameters(); + for (int i = 1; i < parameters.length; i++) { + final Parameter parameter = parameters[i]; + + final dev.triumphteam.cmd.core.annotation.Suggestion suggestion = parameter.getAnnotation(dev.triumphteam.cmd.core.annotation.Suggestion.class); + final SuggestionKey suggestionKey = suggestion == null ? null : SuggestionKey.of(suggestion.value()); + + final Class type = getGenericType(parameter); + final int addIndex = i - 1; + setOrAddSuggestion(addIndex, createSuggestion(suggestionKey, type)); + }*/ + } + + private @NotNull Suggestion createSuggestion(final @Nullable SuggestionKey suggestionKey, final @NotNull Class type) { + if (suggestionKey == null) { + if (Enum.class.isAssignableFrom(type)) return new EnumSuggestion<>((Class>) type); + + final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(type); + if (resolver != null) return new SimpleSuggestion<>(resolver); + + return new EmptySuggestion<>(); + } + + final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(suggestionKey); + if (resolver == null) { + throw createException("Cannot find the suggestion key `" + suggestionKey + "`"); + } + return new SimpleSuggestion<>(resolver); + } + + /** + * Adds a suggestion or overrides an existing one. + * + * @param index The index of the suggestion. + * @param suggestion The suggestion. + */ + private void setOrAddSuggestion(final int index, final @Nullable Suggestion suggestion) { + if (index >= suggestionList.size()) { + if (suggestion == null) { + suggestionList.add(new EmptySuggestion<>()); + return; + } + suggestionList.add(suggestion); + return; + } + + if (suggestion == null) return; + suggestionList.set(index, suggestion); + } + + private @NotNull List getSuggestionsFromAnnotations() { + final Suggestions requirements = annotatedElement.getAnnotation(Suggestions.class); + if (requirements != null) return Arrays.asList(requirements.value()); + + final dev.triumphteam.cmd.core.annotation.Suggestion suggestion = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.Suggestion.class); + if (suggestion == null) return emptyList(); + return singletonList(suggestion); + } + + private @NotNull Class getGenericType(final @NotNull Parameter parameter) { + final Class type = parameter.getType(); + if (COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { + final ParameterizedType parameterizedType = (ParameterizedType) parameter.getParameterizedType(); + final Type[] types = parameterizedType.getActualTypeArguments(); + + if (types.length != 1) { + throw createException("Unsupported collection type \"" + type + "\""); + } + + final Type genericType = types[0]; + return (Class) (genericType instanceof WildcardType ? ((WildcardType) genericType).getUpperBounds()[0] : genericType); + } + + return type; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java index ea3be669..8fb08a31 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java @@ -5,7 +5,9 @@ import dev.triumphteam.cmd.core.annotation.Description; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.lang.reflect.AnnotatedElement; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -67,4 +69,13 @@ private Commands() { final Description commandAnnotation = baseCommand.getClass().getAnnotation(Description.class); return commandAnnotation == null ? baseCommand.getDescription() : commandAnnotation.value(); } + + public static @Nullable String nameOf(final @NotNull AnnotatedElement element) { + final Command commandAnnotation = element.getAnnotation(Command.class); + + // Not a command element + if (commandAnnotation == null) return null; + + return commandAnnotation.value(); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java index 8c808d32..6bf1f82b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java @@ -32,7 +32,7 @@ import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.subcommand.SubCommand; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.core.subcommand.invoker.Invoker; import dev.triumphteam.cmd.core.subcommand.invoker.MethodInvoker; import org.jetbrains.annotations.NotNull; @@ -43,7 +43,6 @@ import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -58,7 +57,7 @@ * * @param Sender type */ -public abstract class OldAbstractCommandProcessor, P extends OldAbstractSubCommandProcessor> { +public abstract class OldAbstractCommandProcessor, P extends OldAbstractSubCommandProcessor> { private String name; // TODO: 11/28/2021 Add better default description diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java index 814ab5fe..fbeb92fc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java @@ -39,23 +39,23 @@ import dev.triumphteam.cmd.core.annotation.Requirements; import dev.triumphteam.cmd.core.annotation.Split; import dev.triumphteam.cmd.core.annotation.Suggestions; -import dev.triumphteam.cmd.core.command.argument.ArgumentRegistry; -import dev.triumphteam.cmd.core.command.argument.ArgumentResolver; -import dev.triumphteam.cmd.core.command.argument.CollectionInternalArgument; -import dev.triumphteam.cmd.core.command.argument.EnumInternalArgument; -import dev.triumphteam.cmd.core.command.argument.FlagInternalArgument; -import dev.triumphteam.cmd.core.command.argument.InternalArgument; -import dev.triumphteam.cmd.core.command.argument.JoinedStringInternalArgument; -import dev.triumphteam.cmd.core.command.argument.LimitlessInternalArgument; -import dev.triumphteam.cmd.core.command.argument.NamedInternalArgument; -import dev.triumphteam.cmd.core.command.argument.ResolverInternalArgument; -import dev.triumphteam.cmd.core.command.argument.SplitStringInternalArgument; -import dev.triumphteam.cmd.core.command.argument.StringInternalArgument; -import dev.triumphteam.cmd.core.command.argument.named.Argument; -import dev.triumphteam.cmd.core.command.argument.named.ArgumentKey; -import dev.triumphteam.cmd.core.command.argument.named.Arguments; -import dev.triumphteam.cmd.core.command.argument.named.ListArgument; -import dev.triumphteam.cmd.core.command.argument.named.NamedArgumentRegistry; +import dev.triumphteam.cmd.core.argument.ArgumentRegistry; +import dev.triumphteam.cmd.core.argument.ArgumentResolver; +import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; +import dev.triumphteam.cmd.core.argument.EnumInternalArgument; +import dev.triumphteam.cmd.core.argument.FlagInternalArgument; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; +import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; +import dev.triumphteam.cmd.core.argument.NamedInternalArgument; +import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; +import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.argument.named.Argument; +import dev.triumphteam.cmd.core.argument.named.ArgumentKey; +import dev.triumphteam.cmd.core.argument.named.Arguments; +import dev.triumphteam.cmd.core.argument.named.ListArgument; +import dev.triumphteam.cmd.core.argument.named.NamedArgumentRegistry; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.flag.Flags; import dev.triumphteam.cmd.core.flag.internal.FlagGroup; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java index ac284dd9..69468854 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java @@ -23,8 +23,8 @@ */ package dev.triumphteam.cmd.core.registry; -import dev.triumphteam.cmd.core.command.argument.ArgumentRegistry; -import dev.triumphteam.cmd.core.command.argument.named.NamedArgumentRegistry; +import dev.triumphteam.cmd.core.argument.ArgumentRegistry; +import dev.triumphteam.cmd.core.argument.named.NamedArgumentRegistry; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.requirement.RequirementRegistry; import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java index 00f3a22e..00a991ab 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.sender; -import dev.triumphteam.cmd.core.subcommand.SubCommand; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.core.message.MessageRegistry; import org.jetbrains.annotations.NotNull; @@ -40,7 +40,7 @@ public interface SenderValidator { boolean validate( final @NotNull MessageRegistry messageRegistry, - final @NotNull SubCommand subCommand, + final @NotNull OldSubCommand subCommand, final @NotNull S sender ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java rename to core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java index 987a1fec..af05fbbc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java @@ -24,9 +24,10 @@ package dev.triumphteam.cmd.core.subcommand; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.command.argument.InternalArgument; -import dev.triumphteam.cmd.core.command.argument.LimitlessInternalArgument; -import dev.triumphteam.cmd.core.command.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.annotation.Default; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.message.MessageKey; @@ -54,7 +55,7 @@ * * @param The sender type. */ -public abstract class SubCommand { +public abstract class OldSubCommand { private final BaseCommand baseCommand; private final Method method = null; @@ -77,7 +78,7 @@ public abstract class SubCommand { private final boolean hasArguments; private final boolean containsLimitless; - public SubCommand( + public OldSubCommand( @NotNull final OldAbstractSubCommandProcessor processor, @NotNull final String parentName, @NotNull final ExecutionProvider executionProvider diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java index 3bb6af1e..e75944a6 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java @@ -28,7 +28,7 @@ import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.subcommand.SubCommand; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -89,7 +89,7 @@ public void addSubCommandAlias(final @NotNull String alias, final @NotNull Prefi * @param args The command arguments. */ public void execute(final @NotNull S sender, final @NotNull List<@NotNull String> args) { - SubCommand subCommand = getDefaultSubCommand(); + OldSubCommand subCommand = getDefaultSubCommand(); String subCommandName = ""; if (args.size() > 0) subCommandName = args.get(0).toLowerCase(); @@ -113,7 +113,7 @@ public void execute(final @NotNull S sender, final @NotNull List<@NotNull String * * @return The default sub command. */ - private @Nullable SubCommand getDefaultSubCommand() { + private @Nullable OldSubCommand getDefaultSubCommand() { return subCommands.get(Default.DEFAULT_CMD_NAME); } @@ -123,7 +123,7 @@ public void execute(final @NotNull S sender, final @NotNull List<@NotNull String * @param key The sub command name. * @return A sub command or null. */ - private @Nullable SubCommand getSubCommand(final @NotNull String key) { + private @Nullable OldSubCommand getSubCommand(final @NotNull String key) { return subCommands.get(key); } diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java index 7034e0e8..0b0b94e9 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java @@ -26,7 +26,7 @@ import com.google.common.collect.ImmutableSet; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.subcommand.SubCommand; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; @@ -51,7 +51,7 @@ class PrefixedSenderValidator implements SenderValidator { @Override public boolean validate( final @NotNull MessageRegistry messageRegistry, - final @NotNull SubCommand subCommand, + final @NotNull OldSubCommand subCommand, final @NotNull PrefixedSender sender ) { return true; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java index 80f1d997..3a4f9aaa 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.prefixed; -import dev.triumphteam.cmd.core.subcommand.SubCommand; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; import org.jetbrains.annotations.NotNull; @@ -31,7 +31,7 @@ import java.util.List; -final class PrefixedSubCommand extends SubCommand { +final class PrefixedSubCommand extends OldSubCommand { public PrefixedSubCommand( final @NotNull OldAbstractSubCommandProcessor processor, diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java index 25303c46..b7289184 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.slash; -import dev.triumphteam.cmd.core.command.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java index 863d241c..e9ea37d2 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.slash; import com.google.common.collect.ImmutableSet; -import dev.triumphteam.cmd.core.subcommand.SubCommand; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.sender.SenderValidator; import dev.triumphteam.cmd.slash.sender.SlashSender; @@ -48,7 +48,7 @@ final class SlashSenderValidator implements SenderValidator { @Override public boolean validate( final @NotNull MessageRegistry messageRegistry, - final @NotNull SubCommand subCommand, + final @NotNull OldSubCommand subCommand, final @NotNull SlashSender sender ) { return true; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java index d3bb1e69..ace3a591 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java @@ -23,8 +23,8 @@ */ package dev.triumphteam.cmd.slash; -import dev.triumphteam.cmd.core.subcommand.SubCommand; -import dev.triumphteam.cmd.core.command.argument.InternalArgument; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; +import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.slash.choices.Choice; import dev.triumphteam.cmd.slash.choices.EmptyChoice; @@ -39,7 +39,7 @@ import java.util.List; import java.util.stream.Collectors; -final class SlashSubCommand extends SubCommand { +final class SlashSubCommand extends OldSubCommand { private final String description; private final List choices; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java index c6350f9e..e4a2cf1b 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.slash; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.command.argument.InternalArgument; +import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; import dev.triumphteam.cmd.core.sender.SenderValidator; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index da7aba52..807256f6 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -23,25 +23,19 @@ */ package dev.triumphteam.cmd.bukkit; -import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; -import dev.triumphteam.cmd.bukkit.message.NoPermissionMessageContext; import dev.triumphteam.cmd.core.Command; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.subcommand.SubCommand; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import java.util.Arrays; -import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; - -import static java.util.Collections.emptyList; public final class BukkitCommand extends org.bukkit.command.Command implements Command { @@ -74,7 +68,7 @@ public boolean execute( final List arguments = Arrays.asList(args); final int argumentSize = arguments.size(); - final SubCommand subCommand = getSubCommand(arguments); + final OldSubCommand subCommand = getSubCommand(arguments); final S mappedSender = senderMapper.map(sender); if (mappedSender == null) { @@ -99,12 +93,12 @@ public boolean execute( } @Override - public @NotNull Map> getSubCommands() { + public @NotNull Map> getSubCommands() { return null; } @Override - public @NotNull Map> getSubCommandAlias() { + public @NotNull Map> getSubCommandAlias() { return null; } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java index d283a1b3..977a1804 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java @@ -25,7 +25,7 @@ import com.google.common.collect.ImmutableSet; import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; -import dev.triumphteam.cmd.core.subcommand.SubCommand; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import dev.triumphteam.cmd.core.sender.SenderValidator; @@ -52,7 +52,7 @@ class BukkitSenderValidator implements SenderValidator { @Override public boolean validate( final @NotNull MessageRegistry messageRegistry, - final @NotNull SubCommand subCommand, + final @NotNull OldSubCommand subCommand, final @NotNull CommandSender sender ) { final Class senderClass = subCommand.getSenderType(); diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java index a1e4d242..bf4c2cad 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java @@ -23,9 +23,9 @@ */ package dev.triumphteam.cmd.bukkit; -import dev.triumphteam.cmd.core.subcommand.SubCommand; -import dev.triumphteam.cmd.core.command.argument.InternalArgument; -import dev.triumphteam.cmd.core.command.argument.LimitlessInternalArgument; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; @@ -35,7 +35,7 @@ import static java.util.Collections.emptyList; -public final class BukkitSubCommand extends SubCommand { +public final class BukkitSubCommand extends OldSubCommand { private final CommandPermission permission; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index 7dac8fc8..dd021072 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -24,20 +24,12 @@ package dev.triumphteam.cmds.simple; import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.annotation.Default; -import dev.triumphteam.cmd.core.subcommand.SubCommand; -import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -48,8 +40,8 @@ public final class SimpleCommand implements Command { private final MessageRegistry messageRegistry; - private final Map> subCommands = new HashMap<>(); - private final Map> subCommandAliases = new HashMap<>(); + private final Map> subCommands = new HashMap<>(); + private final Map> subCommandAliases = new HashMap<>(); @SuppressWarnings("unchecked") public SimpleCommand( @@ -68,7 +60,7 @@ public void execute( ) { final int argumentSize = arguments.size(); - final SubCommand subCommand = getSubCommand(arguments); + final OldSubCommand subCommand = getSubCommand(arguments); if (subCommand == null || (argumentSize > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { final String name = argumentSize == 0 ? dev.triumphteam.cmd.core.annotation.Command.DEFAULT_CMD_NAME : arguments.get(0); @@ -80,12 +72,12 @@ public void execute( } @Override - public @NotNull Map> getSubCommands() { + public @NotNull Map> getSubCommands() { return subCommands; } @Override - public @NotNull Map> getSubCommandAlias() { + public @NotNull Map> getSubCommandAlias() { return subCommandAliases; } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java index b6da39e3..80111081 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java @@ -24,13 +24,10 @@ package dev.triumphteam.cmds.simple; import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.subcommand.SubCommand; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.List; - -public final class SimpleSubCommand extends SubCommand { +public final class SimpleSubCommand extends OldSubCommand { public SimpleSubCommand( final @NotNull SimpleSubCommandProcessor processor, diff --git a/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt b/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt index a56a1233..2c1429d2 100644 --- a/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt +++ b/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt @@ -3,7 +3,7 @@ package dev.triumphteam.tests import dev.triumphteam.cmd.core.message.MessageRegistry import dev.triumphteam.cmd.core.sender.SenderMapper import dev.triumphteam.cmd.core.sender.SenderValidator -import dev.triumphteam.cmd.core.subcommand.SubCommand +import dev.triumphteam.cmd.core.subcommand.OldSubCommand class TestSender @@ -18,7 +18,7 @@ class TestSenderValidator : SenderValidator { override fun validate( messageRegistry: MessageRegistry, - subCommand: SubCommand, + subCommand: OldSubCommand, sender: TestSender, ): Boolean = true } From 16fa7371567c38bb5a552471bbaafec2c70da69b Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Fri, 23 Dec 2022 22:02:14 +0000 Subject: [PATCH 015/101] chore: Sub command processing start = --- core/src/main/java/dev/triumphteam/cmd/core/Command.java | 7 +++---- .../java/dev/triumphteam/cmd/core/argument/SubCommand.java | 3 ++- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/Command.java index 5493624f..38ce885e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/Command.java @@ -23,9 +23,8 @@ */ package dev.triumphteam.cmd.core; -import dev.triumphteam.cmd.core.processor.Commands; +import dev.triumphteam.cmd.core.argument.SubCommand; import dev.triumphteam.cmd.core.subcommand.OldSubCommand; -import dev.triumphteam.cmd.core.subcommand.SubCommand; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -47,7 +46,7 @@ public interface Command { @NotNull Map> getSubCommandAlias(); - void addSubCommand(final @NotNull SubCommand subCommand, final boolean isAlias); + void addSubCommand(final @NotNull SubCommand subCommand, final boolean isAlias); default void addCommandsFrom(final @NotNull BaseCommand baseCommand) { final Class klass = baseCommand.getClass(); @@ -59,7 +58,7 @@ default void addCommandsFrom(final @NotNull BaseCommand baseCommand) { // Not a command, ignore the method if (name == null) continue; - + } // TODO: CLASSES diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java index a3b05475..bf4c48f9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java @@ -1,5 +1,6 @@ package dev.triumphteam.cmd.core.argument; -public class SubCommand { +public interface SubCommand { + } From 140a27406aaf923523630eec89e289ee5ddb4830 Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Fri, 23 Dec 2022 22:48:09 +0000 Subject: [PATCH 016/101] chore: Formatting I guess --- .gitignore | 1 - README.md | 8 ++-- build-logic/build.gradle.kts | 13 +++-- build-logic/settings.gradle.kts | 15 ++++++ .../kotlin/cmds.base-conventions.gradle.kts | 47 ++++++++++++++++--- .../cmds.library-conventions.gradle.kts | 4 +- .../kotlin/cmds.parent-conventions.gradle.kts | 26 ---------- .../dev/triumphteam/cmd/core/Command.java | 2 +- .../triumphteam/cmd/core/CommandManager.java | 8 ++-- .../cmd/core/annotation/ArgDescriptions.java | 8 ++-- .../cmd/core/annotation/ArgName.java | 8 ++-- .../cmd/core/annotation/Async.java | 8 ++-- .../cmd/core/annotation/Choices.java | 8 ++-- .../cmd/core/annotation/Command.java | 14 +++--- .../cmd/core/annotation/CommandFlags.java | 11 ++--- .../cmd/core/annotation/Default.java | 11 ++--- .../triumphteam/cmd/core/annotation/Flag.java | 20 ++++---- .../triumphteam/cmd/core/annotation/Join.java | 11 ++--- .../cmd/core/annotation/NamedArguments.java | 8 ++-- .../cmd/core/annotation/Optional.java | 8 ++-- .../cmd/core/annotation/Requirement.java | 14 +++--- .../cmd/core/annotation/Requirements.java | 8 ++-- .../cmd/core/annotation/Split.java | 11 ++--- .../cmd/core/annotation/SubCommand.java | 14 +++--- .../cmd/core/annotation/Suggestion.java | 8 ++-- .../cmd/core/annotation/Suggestions.java | 8 ++-- .../argument/AbstractInternalArgument.java | 8 ++-- .../cmd/core/argument/ArgumentRegistry.java | 8 ++-- .../cmd/core/argument/ArgumentResolver.java | 8 ++-- .../argument/CollectionInternalArgument.java | 8 ++-- .../core/argument/EnumInternalArgument.java | 8 ++-- .../core/argument/FlagInternalArgument.java | 8 ++-- .../cmd/core/argument/InternalArgument.java | 10 ++-- .../JoinedStringInternalArgument.java | 8 ++-- .../argument/LimitlessInternalArgument.java | 8 ++-- .../core/argument/NamedInternalArgument.java | 8 ++-- .../argument/ResolverInternalArgument.java | 8 ++-- .../argument/SplitStringInternalArgument.java | 8 ++-- .../core/argument/StringInternalArgument.java | 8 ++-- .../cmd/core/argument/SubCommand.java | 23 +++++++++ .../named/AbstractArgumentBuilder.java | 8 ++-- .../cmd/core/argument/named/Argument.java | 8 ++-- .../core/argument/named/ArgumentBuilder.java | 8 ++-- .../cmd/core/argument/named/ArgumentKey.java | 8 ++-- .../cmd/core/argument/named/Arguments.java | 8 ++-- .../cmd/core/argument/named/ListArgument.java | 8 ++-- .../argument/named/ListArgumentBuilder.java | 8 ++-- .../argument/named/NamedArgumentParser.java | 8 ++-- .../argument/named/NamedArgumentRegistry.java | 8 ++-- .../argument/named/NamedArgumentResult.java | 8 ++-- .../core/argument/named/SimpleArgument.java | 8 ++-- .../exceptions/CommandExecutionException.java | 8 ++-- .../CommandRegistrationException.java | 8 ++-- .../SubCommandRegistrationException.java | 8 ++-- .../execution/AsyncExecutionProvider.java | 8 ++-- .../cmd/core/execution/ExecutionProvider.java | 8 ++-- .../core/execution/SyncExecutionProvider.java | 8 ++-- .../triumphteam/cmd/core/flag/FlagKey.java | 8 ++-- .../cmd/core/flag/FlagRegistry.java | 8 ++-- .../dev/triumphteam/cmd/core/flag/Flags.java | 8 ++-- .../cmd/core/flag/internal/ArgFlagValue.java | 8 ++-- .../core/flag/internal/EmptyFlagValue.java | 8 ++-- .../cmd/core/flag/internal/FlagGroup.java | 8 ++-- .../cmd/core/flag/internal/FlagOptions.java | 8 ++-- .../cmd/core/flag/internal/FlagParser.java | 8 ++-- .../cmd/core/flag/internal/FlagScanner.java | 8 ++-- .../cmd/core/flag/internal/FlagValidator.java | 8 ++-- .../cmd/core/flag/internal/FlagValue.java | 8 ++-- .../cmd/core/flag/internal/FlagsResult.java | 8 ++-- .../cmd/core/message/ContextualKey.java | 8 ++-- .../cmd/core/message/MessageKey.java | 8 ++-- .../cmd/core/message/MessageRegistry.java | 8 ++-- .../cmd/core/message/MessageResolver.java | 8 ++-- .../context/AbstractMessageContext.java | 8 ++-- .../context/DefaultMessageContext.java | 8 ++-- .../context/InvalidArgumentContext.java | 8 ++-- .../core/message/context/MessageContext.java | 8 ++-- .../context/MessageContextFactory.java | 8 ++-- .../processor/AbstractCommandProcessor.java | 23 +++++++++ .../AbstractSubCommandProcessor.java | 8 ++-- .../cmd/core/processor/Commands.java | 23 +++++++++ .../OldAbstractCommandProcessor.java | 1 - .../OldAbstractSubCommandProcessor.java | 8 ++-- .../cmd/core/registry/Registry.java | 8 ++-- .../cmd/core/registry/RegistryContainer.java | 8 ++-- .../cmd/core/registry/RegistryKey.java | 8 ++-- .../cmd/core/requirement/Requirement.java | 8 ++-- .../cmd/core/requirement/RequirementKey.java | 8 ++-- .../core/requirement/RequirementRegistry.java | 8 ++-- .../core/requirement/RequirementResolver.java | 8 ++-- .../cmd/core/sender/SenderMapper.java | 8 ++-- .../cmd/core/sender/SenderValidator.java | 8 ++-- .../cmd/core/subcommand/OldSubCommand.java | 8 ++-- .../core/subcommand/invoker/ClassInvoker.java | 23 +++++++++ .../cmd/core/subcommand/invoker/Invoker.java | 23 +++++++++ .../subcommand/invoker/MethodInvoker.java | 23 +++++++++ .../cmd/core/suggestion/EmptySuggestion.java | 8 ++-- .../cmd/core/suggestion/EnumSuggestion.java | 8 ++-- .../cmd/core/suggestion/SimpleSuggestion.java | 8 ++-- .../cmd/core/suggestion/Suggestion.java | 8 ++-- .../core/suggestion/SuggestionContext.java | 8 ++-- .../cmd/core/suggestion/SuggestionKey.java | 8 ++-- .../core/suggestion/SuggestionRegistry.java | 8 ++-- .../core/suggestion/SuggestionResolver.java | 8 ++-- .../triumphteam/cmd/core/util/EnumUtils.java | 8 ++-- .../cmd/jda/annotation/Privileges.java | 8 ++-- .../triumphteam/cmd/jda/annotation/Roles.java | 8 ++-- .../cmd/prefixed/PrefixedCommand.java | 8 ++-- .../cmd/prefixed/PrefixedCommandExecutor.java | 8 ++-- .../cmd/prefixed/PrefixedCommandListener.java | 8 ++-- .../cmd/prefixed/PrefixedCommandManager.java | 8 ++-- .../prefixed/PrefixedCommandProcessor.java | 8 ++-- .../cmd/prefixed/PrefixedCommandSender.java | 8 ++-- .../cmd/prefixed/PrefixedSenderValidator.java | 8 ++-- .../cmd/prefixed/PrefixedSubCommand.java | 8 ++-- .../prefixed/PrefixedSubCommandProcessor.java | 8 ++-- .../cmd/prefixed/annotation/Prefix.java | 8 ++-- .../cmd/prefixed/sender/PrefixedSender.java | 8 ++-- .../cmd/slash/AttachmentArgument.java | 8 ++-- .../cmd/slash/AttachmentRegistry.java | 8 ++-- .../triumphteam/cmd/slash/SlashCommand.java | 8 ++-- .../cmd/slash/SlashCommandListener.java | 8 ++-- .../cmd/slash/SlashCommandManager.java | 8 ++-- .../cmd/slash/SlashCommandProcessor.java | 8 ++-- .../cmd/slash/SlashCommandSender.java | 8 ++-- .../cmd/slash/SlashRegistryContainer.java | 8 ++-- .../cmd/slash/SlashSenderValidator.java | 8 ++-- .../cmd/slash/SlashSubCommand.java | 8 ++-- .../cmd/slash/SlashSubCommandProcessor.java | 8 ++-- .../cmd/slash/annotation/Choice.java | 8 ++-- .../cmd/slash/annotation/Choices.java | 8 ++-- .../triumphteam/cmd/slash/choices/Choice.java | 8 ++-- .../cmd/slash/choices/ChoiceKey.java | 8 ++-- .../cmd/slash/choices/ChoiceRegistry.java | 8 ++-- .../cmd/slash/choices/EmptyChoice.java | 8 ++-- .../cmd/slash/choices/EnumChoice.java | 8 ++-- .../cmd/slash/choices/SimpleChoice.java | 8 ++-- .../cmd/slash/sender/SlashSender.java | 8 ++-- .../cmd/slash/util/JdaOptionUtil.java | 8 ++-- gradle.properties | 3 +- gradle/libs.versions.toml | 31 ++++++++++-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../bukkit/BukkitAsyncExecutionProvider.java | 8 ++-- .../triumphteam/cmd/bukkit/BukkitCommand.java | 1 - .../cmd/bukkit/BukkitSenderValidator.java | 8 ++-- .../cmd/bukkit/BukkitSubCommand.java | 8 ++-- .../cmd/bukkit/BukkitSubCommandProcessor.java | 8 ++-- .../cmd/bukkit/CommandPermission.java | 8 ++-- .../cmd/bukkit/OldBukkitCommand.java | 8 ++-- .../cmd/bukkit/annotation/Permission.java | 8 ++-- .../cmd/bukkit/message/BukkitMessageKey.java | 8 ++-- .../message/NoPermissionMessageContext.java | 8 ++-- .../cmds/simple/SimpleCommandManager.java | 8 ++-- .../cmds/simple/SimpleSubCommand.java | 8 ++-- .../simple/SimpleSubCommandProcessor.java | 8 ++-- .../kotlin/dev/triumphteam/tests/Sender.kt | 23 +++++++++ .../fail/command registration fail test.kt | 23 +++++++++ 157 files changed, 843 insertions(+), 627 deletions(-) create mode 100644 build-logic/settings.gradle.kts diff --git a/.gitignore b/.gitignore index ccd345bc..0f840d89 100644 --- a/.gitignore +++ b/.gitignore @@ -47,7 +47,6 @@ # CMake cmake-build-*/ - # Mongo Explorer plugin .idea/**/mongoSettings.xml diff --git a/README.md b/README.md index 304fbd24..7b240465 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,8 @@ With this, your parameters are the command's arguments! ## Features -- Simplifies how you handle your command arguments, instead of having an array with arguments and handling it one by one, simply add what you want to the parameters of your command method. +- Simplifies how you handle your command arguments, instead of having an array with arguments and handling it one by + one, simply add what you want to the parameters of your command method. - Small, adds only 32KB to your project. - All messages are customizable. - Makes having multiple commands even easier. @@ -28,13 +29,14 @@ You can find the documentation [**here**](https://triumphteam.dev/library/triump ## Contributing -Found any issue? Please report it [**here**](https://github.com/TriumphTeam/triumph-cmds/issues). +Found any issue? Please report it [**here**](https://github.com/TriumphTeam/triumph-cmds/issues). Feel free to PR any changes you'd like to see in it! The source code can be found [**here**](https://github.com/TriumphTeam/triumph-cmds). ## GUI -**Triumph** also has an additional lib to make easier GUI's in Spigot, you can read more about it [**here**](https://triumphteam.dev/library/triumph-gui/introduction). +**Triumph** also has an additional lib to make easier GUI's in Spigot, you can read more about it [**here +**](https://triumphteam.dev/library/triumph-gui/introduction). ## Other diff --git a/build-logic/build.gradle.kts b/build-logic/build.gradle.kts index 917d9b28..8999fb75 100644 --- a/build-logic/build.gradle.kts +++ b/build-logic/build.gradle.kts @@ -2,11 +2,10 @@ plugins { `kotlin-dsl` } -repositories { - gradlePluginPortal() -} - dependencies { - implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.20") - implementation("gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.16.1") -} \ No newline at end of file + // Hack to allow version catalog inside convention plugins + implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location)) + + // Bundled plugins + implementation(libs.bundles.build) +} diff --git a/build-logic/settings.gradle.kts b/build-logic/settings.gradle.kts new file mode 100644 index 00000000..d6c5922e --- /dev/null +++ b/build-logic/settings.gradle.kts @@ -0,0 +1,15 @@ +rootProject.name = "build-logic" + +dependencyResolutionManagement { + repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS) + repositories { + gradlePluginPortal() + mavenCentral() + } + + versionCatalogs { + register("libs") { + from(files("../gradle/libs.versions.toml")) // include from parent project + } + } +} \ No newline at end of file diff --git a/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts b/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts index 05e204cf..94e85781 100644 --- a/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts @@ -1,18 +1,22 @@ +import org.gradle.accessors.dm.LibrariesForLibs import org.jetbrains.kotlin.gradle.tasks.KotlinCompile +// Hack which exposes `libs` to this convention plugin +val libs = the() + plugins { `java-library` - id("com.github.hierynomus.license") kotlin("jvm") + id("com.github.hierynomus.license") + id("com.diffplug.spotless") } repositories { mavenCentral() - mavenLocal() } dependencies { - compileOnly("org.jetbrains:annotations:23.0.0") + compileOnly(libs.annotations) } java { @@ -22,8 +26,14 @@ java { withJavadocJar() } +kotlin { + explicitApi() +} + +val licenseFile: File = rootProject.file("LICENSE") + license { - header = rootProject.file("LICENSE") + header = licenseFile encoding = "UTF-8" mapping("kotlin", "JAVADOC_STYLE") mapping("java", "JAVADOC_STYLE") @@ -32,10 +42,35 @@ license { include("**/*.java") } +spotless { + format("format") { + trimTrailingWhitespace() + endWithNewline() + indentWithSpaces(4) + + target( + "*.md", + ".gitignore", + "*.properties", + ) + } + + java { + formatAnnotations() + } + + kotlin { + ktlint("0.47.1").editorConfigOverride( + mapOf( + "ktlint_disabled_rules" to "filename,trailing-comma-on-call-site,trailing-comma-on-declaration-site", + ) + ) + } +} + tasks { withType { options.encoding = "UTF-8" - //options.compilerArgs.add("-Xlint:unchecked") } withType { @@ -44,4 +79,4 @@ tasks { javaParameters = true } } -} \ No newline at end of file +} diff --git a/build-logic/src/main/kotlin/cmds.library-conventions.gradle.kts b/build-logic/src/main/kotlin/cmds.library-conventions.gradle.kts index 22456b36..4b805d76 100644 --- a/build-logic/src/main/kotlin/cmds.library-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/cmds.library-conventions.gradle.kts @@ -31,7 +31,7 @@ tasks { developers { developer { - id.set("matt") + id.set("Matt") name.set("Mateus Moreira") } } @@ -57,4 +57,4 @@ tasks { } } } -} \ No newline at end of file +} diff --git a/build-logic/src/main/kotlin/cmds.parent-conventions.gradle.kts b/build-logic/src/main/kotlin/cmds.parent-conventions.gradle.kts index e6afc327..a8b3fb23 100644 --- a/build-logic/src/main/kotlin/cmds.parent-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/cmds.parent-conventions.gradle.kts @@ -1,30 +1,4 @@ -import org.jetbrains.kotlin.gradle.tasks.KotlinCompile - plugins { `java-library` kotlin("jvm") } - -repositories { - mavenCentral() - mavenLocal() -} - -java { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 -} - -tasks { - withType { - options.encoding = "UTF-8" - //options.compilerArgs.add("-Xlint:unchecked") - } - - withType { - kotlinOptions { - jvmTarget = "1.8" - javaParameters = true - } - } -} \ No newline at end of file diff --git a/core/src/main/java/dev/triumphteam/cmd/core/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/Command.java index 38ce885e..f35131f4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/Command.java @@ -58,7 +58,7 @@ default void addCommandsFrom(final @NotNull BaseCommand baseCommand) { // Not a command, ignore the method if (name == null) continue; - + } // TODO: CLASSES diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index 244f4bdd..f729329e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgDescriptions.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgDescriptions.java index 6d21aa12..f1f97df4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgDescriptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgDescriptions.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgName.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgName.java index 95a714bb..fe8986e8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgName.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgName.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Async.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Async.java index 4540d4a0..39499c32 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Async.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Async.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Choices.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Choices.java index a94a3811..209f7433 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Choices.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Choices.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java index 2587d030..797aaa8e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -48,8 +48,7 @@ * * @return The command name. */ - @NotNull - String value() default DEFAULT_CMD_NAME; + @NotNull String value() default DEFAULT_CMD_NAME; /** * List with all command aliases. @@ -57,6 +56,5 @@ * * @return The alias array. */ - @NotNull - String[] alias() default {}; + @NotNull String[] alias() default {}; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/CommandFlags.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/CommandFlags.java index 64277685..fadec7c7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/CommandFlags.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/CommandFlags.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -42,6 +42,5 @@ * * @return Array of flags. */ - @NotNull - Flag[] value(); + @NotNull Flag[] value(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Default.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Default.java index de16995c..7190b40f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Default.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Default.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -45,6 +45,5 @@ * * @return An array with command aliases. */ - @NotNull - String[] alias() default {}; + @NotNull String[] alias() default {}; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Flag.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Flag.java index 1301667f..af0bfa52 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Flag.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Flag.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -46,8 +46,7 @@ * * @return The flag's main identifier. */ - @NotNull - String flag() default ""; + @NotNull String flag() default ""; /** * Long flag identifier. Isn't required either, as long as either flag or long flag has values. @@ -55,8 +54,7 @@ * * @return The flag's long identifier. */ - @NotNull - String longFlag() default ""; + @NotNull String longFlag() default ""; /** * Define if the flag should have an argument, and it's type. @@ -64,10 +62,8 @@ * * @return The argument type. */ - @NotNull - Class argument() default void.class; + @NotNull Class argument() default void.class; // TODO: Comments - @NotNull - String suggestion() default ""; + @NotNull String suggestion() default ""; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Join.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Join.java index e511f612..41fc8111 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Join.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Join.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -43,6 +43,5 @@ * * @return The delimiter of to be used by the join method. */ - @NotNull - String value() default " "; + @NotNull String value() default " "; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/NamedArguments.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/NamedArguments.java index d0da031e..d48667ab 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/NamedArguments.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/NamedArguments.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Optional.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Optional.java index 11bb3d55..cc694326 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Optional.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Optional.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirement.java index cff363f2..1b9be8bb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirement.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -46,16 +46,14 @@ * * @return The requirement key. */ - @NotNull - String value(); + @NotNull String value(); /** * The message key will be used to send a custom message if the specified requirement is denied. * * @return The message key or empty if not needed. */ - @NotNull - String messageKey() default ""; + @NotNull String messageKey() default ""; boolean invert() default false; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirements.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirements.java index 723d3670..af2aa90f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirements.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirements.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Split.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Split.java index c167f397..f86d70df 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Split.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Split.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -44,6 +44,5 @@ * * @return The delimiter. */ - @NotNull - String value() default ","; + @NotNull String value() default ","; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/SubCommand.java index c4cde419..e96c3dab 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/SubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -43,14 +43,12 @@ * * @return The sub command name. */ - @NotNull - String value(); + @NotNull String value(); /** * List with all the valid aliases for the command. * * @return An array with command aliases. */ - @NotNull - String[] alias() default {}; + @NotNull String[] alias() default {}; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestion.java index e5cc4582..ec596964 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestion.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestions.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestions.java index 91a55ed8..cb960259 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestions.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java index e748e651..bf30ce43 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java index 73a9ae44..83c1d84e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java index 1d77765d..f8871cc9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java index ae80b2a0..c038de6e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java index 8dd5f61e..0a83374c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java index 971d5d0e..6f16d18d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index aebc0051..92b4b93f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -82,7 +82,7 @@ public interface InternalArgument { @Nullable Object resolve(final @NotNull S sender, final @NotNull T value); // TODO: Comments - @NotNull List<@NotNull String> suggestions( + @NotNull List<@NotNull String> suggestions( final @NotNull S sender, final @NotNull List<@NotNull String> trimmed, final @NotNull SuggestionContext context diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java index aa7a4bed..402ee4fc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java index 1fefb2ae..e635dfb3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java index 138b9438..13dc2b5c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java index e4082e50..635df55b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java index cfd1defc..16b6385c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java index e174b5c7..09ca063f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java index bf4c48f9..b76e1851 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java @@ -1,3 +1,26 @@ +/** + * MIT License + *

+ * Copyright (c) 2019-2021 Matt + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.argument; public interface SubCommand { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java index fc87a18a..6df27220 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java index 351e0508..02045428 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java index 4783756c..46842b7c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java index 5e4e1df5..7dac549c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java index 5046e470..42763855 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java index 4d6952e4..97834ab5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java index c2c34cd8..6b028177 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java index 663a7efc..c75378f2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java index fc5318a6..dbb948c6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java index 09f0e347..c6e0a452 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java index ea6d4a7a..4c389aff 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandExecutionException.java b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandExecutionException.java index e2d8a840..b94a0877 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandExecutionException.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandExecutionException.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java index d57a6045..952d141c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java index 1d516c4c..2f5f660a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/execution/AsyncExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/execution/AsyncExecutionProvider.java index dffbede5..4cb8794a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/execution/AsyncExecutionProvider.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/execution/AsyncExecutionProvider.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/execution/ExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/execution/ExecutionProvider.java index cb5c6fb0..3a29d357 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/execution/ExecutionProvider.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/execution/ExecutionProvider.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/execution/SyncExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/execution/SyncExecutionProvider.java index 2b1e2b0d..e404114b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/execution/SyncExecutionProvider.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/execution/SyncExecutionProvider.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java index 36df4b79..91d64120 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagRegistry.java index d39c59e6..aeb4cd77 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/Flags.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/Flags.java index d93d276a..6f03e229 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/Flags.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/Flags.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java index 1b51a418..627f6b72 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/EmptyFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/EmptyFlagValue.java index e80786da..d349a9d8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/EmptyFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/EmptyFlagValue.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java index 22977c4c..5405198a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java index f908c5d1..9ab5072b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java index 21b6b7c3..087df3fc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagScanner.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagScanner.java index 22c312e2..2d2e6e03 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagScanner.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagScanner.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java index 4e6a2684..7507d8de 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValue.java index ae3994e3..477deb2a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValue.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagsResult.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagsResult.java index 26e312e5..0b0a2fc6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagsResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagsResult.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java b/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java index 5a1b622c..2ab942e0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java index b8cba3e5..7082116c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageRegistry.java index ba9d154a..69ed8c10 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageResolver.java index 02dc3f0e..d771c2c0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageResolver.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/AbstractMessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/AbstractMessageContext.java index 7a70c649..5f32d3f8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/AbstractMessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/AbstractMessageContext.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/DefaultMessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/DefaultMessageContext.java index 7094332d..cd61f16e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/DefaultMessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/DefaultMessageContext.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java index e36c1210..eafa0fa0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java index 4aebe5a7..6dbf6217 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java index 41d08434..fe550e2a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index e5880664..382ab506 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -1,3 +1,26 @@ +/** + * MIT License + *

+ * Copyright (c) 2019-2021 Matt + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java index af55d0f6..4164c0e8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java index 8fb08a31..a260d6a0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java @@ -1,3 +1,26 @@ +/** + * MIT License + *

+ * Copyright (c) 2019-2021 Matt + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java index 6bf1f82b..9b8c40b5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java @@ -248,7 +248,6 @@ private void extractCommandNames() { } alias.addAll(baseCommand.getAlias());*/ - if (name.isEmpty()) { throw new CommandRegistrationException("Command name must not be empty", BaseCommand.class); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java index fbeb92fc..65e190f7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/registry/Registry.java b/core/src/main/java/dev/triumphteam/cmd/core/registry/Registry.java index da309355..c95ba304 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/registry/Registry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/registry/Registry.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java index 69468854..7cd38002 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryKey.java b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryKey.java index dd071b49..4e4478e7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryKey.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java index bc8cc103..4465e979 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java index f556f2d5..b463d56b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementRegistry.java index 72a87dc5..5891dcb5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java index 280e6bfd..e933cfe5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderMapper.java b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderMapper.java index 07850160..2f501884 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderMapper.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderMapper.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java index 00a991ab..9a678452 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java index af05fbbc..4030c864 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java index dde99bcb..3855b7eb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java @@ -1,3 +1,26 @@ +/** + * MIT License + *

+ * Copyright (c) 2019-2021 Matt + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.subcommand.invoker; import dev.triumphteam.cmd.core.BaseCommand; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java index 650f5bc4..ace6c250 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java @@ -1,3 +1,26 @@ +/** + * MIT License + *

+ * Copyright (c) 2019-2021 Matt + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.subcommand.invoker; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java index 8c51a96b..100107b6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java @@ -1,3 +1,26 @@ +/** + * MIT License + *

+ * Copyright (c) 2019-2021 Matt + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.subcommand.invoker; import dev.triumphteam.cmd.core.BaseCommand; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java index 689698f3..f2fe82c0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java index 83b0f976..da3f7e9b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java index 44c1b1c9..f22d3054 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java index 8d28f209..88a1091f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java index 0e00e9d2..7631a4bd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java index 731cbf29..b2a5e0a1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java index 36c0ac1d..b57317dd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java index 39529c9c..3be01e09 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java b/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java index 476eb0dd..59e01082 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java b/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java index 25daa866..7cfc3132 100644 --- a/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java +++ b/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java b/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java index 683feb15..974a58ff 100644 --- a/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java +++ b/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java index e75944a6..6d530e6b 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java index 5630c998..b7800d67 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java index 574a0a6f..6544a310 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java index f03d1842..c4c6b22e 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java index 7b15cc47..42fed75e 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java index 25ea18c2..6d28446d 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java index 0b0b94e9..dad7c864 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java index 3a4f9aaa..d8fc9bbd 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java index 1a36ae02..b07d4b00 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/annotation/Prefix.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/annotation/Prefix.java index 3e32f66e..8e3bc499 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/annotation/Prefix.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/annotation/Prefix.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java index b2d4c2a4..91f1fe04 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java index b7289184..67f72b54 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentRegistry.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentRegistry.java index 7707bb5a..df6e96c8 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentRegistry.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java index 627ae11f..a3c68d4b 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java index 25dcf2c0..d1307218 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java index aa8240db..7f9e4449 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java index f71c9328..94c8d026 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java index 420006e4..a503c3e5 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java index da2dc9ba..24dbfd43 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java index e9ea37d2..2644abfb 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java index ace3a591..b091977a 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java index e4a2cf1b..96849442 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java index 17c54d84..94441a0f 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java index c18eceae..facee2c3 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java index a229be82..f964cbcd 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java index c5fdd3c2..1a0151e4 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java index 7c500ccd..5b33c2b2 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java index b0b21a10..d40cffd5 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java index 2590d549..7bae5640 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java index 663867a4..a2e0e227 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java index 21407391..d07c3fb8 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaOptionUtil.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaOptionUtil.java index 4d4fba2d..653a1636 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaOptionUtil.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaOptionUtil.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/gradle.properties b/gradle.properties index d70df301..717cc1f1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,3 @@ kotlin.stdlib.default.dependency=false - version=2.0.0-SNAPSHOT -group=dev.triumphteam \ No newline at end of file +group=dev.triumphteam diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2fdac743..be7517c0 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,10 +1,14 @@ [versions] -# Code +kotlin = "1.7.21" +license = "0.16.1" + +# Core guava = "31.1-jre" +annotations = "23.0.0" # Testing -junit = "5.8.2" -assertj = "3.22.0" +junit = "5.9.1" +assertj = "3.23.1" # Minecraft spigot = "1.18.2-R0.1-SNAPSHOT" @@ -12,10 +16,13 @@ spigot = "1.18.2-R0.1-SNAPSHOT" # Discord jda = "5.0.0-alpha.18" +# Formatting +spotless = "6.12.0" [libraries] # Core guava = { module = "com.google.guava:guava", version.ref = "guava" } +annotations = { module = "org.jetbrains:annotations", version.ref = "annotations" } # Testing junit-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit" } @@ -27,3 +34,21 @@ spigot = { module = "org.spigotmc:spigot-api", version.ref = "spigot" } # Discord jda = { module = "net.dv8tion:JDA", version.ref = "jda" } + +# build +build-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } +build-license = { module = "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin", version.ref = "license" } +build-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" } + +[bundles] +# Testing +testing = [ + "junit-api", + "junit-engine", + "assertj" +] +build = [ + "build-kotlin", + "build-license", + "build-spotless" +] diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index aa991fce..070cb702 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitAsyncExecutionProvider.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitAsyncExecutionProvider.java index 456bc7da..a8b4faba 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitAsyncExecutionProvider.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitAsyncExecutionProvider.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index 807256f6..944a5f1c 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -87,7 +87,6 @@ public boolean execute( messageRegistry.sendMessage(BukkitMessageKey.NO_PERMISSION, mappedSender, new NoPermissionMessageContext(getName(), subCommand.getName(), permission)); return true; }*/ - subCommand.execute(mappedSender, !subCommand.isDefault() ? arguments.subList(1, argumentSize) : arguments); return true; } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java index 977a1804..13f1adb6 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java index bf4c2cad..f312a914 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java index 5df1d74a..0049cb25 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java index f27a117f..b264caee 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java index 89d0ba87..97d60fdd 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java index f4357922..810042cd 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java index fdc36ce1..03a166b9 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java index c81342d5..29b9334f 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 04330e59..99db2412 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java index 80111081..1f15f9ae 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java index 7cb67bd0..9ed26bc3 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt b/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt index 2c1429d2..a1531d2a 100644 --- a/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt +++ b/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.tests import dev.triumphteam.cmd.core.message.MessageRegistry diff --git a/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt b/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt index 72e63cf9..9352c538 100644 --- a/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt +++ b/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.tests.fail import dev.triumphteam.cmd.core.BaseCommand From bf201ae9b6bf3c15633a93cc9bb33a279405bccc Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Fri, 23 Dec 2022 23:42:59 +0000 Subject: [PATCH 017/101] chore: More formatting --- .../kotlin/cmds.base-conventions.gradle.kts | 7 +--- .../dev/triumphteam/cmd/core/BaseCommand.java | 8 ++-- .../dev/triumphteam/cmd/core/Command.java | 35 +++++++++-------- .../triumphteam/cmd/core/CommandManager.java | 8 ++-- .../cmd/core/annotation/ArgDescriptions.java | 11 +++--- .../cmd/core/annotation/ArgName.java | 8 ++-- .../cmd/core/annotation/Async.java | 8 ++-- .../cmd/core/annotation/Choices.java | 8 ++-- .../cmd/core/annotation/Command.java | 8 ++-- .../cmd/core/annotation/CommandFlags.java | 8 ++-- .../cmd/core/annotation/Default.java | 8 ++-- .../cmd/core/annotation/Description.java | 8 ++-- .../triumphteam/cmd/core/annotation/Flag.java | 8 ++-- .../triumphteam/cmd/core/annotation/Join.java | 8 ++-- .../cmd/core/annotation/NamedArguments.java | 8 ++-- .../cmd/core/annotation/Optional.java | 8 ++-- .../cmd/core/annotation/Requirement.java | 8 ++-- .../cmd/core/annotation/Requirements.java | 8 ++-- .../cmd/core/annotation/Split.java | 8 ++-- .../cmd/core/annotation/SubCommand.java | 8 ++-- .../cmd/core/annotation/Suggestion.java | 8 ++-- .../cmd/core/annotation/Suggestions.java | 8 ++-- .../argument/AbstractInternalArgument.java | 8 ++-- .../cmd/core/argument/ArgumentRegistry.java | 8 ++-- .../cmd/core/argument/ArgumentResolver.java | 8 ++-- .../argument/CollectionInternalArgument.java | 8 ++-- .../core/argument/EnumInternalArgument.java | 8 ++-- .../core/argument/FlagInternalArgument.java | 8 ++-- .../cmd/core/argument/InternalArgument.java | 8 ++-- .../JoinedStringInternalArgument.java | 8 ++-- .../argument/LimitlessInternalArgument.java | 8 ++-- .../core/argument/NamedInternalArgument.java | 8 ++-- .../argument/ResolverInternalArgument.java | 8 ++-- .../argument/SplitStringInternalArgument.java | 8 ++-- .../core/argument/StringInternalArgument.java | 8 ++-- .../cmd/core/argument/SubCommand.java | 8 ++-- .../named/AbstractArgumentBuilder.java | 8 ++-- .../cmd/core/argument/named/Argument.java | 8 ++-- .../core/argument/named/ArgumentBuilder.java | 8 ++-- .../cmd/core/argument/named/ArgumentKey.java | 8 ++-- .../cmd/core/argument/named/Arguments.java | 8 ++-- .../cmd/core/argument/named/ListArgument.java | 8 ++-- .../argument/named/ListArgumentBuilder.java | 8 ++-- .../argument/named/NamedArgumentParser.java | 8 ++-- .../argument/named/NamedArgumentRegistry.java | 8 ++-- .../argument/named/NamedArgumentResult.java | 8 ++-- .../core/argument/named/SimpleArgument.java | 8 ++-- .../exceptions/CommandExecutionException.java | 8 ++-- .../CommandRegistrationException.java | 8 ++-- .../SubCommandRegistrationException.java | 8 ++-- .../execution/AsyncExecutionProvider.java | 8 ++-- .../cmd/core/execution/ExecutionProvider.java | 8 ++-- .../core/execution/SyncExecutionProvider.java | 8 ++-- .../triumphteam/cmd/core/flag/FlagKey.java | 8 ++-- .../cmd/core/flag/FlagRegistry.java | 8 ++-- .../dev/triumphteam/cmd/core/flag/Flags.java | 8 ++-- .../cmd/core/flag/internal/ArgFlagValue.java | 8 ++-- .../core/flag/internal/EmptyFlagValue.java | 8 ++-- .../cmd/core/flag/internal/FlagGroup.java | 8 ++-- .../cmd/core/flag/internal/FlagOptions.java | 8 ++-- .../cmd/core/flag/internal/FlagParser.java | 8 ++-- .../cmd/core/flag/internal/FlagScanner.java | 8 ++-- .../cmd/core/flag/internal/FlagValidator.java | 8 ++-- .../cmd/core/flag/internal/FlagValue.java | 8 ++-- .../cmd/core/flag/internal/FlagsResult.java | 8 ++-- .../cmd/core/message/ContextualKey.java | 8 ++-- .../cmd/core/message/MessageKey.java | 8 ++-- .../cmd/core/message/MessageRegistry.java | 8 ++-- .../cmd/core/message/MessageResolver.java | 8 ++-- .../context/AbstractMessageContext.java | 8 ++-- .../context/DefaultMessageContext.java | 8 ++-- .../context/InvalidArgumentContext.java | 8 ++-- .../core/message/context/MessageContext.java | 8 ++-- .../context/MessageContextFactory.java | 8 ++-- .../processor/AbstractCommandProcessor.java | 8 ++-- .../AbstractSubCommandProcessor.java | 8 ++-- .../cmd/core/processor/Commands.java | 8 ++-- .../OldAbstractCommandProcessor.java | 8 ++-- .../OldAbstractSubCommandProcessor.java | 8 ++-- .../cmd/core/registry/Registry.java | 8 ++-- .../cmd/core/registry/RegistryContainer.java | 8 ++-- .../cmd/core/registry/RegistryKey.java | 8 ++-- .../cmd/core/requirement/Requirement.java | 8 ++-- .../cmd/core/requirement/RequirementKey.java | 8 ++-- .../core/requirement/RequirementRegistry.java | 8 ++-- .../core/requirement/RequirementResolver.java | 8 ++-- .../cmd/core/sender/SenderMapper.java | 8 ++-- .../cmd/core/sender/SenderValidator.java | 8 ++-- .../cmd/core/subcommand/OldSubCommand.java | 38 +++++++------------ .../core/subcommand/invoker/ClassInvoker.java | 8 ++-- .../cmd/core/subcommand/invoker/Invoker.java | 8 ++-- .../subcommand/invoker/MethodInvoker.java | 8 ++-- .../cmd/core/suggestion/EmptySuggestion.java | 8 ++-- .../cmd/core/suggestion/EnumSuggestion.java | 8 ++-- .../cmd/core/suggestion/SimpleSuggestion.java | 8 ++-- .../cmd/core/suggestion/Suggestion.java | 8 ++-- .../core/suggestion/SuggestionContext.java | 8 ++-- .../cmd/core/suggestion/SuggestionKey.java | 8 ++-- .../core/suggestion/SuggestionRegistry.java | 8 ++-- .../core/suggestion/SuggestionResolver.java | 8 ++-- .../triumphteam/cmd/core/util/EnumUtils.java | 8 ++-- .../cmds/simple/SimpleCommand.java | 25 ++++++++---- 102 files changed, 447 insertions(+), 445 deletions(-) diff --git a/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts b/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts index 94e85781..3afb5a17 100644 --- a/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts @@ -30,13 +30,10 @@ kotlin { explicitApi() } -val licenseFile: File = rootProject.file("LICENSE") - license { - header = licenseFile + header = rootProject.file("LICENSE") encoding = "UTF-8" - mapping("kotlin", "JAVADOC_STYLE") - mapping("java", "JAVADOC_STYLE") + useDefaultMappings = true include("**/*.kt") include("**/*.java") diff --git a/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java index c7741b0c..e59a6d53 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/Command.java index f35131f4..c765509b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/Command.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -42,11 +42,15 @@ */ public interface Command { - @NotNull Map> getSubCommands(); + @NotNull Map> getSubCommands(); - @NotNull Map> getSubCommandAlias(); + @NotNull Map> getSubCommandAlias(); - void addSubCommand(final @NotNull SubCommand subCommand, final boolean isAlias); + void addSubCommand( + final @NotNull String name, + final @NotNull SubCommand subCommand, + final boolean isAlias + ); default void addCommandsFrom(final @NotNull BaseCommand baseCommand) { final Class klass = baseCommand.getClass(); @@ -58,14 +62,14 @@ default void addCommandsFrom(final @NotNull BaseCommand baseCommand) { // Not a command, ignore the method if (name == null) continue; - + System.out.println("Sub boy -> " + name); } // TODO: CLASSES } - default @Nullable OldSubCommand getSubCommand(final @NotNull List args) { - OldSubCommand subCommand = getDefaultSubCommand(); + default @Nullable SubCommand getSubCommand(final @NotNull List args) { + SubCommand subCommand = getDefaultSubCommand(); String subCommandName = ""; if (args.size() > 0) subCommandName = args.get(0).toLowerCase(); @@ -73,19 +77,20 @@ default void addCommandsFrom(final @NotNull BaseCommand baseCommand) { subCommand = getSubCommand(subCommandName); } - if (subCommand == null || (args.size() > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { + // TODO + /*if (subCommand == null || (args.size() > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { return null; - } + }*/ return subCommand; } - default @Nullable OldSubCommand getDefaultSubCommand() { + default @Nullable SubCommand getDefaultSubCommand() { return getSubCommands().get(dev.triumphteam.cmd.core.annotation.Command.DEFAULT_CMD_NAME); } - default @Nullable OldSubCommand getSubCommand(final @NotNull String key) { - final OldSubCommand subCommand = getSubCommands().get(key); + default @Nullable SubCommand getSubCommand(final @NotNull String key) { + final SubCommand subCommand = getSubCommands().get(key); if (subCommand != null) return subCommand; return getSubCommandAlias().get(key); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index f729329e..244f4bdd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgDescriptions.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgDescriptions.java index f1f97df4..af5e3b00 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgDescriptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgDescriptions.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -34,6 +34,5 @@ @Target(ElementType.METHOD) public @interface ArgDescriptions { - @NotNull - String[] value(); + @NotNull String[] value(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgName.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgName.java index fe8986e8..95a714bb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgName.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgName.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Async.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Async.java index 39499c32..4540d4a0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Async.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Async.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Choices.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Choices.java index 209f7433..a94a3811 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Choices.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Choices.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java index 797aaa8e..34f0923c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/CommandFlags.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/CommandFlags.java index fadec7c7..e0736053 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/CommandFlags.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/CommandFlags.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Default.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Default.java index 7190b40f..aa8ddea5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Default.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Default.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Description.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Description.java index 04040e57..309833a5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Description.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Description.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Flag.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Flag.java index af0bfa52..a4c4fbd1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Flag.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Flag.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Join.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Join.java index 41fc8111..d8ee9f3d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Join.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Join.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/NamedArguments.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/NamedArguments.java index d48667ab..d0da031e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/NamedArguments.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/NamedArguments.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Optional.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Optional.java index cc694326..11bb3d55 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Optional.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Optional.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirement.java index 1b9be8bb..f094ecc3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirement.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirements.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirements.java index af2aa90f..723d3670 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirements.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirements.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Split.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Split.java index f86d70df..fc64bf2c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Split.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Split.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/SubCommand.java index e96c3dab..9ffcf4fd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/SubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestion.java index ec596964..e5cc4582 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestion.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestions.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestions.java index cb960259..91a55ed8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestions.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java index bf30ce43..e748e651 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java index 83c1d84e..73a9ae44 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java index f8871cc9..1d77765d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java index c038de6e..ae80b2a0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java index 0a83374c..8dd5f61e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java index 6f16d18d..971d5d0e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index 92b4b93f..3f6ac8bf 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java index 402ee4fc..aa7a4bed 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java index e635dfb3..1fefb2ae 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java index 13dc2b5c..138b9438 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java index 635df55b..e4082e50 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java index 16b6385c..cfd1defc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java index 09ca063f..e174b5c7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java index b76e1851..1cb707ca 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java index 6df27220..fc87a18a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java index 02045428..351e0508 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java index 46842b7c..4783756c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java index 7dac549c..5e4e1df5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java index 42763855..5046e470 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java index 97834ab5..4d6952e4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java index 6b028177..c2c34cd8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java index c75378f2..663a7efc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java index dbb948c6..fc5318a6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java index c6e0a452..09f0e347 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java index 4c389aff..ea6d4a7a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandExecutionException.java b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandExecutionException.java index b94a0877..e2d8a840 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandExecutionException.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandExecutionException.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java index 952d141c..d57a6045 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java index 2f5f660a..1d516c4c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/SubCommandRegistrationException.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/execution/AsyncExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/execution/AsyncExecutionProvider.java index 4cb8794a..dffbede5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/execution/AsyncExecutionProvider.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/execution/AsyncExecutionProvider.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/execution/ExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/execution/ExecutionProvider.java index 3a29d357..cb5c6fb0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/execution/ExecutionProvider.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/execution/ExecutionProvider.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/execution/SyncExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/execution/SyncExecutionProvider.java index e404114b..2b1e2b0d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/execution/SyncExecutionProvider.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/execution/SyncExecutionProvider.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java index 91d64120..36df4b79 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagRegistry.java index aeb4cd77..d39c59e6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/Flags.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/Flags.java index 6f03e229..d93d276a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/Flags.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/Flags.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java index 627f6b72..1b51a418 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/EmptyFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/EmptyFlagValue.java index d349a9d8..e80786da 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/EmptyFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/EmptyFlagValue.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java index 5405198a..22977c4c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java index 9ab5072b..f908c5d1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java index 087df3fc..21b6b7c3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagScanner.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagScanner.java index 2d2e6e03..22c312e2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagScanner.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagScanner.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java index 7507d8de..4e6a2684 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValue.java index 477deb2a..ae3994e3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValue.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagsResult.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagsResult.java index 0b0a2fc6..26e312e5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagsResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagsResult.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java b/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java index 2ab942e0..5a1b622c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java index 7082116c..b8cba3e5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageRegistry.java index 69ed8c10..ba9d154a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageResolver.java index d771c2c0..02dc3f0e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageResolver.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/AbstractMessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/AbstractMessageContext.java index 5f32d3f8..7a70c649 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/AbstractMessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/AbstractMessageContext.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/DefaultMessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/DefaultMessageContext.java index cd61f16e..7094332d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/DefaultMessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/DefaultMessageContext.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java index eafa0fa0..e36c1210 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java index 6dbf6217..4aebe5a7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java index fe550e2a..41d08434 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 382ab506..6bdb750d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java index 4164c0e8..af55d0f6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java index a260d6a0..c41df6c0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java index 9b8c40b5..28189bea 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java index 65e190f7..fbeb92fc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/registry/Registry.java b/core/src/main/java/dev/triumphteam/cmd/core/registry/Registry.java index c95ba304..da309355 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/registry/Registry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/registry/Registry.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java index 7cd38002..69468854 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryKey.java b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryKey.java index 4e4478e7..dd071b49 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryKey.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java index 4465e979..bc8cc103 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java index b463d56b..f556f2d5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementRegistry.java index 5891dcb5..72a87dc5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java index e933cfe5..280e6bfd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderMapper.java b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderMapper.java index 2f501884..07850160 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderMapper.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderMapper.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java index 9a678452..00a991ab 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java index 4030c864..69e45a2e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -114,8 +114,7 @@ public boolean isDefault() { } // TODO: 2/5/2022 comments - @NotNull - public Class getSenderType() { + @NotNull public Class getSenderType() { return senderType; } @@ -124,8 +123,7 @@ public Class getSenderType() { * * @return The name of the parent command. */ - @NotNull - public String getParentName() { + @NotNull public String getParentName() { return parentName; } @@ -134,8 +132,7 @@ public String getParentName() { * * @return The name of the sub command. */ - @NotNull - public String getName() { + @NotNull public String getName() { return name; } @@ -148,8 +145,7 @@ public boolean hasArguments() { * * @return The message registry. */ - @NotNull - protected MessageRegistry getMessageRegistry() { + @NotNull protected MessageRegistry getMessageRegistry() { return messageRegistry; } @@ -191,13 +187,11 @@ public void execute(@NotNull final S sender, @NotNull final List args) { * * @return The arguments of the sub command. */ - @NotNull - protected List> getArguments() { + @NotNull protected List> getArguments() { return internalArguments; } - @Nullable - protected InternalArgument getArgument(@NotNull final String name) { + @Nullable protected InternalArgument getArgument(@NotNull final String name) { final List> foundArgs = internalArguments.stream() .filter(internalArgument -> internalArgument.getName().toLowerCase().startsWith(name)) .collect(Collectors.toList()); @@ -206,8 +200,7 @@ public void execute(@NotNull final S sender, @NotNull final List args) { return foundArgs.get(0); } - @Nullable - protected InternalArgument getArgument(final int index) { + @Nullable protected InternalArgument getArgument(final int index) { final int size = internalArguments.size(); if (size == 0) return null; if (index >= size) { @@ -316,8 +309,7 @@ private boolean meetRequirements(@NotNull final S sender) { * @param index The current index of the internalArgument. * @return The internalArgument name or null. */ - @Nullable - private String valueOrNull(@NotNull final List list, final int index) { + @Nullable private String valueOrNull(@NotNull final List list, final int index) { if (index >= list.size()) return null; return list.get(index); } @@ -329,14 +321,12 @@ private String valueOrNull(@NotNull final List list, final int index) { * @param from The index from which should start removing. * @return A list with the leftover arguments. */ - @NotNull - private List leftOvers(@NotNull final List list, final int from) { + @NotNull private List leftOvers(@NotNull final List list, final int from) { if (from > list.size()) return Collections.emptyList(); return list.subList(from, list.size()); } - @NotNull - @Override + @NotNull @Override public String toString() { return "SimpleSubCommand{" + "baseCommand=" + baseCommand + diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java index 3855b7eb..c82ca665 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java index ace6c250..e05b7e7c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java index 100107b6..6e240a30 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java index f2fe82c0..689698f3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java index da3f7e9b..83b0f976 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java index f22d3054..44c1b1c9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java index 88a1091f..8d28f209 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java index 7631a4bd..0e00e9d2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java index b2a5e0a1..731cbf29 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java index b57317dd..36c0ac1d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java index 3be01e09..39529c9c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java b/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java index 59e01082..476eb0dd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index dd021072..40968d39 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -24,6 +24,7 @@ package dev.triumphteam.cmds.simple; import dev.triumphteam.cmd.core.Command; +import dev.triumphteam.cmd.core.argument.SubCommand; import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.MessageRegistry; @@ -40,8 +41,8 @@ public final class SimpleCommand implements Command { private final MessageRegistry messageRegistry; - private final Map> subCommands = new HashMap<>(); - private final Map> subCommandAliases = new HashMap<>(); + private final Map> subCommands = new HashMap<>(); + private final Map> subCommandAliases = new HashMap<>(); @SuppressWarnings("unchecked") public SimpleCommand( @@ -60,24 +61,34 @@ public void execute( ) { final int argumentSize = arguments.size(); - final OldSubCommand subCommand = getSubCommand(arguments); + final SubCommand subCommand = getSubCommand(arguments); - if (subCommand == null || (argumentSize > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { + // TODO + /*if (subCommand == null || (argumentSize > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { final String name = argumentSize == 0 ? dev.triumphteam.cmd.core.annotation.Command.DEFAULT_CMD_NAME : arguments.get(0); messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new DefaultMessageContext(this.name, name)); return; } - subCommand.execute(sender, !subCommand.isDefault() ? arguments.subList(1, argumentSize) : arguments); + subCommand.execute(sender, !subCommand.isDefault() ? arguments.subList(1, argumentSize) : arguments);*/ } @Override - public @NotNull Map> getSubCommands() { + public void addSubCommand( + final @NotNull String name, + final @NotNull SubCommand subCommand, + final boolean isAlias + ) { + subCommands.put(name, subCommand); + } + + @Override + public @NotNull Map> getSubCommands() { return subCommands; } @Override - public @NotNull Map> getSubCommandAlias() { + public @NotNull Map> getSubCommandAlias() { return subCommandAliases; } } From 864c6a7ab40434a44eeba5a8f11e41d187e5a2de Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Sat, 24 Dec 2022 00:25:09 +0000 Subject: [PATCH 018/101] feature: Checkstyle --- .checkstyle/checkstyle.xml | 12 ++++++++++++ .../kotlin/cmds.base-conventions.gradle.kts | 19 ++++++++++++++++--- .../dev/triumphteam/cmd/core/BaseCommand.java | 1 - .../dev/triumphteam/cmd/core/Command.java | 1 - .../cmd/core/flag/internal/FlagGroup.java | 1 - .../processor/AbstractCommandProcessor.java | 2 -- .../cmd/core/processor/Commands.java | 2 -- gradle/libs.versions.toml | 6 +++++- .../cmds/simple/SimpleCommand.java | 4 +--- 9 files changed, 34 insertions(+), 14 deletions(-) create mode 100644 .checkstyle/checkstyle.xml diff --git a/.checkstyle/checkstyle.xml b/.checkstyle/checkstyle.xml new file mode 100644 index 00000000..863a9ebc --- /dev/null +++ b/.checkstyle/checkstyle.xml @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts b/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts index 3afb5a17..79c99499 100644 --- a/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts @@ -1,3 +1,4 @@ +import com.diffplug.gradle.spotless.FormatExtension import org.gradle.accessors.dm.LibrariesForLibs import org.jetbrains.kotlin.gradle.tasks.KotlinCompile @@ -9,6 +10,8 @@ plugins { kotlin("jvm") id("com.github.hierynomus.license") id("com.diffplug.spotless") + id("net.kyori.indra") + id("net.kyori.indra.checkstyle") } repositories { @@ -39,11 +42,19 @@ license { include("**/*.java") } +indra { + checkstyle() +} + +fun FormatExtension.defaults() { + trimTrailingWhitespace() + endWithNewline() + indentWithSpaces(4) +} + spotless { format("format") { - trimTrailingWhitespace() - endWithNewline() - indentWithSpaces(4) + defaults() target( "*.md", @@ -53,10 +64,12 @@ spotless { } java { + defaults() formatAnnotations() } kotlin { + defaults() ktlint("0.47.1").editorConfigOverride( mapOf( "ktlint_disabled_rules" to "filename,trailing-comma-on-call-site,trailing-comma-on-declaration-site", diff --git a/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java index e59a6d53..c2457295 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java @@ -23,7 +23,6 @@ */ package dev.triumphteam.cmd.core; -import dev.triumphteam.cmd.core.annotation.Command; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/Command.java index c765509b..273ceef4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/Command.java @@ -24,7 +24,6 @@ package dev.triumphteam.cmd.core; import dev.triumphteam.cmd.core.argument.SubCommand; -import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java index 22977c4c..bd988aa1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java @@ -25,7 +25,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.annotations.UnknownNullability; import java.util.ArrayList; import java.util.HashMap; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 6bdb750d..b966850e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -24,8 +24,6 @@ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.annotation.Command; -import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import org.jetbrains.annotations.NotNull; import java.util.List; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java index c41df6c0..8eaeff97 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java @@ -31,9 +31,7 @@ import org.jetbrains.annotations.Nullable; import java.lang.reflect.AnnotatedElement; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; public final class Commands { diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index be7517c0..9577c8ca 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,6 +18,8 @@ jda = "5.0.0-alpha.18" # Formatting spotless = "6.12.0" +# For now only using for checkstyle +indra = "3.0.1" [libraries] # Core @@ -39,6 +41,7 @@ jda = { module = "net.dv8tion:JDA", version.ref = "jda" } build-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } build-license = { module = "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin", version.ref = "license" } build-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" } +build-indra = { module = "net.kyori:indra-common", version.ref = "indra" } [bundles] # Testing @@ -50,5 +53,6 @@ testing = [ build = [ "build-kotlin", "build-license", - "build-spotless" + "build-spotless", + "build-indra" ] diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index 40968d39..26174b2e 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -25,10 +25,8 @@ import dev.triumphteam.cmd.core.Command; import dev.triumphteam.cmd.core.argument.SubCommand; -import dev.triumphteam.cmd.core.subcommand.OldSubCommand; -import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.*; import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import org.jetbrains.annotations.NotNull; import java.util.HashMap; From e51db1e6eb9c701b41fa543bef7c1d3d7f7a2c7e Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Sat, 24 Dec 2022 00:33:04 +0000 Subject: [PATCH 019/101] feature: Checks CI --- .github/workflows/checks.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/checks.yml diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml new file mode 100644 index 00000000..fc4cd6b6 --- /dev/null +++ b/.github/workflows/checks.yml @@ -0,0 +1,35 @@ +# This is a basic workflow to help you get started with Actions +name: Checks + +# Controls when the workflow will run +on: + push: + branches: [ "**" ] + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +jobs: + gradle: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + + - name: Setup Gradle + uses: gradle/gradle-build-action@v2 + + - name: Checkstyle + run: ./gradlew checkstyleMain + + - name: Spotless check + run: ./gradlew spotlessCheck + + - name: License check + run: ./gradlew license From bbc1a218071b26f47a35bd8f31681335376c5dbd Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Sat, 24 Dec 2022 01:40:07 +0000 Subject: [PATCH 020/101] feature: Visiting all classes and method commands --- .../dev/triumphteam/cmd/core/Command.java | 16 --- .../core/message/context/MessageContext.java | 1 + .../processor/AbstractCommandProcessor.java | 112 +++++++++++++++--- .../cmd/core/processor/Commands.java | 56 --------- settings.gradle.kts | 2 + simple/build.gradle.kts | 8 +- .../cmds/simple/SimpleCommandManager.java | 10 +- .../cmds/simple/SimpleCommandProcessor.java | 18 +-- 8 files changed, 111 insertions(+), 112 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/Command.java index 273ceef4..522623d1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/Command.java @@ -51,22 +51,6 @@ void addSubCommand( final boolean isAlias ); - default void addCommandsFrom(final @NotNull BaseCommand baseCommand) { - final Class klass = baseCommand.getClass(); - for (final Method method : klass.getDeclaredMethods()) { - // Ignore non-public methods - if (Modifier.isPublic(method.getModifiers())) continue; - - final String name = nameOf(method); - // Not a command, ignore the method - if (name == null) continue; - - System.out.println("Sub boy -> " + name); - } - - // TODO: CLASSES - } - default @Nullable SubCommand getSubCommand(final @NotNull List args) { SubCommand subCommand = getDefaultSubCommand(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java index 4aebe5a7..3fc1758c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.message.context; +import dev.triumphteam.cmd.core.annotation.Default; import org.jetbrains.annotations.NotNull; /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index b966850e..3c0ae610 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,26 +24,34 @@ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.annotation.Command; +import dev.triumphteam.cmd.core.annotation.Description; +import dev.triumphteam.cmd.core.argument.SubCommand; +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; -import static dev.triumphteam.cmd.core.processor.Commands.aliasOf; -import static dev.triumphteam.cmd.core.processor.Commands.descriptionOf; +public abstract class AbstractCommandProcessor { -public abstract class AbstractCommandProcessor { + private final BaseCommand baseCommand; private final String name; private final List alias; private final String description; - public AbstractCommandProcessor( - final @NotNull String name, - final @NotNull BaseCommand baseCommand - ) { - this.name = name; - this.alias = aliasOf(baseCommand); - this.description = descriptionOf(baseCommand); + public AbstractCommandProcessor(final @NotNull BaseCommand baseCommand) { + this.baseCommand = baseCommand; + + this.name = nameOf(); + this.alias = aliasOf(); + this.description = descriptionOf(); } public String getName() { @@ -57,4 +65,80 @@ public List getAlias() { public String getDescription() { return description; } + + public @NotNull List> subCommands() { + final Class klass = baseCommand.getClass(); + + final List> subCommands = new ArrayList<>(); + subCommands.addAll(methodSubCommands(klass.getDeclaredMethods())); + subCommands.addAll(classSubCommands(klass.getDeclaredClasses())); + + return subCommands; + } + + private @NotNull List> classSubCommands(final @NotNull Class[] classes) { + final List> subCommands = new ArrayList<>(); + for (final Class klass : classes) { + // Ignore non-public methods + if (!Modifier.isPublic(klass.getModifiers())) continue; + + final String name = Commands.nameOf(klass); + // Not a command, ignore the method + if (name == null) continue; + + System.out.println("Sub boy -> " + name); + + subCommands.addAll(methodSubCommands(klass.getDeclaredMethods())); + subCommands.addAll(classSubCommands(klass.getDeclaredClasses())); + } + + return subCommands; + } + + private @NotNull List> methodSubCommands(final @NotNull Method[] methods) { + return Arrays.stream(methods).map(method -> { + // Ignore non-public methods + if (!Modifier.isPublic(method.getModifiers())) return null; + + final String name = Commands.nameOf(method); + // Not a command, ignore the method + if (name == null) return null; + + System.out.println("Sub boy -> " + name); + return new SubCommand() {}; + }).filter(Objects::nonNull).collect(Collectors.toList()); + } + + private @NotNull String nameOf() { + final Class commandClass = baseCommand.getClass(); + final Command commandAnnotation = commandClass.getAnnotation(Command.class); + + final String name; + if (commandAnnotation == null) { + final String commandName = baseCommand.getCommand(); + if (commandName == null) { + throw new CommandRegistrationException("Command name or \"@" + Command.class.getSimpleName() + "\" annotation missing", baseCommand.getClass()); + } + + name = commandName; + } else { + name = commandAnnotation.value(); + } + + if (name.isEmpty() || name.equals(Command.DEFAULT_CMD_NAME)) { + throw new CommandRegistrationException("Command name must not be empty", baseCommand.getClass()); + } + + return name; + } + + private @NotNull List aliasOf() { + final Command commandAnnotation = baseCommand.getClass().getAnnotation(Command.class); + return commandAnnotation == null ? baseCommand.getAlias() : Arrays.asList(commandAnnotation.alias()); + } + + private @NotNull String descriptionOf() { + final Description commandAnnotation = baseCommand.getClass().getAnnotation(Description.class); + return commandAnnotation == null ? baseCommand.getDescription() : commandAnnotation.value(); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java index 8eaeff97..5bffa80f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java @@ -23,16 +23,11 @@ */ package dev.triumphteam.cmd.core.processor; -import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.annotation.Command; -import dev.triumphteam.cmd.core.annotation.Description; -import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.reflect.AnnotatedElement; -import java.util.Arrays; -import java.util.List; public final class Commands { @@ -40,57 +35,6 @@ private Commands() { throw new AssertionError("Class cannot be instantiated."); } - /** - * Gets the name of the given {@link BaseCommand}. - * - * @param baseCommand The instance of the {@link BaseCommand}. - * @return The name of the command. - */ - public static @NotNull String nameOf(final @NotNull BaseCommand baseCommand) { - final Class commandClass = baseCommand.getClass(); - final Command commandAnnotation = commandClass.getAnnotation(Command.class); - - final String name; - if (commandAnnotation == null) { - final String commandName = baseCommand.getCommand(); - if (commandName == null) { - throw new CommandRegistrationException("Command name or \"@" + Command.class.getSimpleName() + "\" annotation missing", baseCommand.getClass()); - } - - name = commandName; - } else { - name = commandAnnotation.value(); - } - - if (name.isEmpty() || name.equals(Command.DEFAULT_CMD_NAME)) { - throw new CommandRegistrationException("Command name must not be empty", baseCommand.getClass()); - } - - return name; - } - - /** - * Gets the alias of the given {@link BaseCommand}. - * - * @param baseCommand The instance of the {@link BaseCommand}. - * @return The alias of the command. - */ - public static @NotNull List aliasOf(final @NotNull BaseCommand baseCommand) { - final Command commandAnnotation = baseCommand.getClass().getAnnotation(Command.class); - return commandAnnotation == null ? baseCommand.getAlias() : Arrays.asList(commandAnnotation.alias()); - } - - /** - * Gets the alias of the given {@link BaseCommand}. - * - * @param baseCommand The instance of the {@link BaseCommand}. - * @return The alias of the command. - */ - public static @NotNull String descriptionOf(final @NotNull BaseCommand baseCommand) { - final Description commandAnnotation = baseCommand.getClass().getAnnotation(Description.class); - return commandAnnotation == null ? baseCommand.getDescription() : commandAnnotation.value(); - } - public static @Nullable String nameOf(final @NotNull AnnotatedElement element) { final Command commandAnnotation = element.getAnnotation(Command.class); diff --git a/settings.gradle.kts b/settings.gradle.kts index b52765c8..1b038bfd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,6 +3,8 @@ dependencyResolutionManagement { repositories.gradlePluginPortal() } +enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") + rootProject.name = "triumph-cmd" listOf( diff --git a/simple/build.gradle.kts b/simple/build.gradle.kts index e9bee019..40ca1881 100644 --- a/simple/build.gradle.kts +++ b/simple/build.gradle.kts @@ -4,12 +4,10 @@ plugins { } dependencies { - api(project(":triumph-cmd-core")) + api(projects.triumphCmdCore) testImplementation(kotlin("stdlib")) - testImplementation(libs.junit.api) - testImplementation(libs.junit.engine) - testImplementation(libs.assertj) + testImplementation(libs.bundles.testing) api(libs.guava) } @@ -18,4 +16,4 @@ tasks { test { useJUnitPlatform() } -} \ No newline at end of file +} diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 99db2412..381e2652 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -40,8 +40,6 @@ import java.util.List; import java.util.Map; -import static dev.triumphteam.cmd.core.processor.Commands.nameOf; - public final class SimpleCommandManager extends CommandManager { private final Map> commands = new HashMap<>(); @@ -68,7 +66,9 @@ private SimpleCommandManager( @Override public void registerCommand(final @NotNull BaseCommand baseCommand) { - final String name = nameOf(baseCommand); + final SimpleCommandProcessor processor = new SimpleCommandProcessor<>(baseCommand); + + final String name = processor.getName(); final SimpleCommand command = commands.get(name); if (command != null) { @@ -77,12 +77,10 @@ public void registerCommand(final @NotNull BaseCommand baseCommand) { } // Command does not exist, proceed to add new! - - final SimpleCommandProcessor processor = new SimpleCommandProcessor(name, baseCommand); + processor.subCommands(); final SimpleCommand newCommand = commands.computeIfAbsent(processor.getName(), it -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); - // TODO: ADD SUBCOMMANDS processor.getAlias().forEach(it -> { final SimpleCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java index e1dc13eb..14f94abc 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java @@ -24,24 +24,12 @@ package dev.triumphteam.cmds.simple; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.processor.AbstractCommandProcessor; -import dev.triumphteam.cmd.core.processor.OldAbstractCommandProcessor; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; import org.jetbrains.annotations.NotNull; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Method; -import java.util.function.Supplier; +public final class SimpleCommandProcessor extends AbstractCommandProcessor { -public final class SimpleCommandProcessor extends AbstractCommandProcessor { - - public SimpleCommandProcessor( - final @NotNull String name, - final @NotNull BaseCommand baseCommand - ) { - super(name, baseCommand); + public SimpleCommandProcessor(final @NotNull BaseCommand baseCommand) { + super(baseCommand); } } From 9fa6c320397577edadde3144d18fb53861d73cd3 Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Sat, 24 Dec 2022 18:14:09 +0000 Subject: [PATCH 021/101] chore: Yet another round of re-structuring --- .../cmd/core/annotation/Annotated.java | 8 ++++ .../core/annotation/AnnotationContainer.java | 20 +++++++++ .../cmd/core/annotation/AnnotationTarget.java | 8 ++++ .../ArgDescriptions.java | 2 +- .../{annotation => annotations}/ArgName.java | 2 +- .../{annotation => annotations}/Async.java | 2 +- .../{annotation => annotations}/Choices.java | 2 +- .../{annotation => annotations}/Command.java | 2 +- .../CommandFlags.java | 2 +- .../{annotation => annotations}/Default.java | 2 +- .../Description.java | 2 +- .../{annotation => annotations}/Flag.java | 2 +- .../{annotation => annotations}/Join.java | 2 +- .../NamedArguments.java | 2 +- .../{annotation => annotations}/Optional.java | 2 +- .../Requirement.java | 2 +- .../Requirements.java | 2 +- .../{annotation => annotations}/Split.java | 2 +- .../SubCommand.java | 2 +- .../Suggestion.java | 2 +- .../Suggestions.java | 2 +- .../SubCommand.java => command/Command.java} | 6 ++- .../ParentCommand.java} | 27 +++++------- .../core/message/context/MessageContext.java | 2 +- .../processor/AbstractCommandProcessor.java | 25 ++++++----- .../AbstractSubCommandProcessor.java | 42 +++++++++---------- .../cmd/core/processor/Commands.java | 2 +- .../OldAbstractCommandProcessor.java | 11 ++--- .../OldAbstractSubCommandProcessor.java | 42 +++++++++---------- .../cmd/core/subcommand/OldSubCommand.java | 2 +- .../cmd/prefixed/PrefixedCommand.java | 4 +- .../triumphteam/cmd/slash/SlashCommand.java | 6 +-- .../triumphteam/cmd/bukkit/BukkitCommand.java | 6 +-- .../cmd/bukkit/OldBukkitCommand.java | 4 +- .../cmds/simple/SimpleCommand.java | 25 ++++++----- .../fail/command registration fail test.kt | 2 +- 36 files changed, 158 insertions(+), 120 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/annotation/Annotated.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationTarget.java rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/ArgDescriptions.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/ArgName.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Async.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Choices.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Command.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/CommandFlags.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Default.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Description.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Flag.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Join.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/NamedArguments.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Optional.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Requirement.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Requirements.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Split.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/SubCommand.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Suggestion.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{annotation => annotations}/Suggestions.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{argument/SubCommand.java => command/Command.java} (88%) rename core/src/main/java/dev/triumphteam/cmd/core/{Command.java => command/ParentCommand.java} (73%) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Annotated.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Annotated.java new file mode 100644 index 00000000..38a9c03a --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Annotated.java @@ -0,0 +1,8 @@ +package dev.triumphteam.cmd.core.annotation; + +import org.jetbrains.annotations.NotNull; + +public interface Annotated { + + @NotNull AnnotationContainer getAnnotations(); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java new file mode 100644 index 00000000..041c3b2f --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java @@ -0,0 +1,20 @@ +package dev.triumphteam.cmd.core.annotation; + +import com.google.common.collect.Multimap; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.Annotation; + +public class AnnotationContainer { + + private final Multimap annotations; + private final AnnotationContainer parent; + + public AnnotationContainer( + final @NotNull Multimap annotations, + final @NotNull AnnotationContainer parent + ) { + this.annotations = annotations; + this.parent = parent; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationTarget.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationTarget.java new file mode 100644 index 00000000..219598ea --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationTarget.java @@ -0,0 +1,8 @@ +package dev.triumphteam.cmd.core.annotation; + +public enum AnnotationTarget { + + COMMAND, + SUB_COMMAND, + ARGUMENT; +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgDescriptions.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgDescriptions.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgDescriptions.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgDescriptions.java index af5e3b00..aff5b2dc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgDescriptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgDescriptions.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgName.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgName.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgName.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgName.java index 95a714bb..9a4360cd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/ArgName.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgName.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Async.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Async.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java index 4540d4a0..f7bbfbb8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Async.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Choices.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Choices.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Choices.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Choices.java index a94a3811..2932918b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Choices.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Choices.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Command.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Command.java index 34f0923c..e55200ab 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Command.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/CommandFlags.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/CommandFlags.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/CommandFlags.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/CommandFlags.java index e0736053..3b673f54 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/CommandFlags.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/CommandFlags.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Default.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Default.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Default.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Default.java index aa8ddea5..38971247 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Default.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Default.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Description.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Description.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Description.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Description.java index 309833a5..b04d1d51 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Description.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Description.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Flag.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Flag.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Flag.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Flag.java index a4c4fbd1..ab99ed1e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Flag.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Flag.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Join.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Join.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Join.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Join.java index d8ee9f3d..a380abfc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Join.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Join.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/NamedArguments.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/NamedArguments.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/NamedArguments.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/NamedArguments.java index d0da031e..5204b9f8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/NamedArguments.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/NamedArguments.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Optional.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Optional.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Optional.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Optional.java index 11bb3d55..5b7d6711 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Optional.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Optional.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirement.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java index f094ecc3..f8872a2d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirements.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirements.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirements.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirements.java index 723d3670..c93e2267 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Requirements.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirements.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Split.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Split.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Split.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Split.java index fc64bf2c..b99a74b2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Split.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Split.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/SubCommand.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/SubCommand.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/SubCommand.java index 9ffcf4fd..8836d292 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/SubCommand.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestion.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestion.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestion.java index e5cc4582..5c5229aa 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestion.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestions.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestions.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestions.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestions.java index 91a55ed8..25745286 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Suggestions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestions.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.annotations; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java similarity index 88% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 1cb707ca..91d190bd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -21,9 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.command; -public interface SubCommand { +import dev.triumphteam.cmd.core.annotation.Annotated; + +public interface Command extends Annotated { } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java similarity index 73% rename from core/src/main/java/dev/triumphteam/cmd/core/Command.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index 522623d1..904e2031 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -21,38 +21,33 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core; +package dev.triumphteam.cmd.core.command; -import dev.triumphteam.cmd.core.argument.SubCommand; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.Method; -import java.lang.reflect.Modifier; import java.util.List; import java.util.Map; -import static dev.triumphteam.cmd.core.processor.Commands.nameOf; - /** * Command interface which all platforms will implement. * * @param The sender type. */ -public interface Command { +public interface ParentCommand extends Command { - @NotNull Map> getSubCommands(); + @NotNull Map> getSubCommands(); - @NotNull Map> getSubCommandAlias(); + @NotNull Map> getSubCommandAlias(); void addSubCommand( final @NotNull String name, - final @NotNull SubCommand subCommand, + final @NotNull Command subCommand, final boolean isAlias ); - default @Nullable SubCommand getSubCommand(final @NotNull List args) { - SubCommand subCommand = getDefaultSubCommand(); + default @Nullable Command getSubCommand(final @NotNull List args) { + Command subCommand = getDefaultSubCommand(); String subCommandName = ""; if (args.size() > 0) subCommandName = args.get(0).toLowerCase(); @@ -68,12 +63,12 @@ void addSubCommand( return subCommand; } - default @Nullable SubCommand getDefaultSubCommand() { - return getSubCommands().get(dev.triumphteam.cmd.core.annotation.Command.DEFAULT_CMD_NAME); + default @Nullable Command getDefaultSubCommand() { + return getSubCommands().get(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); } - default @Nullable SubCommand getSubCommand(final @NotNull String key) { - final SubCommand subCommand = getSubCommands().get(key); + default @Nullable Command getSubCommand(final @NotNull String key) { + final Command subCommand = getSubCommands().get(key); if (subCommand != null) return subCommand; return getSubCommandAlias().get(key); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java index 3fc1758c..846e0a1f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.message.context; -import dev.triumphteam.cmd.core.annotation.Default; +import dev.triumphteam.cmd.core.annotations.Default; import org.jetbrains.annotations.NotNull; /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 3c0ae610..432863f3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -24,9 +24,8 @@ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.annotation.Command; -import dev.triumphteam.cmd.core.annotation.Description; -import dev.triumphteam.cmd.core.argument.SubCommand; +import dev.triumphteam.cmd.core.annotations.Description; +import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import org.jetbrains.annotations.NotNull; @@ -66,18 +65,18 @@ public String getDescription() { return description; } - public @NotNull List> subCommands() { + public @NotNull List> subCommands() { final Class klass = baseCommand.getClass(); - final List> subCommands = new ArrayList<>(); + final List> subCommands = new ArrayList<>(); subCommands.addAll(methodSubCommands(klass.getDeclaredMethods())); subCommands.addAll(classSubCommands(klass.getDeclaredClasses())); return subCommands; } - private @NotNull List> classSubCommands(final @NotNull Class[] classes) { - final List> subCommands = new ArrayList<>(); + private @NotNull List> classSubCommands(final @NotNull Class[] classes) { + final List> subCommands = new ArrayList<>(); for (final Class klass : classes) { // Ignore non-public methods if (!Modifier.isPublic(klass.getModifiers())) continue; @@ -95,7 +94,7 @@ public String getDescription() { return subCommands; } - private @NotNull List> methodSubCommands(final @NotNull Method[] methods) { + private @NotNull List> methodSubCommands(final @NotNull Method[] methods) { return Arrays.stream(methods).map(method -> { // Ignore non-public methods if (!Modifier.isPublic(method.getModifiers())) return null; @@ -105,19 +104,19 @@ public String getDescription() { if (name == null) return null; System.out.println("Sub boy -> " + name); - return new SubCommand() {}; + return new Command() {}; }).filter(Objects::nonNull).collect(Collectors.toList()); } private @NotNull String nameOf() { final Class commandClass = baseCommand.getClass(); - final Command commandAnnotation = commandClass.getAnnotation(Command.class); + final dev.triumphteam.cmd.core.annotations.Command commandAnnotation = commandClass.getAnnotation(dev.triumphteam.cmd.core.annotations.Command.class); final String name; if (commandAnnotation == null) { final String commandName = baseCommand.getCommand(); if (commandName == null) { - throw new CommandRegistrationException("Command name or \"@" + Command.class.getSimpleName() + "\" annotation missing", baseCommand.getClass()); + throw new CommandRegistrationException("Command name or \"@" + dev.triumphteam.cmd.core.annotations.Command.class.getSimpleName() + "\" annotation missing", baseCommand.getClass()); } name = commandName; @@ -125,7 +124,7 @@ public String getDescription() { name = commandAnnotation.value(); } - if (name.isEmpty() || name.equals(Command.DEFAULT_CMD_NAME)) { + if (name.isEmpty() || name.equals(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME)) { throw new CommandRegistrationException("Command name must not be empty", baseCommand.getClass()); } @@ -133,7 +132,7 @@ public String getDescription() { } private @NotNull List aliasOf() { - final Command commandAnnotation = baseCommand.getClass().getAnnotation(Command.class); + final dev.triumphteam.cmd.core.annotations.Command commandAnnotation = baseCommand.getClass().getAnnotation(dev.triumphteam.cmd.core.annotations.Command.class); return commandAnnotation == null ? baseCommand.getAlias() : Arrays.asList(commandAnnotation.alias()); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java index af55d0f6..a783e876 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java @@ -26,19 +26,19 @@ import com.google.common.base.CaseFormat; import com.google.common.collect.Maps; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.annotation.ArgDescriptions; -import dev.triumphteam.cmd.core.annotation.ArgName; -import dev.triumphteam.cmd.core.annotation.Async; -import dev.triumphteam.cmd.core.annotation.CommandFlags; -import dev.triumphteam.cmd.core.annotation.Default; -import dev.triumphteam.cmd.core.annotation.Description; -import dev.triumphteam.cmd.core.annotation.Flag; -import dev.triumphteam.cmd.core.annotation.Join; -import dev.triumphteam.cmd.core.annotation.NamedArguments; -import dev.triumphteam.cmd.core.annotation.Optional; -import dev.triumphteam.cmd.core.annotation.Requirements; -import dev.triumphteam.cmd.core.annotation.Split; -import dev.triumphteam.cmd.core.annotation.Suggestions; +import dev.triumphteam.cmd.core.annotations.ArgDescriptions; +import dev.triumphteam.cmd.core.annotations.ArgName; +import dev.triumphteam.cmd.core.annotations.Async; +import dev.triumphteam.cmd.core.annotations.CommandFlags; +import dev.triumphteam.cmd.core.annotations.Default; +import dev.triumphteam.cmd.core.annotations.Description; +import dev.triumphteam.cmd.core.annotations.Flag; +import dev.triumphteam.cmd.core.annotations.Join; +import dev.triumphteam.cmd.core.annotations.NamedArguments; +import dev.triumphteam.cmd.core.annotations.Optional; +import dev.triumphteam.cmd.core.annotations.Requirements; +import dev.triumphteam.cmd.core.annotations.Split; +import dev.triumphteam.cmd.core.annotations.Suggestions; import dev.triumphteam.cmd.core.argument.ArgumentRegistry; import dev.triumphteam.cmd.core.argument.ArgumentResolver; import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; @@ -197,7 +197,7 @@ protected void extractArguments(final @NotNull AnnotatedElement annotatedElement /** * Used for the child factories to get the sub command name. - * It's nullable because a method might not have a {@link dev.triumphteam.cmd.core.annotation.SubCommand} or {@link Default} annotation. + * It's nullable because a method might not have a {@link dev.triumphteam.cmd.core.annotations.SubCommand} or {@link Default} annotation. * * @return The sub command name. */ @@ -593,7 +593,7 @@ private void addArgument(final @NotNull InternalArgument internalArgument) */ private void extractSubCommandNames() { final Default defaultAnnotation = annotatedElement.getAnnotation(Default.class); - final dev.triumphteam.cmd.core.annotation.SubCommand subCommandAnnotation = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.SubCommand.class); + final dev.triumphteam.cmd.core.annotations.SubCommand subCommandAnnotation = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.SubCommand.class); if (defaultAnnotation == null && subCommandAnnotation == null) { return; @@ -692,7 +692,7 @@ private void extractFlags() { * Extract all the requirement data for the sub command from the method. */ public void extractRequirements() { - for (final dev.triumphteam.cmd.core.annotation.Requirement requirementAnnotation : getRequirementsFromAnnotations()) { + for (final dev.triumphteam.cmd.core.annotations.Requirement requirementAnnotation : getRequirementsFromAnnotations()) { final RequirementKey requirementKey = RequirementKey.of(requirementAnnotation.value()); final String messageKeyValue = requirementAnnotation.messageKey(); @@ -714,11 +714,11 @@ public void extractRequirements() { * * @return The list of requirements. */ - private @NotNull List getRequirementsFromAnnotations() { + private @NotNull List getRequirementsFromAnnotations() { final Requirements requirements = annotatedElement.getAnnotation(Requirements.class); if (requirements != null) return Arrays.asList(requirements.value()); - final dev.triumphteam.cmd.core.annotation.Requirement requirement = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.Requirement.class); + final dev.triumphteam.cmd.core.annotations.Requirement requirement = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.Requirement.class); if (requirement == null) return Collections.emptyList(); return Collections.singletonList(requirement); } @@ -795,7 +795,7 @@ private void extractArgDescriptions() { * Extract all suggestions from the method and parameters. */ public void extractSuggestions() { - for (final dev.triumphteam.cmd.core.annotation.Suggestion suggestion : getSuggestionsFromAnnotations()) { + for (final dev.triumphteam.cmd.core.annotations.Suggestion suggestion : getSuggestionsFromAnnotations()) { final String key = suggestion.value(); if (key.isEmpty()) { suggestionList.add(new EmptySuggestion<>()); @@ -870,11 +870,11 @@ private void setOrAddSuggestion(final int index, final @Nullable Suggestion s suggestionList.set(index, suggestion); } - private @NotNull List getSuggestionsFromAnnotations() { + private @NotNull List getSuggestionsFromAnnotations() { final Suggestions requirements = annotatedElement.getAnnotation(Suggestions.class); if (requirements != null) return Arrays.asList(requirements.value()); - final dev.triumphteam.cmd.core.annotation.Suggestion suggestion = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.Suggestion.class); + final dev.triumphteam.cmd.core.annotations.Suggestion suggestion = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.Suggestion.class); if (suggestion == null) return emptyList(); return singletonList(suggestion); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java index 5bffa80f..d2f471fe 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.processor; -import dev.triumphteam.cmd.core.annotation.Command; +import dev.triumphteam.cmd.core.annotations.Command; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java index 28189bea..ca6041ab 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java @@ -24,8 +24,9 @@ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.annotation.Command; -import dev.triumphteam.cmd.core.annotation.Description; +import dev.triumphteam.cmd.core.command.ParentCommand; +import dev.triumphteam.cmd.core.annotations.Command; +import dev.triumphteam.cmd.core.annotations.Description; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.execution.ExecutionProvider; @@ -97,7 +98,7 @@ protected OldAbstractCommandProcessor( } // TODO: Comments - public void addSubCommands(final @NotNull dev.triumphteam.cmd.core.Command command) { + public void addSubCommands(final @NotNull ParentCommand command) { // Method sub commands collectMethodSubCommands(command, commandClass, method -> new MethodInvoker(instanceSupplier, method)); @@ -137,7 +138,7 @@ public void addSubCommands(final @NotNull dev.triumphteam.cmd.core.Command co } private void collectMethodSubCommands( - final @NotNull dev.triumphteam.cmd.core.Command command, + final @NotNull ParentCommand command, final @NotNull Class klass, final @NotNull Function invokerFunction ) { @@ -155,7 +156,7 @@ private void collectMethodSubCommands( if (subCommandName.isEmpty()) { throw new SubCommandRegistrationException( - "@" + dev.triumphteam.cmd.core.annotation.SubCommand.class.getSimpleName() + " name must not be empty", + "@" + dev.triumphteam.cmd.core.annotations.SubCommand.class.getSimpleName() + " name must not be empty", method, klass ); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java index fbeb92fc..13514b7d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java @@ -26,19 +26,19 @@ import com.google.common.base.CaseFormat; import com.google.common.collect.Maps; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.annotation.ArgDescriptions; -import dev.triumphteam.cmd.core.annotation.ArgName; -import dev.triumphteam.cmd.core.annotation.Async; -import dev.triumphteam.cmd.core.annotation.CommandFlags; -import dev.triumphteam.cmd.core.annotation.Default; -import dev.triumphteam.cmd.core.annotation.Description; -import dev.triumphteam.cmd.core.annotation.Flag; -import dev.triumphteam.cmd.core.annotation.Join; -import dev.triumphteam.cmd.core.annotation.NamedArguments; -import dev.triumphteam.cmd.core.annotation.Optional; -import dev.triumphteam.cmd.core.annotation.Requirements; -import dev.triumphteam.cmd.core.annotation.Split; -import dev.triumphteam.cmd.core.annotation.Suggestions; +import dev.triumphteam.cmd.core.annotations.ArgDescriptions; +import dev.triumphteam.cmd.core.annotations.ArgName; +import dev.triumphteam.cmd.core.annotations.Async; +import dev.triumphteam.cmd.core.annotations.CommandFlags; +import dev.triumphteam.cmd.core.annotations.Default; +import dev.triumphteam.cmd.core.annotations.Description; +import dev.triumphteam.cmd.core.annotations.Flag; +import dev.triumphteam.cmd.core.annotations.Join; +import dev.triumphteam.cmd.core.annotations.NamedArguments; +import dev.triumphteam.cmd.core.annotations.Optional; +import dev.triumphteam.cmd.core.annotations.Requirements; +import dev.triumphteam.cmd.core.annotations.Split; +import dev.triumphteam.cmd.core.annotations.Suggestions; import dev.triumphteam.cmd.core.argument.ArgumentRegistry; import dev.triumphteam.cmd.core.argument.ArgumentResolver; import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; @@ -197,7 +197,7 @@ protected void extractArguments(final @NotNull AnnotatedElement annotatedElement /** * Used for the child factories to get the sub command name. - * It's nullable because a method might not have a {@link dev.triumphteam.cmd.core.annotation.SubCommand} or {@link Default} annotation. + * It's nullable because a method might not have a {@link dev.triumphteam.cmd.core.annotations.SubCommand} or {@link Default} annotation. * * @return The sub command name. */ @@ -593,7 +593,7 @@ private void addArgument(final @NotNull InternalArgument internalArgument) */ private void extractSubCommandNames() { final Default defaultAnnotation = annotatedElement.getAnnotation(Default.class); - final dev.triumphteam.cmd.core.annotation.SubCommand subCommandAnnotation = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.SubCommand.class); + final dev.triumphteam.cmd.core.annotations.SubCommand subCommandAnnotation = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.SubCommand.class); if (defaultAnnotation == null && subCommandAnnotation == null) { return; @@ -692,7 +692,7 @@ private void extractFlags() { * Extract all the requirement data for the sub command from the method. */ public void extractRequirements() { - for (final dev.triumphteam.cmd.core.annotation.Requirement requirementAnnotation : getRequirementsFromAnnotations()) { + for (final dev.triumphteam.cmd.core.annotations.Requirement requirementAnnotation : getRequirementsFromAnnotations()) { final RequirementKey requirementKey = RequirementKey.of(requirementAnnotation.value()); final String messageKeyValue = requirementAnnotation.messageKey(); @@ -714,11 +714,11 @@ public void extractRequirements() { * * @return The list of requirements. */ - private @NotNull List getRequirementsFromAnnotations() { + private @NotNull List getRequirementsFromAnnotations() { final Requirements requirements = annotatedElement.getAnnotation(Requirements.class); if (requirements != null) return Arrays.asList(requirements.value()); - final dev.triumphteam.cmd.core.annotation.Requirement requirement = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.Requirement.class); + final dev.triumphteam.cmd.core.annotations.Requirement requirement = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.Requirement.class); if (requirement == null) return Collections.emptyList(); return Collections.singletonList(requirement); } @@ -795,7 +795,7 @@ private void extractArgDescriptions() { * Extract all suggestions from the method and parameters. */ public void extractSuggestions() { - for (final dev.triumphteam.cmd.core.annotation.Suggestion suggestion : getSuggestionsFromAnnotations()) { + for (final dev.triumphteam.cmd.core.annotations.Suggestion suggestion : getSuggestionsFromAnnotations()) { final String key = suggestion.value(); if (key.isEmpty()) { suggestionList.add(new EmptySuggestion<>()); @@ -870,11 +870,11 @@ private void setOrAddSuggestion(final int index, final @Nullable Suggestion s suggestionList.set(index, suggestion); } - private @NotNull List getSuggestionsFromAnnotations() { + private @NotNull List getSuggestionsFromAnnotations() { final Suggestions requirements = annotatedElement.getAnnotation(Suggestions.class); if (requirements != null) return Arrays.asList(requirements.value()); - final dev.triumphteam.cmd.core.annotation.Suggestion suggestion = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotation.Suggestion.class); + final dev.triumphteam.cmd.core.annotations.Suggestion suggestion = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.Suggestion.class); if (suggestion == null) return emptyList(); return singletonList(suggestion); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java index 69e45a2e..2b85d2e8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.core.subcommand; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.annotation.Default; +import dev.triumphteam.cmd.core.annotations.Default; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.argument.StringInternalArgument; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java index 6d530e6b..fe7f1a12 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.prefixed; -import dev.triumphteam.cmd.core.Command; +import dev.triumphteam.cmd.core.command.ParentCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; @@ -42,7 +42,7 @@ * * @param The sender type. */ -final class PrefixedCommand implements Command> { +final class PrefixedCommand implements ParentCommand> { private final Map> subCommands = new HashMap<>(); diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java index a3c68d4b..cd5368c3 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java @@ -23,8 +23,8 @@ */ package dev.triumphteam.cmd.slash; -import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.annotation.Default; +import dev.triumphteam.cmd.core.command.ParentCommand; +import dev.triumphteam.cmd.core.annotations.Default; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.registry.RegistryContainer; @@ -48,7 +48,7 @@ * * @param The sender type. */ -final class SlashCommand implements Command> { +final class SlashCommand implements ParentCommand> { private final Map> subCommands = new HashMap<>(); diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index 944a5f1c..137c8d88 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.bukkit; -import dev.triumphteam.cmd.core.Command; +import dev.triumphteam.cmd.core.command.ParentCommand; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.MessageRegistry; @@ -37,7 +37,7 @@ import java.util.List; import java.util.Map; -public final class BukkitCommand extends org.bukkit.command.Command implements Command { +public final class BukkitCommand extends org.bukkit.command.Command implements ParentCommand { private final SenderMapper senderMapper; private final MessageRegistry messageRegistry; @@ -76,7 +76,7 @@ public boolean execute( } if (subCommand == null || (argumentSize > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { - final String name = argumentSize == 0 ? dev.triumphteam.cmd.core.annotation.Command.DEFAULT_CMD_NAME : arguments.get(0); + final String name = argumentSize == 0 ? dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME : arguments.get(0); messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, mappedSender, new DefaultMessageContext(getName(), name)); return true; } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java index 97d60fdd..cad05b7d 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java @@ -25,7 +25,7 @@ import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; import dev.triumphteam.cmd.bukkit.message.NoPermissionMessageContext; -import dev.triumphteam.cmd.core.Command; +import dev.triumphteam.cmd.core.command.ParentCommand; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.MessageRegistry; @@ -42,7 +42,7 @@ import static java.util.Collections.emptyList; -public final class OldBukkitCommand extends org.bukkit.command.Command implements Command> { +public final class OldBukkitCommand extends org.bukkit.command.Command implements ParentCommand> { private final MessageRegistry messageRegistry; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index 26174b2e..a501a8d6 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -23,9 +23,9 @@ */ package dev.triumphteam.cmds.simple; -import dev.triumphteam.cmd.core.Command; -import dev.triumphteam.cmd.core.argument.SubCommand; -import dev.triumphteam.cmd.core.*; +import dev.triumphteam.cmd.core.annotation.AnnotationContainer; +import dev.triumphteam.cmd.core.command.ParentCommand; +import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.message.MessageRegistry; import org.jetbrains.annotations.NotNull; @@ -33,14 +33,14 @@ import java.util.List; import java.util.Map; -public final class SimpleCommand implements Command { +public final class SimpleCommand implements ParentCommand { private final String name; private final MessageRegistry messageRegistry; - private final Map> subCommands = new HashMap<>(); - private final Map> subCommandAliases = new HashMap<>(); + private final Map> subCommands = new HashMap<>(); + private final Map> subCommandAliases = new HashMap<>(); @SuppressWarnings("unchecked") public SimpleCommand( @@ -59,7 +59,7 @@ public void execute( ) { final int argumentSize = arguments.size(); - final SubCommand subCommand = getSubCommand(arguments); + final Command subCommand = getSubCommand(arguments); // TODO /*if (subCommand == null || (argumentSize > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { @@ -74,19 +74,24 @@ public void execute( @Override public void addSubCommand( final @NotNull String name, - final @NotNull SubCommand subCommand, + final @NotNull Command subCommand, final boolean isAlias ) { subCommands.put(name, subCommand); } @Override - public @NotNull Map> getSubCommands() { + public @NotNull Map> getSubCommands() { return subCommands; } @Override - public @NotNull Map> getSubCommandAlias() { + public @NotNull Map> getSubCommandAlias() { return subCommandAliases; } + + @Override + public @NotNull AnnotationContainer getAnnotations() { + return null; + } } diff --git a/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt b/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt index 9352c538..76436591 100644 --- a/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt +++ b/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt @@ -24,7 +24,7 @@ package dev.triumphteam.tests.fail import dev.triumphteam.cmd.core.BaseCommand -import dev.triumphteam.cmd.core.annotation.Command +import dev.triumphteam.cmd.core.annotations.Command import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException import dev.triumphteam.cmds.simple.SimpleCommandManager import dev.triumphteam.tests.TestSender From f67a27097545b09960a3de664484f6dc5e7f3046 Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Sun, 25 Dec 2022 00:51:21 +0000 Subject: [PATCH 022/101] feature: New processing for commands and sender validation feature --- .../core/annotation/AnnotationContainer.java | 6 +- .../cmd/core/command/ParentCommand.java | 12 +- .../cmd/core/command/ParentSubCommand.java | 37 + .../cmd/core/command/SubCommand.java | 14 + ...java => AbstractRootCommandProcessor.java} | 56 +- .../AbstractSubCommandProcessor.java | 898 ------------------ .../{Commands.java => CommandProcessor.java} | 42 +- .../core/processor/SubCommandProcessor.java | 111 +++ .../core/validation/ArgumentValidator.java | 13 + .../triumphteam/cmd/bukkit/BukkitCommand.java | 4 +- .../cmd/bukkit/BukkitCommandProcessor.java | 11 +- .../cmds/simple/SimpleCommand.java | 6 +- .../cmds/simple/SimpleCommandManager.java | 2 +- .../cmds/simple/SimpleCommandProcessor.java | 4 +- 14 files changed, 265 insertions(+), 951 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java rename core/src/main/java/dev/triumphteam/cmd/core/processor/{AbstractCommandProcessor.java => AbstractRootCommandProcessor.java} (80%) delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java rename core/src/main/java/dev/triumphteam/cmd/core/processor/{Commands.java => CommandProcessor.java} (53%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentValidator.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java index 041c3b2f..099dc7be 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java @@ -1,17 +1,17 @@ package dev.triumphteam.cmd.core.annotation; -import com.google.common.collect.Multimap; import org.jetbrains.annotations.NotNull; import java.lang.annotation.Annotation; +import java.util.List; public class AnnotationContainer { - private final Multimap annotations; + private final List annotations; private final AnnotationContainer parent; public AnnotationContainer( - final @NotNull Multimap annotations, + final @NotNull List annotations, final @NotNull AnnotationContainer parent ) { this.annotations = annotations; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index 904e2031..0433a548 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -36,9 +36,9 @@ */ public interface ParentCommand extends Command { - @NotNull Map> getSubCommands(); + @NotNull Map> getCommands(); - @NotNull Map> getSubCommandAlias(); + @NotNull Map> getCommandAliases(); void addSubCommand( final @NotNull String name, @@ -64,16 +64,16 @@ void addSubCommand( } default @Nullable Command getDefaultSubCommand() { - return getSubCommands().get(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); + return getCommands().get(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); } default @Nullable Command getSubCommand(final @NotNull String key) { - final Command subCommand = getSubCommands().get(key); + final Command subCommand = getCommands().get(key); if (subCommand != null) return subCommand; - return getSubCommandAlias().get(key); + return getCommandAliases().get(key); } default boolean subCommandExists(final @NotNull String key) { - return getSubCommands().containsKey(key) || getSubCommandAlias().containsKey(key); + return getCommands().containsKey(key) || getCommandAliases().containsKey(key); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java new file mode 100644 index 00000000..6f93ca0a --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -0,0 +1,37 @@ +package dev.triumphteam.cmd.core.command; + +import dev.triumphteam.cmd.core.annotation.AnnotationContainer; +import org.jetbrains.annotations.NotNull; + +import java.util.HashMap; +import java.util.Map; + +public class ParentSubCommand implements ParentCommand { + + private final Map> commands = new HashMap<>(); + private final Map> commandAliases = new HashMap<>(); + + @Override + public void addSubCommand( + final @NotNull String name, + final @NotNull Command subCommand, + final boolean isAlias + ) { + + } + + @Override + public @NotNull AnnotationContainer getAnnotations() { + return null; + } + + @Override + public @NotNull Map> getCommands() { + return commands; + } + + @Override + public @NotNull Map> getCommandAliases() { + return commandAliases; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java new file mode 100644 index 00000000..67796f77 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -0,0 +1,14 @@ +package dev.triumphteam.cmd.core.command; + +import dev.triumphteam.cmd.core.annotation.AnnotationContainer; +import org.jetbrains.annotations.NotNull; + +public class SubCommand implements Command { + + + + @Override + public @NotNull AnnotationContainer getAnnotations() { + return null; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java similarity index 80% rename from core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java rename to core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java index 432863f3..f9910ee4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java @@ -24,6 +24,7 @@ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.annotation.AnnotationContainer; import dev.triumphteam.cmd.core.annotations.Description; import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; @@ -37,7 +38,7 @@ import java.util.Objects; import java.util.stream.Collectors; -public abstract class AbstractCommandProcessor { +public abstract class AbstractRootCommandProcessor { private final BaseCommand baseCommand; @@ -45,7 +46,7 @@ public abstract class AbstractCommandProcessor { private final List alias; private final String description; - public AbstractCommandProcessor(final @NotNull BaseCommand baseCommand) { + public AbstractRootCommandProcessor(final @NotNull BaseCommand baseCommand) { this.baseCommand = baseCommand; this.name = nameOf(); @@ -65,49 +66,58 @@ public String getDescription() { return description; } - public @NotNull List> subCommands() { + public AnnotationContainer createAnnotationContainer() { + return null; + } + + public @NotNull List> commands() { final Class klass = baseCommand.getClass(); final List> subCommands = new ArrayList<>(); - subCommands.addAll(methodSubCommands(klass.getDeclaredMethods())); - subCommands.addAll(classSubCommands(klass.getDeclaredClasses())); + subCommands.addAll(methodCommands(klass.getDeclaredMethods())); + subCommands.addAll(classCommands(klass.getDeclaredClasses())); return subCommands; } - private @NotNull List> classSubCommands(final @NotNull Class[] classes) { + private @NotNull List> methodCommands(final @NotNull Method[] methods) { + return Arrays.stream(methods).map(method -> { + // Ignore non-public methods + if (!Modifier.isPublic(method.getModifiers())) return null; + + final SubCommandProcessor processor = new SubCommandProcessor<>( + name, + baseCommand, + method + ); + + // Not a command, ignore the method + if (processor.getName() == null) return null; + + + return (Command) () -> null; + }).filter(Objects::nonNull).collect(Collectors.toList()); + } + + private @NotNull List> classCommands(final @NotNull Class[] classes) { final List> subCommands = new ArrayList<>(); for (final Class klass : classes) { // Ignore non-public methods if (!Modifier.isPublic(klass.getModifiers())) continue; - final String name = Commands.nameOf(klass); + final String name = ""; // Not a command, ignore the method if (name == null) continue; System.out.println("Sub boy -> " + name); - subCommands.addAll(methodSubCommands(klass.getDeclaredMethods())); - subCommands.addAll(classSubCommands(klass.getDeclaredClasses())); + subCommands.addAll(methodCommands(klass.getDeclaredMethods())); + subCommands.addAll(classCommands(klass.getDeclaredClasses())); } return subCommands; } - private @NotNull List> methodSubCommands(final @NotNull Method[] methods) { - return Arrays.stream(methods).map(method -> { - // Ignore non-public methods - if (!Modifier.isPublic(method.getModifiers())) return null; - - final String name = Commands.nameOf(method); - // Not a command, ignore the method - if (name == null) return null; - - System.out.println("Sub boy -> " + name); - return new Command() {}; - }).filter(Objects::nonNull).collect(Collectors.toList()); - } - private @NotNull String nameOf() { final Class commandClass = baseCommand.getClass(); final dev.triumphteam.cmd.core.annotations.Command commandAnnotation = commandClass.getAnnotation(dev.triumphteam.cmd.core.annotations.Command.class); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java deleted file mode 100644 index a783e876..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractSubCommandProcessor.java +++ /dev/null @@ -1,898 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.processor; - -import com.google.common.base.CaseFormat; -import com.google.common.collect.Maps; -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.annotations.ArgDescriptions; -import dev.triumphteam.cmd.core.annotations.ArgName; -import dev.triumphteam.cmd.core.annotations.Async; -import dev.triumphteam.cmd.core.annotations.CommandFlags; -import dev.triumphteam.cmd.core.annotations.Default; -import dev.triumphteam.cmd.core.annotations.Description; -import dev.triumphteam.cmd.core.annotations.Flag; -import dev.triumphteam.cmd.core.annotations.Join; -import dev.triumphteam.cmd.core.annotations.NamedArguments; -import dev.triumphteam.cmd.core.annotations.Optional; -import dev.triumphteam.cmd.core.annotations.Requirements; -import dev.triumphteam.cmd.core.annotations.Split; -import dev.triumphteam.cmd.core.annotations.Suggestions; -import dev.triumphteam.cmd.core.argument.ArgumentRegistry; -import dev.triumphteam.cmd.core.argument.ArgumentResolver; -import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; -import dev.triumphteam.cmd.core.argument.EnumInternalArgument; -import dev.triumphteam.cmd.core.argument.FlagInternalArgument; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; -import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; -import dev.triumphteam.cmd.core.argument.NamedInternalArgument; -import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; -import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; -import dev.triumphteam.cmd.core.argument.named.Argument; -import dev.triumphteam.cmd.core.argument.named.ArgumentKey; -import dev.triumphteam.cmd.core.argument.named.Arguments; -import dev.triumphteam.cmd.core.argument.named.ListArgument; -import dev.triumphteam.cmd.core.argument.named.NamedArgumentRegistry; -import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.flag.Flags; -import dev.triumphteam.cmd.core.flag.internal.FlagGroup; -import dev.triumphteam.cmd.core.flag.internal.FlagOptions; -import dev.triumphteam.cmd.core.flag.internal.FlagValidator; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; -import dev.triumphteam.cmd.core.message.context.MessageContext; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.requirement.Requirement; -import dev.triumphteam.cmd.core.requirement.RequirementKey; -import dev.triumphteam.cmd.core.requirement.RequirementRegistry; -import dev.triumphteam.cmd.core.requirement.RequirementResolver; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; -import dev.triumphteam.cmd.core.suggestion.EnumSuggestion; -import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; -import dev.triumphteam.cmd.core.suggestion.Suggestion; -import dev.triumphteam.cmd.core.suggestion.SuggestionKey; -import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; -import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Parameter; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.WildcardType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.stream.Collectors; - -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; - -/** - * Abstracts most of the "extracting" from sub command annotations, allows for extending. - *
- * I know this could be done better, but couldn't think of a better way. - * If you do please PR or let me know on my discord! - * - * @param The sender type. - */ -@SuppressWarnings("unchecked") -public abstract class AbstractSubCommandProcessor { - - private final BaseCommand baseCommand; - private final String parentName; - - private final AnnotatedElement annotatedElement; - // Name is nullable to detect if the method should or not be considered a sub command. - private String name = null; - // TODO: 11/28/2021 Add better default description - private String description = "No description provided."; - private final List argDescriptions = new ArrayList<>(); - private final List alias = new ArrayList<>(); - - private boolean isDefault = false; - private final boolean isAsync; - - private Class senderType; - - private final FlagGroup flagGroup = new FlagGroup<>(); - private final List> suggestionList = new ArrayList<>(); - private final List> internalArguments = new ArrayList<>(); - private final Set> requirements = new HashSet<>(); - - private final RegistryContainer registryContainer; - private final SuggestionRegistry suggestionRegistry; - private final ArgumentRegistry argumentRegistry; - private final NamedArgumentRegistry namedArgumentRegistry; - private final RequirementRegistry requirementRegistry; - private final MessageRegistry messageRegistry; - private final SenderValidator senderValidator; - - private static final Set> COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); - - protected AbstractSubCommandProcessor( - final @NotNull BaseCommand baseCommand, - final @NotNull String parentName, - final @NotNull AnnotatedElement annotatedElement, - final @NotNull RegistryContainer registryContainer, - final @NotNull SenderValidator senderValidator - ) { - this.baseCommand = baseCommand; - this.parentName = parentName; - - this.annotatedElement = annotatedElement; - - this.registryContainer = registryContainer; - this.suggestionRegistry = registryContainer.getSuggestionRegistry(); - this.argumentRegistry = registryContainer.getArgumentRegistry(); - this.namedArgumentRegistry = registryContainer.getNamedArgumentRegistry(); - this.requirementRegistry = registryContainer.getRequirementRegistry(); - this.messageRegistry = registryContainer.getMessageRegistry(); - this.senderValidator = senderValidator; - - this.isAsync = annotatedElement.isAnnotationPresent(Async.class); - - extractSubCommandNames(); - if (name == null) return; - - extractFlags(); - extractRequirements(); - extractDescription(); - extractArgDescriptions(); - extractSuggestions(); - extractArguments(annotatedElement); - validateArguments(); - } - - /** - * Allows for customizing the internalArgument parsing, for example @Value and @Completion annotations. - * - * @param annotatedElement The method to search from. - */ - protected void extractArguments(final @NotNull AnnotatedElement annotatedElement) { - /*final Parameter[] parameters = method.getParameters(); - for (int i = 0; i < parameters.length; i++) { - final Parameter parameter = parameters[i]; - if (i == 0) { - validateSender(parameter.getType()); - continue; - } - - createArgument(parameter, i - 1); - }*/ - } - - /** - * Used for the child factories to get the sub command name. - * It's nullable because a method might not have a {@link dev.triumphteam.cmd.core.annotations.SubCommand} or {@link Default} annotation. - * - * @return The sub command name. - */ - public @Nullable String getName() { - return name; - } - - /** - * gets the Description of the SubCommand. - * - * @return either the extracted Description or the default one. - */ - public @NotNull String getDescription() { - return description; - } - - public @NotNull Class getSenderType() { - if (senderType == null) throw createException("Sender type could not be found."); - return senderType; - } - - /** - * Used for the child factories to get a {@link List} with the sub command's alias. - * - * @return The sub command alias. - */ - public @NotNull List<@NotNull String> getAlias() { - return alias; - } - - /** - * Used for the child factories to get whether the sub command is default. - * - * @return Whether the command is default. - */ - public boolean isDefault() { - return isDefault; - } - - /** - * Gets whether the sub command is to be executed asynchronously. - * - * @return If the sub command is async. - */ - public boolean isAsync() { - return isAsync; - } - - /** - * Gets the {@link BaseCommand} instance, so it can be used later to invoke. - * - * @return The base command instance. - */ - public @NotNull BaseCommand getBaseCommand() { - return baseCommand; - } - - // TODO comments - public @NotNull AnnotatedElement getAnnotatedElement() { - return annotatedElement; - } - - /** - * Gets a set with the requirements. - * - * @return The requirements. - */ - public @NotNull Set<@NotNull Requirement> getRequirements() { - return requirements; - } - - /** - * Gets the message registry. - * - * @return The message registry. - */ - public @NotNull MessageRegistry getMessageRegistry() { - return messageRegistry; - } - - public @NotNull RegistryContainer getRegistryContainer() { - return registryContainer; - } - - // TODO: 2/4/2022 comments - public @NotNull SenderValidator getSenderValidator() { - return senderValidator; - } - - /** - * Simple utility method for creating a new exception using the method and base command class. - * - * @param message The main message to pass to the exception. - * @return A new {@link SubCommandRegistrationException}. - */ - @Contract("_ -> new") - protected @NotNull SubCommandRegistrationException createException(final @NotNull String message) { - return new SubCommandRegistrationException(message, annotatedElement, baseCommand.getClass()); - } - - /** - * Used for validating if the sender is valid or not. - * - * @param type The sender type. - */ - protected void validateSender(final @NotNull Class type) { - final Set> allowedSenders = senderValidator.getAllowedSenders(); - if (allowedSenders.contains(type)) { - senderType = (Class) type; - return; - } - - throw createException( - "\"" + type.getSimpleName() + "\" is not a valid sender. " + - "Sender must be one of the following: " + - allowedSenders - .stream() - .map(it -> "\"" + it.getSimpleName() + "\"") - .collect(Collectors.joining(", ")) - ); - } - - /** - * Gets the necessary arguments for the command. - * - * @return The arguments list. - */ - public @NotNull List<@NotNull InternalArgument> getArguments() { - return internalArguments; - } - - /** - * Creates and adds the internalArgument to the arguments list. - * - * @param parameter The current parameter to get data from. - */ - protected void createArgument(final @NotNull Parameter parameter, final int position) { - final Class type = parameter.getType(); - final String argumentName = getArgName(parameter); - final String argumentDescription = getArgumentDescription(parameter, position); - final boolean optional = parameter.isAnnotationPresent(Optional.class); - - // Handles collection internalArgument. - // TODO: Add more collection types. - if (COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { - final Class collectionType = getGenericType(parameter); - final InternalArgument internalArgument = createSimpleArgument( - collectionType, - argumentName, - argumentDescription, - suggestionList.get(position), - 0, - true - ); - - if (parameter.isAnnotationPresent(Split.class)) { - final Split splitAnnotation = parameter.getAnnotation(Split.class); - addArgument( - new SplitStringInternalArgument<>( - argumentName, - argumentDescription, - splitAnnotation.value(), - internalArgument, - type, - suggestionList.get(position), - position, - optional - ) - ); - return; - } - - addArgument( - new CollectionInternalArgument<>( - argumentName, - argumentDescription, - internalArgument, - type, - suggestionList.get(position), - position, - optional - ) - ); - return; - } - - // Handler for using String with `@Join`. - if (type == String.class && parameter.isAnnotationPresent(Join.class)) { - final Join joinAnnotation = parameter.getAnnotation(Join.class); - addArgument( - new JoinedStringInternalArgument<>( - argumentName, - argumentDescription, - joinAnnotation.value(), - suggestionList.get(position), - position, - optional - ) - ); - return; - } - - // Handler for flags. - if (type == Flags.class) { - if (flagGroup.isEmpty()) { - throw createException("Flags internalArgument detected but no flag annotation declared"); - } - - addArgument( - new FlagInternalArgument<>( - argumentName, - argumentDescription, - flagGroup, - position, - optional - ) - ); - return; - } - - // Handler for named arguments - if (type == Arguments.class) { - final NamedArguments namedArguments = annotatedElement.getAnnotation(NamedArguments.class); - if (namedArguments == null) { - throw createException("TODO"); - } - - addArgument( - new NamedInternalArgument<>( - argumentName, - argumentDescription, - collectNamedArgs(namedArguments.value()), - position, - optional - ) - ); - return; - } - - addArgument(createSimpleArgument(type, argumentName, argumentDescription, suggestionList.get(position), position, optional)); - } - - private @NotNull Map<@NotNull String, @NotNull InternalArgument> collectNamedArgs(final @NotNull String key) { - final List arguments = namedArgumentRegistry.getResolver(ArgumentKey.of(key)); - if (arguments == null || arguments.isEmpty()) { - throw createException("No registered named arguments found for key \"" + key + "\""); - } - - // TODO: Handle list - return arguments.stream().map(argument -> { - final Suggestion suggestion = createSuggestion(argument.getSuggestion(), argument.getType()); - - if (argument instanceof ListArgument) { - final ListArgument listArgument = (ListArgument) argument; - - final InternalArgument internalArgument = createSimpleArgument( - listArgument.getType(), - listArgument.getName(), - listArgument.getDescription(), - suggestion, - 0, - true - ); - - return Maps.immutableEntry( - listArgument.getName(), - new SplitStringInternalArgument<>( - listArgument.getName(), - listArgument.getDescription(), - listArgument.getSeparator(), - internalArgument, - listArgument.getType(), - suggestion, - 0, - true - ) - ); - } - - return Maps.immutableEntry( - argument.getName(), - createSimpleArgument( - argument.getType(), - argument.getName(), - argument.getDescription(), - suggestion, - 0, - true - ) - ); - }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - } - - /** - * Gets the internalArgument name, either from the parameter or from the annotation. - * If the parameter is not annotated, turn the name from Camel Case to "lower-hyphen". - * - * @param parameter The parameter to get data from. - * @return The final internalArgument name. - */ - private @NotNull String getArgName(final @NotNull Parameter parameter) { - if (parameter.isAnnotationPresent(ArgName.class)) { - return parameter.getAnnotation(ArgName.class).value(); - } - - return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, parameter.getName()); - } - - /** - * Gets the internalArgument description. - * - * @param parameter The parameter to get data from. - * @param index The index of the internalArgument. - * @return The final internalArgument description. - */ - private @NotNull String getArgumentDescription(final @NotNull Parameter parameter, final int index) { - final Description description = parameter.getAnnotation(Description.class); - if (description != null) { - return description.value(); - } - - if (index < argDescriptions.size()) return argDescriptions.get(index); - // TODO: 11/28/2021 Add better default description - return "No description provided."; - } - - /** - * Create a SimpleArgument. - * - * @param type The Type of this Argument. - * @param parameterName The Name to use for this Argument. - * @param argumentDescription the Description to use for this Argument. - * @param optional whether this Argument is optional. - * @return The created {@link InternalArgument}. - */ - protected @NotNull InternalArgument createSimpleArgument( - final @NotNull Class type, - final @NotNull String parameterName, - final @NotNull String argumentDescription, - final @NotNull Suggestion suggestion, - final int position, - final boolean optional - ) { - // All other types default to the resolver. - final ArgumentResolver resolver = argumentRegistry.getResolver(type); - if (resolver == null) { - // Handler for using any Enum. - if (Enum.class.isAssignableFrom(type)) { - //noinspection unchecked - return new EnumInternalArgument<>( - parameterName, - argumentDescription, - (Class>) type, - suggestion, - position, - optional - ); - } - - throw createException("No internalArgument of type \"" + type.getName() + "\" registered"); - } - return new ResolverInternalArgument<>( - parameterName, - argumentDescription, - type, - resolver, - suggestion, - position, - optional - ); - } - - /** - * Adds a required internalArgument to the list. - * - * @param requirement The requirement to add. - */ - protected void addRequirement(final @NotNull Requirement requirement) { - requirements.add(requirement); - } - - /** - * Utility to add the internalArgument to the list. - * - * @param internalArgument The created internalArgument. - */ - private void addArgument(final @NotNull InternalArgument internalArgument) { - internalArguments.add(internalArgument); - } - - /** - * Extracts the data from the method to retrieve the sub command name or the default name. - */ - private void extractSubCommandNames() { - final Default defaultAnnotation = annotatedElement.getAnnotation(Default.class); - final dev.triumphteam.cmd.core.annotations.SubCommand subCommandAnnotation = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.SubCommand.class); - - if (defaultAnnotation == null && subCommandAnnotation == null) { - return; - } - - if (defaultAnnotation != null) { - name = Default.DEFAULT_CMD_NAME; - alias.addAll(Arrays.stream(defaultAnnotation.alias()).map(String::toLowerCase).collect(Collectors.toList())); - isDefault = true; - return; - } - - name = subCommandAnnotation.value().toLowerCase(); - alias.addAll(Arrays.stream(subCommandAnnotation.alias()).map(String::toLowerCase).collect(Collectors.toList())); - } - - /** - * Extract all the flag data for the subcommand from the method. - */ - private void extractFlags() { - final List flags = getFlagsFromAnnotations(); - if (flags.isEmpty()) return; - - for (final Flag flagAnnotation : flags) { - String flag = flagAnnotation.flag(); - if (flag.isEmpty()) flag = null; - FlagValidator.validate(flag, annotatedElement, baseCommand); - - String longFlag = flagAnnotation.longFlag(); - if (longFlag.contains(" ")) { - throw createException("@" + Flag.class.getSimpleName() + "'s identifiers must not contain spaces"); - } - - if (longFlag.isEmpty()) longFlag = null; - - final Class argumentType = flagAnnotation.argument(); - - final SuggestionKey suggestionKey = flagAnnotation.suggestion().isEmpty() ? null : SuggestionKey.of(flagAnnotation.suggestion()); - final Suggestion suggestion = createSuggestion(suggestionKey, flagAnnotation.argument()); - - StringInternalArgument internalArgument = null; - if (argumentType != void.class) { - if (Enum.class.isAssignableFrom(argumentType)) { - //noinspection unchecked - internalArgument = new EnumInternalArgument<>( - argumentType.getName(), - "", - (Class>) argumentType, - suggestion, - 0, - false - ); - } else { - final ArgumentResolver resolver = argumentRegistry.getResolver(argumentType); - if (resolver == null) { - throw createException("@" + Flag.class.getSimpleName() + "'s internalArgument contains unregistered type \"" + argumentType.getName() + "\""); - } - - internalArgument = new ResolverInternalArgument<>( - argumentType.getName(), - "", - argumentType, - resolver, - suggestion, - 0, - false - ); - } - } - - flagGroup.addFlag( - new FlagOptions<>( - flag, - longFlag, - internalArgument - ) - ); - } - } - - /** - * Gets the flags from the annotations. - * - * @return The list of flags. - */ - private @NotNull List<@NotNull Flag> getFlagsFromAnnotations() { - final CommandFlags flags = annotatedElement.getAnnotation(CommandFlags.class); - if (flags != null) return Arrays.asList(flags.value()); - - final Flag flag = annotatedElement.getAnnotation(Flag.class); - if (flag == null) return Collections.emptyList(); - return Collections.singletonList(flag); - } - - /** - * Extract all the requirement data for the sub command from the method. - */ - public void extractRequirements() { - for (final dev.triumphteam.cmd.core.annotations.Requirement requirementAnnotation : getRequirementsFromAnnotations()) { - final RequirementKey requirementKey = RequirementKey.of(requirementAnnotation.value()); - final String messageKeyValue = requirementAnnotation.messageKey(); - - final MessageKey messageKey; - if (messageKeyValue.isEmpty()) messageKey = null; - else messageKey = MessageKey.of(messageKeyValue, MessageContext.class); - - final RequirementResolver resolver = requirementRegistry.getRequirement(requirementKey); - if (resolver == null) { - throw createException("Could not find Requirement Key \"" + requirementKey.getKey() + "\""); - } - - addRequirement(new Requirement<>(resolver, messageKey, DefaultMessageContext::new, requirementAnnotation.invert())); - } - } - - /** - * Gets the requirements from the annotations. - * - * @return The list of requirements. - */ - private @NotNull List getRequirementsFromAnnotations() { - final Requirements requirements = annotatedElement.getAnnotation(Requirements.class); - if (requirements != null) return Arrays.asList(requirements.value()); - - final dev.triumphteam.cmd.core.annotations.Requirement requirement = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.Requirement.class); - if (requirement == null) return Collections.emptyList(); - return Collections.singletonList(requirement); - } - - /** - * Gets a list of all the arg validations for the platform. - * Defaults to just optional and limitless. - * This is likely to change. - * - * @return A list of BiConsumers with checks. - */ - protected @NotNull List<@NotNull BiConsumer<@NotNull Boolean, @NotNull InternalArgument>> getArgValidations() { - return Arrays.asList(validateOptionals(), validateLimitless()); - } - - /** - * Argument validation makes sure some arguments are placed in the correct place. - * For example a limitless arguments and optional arguments are only allowed at the end of the command. - */ - private void validateArguments() { - final List>> validations = getArgValidations(); - final Iterator> iterator = internalArguments.iterator(); - while (iterator.hasNext()) { - final InternalArgument internalArgument = iterator.next(); - validations.forEach(consumer -> consumer.accept(iterator.hasNext(), internalArgument)); - } - } - - /** - * Validation function for optionals. - * - * @return Returns a BiConsumer with an is optional check. - */ - protected @NotNull BiConsumer<@NotNull Boolean, @NotNull InternalArgument> validateOptionals() { - return (hasNext, internalArgument) -> { - if (hasNext && internalArgument.isOptional()) { - throw createException("Optional internalArgument is only allowed as the last internalArgument"); - } - }; - } - - /** - * Validation function for limitless position. - * - * @return Returns a BiConsumer with an instance of check. - */ - protected @NotNull BiConsumer<@NotNull Boolean, @NotNull InternalArgument> validateLimitless() { - return (hasNext, internalArgument) -> { - if (hasNext && internalArgument instanceof LimitlessInternalArgument) { - throw createException("Limitless internalArgument is only allowed as the last internalArgument"); - } - }; - } - - /** - * Extracts the {@link Description} Annotation from the Method. - */ - private void extractDescription() { - final Description description = annotatedElement.getAnnotation(Description.class); - if (description == null) return; - this.description = description.value(); - } - - /** - * Extracts the {@link ArgDescriptions} Annotation from the Method. - */ - private void extractArgDescriptions() { - final ArgDescriptions argDescriptions = annotatedElement.getAnnotation(ArgDescriptions.class); - if (argDescriptions == null) return; - this.argDescriptions.addAll(Arrays.asList(argDescriptions.value())); - } - - /** - * Extract all suggestions from the method and parameters. - */ - public void extractSuggestions() { - for (final dev.triumphteam.cmd.core.annotations.Suggestion suggestion : getSuggestionsFromAnnotations()) { - final String key = suggestion.value(); - if (key.isEmpty()) { - suggestionList.add(new EmptySuggestion<>()); - continue; - } - - final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(SuggestionKey.of(key)); - - if (resolver == null) { - throw createException("Cannot find the suggestion key `" + key + "`"); - } - - suggestionList.add(new SimpleSuggestion<>(resolver)); - } - - extractSuggestionFromParams(); - } - - /** - * Extract all suggestions from the parameters. - * Adds the suggestions to the passed list. - */ - private void extractSuggestionFromParams() { - // TODO SUGGESTIONS - /*final Parameter[] parameters = annotatedElement.getParameters(); - for (int i = 1; i < parameters.length; i++) { - final Parameter parameter = parameters[i]; - - final dev.triumphteam.cmd.core.annotation.Suggestion suggestion = parameter.getAnnotation(dev.triumphteam.cmd.core.annotation.Suggestion.class); - final SuggestionKey suggestionKey = suggestion == null ? null : SuggestionKey.of(suggestion.value()); - - final Class type = getGenericType(parameter); - final int addIndex = i - 1; - setOrAddSuggestion(addIndex, createSuggestion(suggestionKey, type)); - }*/ - } - - private @NotNull Suggestion createSuggestion(final @Nullable SuggestionKey suggestionKey, final @NotNull Class type) { - if (suggestionKey == null) { - if (Enum.class.isAssignableFrom(type)) return new EnumSuggestion<>((Class>) type); - - final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(type); - if (resolver != null) return new SimpleSuggestion<>(resolver); - - return new EmptySuggestion<>(); - } - - final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(suggestionKey); - if (resolver == null) { - throw createException("Cannot find the suggestion key `" + suggestionKey + "`"); - } - return new SimpleSuggestion<>(resolver); - } - - /** - * Adds a suggestion or overrides an existing one. - * - * @param index The index of the suggestion. - * @param suggestion The suggestion. - */ - private void setOrAddSuggestion(final int index, final @Nullable Suggestion suggestion) { - if (index >= suggestionList.size()) { - if (suggestion == null) { - suggestionList.add(new EmptySuggestion<>()); - return; - } - suggestionList.add(suggestion); - return; - } - - if (suggestion == null) return; - suggestionList.set(index, suggestion); - } - - private @NotNull List getSuggestionsFromAnnotations() { - final Suggestions requirements = annotatedElement.getAnnotation(Suggestions.class); - if (requirements != null) return Arrays.asList(requirements.value()); - - final dev.triumphteam.cmd.core.annotations.Suggestion suggestion = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.Suggestion.class); - if (suggestion == null) return emptyList(); - return singletonList(suggestion); - } - - private @NotNull Class getGenericType(final @NotNull Parameter parameter) { - final Class type = parameter.getType(); - if (COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { - final ParameterizedType parameterizedType = (ParameterizedType) parameter.getParameterizedType(); - final Type[] types = parameterizedType.getActualTypeArguments(); - - if (types.length != 1) { - throw createException("Unsupported collection type \"" + type + "\""); - } - - final Type genericType = types[0]; - return (Class) (genericType instanceof WildcardType ? ((WildcardType) genericType).getUpperBounds()[0] : genericType); - } - - return type; - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java similarity index 53% rename from core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java rename to core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index d2f471fe..e0786c78 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/Commands.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -23,19 +23,49 @@ */ package dev.triumphteam.cmd.core.processor; +import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.annotations.Command; +import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.reflect.AnnotatedElement; -public final class Commands { +/** + * Abstracts most of the "extracting" from sub command annotations, allows for extending. + *
+ * I know this could be done better, but couldn't think of a better way. + * If you do please PR or let me know on my discord! + * + * @param The sender type. + */ +@SuppressWarnings("unchecked") +public abstract class CommandProcessor { + + private final String parentName; + private final BaseCommand baseCommand; + private final String name; - private Commands() { - throw new AssertionError("Class cannot be instantiated."); + CommandProcessor( + final @NotNull String parentName, + final @NotNull BaseCommand baseCommand, + final @NotNull AnnotatedElement annotatedElement + ) { + this.parentName = parentName; + this.baseCommand = baseCommand; + this.name = nameOf(annotatedElement); } - public static @Nullable String nameOf(final @NotNull AnnotatedElement element) { + @Contract("_, _ -> new") + protected @NotNull SubCommandRegistrationException createException( + final @NotNull String message, + final @NotNull AnnotatedElement element + ) { + return new SubCommandRegistrationException(message, element, baseCommand.getClass()); + } + + private @Nullable String nameOf(final @NotNull AnnotatedElement element) { final Command commandAnnotation = element.getAnnotation(Command.class); // Not a command element @@ -43,4 +73,8 @@ private Commands() { return commandAnnotation.value(); } + + public @Nullable String getName() { + return name; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java new file mode 100644 index 00000000..4839a961 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -0,0 +1,111 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.processor; + +import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.sender.SenderValidator; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * Abstracts most of the "extracting" from sub command annotations, allows for extending. + *
+ * I know this could be done better, but couldn't think of a better way. + * If you do please PR or let me know on my discord! + * + * @param The sender type. + */ +@SuppressWarnings("unchecked") +final class SubCommandProcessor extends CommandProcessor { + + private final Method method; + private final SenderValidator senderValidator; + + SubCommandProcessor( + final @NotNull String parentName, + final @NotNull BaseCommand baseCommand, + final @NotNull Method method, + final @NotNull SenderValidator senderValidator + ) { + super(parentName, baseCommand, method); + + this.method = method; + this.senderValidator = senderValidator; + } + + /** + * Gets the correct sender type for the command. + * It'll validate the sender with the {@link #senderValidator}. + * + * @return The validated sender type. + */ + public Class senderType() { + final Parameter[] parameters = method.getParameters(); + if (parameters.length == 0) { + throw createException( + "Sender parameter missing", + method + ); + } + + final Class type = parameters[0].getType(); + final Set> allowedSenders = senderValidator.getAllowedSenders(); + + if (allowedSenders.contains(type)) { + throw createException( + "\"" + type.getSimpleName() + "\" is not a valid sender. Sender must be one of the following: " + + allowedSenders + .stream() + .map(it -> "\"" + it.getSimpleName() + "\"") + .collect(Collectors.joining(", ")), + method + ); + } + + // Sender is allowed + return (Class) type; + } + + public List> arguments() { + final Parameter[] parameters = method.getParameters(); + + // Starting at 1 because we don't care about sender here. + for (int i = 1; i < parameters.length; i++) { + final Parameter parameter = parameters[i]; + final Class type = parameter.getType(); + + + // createArgument(parameter, i - 1); + } + + return Collections.emptyList(); + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentValidator.java new file mode 100644 index 00000000..b4ea06f7 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentValidator.java @@ -0,0 +1,13 @@ +package dev.triumphteam.cmd.core.validation; + +import dev.triumphteam.cmd.core.processor.CommandProcessor; +import org.jetbrains.annotations.NotNull; + +public interface ArgumentValidator { + + boolean validate( + final @NotNull CommandProcessor processor, + final @NotNull Class argumentType, + final int position + ); +} diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index 137c8d88..38d9d217 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -92,12 +92,12 @@ public boolean execute( } @Override - public @NotNull Map> getSubCommands() { + public @NotNull Map> getCommands() { return null; } @Override - public @NotNull Map> getSubCommandAlias() { + public @NotNull Map> getCommandAliases() { return null; } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java index ea2fc2fd..2bf8a46a 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java @@ -25,22 +25,15 @@ import dev.triumphteam.cmd.bukkit.annotation.Permission; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.processor.AbstractCommandProcessor; -import dev.triumphteam.cmd.core.processor.OldAbstractCommandProcessor; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import org.bukkit.command.CommandSender; +import dev.triumphteam.cmd.core.processor.AbstractRootCommandProcessor; import org.bukkit.permissions.PermissionDefault; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.stream.Collectors; -import java.lang.reflect.AnnotatedElement; -final class BukkitCommandProcessor extends AbstractCommandProcessor { +final class BukkitCommandProcessor extends AbstractRootCommandProcessor { private final CommandPermission basePermission; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index a501a8d6..98252d8a 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -44,7 +44,7 @@ public final class SimpleCommand implements ParentCommand { @SuppressWarnings("unchecked") public SimpleCommand( - final @NotNull SimpleCommandProcessor processor, + final @NotNull SimpleCommandProcessor processor, final @NotNull MessageRegistry messageRegistry ) { this.name = processor.getName(); @@ -81,12 +81,12 @@ public void addSubCommand( } @Override - public @NotNull Map> getSubCommands() { + public @NotNull Map> getCommands() { return subCommands; } @Override - public @NotNull Map> getSubCommandAlias() { + public @NotNull Map> getCommandAliases() { return subCommandAliases; } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 381e2652..c32715dc 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -77,7 +77,7 @@ public void registerCommand(final @NotNull BaseCommand baseCommand) { } // Command does not exist, proceed to add new! - processor.subCommands(); + processor.commands(); final SimpleCommand newCommand = commands.computeIfAbsent(processor.getName(), it -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java index 14f94abc..ad4bebe7 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java @@ -24,10 +24,10 @@ package dev.triumphteam.cmds.simple; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.processor.AbstractCommandProcessor; +import dev.triumphteam.cmd.core.processor.AbstractRootCommandProcessor; import org.jetbrains.annotations.NotNull; -public final class SimpleCommandProcessor extends AbstractCommandProcessor { +public final class SimpleCommandProcessor extends AbstractRootCommandProcessor { public SimpleCommandProcessor(final @NotNull BaseCommand baseCommand) { super(baseCommand); From 4312755667fb1c4546c2c799020b29398f52841b Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Sun, 25 Dec 2022 02:31:24 +0000 Subject: [PATCH 023/101] chore: Re-add suggestions --- .../argument/AbstractInternalArgument.java | 9 - .../cmd/core/argument/ArgumentResolver.java | 1 - .../argument/CollectionInternalArgument.java | 3 +- .../core/argument/EnumInternalArgument.java | 3 +- .../core/argument/FlagInternalArgument.java | 3 +- .../core/argument/IgnoreInternalArgument.java | 47 ++++ .../cmd/core/argument/InternalArgument.java | 3 - .../JoinedStringInternalArgument.java | 3 +- .../argument/LimitlessInternalArgument.java | 3 +- .../core/argument/NamedInternalArgument.java | 3 +- .../argument/ResolverInternalArgument.java | 3 +- .../argument/SplitStringInternalArgument.java | 3 +- .../core/argument/StringInternalArgument.java | 3 +- .../AbstractRootCommandProcessor.java | 4 +- .../cmd/core/processor/CommandProcessor.java | 251 +++++++++++++++++- .../OldAbstractSubCommandProcessor.java | 36 +-- .../core/processor/SubCommandProcessor.java | 98 ++++++- .../validation/ArgumentExtensionHandler.java | 22 ++ .../core/validation/ArgumentValidator.java | 13 - .../DefaultArgumentExtensionHandler.java | 51 ++++ .../cmd/slash/SlashCommandListener.java | 3 +- 21 files changed, 472 insertions(+), 93 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/IgnoreInternalArgument.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentExtensionHandler.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentValidator.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java index e748e651..319d2afa 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java @@ -43,7 +43,6 @@ public abstract class AbstractInternalArgument implements InternalArgument private final String name; private final String description; private final Class type; - private final int position; private final boolean optional; private final Suggestion suggestion; @@ -52,14 +51,12 @@ public AbstractInternalArgument( final @NotNull String description, final @NotNull Class type, final @NotNull Suggestion suggestion, - final int position, final boolean optional ) { this.name = name; this.description = description; this.type = type; this.suggestion = suggestion; - this.position = position; this.optional = optional; } @@ -84,11 +81,6 @@ public AbstractInternalArgument( return name; } - @Override - public int getPosition() { - return position; - } - @Override public @NotNull String getDescription() { return description; @@ -138,7 +130,6 @@ public int hashCode() { "name='" + name + '\'' + ", description='" + description + '\'' + ", type=" + type + - ", position=" + position + ", optional=" + optional + ", suggestion=" + suggestion + '}'; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java index 1d77765d..324da4a6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentResolver.java @@ -42,5 +42,4 @@ public interface ArgumentResolver { * @return An Object with the resolved value or null. */ @Nullable Object resolve(final @NotNull S sender, final @NotNull String arg); - } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java index ae80b2a0..9684ce42 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java @@ -50,10 +50,9 @@ public CollectionInternalArgument( final @NotNull InternalArgument internalArgument, final @NotNull Class collectionType, final @NotNull Suggestion suggestion, - final int position, final boolean optional ) { - super(name, description, String.class, suggestion, position, optional); + super(name, description, String.class, suggestion, optional); this.internalArgument = internalArgument; this.collectionType = collectionType; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java index 8dd5f61e..bf35e1ea 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java @@ -48,10 +48,9 @@ public EnumInternalArgument( final @NotNull String description, final @NotNull Class> type, final @NotNull Suggestion suggestion, - final int position, final boolean optional ) { - super(name, description, type, suggestion, position, optional); + super(name, description, type, suggestion, optional); this.enumType = type; // Populates on creation to reduce runtime of first run for certain enums, like Bukkit's Material. diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java index 971d5d0e..9b157767 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java @@ -55,10 +55,9 @@ public FlagInternalArgument( final @NotNull String name, final @NotNull String description, final @NotNull FlagGroup flagGroup, - final int position, final boolean isOptional ) { - super(name, description, Flags.class, new EmptySuggestion<>(), position, isOptional); + super(name, description, Flags.class, new EmptySuggestion<>(), isOptional); this.flagGroup = flagGroup; this.flagParser = new FlagParser<>(flagGroup); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/IgnoreInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/IgnoreInternalArgument.java new file mode 100644 index 00000000..e6d090e8 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/IgnoreInternalArgument.java @@ -0,0 +1,47 @@ +package dev.triumphteam.cmd.core.argument; + +import dev.triumphteam.cmd.core.suggestion.SuggestionContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; + +/** + * This argument type is always ignored by the creator. + * This is only used for arguments that are meant to be hidden and not actually part of a command. + */ +public final class IgnoreInternalArgument implements InternalArgument { + + public IgnoreInternalArgument() {} + + @Override + public @NotNull String getName() { + return "ignored"; + } + + @Override + public @NotNull String getDescription() { + return "Ignored."; + } + + @Override + public @NotNull Class getType() { + return Void.TYPE; + } + + @Override + public boolean isOptional() { + return false; + } + + @Override + public @Nullable Object resolve(@NotNull final S sender, final @NotNull Void value) { + return null; + } + + @Override + public @NotNull List<@NotNull String> suggestions(@NotNull final S sender, final @NotNull List<@NotNull String> trimmed, final @NotNull SuggestionContext context) { + return Collections.emptyList(); + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index 3f6ac8bf..0d03da52 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -46,9 +46,6 @@ public interface InternalArgument { */ @NotNull String getName(); - // TODO: 1/31/2022 - int getPosition(); - /** * The description of this Argument. * Holds the description. diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java index aa7a4bed..9c4e6fc2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java @@ -45,10 +45,9 @@ public JoinedStringInternalArgument( final @NotNull String description, final @NotNull CharSequence delimiter, final @NotNull Suggestion suggestion, - final int position, final boolean optional ) { - super(name, description, String.class, suggestion, position, optional); + super(name, description, String.class, suggestion, optional); this.delimiter = delimiter; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java index 1fefb2ae..00d57849 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java @@ -42,10 +42,9 @@ public LimitlessInternalArgument( final @NotNull String description, final @NotNull Class type, final @NotNull Suggestion suggestion, - final int position, final boolean isOptional ) { - super(name, description, type, suggestion, position, isOptional); + super(name, description, type, suggestion, isOptional); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java index 138b9438..03fbe7d9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java @@ -46,10 +46,9 @@ public NamedInternalArgument( final @NotNull String name, final @NotNull String description, final @NotNull Map> arguments, - final int position, final boolean isOptional ) { - super(name, description, Arguments.class, new EmptySuggestion<>(), position, isOptional); + super(name, description, Arguments.class, new EmptySuggestion<>(), isOptional); this.arguments = arguments; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java index e4082e50..0d6cbe90 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java @@ -47,10 +47,9 @@ public ResolverInternalArgument( final @NotNull Class type, final @NotNull ArgumentResolver resolver, final @NotNull Suggestion suggestion, - final int position, final boolean optional ) { - super(name, description, type, suggestion, position, optional); + super(name, description, type, suggestion, optional); this.resolver = resolver; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java index cfd1defc..b98b7615 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java @@ -52,10 +52,9 @@ public SplitStringInternalArgument( final @NotNull InternalArgument internalArgument, final @NotNull Class collectionType, final @NotNull Suggestion suggestion, - final int position, final boolean optional ) { - super(name, description, String.class, suggestion, position, optional); + super(name, description, String.class, suggestion, optional); this.regex = regex; this.internalArgument = internalArgument; this.collectionType = collectionType; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java index e174b5c7..0cf7d5f8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java @@ -39,10 +39,9 @@ public StringInternalArgument( final @NotNull String description, final @NotNull Class type, final @NotNull Suggestion suggestion, - final int position, final boolean optional ) { - super(name, description, type, suggestion, position, optional); + super(name, description, type, suggestion, optional); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java index f9910ee4..ad09f939 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java @@ -85,7 +85,7 @@ public AnnotationContainer createAnnotationContainer() { // Ignore non-public methods if (!Modifier.isPublic(method.getModifiers())) return null; - final SubCommandProcessor processor = new SubCommandProcessor<>( + /*final SubCommandProcessor processor = new SubCommandProcessor<>( name, baseCommand, method @@ -94,7 +94,7 @@ public AnnotationContainer createAnnotationContainer() { // Not a command, ignore the method if (processor.getName() == null) return null; - +*/ return (Command) () -> null; }).filter(Objects::nonNull).collect(Collectors.toList()); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index e0786c78..4574c229 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -23,14 +23,46 @@ */ package dev.triumphteam.cmd.core.processor; +import com.google.common.base.CaseFormat; import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.annotations.ArgName; import dev.triumphteam.cmd.core.annotations.Command; +import dev.triumphteam.cmd.core.annotations.Description; +import dev.triumphteam.cmd.core.annotations.Join; +import dev.triumphteam.cmd.core.annotations.NamedArguments; +import dev.triumphteam.cmd.core.annotations.Optional; +import dev.triumphteam.cmd.core.annotations.Split; +import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; +import dev.triumphteam.cmd.core.argument.FlagInternalArgument; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; +import dev.triumphteam.cmd.core.argument.NamedInternalArgument; +import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; +import dev.triumphteam.cmd.core.argument.named.Arguments; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; +import dev.triumphteam.cmd.core.flag.Flags; +import dev.triumphteam.cmd.core.registry.RegistryContainer; +import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; +import dev.triumphteam.cmd.core.suggestion.EnumSuggestion; +import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; +import dev.triumphteam.cmd.core.suggestion.Suggestion; +import dev.triumphteam.cmd.core.suggestion.SuggestionKey; +import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; +import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Parameter; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.WildcardType; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; /** * Abstracts most of the "extracting" from sub command annotations, allows for extending. @@ -43,30 +75,36 @@ @SuppressWarnings("unchecked") public abstract class CommandProcessor { + private static final Set> SUPPORTED_COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); + private final String parentName; private final BaseCommand baseCommand; private final String name; + private final AnnotatedElement annotatedElement; + + private final SuggestionRegistry suggestionRegistry; CommandProcessor( final @NotNull String parentName, final @NotNull BaseCommand baseCommand, - final @NotNull AnnotatedElement annotatedElement + final @NotNull AnnotatedElement annotatedElement, + final @NotNull RegistryContainer registryContainer ) { this.parentName = parentName; this.baseCommand = baseCommand; - this.name = nameOf(annotatedElement); + this.annotatedElement = annotatedElement; + this.name = nameOf(); + + this.suggestionRegistry = registryContainer.getSuggestionRegistry(); } - @Contract("_, _ -> new") - protected @NotNull SubCommandRegistrationException createException( - final @NotNull String message, - final @NotNull AnnotatedElement element - ) { - return new SubCommandRegistrationException(message, element, baseCommand.getClass()); + @Contract("_ -> new") + protected @NotNull SubCommandRegistrationException createException(final @NotNull String message) { + return new SubCommandRegistrationException(message, annotatedElement, baseCommand.getClass()); } - private @Nullable String nameOf(final @NotNull AnnotatedElement element) { - final Command commandAnnotation = element.getAnnotation(Command.class); + private @Nullable String nameOf() { + final Command commandAnnotation = annotatedElement.getAnnotation(Command.class); // Not a command element if (commandAnnotation == null) return null; @@ -77,4 +115,197 @@ public abstract class CommandProcessor { public @Nullable String getName() { return name; } + + // TODO COMMENTS + protected InternalArgument createArgument( + final @NotNull Parameter parameter, + final @NotNull List argDescriptions, + final @NotNull Map> suggestions, + final int position + ) { + final Class type = parameter.getType(); + final String argumentName = getArgName(parameter); + final String argumentDescription = getArgumentDescription(argDescriptions, parameter, position); + final boolean optional = parameter.isAnnotationPresent(Optional.class); + + // Handles collection internalArgument. + // TODO: Add more collection types. + if (SUPPORTED_COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { + final Class collectionType = getGenericType(parameter); + final InternalArgument internalArgument = createSimpleArgument( + collectionType, + argumentName, + argumentDescription, + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + true + ); + + if (parameter.isAnnotationPresent(Split.class)) { + final Split splitAnnotation = parameter.getAnnotation(Split.class); + return new SplitStringInternalArgument<>( + argumentName, + argumentDescription, + splitAnnotation.value(), + internalArgument, + type, + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + optional + ); + } + + addArgument( + new CollectionInternalArgument<>( + argumentName, + argumentDescription, + internalArgument, + type, + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + optional + ) + ); + return; + } + + // Handler for using String with `@Join`. + if (type == String.class && parameter.isAnnotationPresent(Join.class)) { + final Join joinAnnotation = parameter.getAnnotation(Join.class); + addArgument( + new JoinedStringInternalArgument<>( + argumentName, + argumentDescription, + joinAnnotation.value(), + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + optional + ) + ); + return; + } + + // Handler for flags. + if (type == Flags.class) { + if (flagGroup.isEmpty()) { + throw createException("Flags internalArgument detected but no flag annotation declared"); + } + + addArgument( + new FlagInternalArgument<>( + argumentName, + argumentDescription, + flagGroup, + optional + ) + ); + return; + } + + // Handler for named arguments + if (type == Arguments.class) { + final NamedArguments namedArguments = annotatedElement.getAnnotation(NamedArguments.class); + if (namedArguments == null) { + throw createException("TODO"); + } + + addArgument( + new NamedInternalArgument<>( + argumentName, + argumentDescription, + collectNamedArgs(namedArguments.value()), + optional + ) + ); + return; + } + + return createSimpleArgument( + type, + argumentName, + argumentDescription, + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + position, + optional + ); + } + + /** + * Gets the internalArgument name, either from the parameter or from the annotation. + * If the parameter is not annotated, turn the name from Camel Case to "lower-hyphen". + * + * @param parameter The parameter to get data from. + * @return The final internalArgument name. + */ + private @NotNull String getArgName(final @NotNull Parameter parameter) { + if (parameter.isAnnotationPresent(ArgName.class)) { + return parameter.getAnnotation(ArgName.class).value(); + } + + return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, parameter.getName()); + } + + /** + * Gets the internalArgument description. + * + * @param argDescriptions List with collected method annotation instead of argument annotation. + * @param parameter The parameter to get data from. + * @param index The index of the internalArgument. + * @return The final internalArgument description. + */ + private @NotNull String getArgumentDescription( + final List argDescriptions, + final @NotNull Parameter parameter, + final int index + ) { + final Description description = parameter.getAnnotation(Description.class); + if (description != null) { + return description.value(); + } + + if (index < argDescriptions.size()) return argDescriptions.get(index); + return ""; + } + + private @NotNull Class getGenericType(final @NotNull Parameter parameter) { + final Class type = parameter.getType(); + if (SUPPORTED_COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { + final ParameterizedType parameterizedType = (ParameterizedType) parameter.getParameterizedType(); + final Type[] types = parameterizedType.getActualTypeArguments(); + + if (types.length != 1) { + throw createException("Unsupported collection type \"" + type + "\""); + } + + final Type genericType = types[0]; + return (Class) (genericType instanceof WildcardType ? ((WildcardType) genericType).getUpperBounds()[0] : genericType); + } + + return type; + } + + protected @Nullable Suggestion createSuggestion(final @Nullable SuggestionKey suggestionKey, final @NotNull Class type) { + if (suggestionKey == null) { + if (Enum.class.isAssignableFrom(type)) return new EnumSuggestion<>((Class>) type); + + final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(type); + if (resolver != null) return new SimpleSuggestion<>(resolver); + + return null; + } + + final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(suggestionKey); + if (resolver == null) { + throw createException("Cannot find the suggestion key `" + suggestionKey + "`"); + } + return new SimpleSuggestion<>(resolver); + } + + private @NotNull Suggestion suggestionFromParam(final @NotNull Parameter parameter) { + final dev.triumphteam.cmd.core.annotations.Suggestion parameterAnnotation = parameter.getAnnotation(dev.triumphteam.cmd.core.annotations.Suggestion.class); + final SuggestionKey suggestionKey = parameterAnnotation == null ? null : SuggestionKey.of(parameterAnnotation.value()); + + final Class type = getGenericType(parameter); + final Suggestion suggestion = createSuggestion(suggestionKey, type); + + if (suggestion == null) return new EmptySuggestion<>(); + + return suggestion; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java index 13514b7d..3226164a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java @@ -112,27 +112,17 @@ @SuppressWarnings("unchecked") public abstract class OldAbstractSubCommandProcessor { + private static final Set> COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); private final BaseCommand baseCommand; private final String parentName; - private final AnnotatedElement annotatedElement; - // Name is nullable to detect if the method should or not be considered a sub command. - private String name = null; - // TODO: 11/28/2021 Add better default description - private String description = "No description provided."; private final List argDescriptions = new ArrayList<>(); private final List alias = new ArrayList<>(); - - private boolean isDefault = false; private final boolean isAsync; - - private Class senderType; - private final FlagGroup flagGroup = new FlagGroup<>(); private final List> suggestionList = new ArrayList<>(); private final List> internalArguments = new ArrayList<>(); private final Set> requirements = new HashSet<>(); - private final RegistryContainer registryContainer; private final SuggestionRegistry suggestionRegistry; private final ArgumentRegistry argumentRegistry; @@ -140,8 +130,12 @@ public abstract class OldAbstractSubCommandProcessor { private final RequirementRegistry requirementRegistry; private final MessageRegistry messageRegistry; private final SenderValidator senderValidator; - - private static final Set> COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); + // Name is nullable to detect if the method should or not be considered a sub command. + private String name = null; + // TODO: 11/28/2021 Add better default description + private String description = "No description provided."; + private boolean isDefault = false; + private Class senderType; protected OldAbstractSubCommandProcessor( final @NotNull BaseCommand baseCommand, @@ -349,7 +343,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi argumentName, argumentDescription, suggestionList.get(position), - 0, true ); @@ -363,7 +356,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi internalArgument, type, suggestionList.get(position), - position, optional ) ); @@ -377,7 +369,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi internalArgument, type, suggestionList.get(position), - position, optional ) ); @@ -393,7 +384,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi argumentDescription, joinAnnotation.value(), suggestionList.get(position), - position, optional ) ); @@ -411,7 +401,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi argumentName, argumentDescription, flagGroup, - position, optional ) ); @@ -430,14 +419,13 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi argumentName, argumentDescription, collectNamedArgs(namedArguments.value()), - position, optional ) ); return; } - addArgument(createSimpleArgument(type, argumentName, argumentDescription, suggestionList.get(position), position, optional)); + addArgument(createSimpleArgument(type, argumentName, argumentDescription, suggestionList.get(position), optional)); } private @NotNull Map<@NotNull String, @NotNull InternalArgument> collectNamedArgs(final @NotNull String key) { @@ -458,7 +446,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi listArgument.getName(), listArgument.getDescription(), suggestion, - 0, true ); @@ -471,7 +458,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi internalArgument, listArgument.getType(), suggestion, - 0, true ) ); @@ -484,7 +470,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi argument.getName(), argument.getDescription(), suggestion, - 0, true ) ); @@ -538,7 +523,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi final @NotNull String parameterName, final @NotNull String argumentDescription, final @NotNull Suggestion suggestion, - final int position, final boolean optional ) { // All other types default to the resolver. @@ -552,7 +536,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi argumentDescription, (Class>) type, suggestion, - position, optional ); } @@ -565,7 +548,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi type, resolver, suggestion, - position, optional ); } @@ -643,7 +625,6 @@ private void extractFlags() { "", (Class>) argumentType, suggestion, - 0, false ); } else { @@ -658,7 +639,6 @@ private void extractFlags() { argumentType, resolver, suggestion, - 0, false ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index 4839a961..4cf122ce 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -24,17 +24,31 @@ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.annotations.ArgDescriptions; +import dev.triumphteam.cmd.core.annotations.Suggestions; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; +import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; +import dev.triumphteam.cmd.core.suggestion.Suggestion; +import dev.triumphteam.cmd.core.suggestion.SuggestionKey; +import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; +import dev.triumphteam.cmd.core.validation.ArgumentExtensionHandler; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Method; import java.lang.reflect.Parameter; +import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + /** * Abstracts most of the "extracting" from sub command annotations, allows for extending. *
@@ -44,21 +58,24 @@ * @param The sender type. */ @SuppressWarnings("unchecked") -final class SubCommandProcessor extends CommandProcessor { +public final class SubCommandProcessor extends CommandProcessor { private final Method method; private final SenderValidator senderValidator; + private final ArgumentExtensionHandler argumentExtensionHandler; SubCommandProcessor( final @NotNull String parentName, final @NotNull BaseCommand baseCommand, final @NotNull Method method, - final @NotNull SenderValidator senderValidator + final @NotNull SenderValidator senderValidator, + final @NotNull ArgumentExtensionHandler argumentExtensionHandler ) { super(parentName, baseCommand, method); this.method = method; this.senderValidator = senderValidator; + this.argumentExtensionHandler = argumentExtensionHandler; } /** @@ -70,10 +87,7 @@ final class SubCommandProcessor extends CommandProcessor { public Class senderType() { final Parameter[] parameters = method.getParameters(); if (parameters.length == 0) { - throw createException( - "Sender parameter missing", - method - ); + throw createException("Sender parameter missing"); } final Class type = parameters[0].getType(); @@ -85,8 +99,7 @@ public Class senderType() { allowedSenders .stream() .map(it -> "\"" + it.getSimpleName() + "\"") - .collect(Collectors.joining(", ")), - method + .collect(Collectors.joining(", ")) ); } @@ -97,15 +110,84 @@ public Class senderType() { public List> arguments() { final Parameter[] parameters = method.getParameters(); + // Ignore everything if command doesn't have arguments. + if (parameters.length <= 1) return Collections.emptyList(); + + final List argDescriptions = argDescriptionFromMethodAnnotation(); + final Map> suggestions = suggestionsFromMethodAnnotation(); + + // Position of the last argument. + final int last = parameters.length - 1; + // Starting at 1 because we don't care about sender here. for (int i = 1; i < parameters.length; i++) { final Parameter parameter = parameters[i]; final Class type = parameter.getType(); + // argumentExtensionHandler.validate(this, type, ) // createArgument(parameter, i - 1); } return Collections.emptyList(); } + + /** + * Extracts the {@link ArgDescriptions} Annotation from the Method. + * + * @return A list with the descriptions ordered by parameter order. + */ + private List argDescriptionFromMethodAnnotation() { + final ArgDescriptions argDescriptions = method.getAnnotation(ArgDescriptions.class); + if (argDescriptions == null) return Collections.emptyList(); + return Arrays.asList(argDescriptions.value()); + } + + public Map> suggestionsFromMethodAnnotation() { + final Map> map = new HashMap<>(); + + @NotNull List suggestionsFromAnnotations = getSuggestionsFromAnnotations(); + for (int i = 0; i < suggestionsFromAnnotations.size(); i++) { + final dev.triumphteam.cmd.core.annotations.Suggestion suggestion = suggestionsFromAnnotations.get(i); + final String key = suggestion.value(); + + // Empty suggestion + if (key.isEmpty()) { + map.put(i, new EmptySuggestion<>()); + continue; + } + + map.put(i, createSuggestion(SuggestionKey.of(key), Void.TYPE)); + } + + return map; + } + + /** + * Extract all suggestions from the parameters. + * Adds the suggestions to the passed list. + */ + private void extractSuggestionFromParams() { + // TODO SUGGESTIONS + /*final Parameter[] parameters = annotatedElement.getParameters(); + for (int i = 1; i < parameters.length; i++) { + final Parameter parameter = parameters[i]; + + final dev.triumphteam.cmd.core.annotation.Suggestion suggestion = parameter.getAnnotation(dev.triumphteam.cmd.core.annotation.Suggestion.class); + final SuggestionKey suggestionKey = suggestion == null ? null : SuggestionKey.of(suggestion.value()); + + final Class type = getGenericType(parameter); + final int addIndex = i - 1; + setOrAddSuggestion(addIndex, createSuggestion(suggestionKey, type)); + }*/ + } + + private @NotNull List getSuggestionsFromAnnotations() { + final Suggestions requirements = method.getAnnotation(Suggestions.class); + if (requirements != null) return Arrays.asList(requirements.value()); + + final dev.triumphteam.cmd.core.annotations.Suggestion suggestion = method.getAnnotation(dev.triumphteam.cmd.core.annotations.Suggestion.class); + if (suggestion == null) return emptyList(); + return singletonList(suggestion); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentExtensionHandler.java b/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentExtensionHandler.java new file mode 100644 index 00000000..c20de608 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentExtensionHandler.java @@ -0,0 +1,22 @@ +package dev.triumphteam.cmd.core.validation; + +import dev.triumphteam.cmd.core.argument.IgnoreInternalArgument; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.processor.SubCommandProcessor; +import org.jetbrains.annotations.NotNull; + +public interface ArgumentExtensionHandler { + + void validate( + final @NotNull SubCommandProcessor subCommandProcessor, + final @NotNull InternalArgument argument, + final int position, + final int last + ); + + default InternalArgument create( + + ) { + return new IgnoreInternalArgument<>(); + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentValidator.java deleted file mode 100644 index b4ea06f7..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentValidator.java +++ /dev/null @@ -1,13 +0,0 @@ -package dev.triumphteam.cmd.core.validation; - -import dev.triumphteam.cmd.core.processor.CommandProcessor; -import org.jetbrains.annotations.NotNull; - -public interface ArgumentValidator { - - boolean validate( - final @NotNull CommandProcessor processor, - final @NotNull Class argumentType, - final int position - ); -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java b/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java new file mode 100644 index 00000000..3007e5c6 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java @@ -0,0 +1,51 @@ +package dev.triumphteam.cmd.core.validation; + +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; +import dev.triumphteam.cmd.core.processor.SubCommandProcessor; +import org.jetbrains.annotations.NotNull; + +public class DefaultArgumentExtensionHandler implements ArgumentExtensionHandler { + + @Override + public void validate( + final @NotNull SubCommandProcessor subCommandProcessor, + final @NotNull InternalArgument argument, + final int position, + final int last + ) { + validateOptionals(argument, position, last); + validateLimitless(argument, position, last); + } + + @Override + public InternalArgument create() { + return null; + } + + /** + * Validation for optionals. + */ + private void validateOptionals( + final @NotNull InternalArgument argument, + final int position, + final int last + ) { + if (position == last && argument.isOptional()) { + // throw createException("Optional internalArgument is only allowed as the last internalArgument"); + } + } + + /** + * Validation for {@link LimitlessInternalArgument}. + */ + private void validateLimitless( + final @NotNull InternalArgument argument, + final int position, + final int last + ) { + if (position == last && argument instanceof LimitlessInternalArgument) { + // throw createException("Limitless internalArgument is only allowed as the last internalArgument"); + } + } +} diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java index d1307218..ac86f910 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java @@ -24,6 +24,7 @@ package dev.triumphteam.cmd.slash; import com.google.common.collect.Maps; +import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.slash.sender.SlashSender; @@ -99,7 +100,7 @@ public void onSlashCommandInteraction(final @NotNull SlashCommandInteractionEven return Maps.immutableEntry(it.getName(), it.getAsString()); }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - command.execute(sender, subCommandName != null ? subCommandName : Default.DEFAULT_CMD_NAME, args); + command.execute(sender, subCommandName != null ? subCommandName : Command.DEFAULT_CMD_NAME, args); } // private static final List ass = Arrays.asList("Hello", "There", "Ass", "Fuck", "Hoy"); From cebdbfd3f923e236123aa6b74053e75f2a76639b Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Sun, 25 Dec 2022 12:45:20 +0000 Subject: [PATCH 024/101] chore: Re-add command creation --- .../cmd/core/processor/CommandProcessor.java | 109 +++++++++++------- .../core/processor/SubCommandProcessor.java | 6 +- .../cmd/prefixed/PrefixedCommand.java | 56 +++------ .../prefixed/PrefixedCommandProcessor.java | 8 +- .../cmd/prefixed/PrefixedSubCommand.java | 10 +- .../cmd/bukkit/BukkitCommandManager.java | 8 +- .../cmd/bukkit/BukkitCommandProcessor.java | 2 +- .../cmd/bukkit/OldBukkitCommand.java | 31 ++++- settings.gradle.kts | 8 +- 9 files changed, 127 insertions(+), 111 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index 4574c229..37715c6c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -29,18 +29,17 @@ import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.core.annotations.Description; import dev.triumphteam.cmd.core.annotations.Join; -import dev.triumphteam.cmd.core.annotations.NamedArguments; import dev.triumphteam.cmd.core.annotations.Optional; import dev.triumphteam.cmd.core.annotations.Split; +import dev.triumphteam.cmd.core.argument.ArgumentRegistry; +import dev.triumphteam.cmd.core.argument.ArgumentResolver; import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; -import dev.triumphteam.cmd.core.argument.FlagInternalArgument; +import dev.triumphteam.cmd.core.argument.EnumInternalArgument; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; -import dev.triumphteam.cmd.core.argument.NamedInternalArgument; +import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; -import dev.triumphteam.cmd.core.argument.named.Arguments; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.flag.Flags; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.EnumSuggestion; @@ -83,6 +82,7 @@ public abstract class CommandProcessor { private final AnnotatedElement annotatedElement; private final SuggestionRegistry suggestionRegistry; + private final ArgumentRegistry argumentRegistry; CommandProcessor( final @NotNull String parentName, @@ -96,6 +96,7 @@ public abstract class CommandProcessor { this.name = nameOf(); this.suggestionRegistry = registryContainer.getSuggestionRegistry(); + this.argumentRegistry = registryContainer.getArgumentRegistry(); } @Contract("_ -> new") @@ -153,49 +154,41 @@ public abstract class CommandProcessor { ); } - addArgument( - new CollectionInternalArgument<>( - argumentName, - argumentDescription, - internalArgument, - type, - suggestions.getOrDefault(position, suggestionFromParam(parameter)), - optional - ) + return new CollectionInternalArgument<>( + argumentName, + argumentDescription, + internalArgument, + type, + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + optional ); - return; } // Handler for using String with `@Join`. if (type == String.class && parameter.isAnnotationPresent(Join.class)) { final Join joinAnnotation = parameter.getAnnotation(Join.class); - addArgument( - new JoinedStringInternalArgument<>( - argumentName, - argumentDescription, - joinAnnotation.value(), - suggestions.getOrDefault(position, suggestionFromParam(parameter)), - optional - ) + return new JoinedStringInternalArgument<>( + argumentName, + argumentDescription, + joinAnnotation.value(), + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + optional ); - return; } // Handler for flags. - if (type == Flags.class) { + // TODO RE-ADD FLAGS AND NAMED ARGUMENTS AS A SINGLE TYPE + /*if (type == Flags.class) { if (flagGroup.isEmpty()) { throw createException("Flags internalArgument detected but no flag annotation declared"); } - addArgument( - new FlagInternalArgument<>( - argumentName, - argumentDescription, - flagGroup, - optional - ) + return new FlagInternalArgument<>( + argumentName, + argumentDescription, + flagGroup, + optional ); - return; } // Handler for named arguments @@ -205,23 +198,53 @@ public abstract class CommandProcessor { throw createException("TODO"); } - addArgument( - new NamedInternalArgument<>( - argumentName, - argumentDescription, - collectNamedArgs(namedArguments.value()), - optional - ) + return new NamedInternalArgument<>( + argumentName, + argumentDescription, + collectNamedArgs(namedArguments.value()), + optional ); - return; - } + }*/ return createSimpleArgument( type, argumentName, argumentDescription, suggestions.getOrDefault(position, suggestionFromParam(parameter)), - position, + optional + ); + } + + protected @NotNull InternalArgument createSimpleArgument( + final @NotNull Class type, + final @NotNull String parameterName, + final @NotNull String argumentDescription, + final @NotNull Suggestion suggestion, + final boolean optional + ) { + // All other types default to the resolver. + final ArgumentResolver resolver = argumentRegistry.getResolver(type); + if (resolver == null) { + // Handler for using any Enum. + if (Enum.class.isAssignableFrom(type)) { + //noinspection unchecked + return new EnumInternalArgument<>( + parameterName, + argumentDescription, + (Class>) type, + suggestion, + optional + ); + } + + throw createException("No internalArgument of type \"" + type.getName() + "\" registered"); + } + return new ResolverInternalArgument<>( + parameterName, + argumentDescription, + type, + resolver, + suggestion, optional ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index 4cf122ce..c3efebef 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -27,12 +27,11 @@ import dev.triumphteam.cmd.core.annotations.ArgDescriptions; import dev.triumphteam.cmd.core.annotations.Suggestions; import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderValidator; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; -import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; -import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; import dev.triumphteam.cmd.core.validation.ArgumentExtensionHandler; import org.jetbrains.annotations.NotNull; @@ -69,9 +68,10 @@ public final class SubCommandProcessor extends CommandProcessor { final @NotNull BaseCommand baseCommand, final @NotNull Method method, final @NotNull SenderValidator senderValidator, + final @NotNull RegistryContainer registryContainer, final @NotNull ArgumentExtensionHandler argumentExtensionHandler ) { - super(parentName, baseCommand, method); + super(parentName, baseCommand, method, registryContainer); this.method = method; this.senderValidator = senderValidator; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java index fe7f1a12..285013bc 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java @@ -23,15 +23,15 @@ */ package dev.triumphteam.cmd.prefixed; +import dev.triumphteam.cmd.core.annotation.AnnotationContainer; +import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.command.ParentCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.List; @@ -42,7 +42,7 @@ * * @param The sender type. */ -final class PrefixedCommand implements ParentCommand> { +final class PrefixedCommand implements ParentCommand { private final Map> subCommands = new HashMap<>(); @@ -72,16 +72,6 @@ public PrefixedCommand( this.asyncExecutionProvider = asyncExecutionProvider; } - @Override - public void addSubCommand(final @NotNull String name, final @NotNull PrefixedSubCommand subCommand) { - this.subCommands.putIfAbsent(name, subCommand); - } - - @Override - public void addSubCommandAlias(final @NotNull String alias, final @NotNull PrefixedSubCommand subCommand) { - this.subCommands.putIfAbsent(alias, subCommand); - } - /** * Executes the current command for the given sender. * @@ -89,7 +79,7 @@ public void addSubCommandAlias(final @NotNull String alias, final @NotNull Prefi * @param args The command arguments. */ public void execute(final @NotNull S sender, final @NotNull List<@NotNull String> args) { - OldSubCommand subCommand = getDefaultSubCommand(); + /*OldSubCommand subCommand = getDefaultSubCommand(); String subCommandName = ""; if (args.size() > 0) subCommandName = args.get(0).toLowerCase(); @@ -105,36 +95,26 @@ public void execute(final @NotNull S sender, final @NotNull List<@NotNull String // TODO: 11/28/2021 Alias check final List arguments = !subCommand.isDefault() ? args.subList(1, args.size()) : args; - subCommand.execute(sender, arguments); + subCommand.execute(sender, arguments);*/ } - /** - * Gets the default sub command or null if there is none. - * - * @return The default sub command. - */ - private @Nullable OldSubCommand getDefaultSubCommand() { - return subCommands.get(Default.DEFAULT_CMD_NAME); + @Override + public @NotNull Map> getCommands() { + return null; } - /** - * Gets the valid sub command for the given name or null if there is none. - * - * @param key The sub command name. - * @return A sub command or null. - */ - private @Nullable OldSubCommand getSubCommand(final @NotNull String key) { - return subCommands.get(key); + @Override + public @NotNull Map> getCommandAliases() { + return null; } - /** - * Checks if the given sub command exists. - * - * @param key The sub command name. - * @return True if the sub command exists. - */ - private boolean subCommandExists(final @NotNull String key) { - return subCommands.containsKey(key); + @Override + public void addSubCommand(final @NotNull String name, final @NotNull Command subCommand, final boolean isAlias) { + } + @Override + public @NotNull AnnotationContainer getAnnotations() { + return null; + } } diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java index 42fed75e..e6f3ce21 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java @@ -29,7 +29,6 @@ import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.prefixed.annotation.Prefix; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; @@ -52,7 +51,7 @@ public PrefixedCommandProcessor( final @NotNull ExecutionProvider syncExecutionProvider, final @NotNull ExecutionProvider asyncExecutionProvider ) { - super(baseCommand, registryContainer, senderMapper, senderValidator, syncExecutionProvider, asyncExecutionProvider); + super(null, null, null, null, null, null, null); prefix = extractPrefix(); } @@ -72,8 +71,9 @@ public PrefixedCommandProcessor( * @return The prefix from the annotation or an empty string. */ private @NotNull String extractPrefix() { - final Prefix prefixAnnotation = getBaseCommand().getClass().getAnnotation(Prefix.class); - return prefixAnnotation == null ? "" : prefixAnnotation.value(); + /*final Prefix prefixAnnotation = getBaseCommand().getClass().getAnnotation(Prefix.class); + return prefixAnnotation == null ? "" : prefixAnnotation.value();*/ + return ""; } @Override diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java index d8fc9bbd..070b51dc 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java @@ -23,13 +23,10 @@ */ package dev.triumphteam.cmd.prefixed; -import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; +import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; final class PrefixedSubCommand extends OldSubCommand { @@ -41,9 +38,4 @@ public PrefixedSubCommand( super(processor, parentName, executionProvider); } - // TODO: - @Override - public @Nullable Object resolve(@NotNull final S sender, final @NotNull List value) { - return null; - } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index 0c89fb60..265b11a6 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -51,8 +51,6 @@ import java.util.*; import java.util.stream.Collectors; -import static dev.triumphteam.cmd.core.processor.Commands.nameOf; - public final class BukkitCommandManager extends CommandManager { private final Plugin plugin; @@ -127,7 +125,7 @@ private BukkitCommandManager( @Override public void registerCommand(final @NotNull BaseCommand baseCommand) { - final String name = nameOf(baseCommand); + final String name = "nameOf(baseCommand)"; final BukkitCommand command = commands.get(name); if (command != null) { @@ -143,11 +141,11 @@ public void registerCommand(final @NotNull BaseCommand baseCommand) { // TODO: ADD SUBCOMMANDS - processor.getAlias().forEach(it -> { + /*processor.getAlias().forEach(it -> { final BukkitCommand aliasCommand = commands.computeIfAbsent(it, ignored -> createAndRegisterCommand(it, processor)); // Adding sub commands. // TODO: ADD SUBCOMMANDS - }); + });*/ } @Override diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java index 2bf8a46a..2b5ad452 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java @@ -33,7 +33,7 @@ import java.util.*; import java.util.stream.Collectors; -final class BukkitCommandProcessor extends AbstractRootCommandProcessor { +final class BukkitCommandProcessor extends AbstractRootCommandProcessor { private final CommandPermission basePermission; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java index cad05b7d..4b47ef52 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java @@ -25,6 +25,8 @@ import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; import dev.triumphteam.cmd.bukkit.message.NoPermissionMessageContext; +import dev.triumphteam.cmd.core.annotation.AnnotationContainer; +import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.command.ParentCommand; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.message.MessageKey; @@ -79,7 +81,7 @@ public boolean execute( final @NotNull String commandLabel, final @NotNull String @NotNull [] args ) { - BukkitSubCommand subCommand = getDefaultSubCommand(); + /*BukkitSubCommand subCommand = getDefaultSubCommand(); String subCommandName = ""; if (args.length > 0) subCommandName = args[0].toLowerCase(); @@ -105,14 +107,15 @@ public boolean execute( final List commandArgs = Arrays.asList(!subCommand.isDefault() ? Arrays.copyOfRange(args, 1, args.length) : args); - subCommand.execute(mappedSender, commandArgs); + subCommand.execute(mappedSender, commandArgs);*/ return true; } @Override public @NotNull List<@NotNull String> tabComplete(final @NotNull CommandSender sender, final @NotNull String alias, final @NotNull String @NotNull [] args) throws IllegalArgumentException { if (args.length == 0) return emptyList(); - BukkitSubCommand subCommand = getDefaultSubCommand(); + return emptyList(); + /*BukkitSubCommand subCommand = getDefaultSubCommand(); final String arg = args[0].toLowerCase(); @@ -140,6 +143,26 @@ public boolean execute( } final List commandArgs = Arrays.asList(args); - return subCommand.getSuggestions(mappedSender, !subCommand.isDefault() ? commandArgs.subList(1, commandArgs.size()) : commandArgs); + return subCommand.getSuggestions(mappedSender, !subCommand.isDefault() ? commandArgs.subList(1, commandArgs.size()) : commandArgs);*/ + } + + @Override + public @NotNull AnnotationContainer getAnnotations() { + return null; + } + + @Override + public @NotNull Map> getCommands() { + return null; + } + + @Override + public @NotNull Map> getCommandAliases() { + return null; + } + + @Override + public void addSubCommand(final @NotNull String name, final @NotNull Command subCommand, final boolean isAlias) { + } } diff --git a/settings.gradle.kts b/settings.gradle.kts index 1b038bfd..f6a38440 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -14,10 +14,10 @@ listOf( ).forEach(::includeProject) listOf( - "minecraft/bukkit", - "discord/jda-common", - "discord/jda-prefixed", - "discord/jda-slash", + // "minecraft/bukkit", + "discord/jda-common", + "discord/jda-prefixed", + // "discord/jda-slash", ).forEach { val (folder, name) = it.split('/') includeProject(name, folder) From 7943e0453ecff849ba36b539299ae64a76315408 Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Sun, 25 Dec 2022 13:58:06 +0000 Subject: [PATCH 025/101] chore: Re-add arguments and suggestions --- .../argument/SplitStringInternalArgument.java | 5 +++ .../core/argument/StringInternalArgument.java | 1 - .../AbstractRootCommandProcessor.java | 28 +++++++++++-- .../cmd/core/processor/CommandProcessor.java | 3 +- .../core/processor/SubCommandProcessor.java | 19 +++++++-- .../DefaultArgumentExtensionHandler.java | 39 +++++-------------- .../cmds/simple/SimpleCommandManager.java | 8 +++- .../cmds/simple/SimpleCommandProcessor.java | 12 +++++- 8 files changed, 73 insertions(+), 42 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java index b98b7615..118f264f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java @@ -91,4 +91,9 @@ public SplitStringInternalArgument( .map(it -> map + it) .collect(Collectors.toList()); } + + @Override + public @NotNull String toString() { + return "SplitArgument{super=" + super.toString() + "}"; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java index 0cf7d5f8..604083bb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java @@ -48,5 +48,4 @@ public StringInternalArgument( public @NotNull String toString() { return "StringArgument{super=" + super.toString() + "}"; } - } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java index ad09f939..a63ce42c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java @@ -28,6 +28,9 @@ import dev.triumphteam.cmd.core.annotations.Description; import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; +import dev.triumphteam.cmd.core.registry.RegistryContainer; +import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.validation.ArgumentExtensionHandler; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Method; @@ -46,12 +49,25 @@ public abstract class AbstractRootCommandProcessor { private final List alias; private final String description; - public AbstractRootCommandProcessor(final @NotNull BaseCommand baseCommand) { + private final SenderValidator senderValidator; + private final RegistryContainer registryContainer; + private final ArgumentExtensionHandler argumentExtensionHandler; + + public AbstractRootCommandProcessor( + final @NotNull BaseCommand baseCommand, + final @NotNull SenderValidator senderValidator, + final @NotNull RegistryContainer registryContainer, + final @NotNull ArgumentExtensionHandler argumentExtensionHandler + ) { this.baseCommand = baseCommand; this.name = nameOf(); this.alias = aliasOf(); this.description = descriptionOf(); + + this.senderValidator = senderValidator; + this.registryContainer = registryContainer; + this.argumentExtensionHandler = argumentExtensionHandler; } public String getName() { @@ -85,16 +101,20 @@ public AnnotationContainer createAnnotationContainer() { // Ignore non-public methods if (!Modifier.isPublic(method.getModifiers())) return null; - /*final SubCommandProcessor processor = new SubCommandProcessor<>( + final SubCommandProcessor processor = new SubCommandProcessor<>( name, baseCommand, - method + method, + senderValidator, + registryContainer, + argumentExtensionHandler ); // Not a command, ignore the method if (processor.getName() == null) return null; -*/ + processor.senderType(); + System.out.println(processor.arguments()); return (Command) () -> null; }).filter(Objects::nonNull).collect(Collectors.toList()); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index 37715c6c..16d0bb9e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -100,7 +100,8 @@ public abstract class CommandProcessor { } @Contract("_ -> new") - protected @NotNull SubCommandRegistrationException createException(final @NotNull String message) { + @NotNull + public SubCommandRegistrationException createException(final @NotNull String message) { return new SubCommandRegistrationException(message, annotatedElement, baseCommand.getClass()); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index c3efebef..9a652edd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -37,6 +37,7 @@ import java.lang.reflect.Method; import java.lang.reflect.Parameter; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; @@ -93,7 +94,7 @@ public Class senderType() { final Class type = parameters[0].getType(); final Set> allowedSenders = senderValidator.getAllowedSenders(); - if (allowedSenders.contains(type)) { + if (!allowedSenders.contains(type)) { throw createException( "\"" + type.getSimpleName() + "\" is not a valid sender. Sender must be one of the following: " + allowedSenders @@ -119,17 +120,27 @@ public Class senderType() { // Position of the last argument. final int last = parameters.length - 1; + final List> arguments = new ArrayList<>(); + // Starting at 1 because we don't care about sender here. for (int i = 1; i < parameters.length; i++) { final Parameter parameter = parameters[i]; final Class type = parameter.getType(); - // argumentExtensionHandler.validate(this, type, ) - // createArgument(parameter, i - 1); + final InternalArgument argument = createArgument( + parameter, + argDescriptions, + suggestions, + i + ); + + argumentExtensionHandler.validate(this, argument, i, last); + + arguments.add(argument); } - return Collections.emptyList(); + return arguments; } /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java b/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java index 3007e5c6..acf4c72b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java @@ -9,43 +9,24 @@ public class DefaultArgumentExtensionHandler implements ArgumentExtensionHand @Override public void validate( - final @NotNull SubCommandProcessor subCommandProcessor, + final @NotNull SubCommandProcessor processor, final @NotNull InternalArgument argument, final int position, final int last ) { - validateOptionals(argument, position, last); - validateLimitless(argument, position, last); + // Validation for optionals + if (position != last && argument.isOptional()) { + throw processor.createException("Optional internalArgument is only allowed as the last internalArgument"); + } + + // Validation for limitless + if (position != last && argument instanceof LimitlessInternalArgument) { + throw processor.createException("Limitless internalArgument is only allowed as the last internalArgument"); + } } @Override public InternalArgument create() { return null; } - - /** - * Validation for optionals. - */ - private void validateOptionals( - final @NotNull InternalArgument argument, - final int position, - final int last - ) { - if (position == last && argument.isOptional()) { - // throw createException("Optional internalArgument is only allowed as the last internalArgument"); - } - } - - /** - * Validation for {@link LimitlessInternalArgument}. - */ - private void validateLimitless( - final @NotNull InternalArgument argument, - final int position, - final int last - ) { - if (position == last && argument instanceof LimitlessInternalArgument) { - // throw createException("Limitless internalArgument is only allowed as the last internalArgument"); - } - } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index c32715dc..50c583f7 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -33,6 +33,7 @@ import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.validation.DefaultArgumentExtensionHandler; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -66,7 +67,12 @@ private SimpleCommandManager( @Override public void registerCommand(final @NotNull BaseCommand baseCommand) { - final SimpleCommandProcessor processor = new SimpleCommandProcessor<>(baseCommand); + final SimpleCommandProcessor processor = new SimpleCommandProcessor<>( + baseCommand, + getSenderValidator(), + getRegistryContainer(), + new DefaultArgumentExtensionHandler<>() + ); final String name = processor.getName(); diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java index ad4bebe7..31dc06f5 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java @@ -25,11 +25,19 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.processor.AbstractRootCommandProcessor; +import dev.triumphteam.cmd.core.registry.RegistryContainer; +import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.validation.ArgumentExtensionHandler; import org.jetbrains.annotations.NotNull; public final class SimpleCommandProcessor extends AbstractRootCommandProcessor { - public SimpleCommandProcessor(final @NotNull BaseCommand baseCommand) { - super(baseCommand); + public SimpleCommandProcessor( + final @NotNull BaseCommand baseCommand, + final @NotNull SenderValidator senderValidator, + final @NotNull RegistryContainer registryContainer, + final @NotNull ArgumentExtensionHandler argumentExtensionHandler + ) { + super(baseCommand, senderValidator, registryContainer, argumentExtensionHandler); } } From cc5b98c074b9fa9a79011177732285ed3c051012 Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Sun, 25 Dec 2022 15:10:20 +0000 Subject: [PATCH 026/101] chore: Extension customization preparation --- ...rgument.java => UnknownInternalArgument.java} | 16 ++++++++++------ .../cmd/core/processor/CommandProcessor.java | 16 +++++++++++----- .../cmd/core/processor/SubCommandProcessor.java | 5 ++--- .../validation/ArgumentExtensionHandler.java | 9 +-------- .../DefaultArgumentExtensionHandler.java | 13 ++++++++----- .../cmds/simple/SimpleCommandManager.java | 16 +++++++++++----- 6 files changed, 43 insertions(+), 32 deletions(-) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{IgnoreInternalArgument.java => UnknownInternalArgument.java} (75%) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/IgnoreInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java similarity index 75% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/IgnoreInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index e6d090e8..d4861c7d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/IgnoreInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -11,23 +11,27 @@ * This argument type is always ignored by the creator. * This is only used for arguments that are meant to be hidden and not actually part of a command. */ -public final class IgnoreInternalArgument implements InternalArgument { +public final class UnknownInternalArgument implements InternalArgument { - public IgnoreInternalArgument() {} + private final Class type; + + public UnknownInternalArgument(final @NotNull Class type) { + this.type = type; + } @Override public @NotNull String getName() { - return "ignored"; + return "unknown"; } @Override public @NotNull String getDescription() { - return "Ignored."; + return "Unknown."; } @Override public @NotNull Class getType() { - return Void.TYPE; + return type; } @Override @@ -36,7 +40,7 @@ public boolean isOptional() { } @Override - public @Nullable Object resolve(@NotNull final S sender, final @NotNull Void value) { + public @Nullable Object resolve(@NotNull final S sender, final @NotNull String value) { return null; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index 16d0bb9e..d99e744a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -39,6 +39,7 @@ import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; +import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; @@ -119,7 +120,7 @@ public SubCommandRegistrationException createException(final @NotNull String mes } // TODO COMMENTS - protected InternalArgument createArgument( + protected @NotNull InternalArgument createArgument( final @NotNull Parameter parameter, final @NotNull List argDescriptions, final @NotNull Map> suggestions, @@ -134,7 +135,7 @@ public SubCommandRegistrationException createException(final @NotNull String mes // TODO: Add more collection types. if (SUPPORTED_COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { final Class collectionType = getGenericType(parameter); - final InternalArgument internalArgument = createSimpleArgument( + final InternalArgument argument = createSimpleArgument( collectionType, argumentName, argumentDescription, @@ -142,13 +143,18 @@ public SubCommandRegistrationException createException(final @NotNull String mes true ); + // Throw exception on unknown arguments for collection parameter type + if (argument instanceof UnknownInternalArgument) { + throw createException("No internalArgument of type \"" + argument.getType().getName() + "\" registered"); + } + if (parameter.isAnnotationPresent(Split.class)) { final Split splitAnnotation = parameter.getAnnotation(Split.class); return new SplitStringInternalArgument<>( argumentName, argumentDescription, splitAnnotation.value(), - internalArgument, + argument, type, suggestions.getOrDefault(position, suggestionFromParam(parameter)), optional @@ -158,7 +164,7 @@ public SubCommandRegistrationException createException(final @NotNull String mes return new CollectionInternalArgument<>( argumentName, argumentDescription, - internalArgument, + argument, type, suggestions.getOrDefault(position, suggestionFromParam(parameter)), optional @@ -238,7 +244,7 @@ public SubCommandRegistrationException createException(final @NotNull String mes ); } - throw createException("No internalArgument of type \"" + type.getName() + "\" registered"); + return new UnknownInternalArgument<>(type); } return new ResolverInternalArgument<>( parameterName, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index 9a652edd..b4babd69 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -125,8 +125,6 @@ public Class senderType() { // Starting at 1 because we don't care about sender here. for (int i = 1; i < parameters.length; i++) { final Parameter parameter = parameters[i]; - final Class type = parameter.getType(); - final InternalArgument argument = createArgument( parameter, @@ -135,7 +133,8 @@ public Class senderType() { i ); - argumentExtensionHandler.validate(this, argument, i, last); + // If validation is false ignore it + if (!argumentExtensionHandler.validate(this, argument, i, last)) continue; arguments.add(argument); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentExtensionHandler.java b/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentExtensionHandler.java index c20de608..ff3bce25 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentExtensionHandler.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentExtensionHandler.java @@ -1,22 +1,15 @@ package dev.triumphteam.cmd.core.validation; -import dev.triumphteam.cmd.core.argument.IgnoreInternalArgument; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.processor.SubCommandProcessor; import org.jetbrains.annotations.NotNull; public interface ArgumentExtensionHandler { - void validate( + boolean validate( final @NotNull SubCommandProcessor subCommandProcessor, final @NotNull InternalArgument argument, final int position, final int last ); - - default InternalArgument create( - - ) { - return new IgnoreInternalArgument<>(); - } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java b/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java index acf4c72b..10ef48ad 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java @@ -2,13 +2,14 @@ import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; +import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; import dev.triumphteam.cmd.core.processor.SubCommandProcessor; import org.jetbrains.annotations.NotNull; public class DefaultArgumentExtensionHandler implements ArgumentExtensionHandler { @Override - public void validate( + public boolean validate( final @NotNull SubCommandProcessor processor, final @NotNull InternalArgument argument, final int position, @@ -23,10 +24,12 @@ public void validate( if (position != last && argument instanceof LimitlessInternalArgument) { throw processor.createException("Limitless internalArgument is only allowed as the last internalArgument"); } - } - @Override - public InternalArgument create() { - return null; + // Unknown types by default throw + if (argument instanceof UnknownInternalArgument) { + throw processor.createException("No internalArgument of type \"" + argument.getType().getName() + "\" registered"); + } + + return true; } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 50c583f7..5aa475fc 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -33,7 +33,7 @@ import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.sender.SenderMapper; import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.validation.DefaultArgumentExtensionHandler; +import dev.triumphteam.cmd.core.validation.ArgumentExtensionHandler; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -50,19 +50,25 @@ public final class SimpleCommandManager extends CommandManager { private final ExecutionProvider syncExecutionProvider = new SyncExecutionProvider(); private final ExecutionProvider asyncExecutionProvider = new AsyncExecutionProvider(); + private final ArgumentExtensionHandler extensionHandler; + private SimpleCommandManager( final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator + final @NotNull SenderValidator senderValidator, + final @NotNull ArgumentExtensionHandler extensionHandler ) { super(senderMapper, senderValidator); + + this.extensionHandler = extensionHandler; } @Contract("_, _ -> new") public static @NotNull SimpleCommandManager create( final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator + final @NotNull SenderValidator senderValidator, + final @NotNull ArgumentExtensionHandler extensionHandler ) { - return new SimpleCommandManager<>(senderMapper, senderValidator); + return new SimpleCommandManager<>(senderMapper, senderValidator, extensionHandler); } @Override @@ -71,7 +77,7 @@ public void registerCommand(final @NotNull BaseCommand baseCommand) { baseCommand, getSenderValidator(), getRegistryContainer(), - new DefaultArgumentExtensionHandler<>() + extensionHandler ); final String name = processor.getName(); From 38ecdf5712beea0d2ef433240fe81be87f59bc1b Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Sun, 25 Dec 2022 21:15:09 +0000 Subject: [PATCH 027/101] feature: Command extensions trial --- .../triumphteam/cmd/core/CommandManager.java | 26 ++----- .../cmd/core/annotation/Annotated.java | 8 -- .../core/annotation/AnnotationContainer.java | 20 ----- .../argument/ResolverInternalArgument.java | 1 + .../cmd/core/argument/named/ArgumentKey.java | 4 +- .../triumphteam/cmd/core/command/Command.java | 4 +- .../cmd/core/command/ParentSubCommand.java | 6 -- .../cmd/core/command/SubCommand.java | 9 --- .../core/exceptions/TriumphCmdException.java | 10 +++ .../cmd/core/extention/CommandExtensions.java | 47 ++++++++++++ .../DefaultArgumentValidator.java} | 5 +- .../cmd/core/extention/ExtensionBuilder.java | 75 +++++++++++++++++++ .../StringKey.java} | 8 +- .../annotation/AnnotationProcessor.java | 15 ++++ .../annotation/AnnotationTarget.java | 2 +- .../extention/argument/ArgumentProcessor.java | 12 +++ .../argument/ArgumentValidator.java} | 4 +- .../cmd/core/extention/meta/CommandMeta.java | 35 +++++++++ .../cmd/core/extention/meta/MetaKey.java | 24 ++++++ .../registry}/ArgumentRegistry.java | 4 +- .../registry}/FlagRegistry.java | 4 +- .../registry}/MessageRegistry.java | 5 +- .../registry}/NamedArgumentRegistry.java | 5 +- .../{ => extention}/registry/Registry.java | 2 +- .../registry/RegistryContainer.java | 6 +- .../registry}/RequirementRegistry.java | 5 +- .../extention/sender/SenderExtension.java | 21 ++++++ .../{ => extention}/sender/SenderMapper.java | 2 +- .../sender/SenderValidator.java | 4 +- .../triumphteam/cmd/core/flag/FlagKey.java | 4 +- .../cmd/core/message/ContextualKey.java | 4 +- .../AbstractRootCommandProcessor.java | 24 ++---- .../cmd/core/processor/CommandProcessor.java | 15 +++- .../OldAbstractCommandProcessor.java | 6 +- .../OldAbstractSubCommandProcessor.java | 12 +-- .../core/processor/SubCommandProcessor.java | 21 ++---- .../cmd/core/requirement/Requirement.java | 2 +- .../cmd/core/requirement/RequirementKey.java | 5 +- .../cmd/core/subcommand/OldSubCommand.java | 4 +- .../cmd/core/suggestion/SuggestionKey.java | 4 +- .../core/suggestion/SuggestionRegistry.java | 2 +- .../cmd/prefixed/PrefixedCommand.java | 6 +- .../cmd/prefixed/PrefixedCommandExecutor.java | 2 +- .../cmd/prefixed/PrefixedCommandListener.java | 6 +- .../cmd/prefixed/PrefixedCommandManager.java | 6 +- .../prefixed/PrefixedCommandProcessor.java | 6 +- .../cmd/prefixed/PrefixedSenderValidator.java | 4 +- .../prefixed/PrefixedSubCommandProcessor.java | 4 +- .../cmds/simple/SimpleCommand.java | 10 +-- .../cmds/simple/SimpleCommandManager.java | 39 ++++------ .../cmds/simple/SimpleCommandProcessor.java | 10 +-- .../cmds/simple/SimpleExtensionBuilder.java | 19 +++++ .../simple/SimpleSubCommandProcessor.java | 4 +- .../kotlin/dev/triumphteam/tests/Sender.kt | 9 ++- 54 files changed, 392 insertions(+), 209 deletions(-) delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/annotation/Annotated.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/exceptions/TriumphCmdException.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java rename core/src/main/java/dev/triumphteam/cmd/core/{validation/DefaultArgumentExtensionHandler.java => extention/DefaultArgumentValidator.java} (87%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java rename core/src/main/java/dev/triumphteam/cmd/core/{registry/RegistryKey.java => extention/StringKey.java} (91%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java rename core/src/main/java/dev/triumphteam/cmd/core/{ => extention}/annotation/AnnotationTarget.java (58%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentProcessor.java rename core/src/main/java/dev/triumphteam/cmd/core/{validation/ArgumentExtensionHandler.java => extention/argument/ArgumentValidator.java} (80%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java rename core/src/main/java/dev/triumphteam/cmd/core/{argument => extention/registry}/ArgumentRegistry.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{flag => extention/registry}/FlagRegistry.java (94%) rename core/src/main/java/dev/triumphteam/cmd/core/{message => extention/registry}/MessageRegistry.java (94%) rename core/src/main/java/dev/triumphteam/cmd/core/{argument/named => extention/registry}/NamedArgumentRegistry.java (91%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => extention}/registry/Registry.java (95%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => extention}/registry/RegistryContainer.java (88%) rename core/src/main/java/dev/triumphteam/cmd/core/{requirement => extention/registry}/RequirementRegistry.java (92%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java rename core/src/main/java/dev/triumphteam/cmd/core/{ => extention}/sender/SenderMapper.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => extention}/sender/SenderValidator.java (93%) create mode 100644 simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index 244f4bdd..e1a95ddb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -26,14 +26,13 @@ import dev.triumphteam.cmd.core.argument.ArgumentResolver; import dev.triumphteam.cmd.core.argument.named.Argument; import dev.triumphteam.cmd.core.argument.named.ArgumentKey; +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.message.ContextualKey; import dev.triumphteam.cmd.core.message.MessageResolver; import dev.triumphteam.cmd.core.message.context.MessageContext; -import dev.triumphteam.cmd.core.registry.RegistryContainer; import dev.triumphteam.cmd.core.requirement.RequirementKey; import dev.triumphteam.cmd.core.requirement.RequirementResolver; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; import org.jetbrains.annotations.NotNull; @@ -50,15 +49,10 @@ @SuppressWarnings("unchecked") public abstract class CommandManager { - private final SenderMapper senderMapper; - private final SenderValidator senderValidator; + private final CommandExtensions commandExtensions; - public CommandManager( - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator - ) { - this.senderMapper = senderMapper; - this.senderValidator = senderValidator; + public CommandManager(final @NotNull CommandExtensions commandExtensions) { + this.commandExtensions = commandExtensions; } /** @@ -152,15 +146,9 @@ public final void registerRequirement( getRegistryContainer().getRequirementRegistry().register(key, resolver); } - // TODO: Comments protected abstract @NotNull RegistryContainer getRegistryContainer(); - // TODO: 2/4/2022 comments - protected @NotNull SenderMapper getSenderMapper() { - return senderMapper; - } - - protected @NotNull SenderValidator getSenderValidator() { - return senderValidator; + protected @NotNull CommandExtensions getCommandExtensions() { + return commandExtensions; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Annotated.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/Annotated.java deleted file mode 100644 index 38a9c03a..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/Annotated.java +++ /dev/null @@ -1,8 +0,0 @@ -package dev.triumphteam.cmd.core.annotation; - -import org.jetbrains.annotations.NotNull; - -public interface Annotated { - - @NotNull AnnotationContainer getAnnotations(); -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java deleted file mode 100644 index 099dc7be..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationContainer.java +++ /dev/null @@ -1,20 +0,0 @@ -package dev.triumphteam.cmd.core.annotation; - -import org.jetbrains.annotations.NotNull; - -import java.lang.annotation.Annotation; -import java.util.List; - -public class AnnotationContainer { - - private final List annotations; - private final AnnotationContainer parent; - - public AnnotationContainer( - final @NotNull List annotations, - final @NotNull AnnotationContainer parent - ) { - this.annotations = annotations; - this.parent = parent; - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java index 0d6cbe90..f0050359 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java index 5e4e1df5..25a6c6e9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java @@ -23,11 +23,11 @@ */ package dev.triumphteam.cmd.core.argument.named; -import dev.triumphteam.cmd.core.registry.RegistryKey; +import dev.triumphteam.cmd.core.extention.StringKey; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -public class ArgumentKey extends RegistryKey { +public class ArgumentKey extends StringKey { private ArgumentKey(final @NotNull String key) { super(key); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 91d190bd..24ed293a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -23,9 +23,7 @@ */ package dev.triumphteam.cmd.core.command; -import dev.triumphteam.cmd.core.annotation.Annotated; - -public interface Command extends Annotated { +public interface Command { } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 6f93ca0a..9263c668 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -1,6 +1,5 @@ package dev.triumphteam.cmd.core.command; -import dev.triumphteam.cmd.core.annotation.AnnotationContainer; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -20,11 +19,6 @@ public void addSubCommand( } - @Override - public @NotNull AnnotationContainer getAnnotations() { - return null; - } - @Override public @NotNull Map> getCommands() { return commands; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 67796f77..04f914ef 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -1,14 +1,5 @@ package dev.triumphteam.cmd.core.command; -import dev.triumphteam.cmd.core.annotation.AnnotationContainer; -import org.jetbrains.annotations.NotNull; - public class SubCommand implements Command { - - - @Override - public @NotNull AnnotationContainer getAnnotations() { - return null; - } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/TriumphCmdException.java b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/TriumphCmdException.java new file mode 100644 index 00000000..fde3abfc --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/TriumphCmdException.java @@ -0,0 +1,10 @@ +package dev.triumphteam.cmd.core.exceptions; + +import org.jetbrains.annotations.NotNull; + +public final class TriumphCmdException extends RuntimeException { + + public TriumphCmdException(final @NotNull String message) { + super(message); + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java new file mode 100644 index 00000000..091ee918 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java @@ -0,0 +1,47 @@ +package dev.triumphteam.cmd.core.extention; + +import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; +import dev.triumphteam.cmd.core.extention.argument.ArgumentProcessor; +import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.Annotation; +import java.util.Map; + +public final class CommandExtensions { + + private final Map, AnnotationProcessor> annotationProcessors; + private final Map, ArgumentProcessor> argumentProcessors; + + private final SenderExtension senderExtension; + private final ArgumentValidator argumentValidator; + + public CommandExtensions( + final @NotNull Map, AnnotationProcessor> annotationProcessors, + final @NotNull Map, ArgumentProcessor> argumentProcessors, + final @NotNull SenderExtension senderExtension, + final @NotNull ArgumentValidator argumentValidator + ) { + this.annotationProcessors = annotationProcessors; + this.argumentProcessors = argumentProcessors; + this.senderExtension = senderExtension; + this.argumentValidator = argumentValidator; + } + + public @NotNull Map, AnnotationProcessor> getAnnotationProcessors() { + return annotationProcessors; + } + + public @NotNull Map, ArgumentProcessor> getArgumentProcessors() { + return argumentProcessors; + } + + public @NotNull SenderExtension getSenderExtension() { + return senderExtension; + } + + public @NotNull ArgumentValidator getArgumentValidator() { + return argumentValidator; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/DefaultArgumentValidator.java similarity index 87% rename from core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/DefaultArgumentValidator.java index 10ef48ad..ebc9a1e6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/validation/DefaultArgumentExtensionHandler.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/DefaultArgumentValidator.java @@ -1,12 +1,13 @@ -package dev.triumphteam.cmd.core.validation; +package dev.triumphteam.cmd.core.extention; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; +import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; import dev.triumphteam.cmd.core.processor.SubCommandProcessor; import org.jetbrains.annotations.NotNull; -public class DefaultArgumentExtensionHandler implements ArgumentExtensionHandler { +public class DefaultArgumentValidator implements ArgumentValidator { @Override public boolean validate( diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java new file mode 100644 index 00000000..6e4e1926 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java @@ -0,0 +1,75 @@ +package dev.triumphteam.cmd.core.extention; + +import dev.triumphteam.cmd.core.exceptions.TriumphCmdException; +import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; +import dev.triumphteam.cmd.core.extention.argument.ArgumentProcessor; +import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.annotation.Annotation; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +public abstract class ExtensionBuilder { + + private final Map, AnnotationProcessor> annotationProcessors = new HashMap<>(); + private final Map, ArgumentProcessor> argumentProcessors = new HashMap<>(); + + private SenderExtension senderExtension; + private ArgumentValidator argumentValidator; + + @Contract("_, _ -> this") + public ExtensionBuilder addAnnotationProcessor( + final Class annotation, + final @NotNull AnnotationProcessor annotationProcessor + ) { + annotationProcessors.put(annotation, annotationProcessor); + return this; + } + + @Contract("_, _ -> this") + public ExtensionBuilder addArgumentProcessor( + final Class argumentType, + final @NotNull ArgumentProcessor argumentProcessor + ) { + argumentProcessors.put(argumentType, argumentProcessor); + return this; + } + + @Contract("_ -> this") + public ExtensionBuilder setSenderExtension(final @NotNull SenderExtension senderExtension) { + this.senderExtension = senderExtension; + return this; + } + + @Contract("_ -> this") + public ExtensionBuilder setArgumentValidator(final @NotNull ArgumentValidator argumentValidator) { + this.argumentValidator = argumentValidator; + return this; + } + + protected abstract @NotNull CommandExtensions build(); + + protected @NotNull Map, AnnotationProcessor> getAnnotationProcessors() { + return Collections.unmodifiableMap(annotationProcessors); + } + + protected @NotNull Map, ArgumentProcessor> getArgumentProcessors() { + return Collections.unmodifiableMap(argumentProcessors); + } + + protected @NotNull SenderExtension getSenderExtension(final @Nullable SenderExtension def) { + if (senderExtension == null && def == null) { + throw new TriumphCmdException("No sender extension was added to Command Manager."); + } + return senderExtension == null ? def : senderExtension; + } + + protected @NotNull ArgumentValidator getArgumentValidator(final @NotNull ArgumentValidator def) { + return argumentValidator == null ? def : argumentValidator; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryKey.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/StringKey.java similarity index 91% rename from core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryKey.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/StringKey.java index dd071b49..6326a960 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/StringKey.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.registry; +package dev.triumphteam.cmd.core.extention; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -31,11 +31,11 @@ /** * Registry key, for more organized way of registering and getting things from the registries. */ -public abstract class RegistryKey { +public abstract class StringKey { private final String key; - public RegistryKey(final @NotNull String key) { + public StringKey(final @NotNull String key) { this.key = key; } @@ -52,7 +52,7 @@ public RegistryKey(final @NotNull String key) { public boolean equals(final @Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - final RegistryKey that = (RegistryKey) o; + final StringKey that = (StringKey) o; return key.equals(that.key); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java new file mode 100644 index 00000000..99551874 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java @@ -0,0 +1,15 @@ +package dev.triumphteam.cmd.core.extention.annotation; + +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.Annotation; + +public interface AnnotationProcessor { + + void process( + final @NotNull A annotation, + final @NotNull AnnotationTarget target, + final @NotNull CommandMeta meta + ); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationTarget.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationTarget.java similarity index 58% rename from core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationTarget.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationTarget.java index 219598ea..0f0981ae 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotation/AnnotationTarget.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationTarget.java @@ -1,4 +1,4 @@ -package dev.triumphteam.cmd.core.annotation; +package dev.triumphteam.cmd.core.extention.annotation; public enum AnnotationTarget { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentProcessor.java new file mode 100644 index 00000000..1da9e082 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentProcessor.java @@ -0,0 +1,12 @@ +package dev.triumphteam.cmd.core.extention.argument; + +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import org.jetbrains.annotations.NotNull; + +public interface ArgumentProcessor { + + void process( + final @NotNull Class annotation, + final @NotNull CommandMeta meta + ); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentExtensionHandler.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java similarity index 80% rename from core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentExtensionHandler.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java index ff3bce25..c06d904c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/validation/ArgumentExtensionHandler.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java @@ -1,10 +1,10 @@ -package dev.triumphteam.cmd.core.validation; +package dev.triumphteam.cmd.core.extention.argument; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.processor.SubCommandProcessor; import org.jetbrains.annotations.NotNull; -public interface ArgumentExtensionHandler { +public interface ArgumentValidator { boolean validate( final @NotNull SubCommandProcessor subCommandProcessor, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java new file mode 100644 index 00000000..80c37a20 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java @@ -0,0 +1,35 @@ +package dev.triumphteam.cmd.core.extention.meta; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; +import java.util.Map; + +public final class CommandMeta { + + private final Map, Object> dataMap = new HashMap<>(); + + private final CommandMeta parentMeta; + + public CommandMeta(final @Nullable CommandMeta parentMeta) { + this.parentMeta = parentMeta; + } + + public void add(final @NotNull MetaKey metaKey, final @NotNull V value) { + dataMap.put(metaKey, value); + } + + @SuppressWarnings("unchecked") + public @Nullable V get(final @NotNull MetaKey metaKey) { + return (V) dataMap.get(metaKey); + } + + public boolean isPresent(final @NotNull MetaKey metaKey) { + return dataMap.containsKey(metaKey); + } + + public @Nullable CommandMeta getParentMeta() { + return parentMeta; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java new file mode 100644 index 00000000..230edc4d --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java @@ -0,0 +1,24 @@ +package dev.triumphteam.cmd.core.extention.meta; + +import dev.triumphteam.cmd.core.extention.StringKey; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +public final class MetaKey extends StringKey { + + private final Class valueType; + + private MetaKey( + final @NotNull String key, + final @NotNull Class valueType + ) { + super(key); + + this.valueType = valueType; + } + + @Contract("_, _ -> new") + public static @NotNull MetaKey of(final @NotNull String key, final @NotNull Class valueType) { + return new MetaKey<>(key, valueType); + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/ArgumentRegistry.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/registry/ArgumentRegistry.java index 73a9ae44..3ac9e8f5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/ArgumentRegistry.java @@ -21,13 +21,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.extention.registry; import com.google.common.primitives.Doubles; import com.google.common.primitives.Floats; import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; -import dev.triumphteam.cmd.core.registry.Registry; +import dev.triumphteam.cmd.core.argument.ArgumentResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java similarity index 94% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/FlagRegistry.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java index d39c59e6..37257329 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag; +package dev.triumphteam.cmd.core.extention.registry; -import dev.triumphteam.cmd.core.registry.Registry; +import dev.triumphteam.cmd.core.flag.FlagKey; import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/MessageRegistry.java similarity index 94% rename from core/src/main/java/dev/triumphteam/cmd/core/message/MessageRegistry.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/registry/MessageRegistry.java index ba9d154a..1b11fbec 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/MessageRegistry.java @@ -21,10 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.message; +package dev.triumphteam.cmd.core.extention.registry; +import dev.triumphteam.cmd.core.message.ContextualKey; +import dev.triumphteam.cmd.core.message.MessageResolver; import dev.triumphteam.cmd.core.message.context.MessageContext; -import dev.triumphteam.cmd.core.registry.Registry; import org.jetbrains.annotations.NotNull; import java.util.HashMap; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java similarity index 91% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java index fc5318a6..1908bde9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java @@ -21,9 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.extention.registry; -import dev.triumphteam.cmd.core.registry.Registry; +import dev.triumphteam.cmd.core.argument.named.Argument; +import dev.triumphteam.cmd.core.argument.named.ArgumentKey; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/registry/Registry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/Registry.java similarity index 95% rename from core/src/main/java/dev/triumphteam/cmd/core/registry/Registry.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/registry/Registry.java index da309355..8c1274d4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/registry/Registry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/Registry.java @@ -21,6 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.registry; +package dev.triumphteam.cmd.core.extention.registry; public interface Registry {} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RegistryContainer.java similarity index 88% rename from core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RegistryContainer.java index 69468854..f8144379 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/registry/RegistryContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RegistryContainer.java @@ -21,12 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.registry; +package dev.triumphteam.cmd.core.extention.registry; -import dev.triumphteam.cmd.core.argument.ArgumentRegistry; -import dev.triumphteam.cmd.core.argument.named.NamedArgumentRegistry; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.requirement.RequirementRegistry; import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RequirementRegistry.java similarity index 92% rename from core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementRegistry.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RequirementRegistry.java index 72a87dc5..73339657 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RequirementRegistry.java @@ -21,9 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.requirement; +package dev.triumphteam.cmd.core.extention.registry; -import dev.triumphteam.cmd.core.registry.Registry; +import dev.triumphteam.cmd.core.requirement.RequirementKey; +import dev.triumphteam.cmd.core.requirement.RequirementResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java new file mode 100644 index 00000000..ca718d91 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java @@ -0,0 +1,21 @@ +package dev.triumphteam.cmd.core.extention.sender; + +import dev.triumphteam.cmd.core.command.Command; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Set; + +public interface SenderExtension { + + @NotNull Set> getAllowedSenders(); + + boolean validate( + final @NotNull MessageRegistry messageRegistry, + final @NotNull Command command, + final @NotNull S sender + ); + + @Nullable S map(final @NotNull DS defaultSender); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderMapper.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/sender/SenderMapper.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java index 07850160..5027c5c3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderMapper.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.sender; +package dev.triumphteam.cmd.core.extention.sender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderValidator.java similarity index 93% rename from core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderValidator.java index 00a991ab..10da1d16 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/sender/SenderValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderValidator.java @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.sender; +package dev.triumphteam.cmd.core.extention.sender; import dev.triumphteam.cmd.core.subcommand.OldSubCommand; -import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import org.jetbrains.annotations.NotNull; import java.util.Set; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java index 36df4b79..9acd63cc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.flag; -import dev.triumphteam.cmd.core.registry.RegistryKey; +import dev.triumphteam.cmd.core.extention.StringKey; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -31,7 +31,7 @@ import java.util.HashSet; import java.util.Set; -public final class FlagKey extends RegistryKey { +public final class FlagKey extends StringKey { // Holds all registered keys, default and custom ones private static final Set REGISTERED_KEYS = new HashSet<>(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java b/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java index 5a1b622c..aef5527c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.message; -import dev.triumphteam.cmd.core.registry.RegistryKey; +import dev.triumphteam.cmd.core.extention.StringKey; import dev.triumphteam.cmd.core.message.context.MessageContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,7 +36,7 @@ /** * Registry key, for more organized way of registering and getting things from the registries. */ -public abstract class ContextualKey extends RegistryKey { +public abstract class ContextualKey extends StringKey { // Holds all registered keys, default and custom ones private static final Set> REGISTERED_KEYS = new HashSet<>(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java index a63ce42c..9f1a3edf 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java @@ -24,13 +24,11 @@ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.annotation.AnnotationContainer; import dev.triumphteam.cmd.core.annotations.Description; import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.validation.ArgumentExtensionHandler; +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Method; @@ -49,15 +47,13 @@ public abstract class AbstractRootCommandProcessor { private final List alias; private final String description; - private final SenderValidator senderValidator; + private final CommandExtensions commandExtensions; private final RegistryContainer registryContainer; - private final ArgumentExtensionHandler argumentExtensionHandler; public AbstractRootCommandProcessor( final @NotNull BaseCommand baseCommand, - final @NotNull SenderValidator senderValidator, final @NotNull RegistryContainer registryContainer, - final @NotNull ArgumentExtensionHandler argumentExtensionHandler + final @NotNull CommandExtensions commandExtensions ) { this.baseCommand = baseCommand; @@ -65,9 +61,8 @@ public AbstractRootCommandProcessor( this.alias = aliasOf(); this.description = descriptionOf(); - this.senderValidator = senderValidator; this.registryContainer = registryContainer; - this.argumentExtensionHandler = argumentExtensionHandler; + this.commandExtensions = commandExtensions; } public String getName() { @@ -82,10 +77,6 @@ public String getDescription() { return description; } - public AnnotationContainer createAnnotationContainer() { - return null; - } - public @NotNull List> commands() { final Class klass = baseCommand.getClass(); @@ -105,9 +96,8 @@ public AnnotationContainer createAnnotationContainer() { name, baseCommand, method, - senderValidator, registryContainer, - argumentExtensionHandler + commandExtensions ); // Not a command, ignore the method @@ -115,7 +105,7 @@ public AnnotationContainer createAnnotationContainer() { processor.senderType(); System.out.println(processor.arguments()); - return (Command) () -> null; + return new Command() {}; }).filter(Objects::nonNull).collect(Collectors.toList()); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index d99e744a..ffc8e2d4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -31,7 +31,8 @@ import dev.triumphteam.cmd.core.annotations.Join; import dev.triumphteam.cmd.core.annotations.Optional; import dev.triumphteam.cmd.core.annotations.Split; -import dev.triumphteam.cmd.core.argument.ArgumentRegistry; +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; import dev.triumphteam.cmd.core.argument.ArgumentResolver; import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; import dev.triumphteam.cmd.core.argument.EnumInternalArgument; @@ -41,7 +42,7 @@ import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.EnumSuggestion; import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; @@ -85,17 +86,21 @@ public abstract class CommandProcessor { private final SuggestionRegistry suggestionRegistry; private final ArgumentRegistry argumentRegistry; + private final CommandExtensions commandExtensions; + CommandProcessor( final @NotNull String parentName, final @NotNull BaseCommand baseCommand, final @NotNull AnnotatedElement annotatedElement, - final @NotNull RegistryContainer registryContainer + final @NotNull RegistryContainer registryContainer, + final @NotNull CommandExtensions commandExtensions ) { this.parentName = parentName; this.baseCommand = baseCommand; this.annotatedElement = annotatedElement; this.name = nameOf(); + this.commandExtensions = commandExtensions; this.suggestionRegistry = registryContainer.getSuggestionRegistry(); this.argumentRegistry = registryContainer.getArgumentRegistry(); } @@ -338,4 +343,8 @@ public SubCommandRegistrationException createException(final @NotNull String mes return suggestion; } + + protected @NotNull CommandExtensions getCommandExtensions() { + return commandExtensions; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java index ca6041ab..d37109a8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java @@ -30,9 +30,9 @@ import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import dev.triumphteam.cmd.core.extention.sender.SenderValidator; import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.core.subcommand.invoker.Invoker; import dev.triumphteam.cmd.core.subcommand.invoker.MethodInvoker; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java index 3226164a..0f7a8e07 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java @@ -39,7 +39,7 @@ import dev.triumphteam.cmd.core.annotations.Requirements; import dev.triumphteam.cmd.core.annotations.Split; import dev.triumphteam.cmd.core.annotations.Suggestions; -import dev.triumphteam.cmd.core.argument.ArgumentRegistry; +import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; import dev.triumphteam.cmd.core.argument.ArgumentResolver; import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; import dev.triumphteam.cmd.core.argument.EnumInternalArgument; @@ -55,22 +55,22 @@ import dev.triumphteam.cmd.core.argument.named.ArgumentKey; import dev.triumphteam.cmd.core.argument.named.Arguments; import dev.triumphteam.cmd.core.argument.named.ListArgument; -import dev.triumphteam.cmd.core.argument.named.NamedArgumentRegistry; +import dev.triumphteam.cmd.core.extention.registry.NamedArgumentRegistry; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.flag.Flags; import dev.triumphteam.cmd.core.flag.internal.FlagGroup; import dev.triumphteam.cmd.core.flag.internal.FlagOptions; import dev.triumphteam.cmd.core.flag.internal.FlagValidator; import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import dev.triumphteam.cmd.core.message.context.MessageContext; -import dev.triumphteam.cmd.core.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.requirement.Requirement; import dev.triumphteam.cmd.core.requirement.RequirementKey; -import dev.triumphteam.cmd.core.requirement.RequirementRegistry; +import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry; import dev.triumphteam.cmd.core.requirement.RequirementResolver; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.sender.SenderValidator; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.EnumSuggestion; import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index b4babd69..81c1209c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -27,12 +27,12 @@ import dev.triumphteam.cmd.core.annotations.ArgDescriptions; import dev.triumphteam.cmd.core.annotations.Suggestions; import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; -import dev.triumphteam.cmd.core.validation.ArgumentExtensionHandler; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Method; @@ -61,27 +61,22 @@ public final class SubCommandProcessor extends CommandProcessor { private final Method method; - private final SenderValidator senderValidator; - private final ArgumentExtensionHandler argumentExtensionHandler; SubCommandProcessor( final @NotNull String parentName, final @NotNull BaseCommand baseCommand, final @NotNull Method method, - final @NotNull SenderValidator senderValidator, final @NotNull RegistryContainer registryContainer, - final @NotNull ArgumentExtensionHandler argumentExtensionHandler + final @NotNull CommandExtensions commandExtensions ) { - super(parentName, baseCommand, method, registryContainer); + super(parentName, baseCommand, method, registryContainer, commandExtensions); this.method = method; - this.senderValidator = senderValidator; - this.argumentExtensionHandler = argumentExtensionHandler; } /** * Gets the correct sender type for the command. - * It'll validate the sender with the {@link #senderValidator}. + * It'll validate the sender with a {@link SenderExtension}. * * @return The validated sender type. */ @@ -92,7 +87,7 @@ public Class senderType() { } final Class type = parameters[0].getType(); - final Set> allowedSenders = senderValidator.getAllowedSenders(); + final Set> allowedSenders = getCommandExtensions().getSenderExtension().getAllowedSenders(); if (!allowedSenders.contains(type)) { throw createException( @@ -134,7 +129,7 @@ public Class senderType() { ); // If validation is false ignore it - if (!argumentExtensionHandler.validate(this, argument, i, last)) continue; + if (!getCommandExtensions().getArgumentValidator().validate(this, argument, i, last)) continue; arguments.add(argument); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java index bc8cc103..780fcc48 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.core.requirement; import dev.triumphteam.cmd.core.message.ContextualKey; -import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.context.MessageContext; import dev.triumphteam.cmd.core.message.context.MessageContextFactory; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java index f556f2d5..e10a91b5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java @@ -23,7 +23,8 @@ */ package dev.triumphteam.cmd.core.requirement; -import dev.triumphteam.cmd.core.registry.RegistryKey; +import dev.triumphteam.cmd.core.extention.StringKey; +import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -34,7 +35,7 @@ /** * Key used to identify the {@link RequirementResolver} in the {@link RequirementRegistry}. */ -public final class RequirementKey extends RegistryKey { +public final class RequirementKey extends StringKey { // Holds all registered keys, default and custom ones private static final Set REGISTERED_KEYS = new HashSet<>(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java index 2b85d2e8..9f307b0a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java @@ -31,12 +31,12 @@ import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; import dev.triumphteam.cmd.core.requirement.Requirement; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.sender.SenderValidator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java index 731cbf29..dc2199dd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.suggestion; -import dev.triumphteam.cmd.core.registry.RegistryKey; +import dev.triumphteam.cmd.core.extention.StringKey; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -34,7 +34,7 @@ /** * Key used to identify the {@link } in the {@link }. */ -public final class SuggestionKey extends RegistryKey { +public final class SuggestionKey extends StringKey { // Holds all registered keys, default and custom ones private static final Set REGISTERED_KEYS = new HashSet<>(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java index 36c0ac1d..735622e0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.suggestion; -import dev.triumphteam.cmd.core.registry.Registry; +import dev.triumphteam.cmd.core.extention.registry.Registry; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java index 285013bc..fcb4eccc 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java @@ -27,9 +27,9 @@ import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.command.ParentCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import dev.triumphteam.cmd.core.extention.sender.SenderValidator; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java index b7800d67..d9e9a384 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java @@ -25,7 +25,7 @@ import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import org.jetbrains.annotations.NotNull; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java index 6544a310..b28fc95f 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java @@ -25,10 +25,10 @@ import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderMapper; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Message; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java index c4c6b22e..68c46bdb 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java @@ -31,9 +31,9 @@ import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.execution.SyncExecutionProvider; import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import dev.triumphteam.cmd.core.extention.sender.SenderValidator; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java index e6f3ce21..e3db2b5b 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java @@ -26,9 +26,9 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.processor.OldAbstractCommandProcessor; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import dev.triumphteam.cmd.core.extention.sender.SenderValidator; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java index dad7c864..34beec60 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java @@ -24,8 +24,8 @@ package dev.triumphteam.cmd.prefixed; import com.google.common.collect.ImmutableSet; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.sender.SenderValidator; import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java index b07d4b00..40c3c1a4 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java @@ -25,8 +25,8 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderValidator; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Method; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index 98252d8a..ff01ef6d 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -23,10 +23,9 @@ */ package dev.triumphteam.cmds.simple; -import dev.triumphteam.cmd.core.annotation.AnnotationContainer; -import dev.triumphteam.cmd.core.command.ParentCommand; import dev.triumphteam.cmd.core.command.Command; -import dev.triumphteam.cmd.core.message.MessageRegistry; +import dev.triumphteam.cmd.core.command.ParentCommand; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -89,9 +88,4 @@ public void addSubCommand( public @NotNull Map> getCommandAliases() { return subCommandAliases; } - - @Override - public @NotNull AnnotationContainer getAnnotations() { - return null; - } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 5aa475fc..a6c0f066 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -28,18 +28,22 @@ import dev.triumphteam.cmd.core.execution.AsyncExecutionProvider; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.execution.SyncExecutionProvider; +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.DefaultArgumentValidator; +import dev.triumphteam.cmd.core.extention.ExtensionBuilder; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.validation.ArgumentExtensionHandler; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import dev.triumphteam.cmd.core.extention.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Consumer; public final class SimpleCommandManager extends CommandManager { @@ -50,34 +54,23 @@ public final class SimpleCommandManager extends CommandManager { private final ExecutionProvider syncExecutionProvider = new SyncExecutionProvider(); private final ExecutionProvider asyncExecutionProvider = new AsyncExecutionProvider(); - private final ArgumentExtensionHandler extensionHandler; - - private SimpleCommandManager( - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator, - final @NotNull ArgumentExtensionHandler extensionHandler - ) { - super(senderMapper, senderValidator); - - this.extensionHandler = extensionHandler; + private SimpleCommandManager(final @NotNull CommandExtensions commandExtensions) { + super(commandExtensions); } - @Contract("_, _ -> new") - public static @NotNull SimpleCommandManager create( - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator, - final @NotNull ArgumentExtensionHandler extensionHandler - ) { - return new SimpleCommandManager<>(senderMapper, senderValidator, extensionHandler); + @Contract("_ -> new") + public static @NotNull SimpleCommandManager create(final @NotNull Consumer> builder) { + final SimpleExtensionBuilder extensionBuilder = new SimpleExtensionBuilder<>(); + builder.accept(extensionBuilder); + return new SimpleCommandManager<>(extensionBuilder.build()); } @Override public void registerCommand(final @NotNull BaseCommand baseCommand) { final SimpleCommandProcessor processor = new SimpleCommandProcessor<>( baseCommand, - getSenderValidator(), getRegistryContainer(), - extensionHandler + getCommandExtensions() ); final String name = processor.getName(); diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java index 31dc06f5..74f851fe 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java @@ -24,20 +24,18 @@ package dev.triumphteam.cmds.simple; import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.processor.AbstractRootCommandProcessor; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.validation.ArgumentExtensionHandler; import org.jetbrains.annotations.NotNull; public final class SimpleCommandProcessor extends AbstractRootCommandProcessor { public SimpleCommandProcessor( final @NotNull BaseCommand baseCommand, - final @NotNull SenderValidator senderValidator, final @NotNull RegistryContainer registryContainer, - final @NotNull ArgumentExtensionHandler argumentExtensionHandler + final @NotNull CommandExtensions commandExtensions ) { - super(baseCommand, senderValidator, registryContainer, argumentExtensionHandler); + super(baseCommand, registryContainer, commandExtensions); } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java new file mode 100644 index 00000000..2e9e27f2 --- /dev/null +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java @@ -0,0 +1,19 @@ +package dev.triumphteam.cmds.simple; + +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.DefaultArgumentValidator; +import dev.triumphteam.cmd.core.extention.ExtensionBuilder; +import org.jetbrains.annotations.NotNull; + +final class SimpleExtensionBuilder extends ExtensionBuilder { + + @Override + public @NotNull CommandExtensions build() { + return new CommandExtensions<>( + getAnnotationProcessors(), + getArgumentProcessors(), + getSenderExtension(null), + getArgumentValidator(new DefaultArgumentValidator<>()) + ); + } +} diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java index 9ed26bc3..2c54b75e 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java @@ -25,8 +25,8 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderValidator; import org.jetbrains.annotations.NotNull; import java.lang.reflect.Method; diff --git a/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt b/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt index a1531d2a..51b82c63 100644 --- a/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt +++ b/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt @@ -23,14 +23,15 @@ */ package dev.triumphteam.tests -import dev.triumphteam.cmd.core.message.MessageRegistry -import dev.triumphteam.cmd.core.sender.SenderMapper -import dev.triumphteam.cmd.core.sender.SenderValidator +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry +import dev.triumphteam.cmd.core.extention.sender.SenderMapper +import dev.triumphteam.cmd.core.extention.sender.SenderValidator import dev.triumphteam.cmd.core.subcommand.OldSubCommand class TestSender -class TestSenderMapper : SenderMapper { +class TestSenderMapper : + SenderMapper { override fun map(defaultSender: TestSender): TestSender = defaultSender } From 9571c38dfa53a07255f6db1b79b8def8a361385f Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Sun, 25 Dec 2022 22:55:28 +0000 Subject: [PATCH 028/101] feature: Custom processors --- .../cmd/core/annotations/Async.java | 7 ++- .../triumphteam/cmd/core/command/Command.java | 4 +- .../cmd/core/command/ParentSubCommand.java | 10 +++ .../cmd/core/command/SubCommand.java | 11 ++++ .../annotation/AnnotationProcessor.java | 2 +- .../extention/argument/ArgumentProcessor.java | 2 +- .../defaults/AsyncAnnotationProcessor.java | 20 ++++++ .../DefaultArgumentValidator.java | 2 +- .../cmd/core/extention/meta/CommandMeta.java | 43 +++++++------ .../extention/meta/CommandMetaContainer.java | 8 +++ .../extention/meta/ImmutableCommandMeta.java | 26 ++++++++ .../AbstractRootCommandProcessor.java | 61 ++++++++++++++++--- .../cmds/simple/SimpleCommand.java | 9 +++ .../cmds/simple/SimpleCommandManager.java | 10 +-- .../cmds/simple/SimpleExtensionBuilder.java | 5 +- 15 files changed, 180 insertions(+), 40 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java rename core/src/main/java/dev/triumphteam/cmd/core/extention/{ => defaults}/DefaultArgumentValidator.java (96%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java index f7bbfbb8..387549db 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java @@ -23,6 +23,8 @@ */ package dev.triumphteam.cmd.core.annotations; +import dev.triumphteam.cmd.core.extention.meta.MetaKey; + import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -33,4 +35,7 @@ */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) -public @interface Async {} +public @interface Async { + + MetaKey META_KEY = MetaKey.of("async", Void.TYPE); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 24ed293a..d3b3c74e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -23,7 +23,9 @@ */ package dev.triumphteam.cmd.core.command; -public interface Command { +import dev.triumphteam.cmd.core.extention.meta.CommandMetaContainer; + +public interface Command extends CommandMetaContainer { } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 9263c668..38c725ea 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -1,5 +1,6 @@ package dev.triumphteam.cmd.core.command; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -10,6 +11,10 @@ public class ParentSubCommand implements ParentCommand { private final Map> commands = new HashMap<>(); private final Map> commandAliases = new HashMap<>(); + private final CommandMeta meta; + + public ParentSubCommand(final @NotNull CommandMeta meta) {this.meta = meta;} + @Override public void addSubCommand( final @NotNull String name, @@ -28,4 +33,9 @@ public void addSubCommand( public @NotNull Map> getCommandAliases() { return commandAliases; } + + @Override + public @NotNull CommandMeta getMeta() { + return meta; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 04f914ef..5f4bf788 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -1,5 +1,16 @@ package dev.triumphteam.cmd.core.command; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import org.jetbrains.annotations.NotNull; + public class SubCommand implements Command { + private final CommandMeta meta; + + public SubCommand(final @NotNull CommandMeta meta) {this.meta = meta;} + + @Override + public @NotNull CommandMeta getMeta() { + return meta; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java index 99551874..64a57f72 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java @@ -10,6 +10,6 @@ public interface AnnotationProcessor { void process( final @NotNull A annotation, final @NotNull AnnotationTarget target, - final @NotNull CommandMeta meta + final @NotNull CommandMeta.Builder meta ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentProcessor.java index 1da9e082..2758f4dd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentProcessor.java @@ -7,6 +7,6 @@ public interface ArgumentProcessor { void process( final @NotNull Class annotation, - final @NotNull CommandMeta meta + final @NotNull CommandMeta.Builder meta ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java new file mode 100644 index 00000000..15d49104 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java @@ -0,0 +1,20 @@ +package dev.triumphteam.cmd.core.extention.defaults; + +import dev.triumphteam.cmd.core.annotations.Async; +import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; +import dev.triumphteam.cmd.core.extention.annotation.AnnotationTarget; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import org.jetbrains.annotations.NotNull; + +public final class AsyncAnnotationProcessor implements AnnotationProcessor { + + @Override + public void process( + final @NotNull Async annotation, + final @NotNull AnnotationTarget target, + final @NotNull CommandMeta.@NotNull Builder meta + ) { + if (target != AnnotationTarget.SUB_COMMAND) return; + meta.add(Async.META_KEY); + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/DefaultArgumentValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/extention/DefaultArgumentValidator.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java index ebc9a1e6..75403786 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/DefaultArgumentValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java @@ -1,4 +1,4 @@ -package dev.triumphteam.cmd.core.extention; +package dev.triumphteam.cmd.core.extention.defaults; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java index 80c37a20..65effa8e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java @@ -3,33 +3,40 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; import java.util.HashMap; import java.util.Map; -public final class CommandMeta { +public interface CommandMeta { - private final Map, Object> dataMap = new HashMap<>(); + @SuppressWarnings("unchecked") + @Nullable V get(final @NotNull MetaKey metaKey); - private final CommandMeta parentMeta; + boolean isPresent(final @NotNull MetaKey metaKey); - public CommandMeta(final @Nullable CommandMeta parentMeta) { - this.parentMeta = parentMeta; - } + final class Builder { + private final Map, Object> dataMap = new HashMap<>(); - public void add(final @NotNull MetaKey metaKey, final @NotNull V value) { - dataMap.put(metaKey, value); - } + private final CommandMeta parentMeta; - @SuppressWarnings("unchecked") - public @Nullable V get(final @NotNull MetaKey metaKey) { - return (V) dataMap.get(metaKey); - } + public Builder(final @Nullable CommandMeta parentMeta) { + this.parentMeta = parentMeta; + } - public boolean isPresent(final @NotNull MetaKey metaKey) { - return dataMap.containsKey(metaKey); - } + public void add(final @NotNull MetaKey metaKey, final @Nullable V value) { + dataMap.put(metaKey, value); + } + + public void add(final @NotNull MetaKey metaKey) { + add(metaKey, null); + } + + public @Nullable CommandMeta getParentMeta() { + return parentMeta; + } - public @Nullable CommandMeta getParentMeta() { - return parentMeta; + public CommandMeta build() { + return new ImmutableCommandMeta(Collections.unmodifiableMap(dataMap)); + } } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java new file mode 100644 index 00000000..dba7d432 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java @@ -0,0 +1,8 @@ +package dev.triumphteam.cmd.core.extention.meta; + +import org.jetbrains.annotations.NotNull; + +public interface CommandMetaContainer { + + @NotNull CommandMeta getMeta(); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java new file mode 100644 index 00000000..c692c32c --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java @@ -0,0 +1,26 @@ +package dev.triumphteam.cmd.core.extention.meta; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; + +final class ImmutableCommandMeta implements CommandMeta { + + private final Map, Object> meta; + + public ImmutableCommandMeta(final @NotNull Map, Object> meta) { + this.meta = meta; + } + + @SuppressWarnings("unchecked") + @Override + public @Nullable V get(final @NotNull MetaKey metaKey) { + return (V) meta.get(metaKey); + } + + @Override + public boolean isPresent(final @NotNull MetaKey metaKey) { + return meta.containsKey(metaKey); + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java index 9f1a3edf..61e6dae8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java @@ -26,19 +26,26 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.annotations.Description; import dev.triumphteam.cmd.core.command.Command; +import dev.triumphteam.cmd.core.command.SubCommand; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; +import dev.triumphteam.cmd.core.extention.annotation.AnnotationTarget; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import org.jetbrains.annotations.NotNull; +import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; +@SuppressWarnings("unchecked") public abstract class AbstractRootCommandProcessor { private final BaseCommand baseCommand; @@ -77,21 +84,47 @@ public String getDescription() { return description; } - public @NotNull List> commands() { + public CommandMeta createMeta() { + final CommandMeta.Builder meta = new CommandMeta.Builder(null); + final Map, AnnotationProcessor> processors + = commandExtensions.getAnnotationProcessors(); + + for (final Annotation annotation : baseCommand.getClass().getAnnotations()) { + @SuppressWarnings("rawtypes") final AnnotationProcessor annotationProcessor + = processors.get(annotation.annotationType()); + + // No processors available + if (annotationProcessor == null) continue; + + annotationProcessor.process(annotation, AnnotationTarget.COMMAND, meta); + } + + return meta.build(); + } + + public @NotNull List> commands(final @NotNull CommandMeta parentMeta) { final Class klass = baseCommand.getClass(); final List> subCommands = new ArrayList<>(); - subCommands.addAll(methodCommands(klass.getDeclaredMethods())); - subCommands.addAll(classCommands(klass.getDeclaredClasses())); + subCommands.addAll(methodCommands(parentMeta, klass.getDeclaredMethods())); + subCommands.addAll(classCommands(parentMeta, klass.getDeclaredClasses())); return subCommands; } - private @NotNull List> methodCommands(final @NotNull Method[] methods) { + private @NotNull List> methodCommands( + final @NotNull CommandMeta parentMeta, + final @NotNull Method[] methods + ) { + final Map, AnnotationProcessor> annotationProcessors + = commandExtensions.getAnnotationProcessors(); + return Arrays.stream(methods).map(method -> { // Ignore non-public methods if (!Modifier.isPublic(method.getModifiers())) return null; + final CommandMeta.Builder meta = new CommandMeta.Builder(parentMeta); + final SubCommandProcessor processor = new SubCommandProcessor<>( name, baseCommand, @@ -103,13 +136,24 @@ public String getDescription() { // Not a command, ignore the method if (processor.getName() == null) return null; + // Process annotations + for (final Annotation annotation : method.getAnnotations()) { + @SuppressWarnings("rawtypes") final AnnotationProcessor annotationProcessor + = annotationProcessors.get(annotation.annotationType()); + if (annotationProcessor == null) continue; + annotationProcessor.process(annotation, AnnotationTarget.SUB_COMMAND, meta); + } + processor.senderType(); System.out.println(processor.arguments()); - return new Command() {}; + return new SubCommand(null); }).filter(Objects::nonNull).collect(Collectors.toList()); } - private @NotNull List> classCommands(final @NotNull Class[] classes) { + private @NotNull List> classCommands( + final @NotNull CommandMeta parentMeta, + final @NotNull Class[] classes + ) { final List> subCommands = new ArrayList<>(); for (final Class klass : classes) { // Ignore non-public methods @@ -121,8 +165,9 @@ public String getDescription() { System.out.println("Sub boy -> " + name); - subCommands.addAll(methodCommands(klass.getDeclaredMethods())); - subCommands.addAll(classCommands(klass.getDeclaredClasses())); + // TODO THIS NEEDS TO BE A NEW META FROM PARENT, NOT CURRENT PARENT + subCommands.addAll(methodCommands(parentMeta, klass.getDeclaredMethods())); + subCommands.addAll(classCommands(parentMeta, klass.getDeclaredClasses())); } return subCommands; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index ff01ef6d..61140bf8 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -25,6 +25,7 @@ import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.command.ParentCommand; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import org.jetbrains.annotations.NotNull; @@ -41,12 +42,15 @@ public final class SimpleCommand implements ParentCommand { private final Map> subCommands = new HashMap<>(); private final Map> subCommandAliases = new HashMap<>(); + private final CommandMeta meta; + @SuppressWarnings("unchecked") public SimpleCommand( final @NotNull SimpleCommandProcessor processor, final @NotNull MessageRegistry messageRegistry ) { this.name = processor.getName(); + this.meta = processor.createMeta(); this.messageRegistry = messageRegistry; } @@ -88,4 +92,9 @@ public void addSubCommand( public @NotNull Map> getCommandAliases() { return subCommandAliases; } + + @Override + public @NotNull CommandMeta getMeta() { + return meta; + } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index a6c0f066..1f7171f8 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -29,14 +29,10 @@ import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.execution.SyncExecutionProvider; import dev.triumphteam.cmd.core.extention.CommandExtensions; -import dev.triumphteam.cmd.core.extention.DefaultArgumentValidator; import dev.triumphteam.cmd.core.extention.ExtensionBuilder; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; -import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import dev.triumphteam.cmd.core.extention.sender.SenderMapper; -import dev.triumphteam.cmd.core.extention.sender.SenderValidator; -import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -82,10 +78,8 @@ public void registerCommand(final @NotNull BaseCommand baseCommand) { } // Command does not exist, proceed to add new! - processor.commands(); - final SimpleCommand newCommand = commands.computeIfAbsent(processor.getName(), it -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); - + processor.commands(newCommand.getMeta()); processor.getAlias().forEach(it -> { final SimpleCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java index 2e9e27f2..3a15f4b8 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java @@ -1,7 +1,9 @@ package dev.triumphteam.cmds.simple; +import dev.triumphteam.cmd.core.annotations.Async; import dev.triumphteam.cmd.core.extention.CommandExtensions; -import dev.triumphteam.cmd.core.extention.DefaultArgumentValidator; +import dev.triumphteam.cmd.core.extention.defaults.AsyncAnnotationProcessor; +import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; import dev.triumphteam.cmd.core.extention.ExtensionBuilder; import org.jetbrains.annotations.NotNull; @@ -9,6 +11,7 @@ final class SimpleExtensionBuilder extends ExtensionBuilder { @Override public @NotNull CommandExtensions build() { + addAnnotationProcessor(Async.class, new AsyncAnnotationProcessor()); return new CommandExtensions<>( getAnnotationProcessors(), getArgumentProcessors(), From eeeeb229d8891943ff7b66bf099eb19ad214ca4a Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Mon, 26 Dec 2022 00:06:08 +0000 Subject: [PATCH 029/101] chore: Custom processors with meta polish --- .../cmd/core/annotations/Async.java | 1 + .../cmd/core/command/SubCommand.java | 15 +- .../defaults/AsyncAnnotationProcessor.java | 1 + .../processor/AbstractCommandProcessor.java | 389 ++++++++++++++++++ .../AbstractRootCommandProcessor.java | 48 +-- .../cmd/core/processor/CommandProcessor.java | 347 +--------------- .../core/processor/SubCommandProcessor.java | 28 +- 7 files changed, 445 insertions(+), 384 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java index 387549db..087a65f4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java @@ -37,5 +37,6 @@ @Target(ElementType.METHOD) public @interface Async { + // Async's annotation meta key MetaKey META_KEY = MetaKey.of("async", Void.TYPE); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 5f4bf788..1c85fa49 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -1,13 +1,26 @@ package dev.triumphteam.cmd.core.command; +import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.processor.SubCommandProcessor; import org.jetbrains.annotations.NotNull; +import java.util.List; + public class SubCommand implements Command { + private final List> arguments; + private final Class senderType; + private final CommandMeta meta; - public SubCommand(final @NotNull CommandMeta meta) {this.meta = meta;} + public SubCommand( + final @NotNull SubCommandProcessor processor + ) { + this.meta = processor.createMeta(); + this.senderType = processor.senderType(); + this.arguments = processor.arguments(meta); + } @Override public @NotNull CommandMeta getMeta() { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java index 15d49104..6d18da23 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java @@ -14,6 +14,7 @@ public void process( final @NotNull AnnotationTarget target, final @NotNull CommandMeta.@NotNull Builder meta ) { + System.out.println(target); if (target != AnnotationTarget.SUB_COMMAND) return; meta.add(Async.META_KEY); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java new file mode 100644 index 00000000..ed03a544 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -0,0 +1,389 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.processor; + +import com.google.common.base.CaseFormat; +import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.annotations.ArgName; +import dev.triumphteam.cmd.core.annotations.Command; +import dev.triumphteam.cmd.core.annotations.Description; +import dev.triumphteam.cmd.core.annotations.Join; +import dev.triumphteam.cmd.core.annotations.Optional; +import dev.triumphteam.cmd.core.annotations.Split; +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; +import dev.triumphteam.cmd.core.extention.annotation.AnnotationTarget; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; +import dev.triumphteam.cmd.core.argument.ArgumentResolver; +import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; +import dev.triumphteam.cmd.core.argument.EnumInternalArgument; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; +import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; +import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; +import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; +import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; +import dev.triumphteam.cmd.core.suggestion.EnumSuggestion; +import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; +import dev.triumphteam.cmd.core.suggestion.Suggestion; +import dev.triumphteam.cmd.core.suggestion.SuggestionKey; +import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; +import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Parameter; +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; +import java.lang.reflect.WildcardType; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Abstracts most of the "extracting" from sub command annotations, allows for extending. + *
+ * I know this could be done better, but couldn't think of a better way. + * If you do please PR or let me know on my discord! + * + * @param The sender type. + */ +@SuppressWarnings("unchecked") +abstract class AbstractCommandProcessor implements CommandProcessor { + + private static final Set> SUPPORTED_COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); + + private final String parentName; + private final BaseCommand baseCommand; + private final String name; + private final AnnotatedElement annotatedElement; + + private final SuggestionRegistry suggestionRegistry; + private final ArgumentRegistry argumentRegistry; + + private final CommandExtensions commandExtensions; + private final CommandMeta parentMeta; + + AbstractCommandProcessor( + final @NotNull String parentName, + final @NotNull BaseCommand baseCommand, + final @NotNull AnnotatedElement annotatedElement, + final @NotNull RegistryContainer registryContainer, + final @NotNull CommandExtensions commandExtensions, + final @NotNull CommandMeta parentMeta + ) { + this.parentName = parentName; + this.baseCommand = baseCommand; + this.annotatedElement = annotatedElement; + this.name = nameOf(); + this.parentMeta = parentMeta; + + this.commandExtensions = commandExtensions; + this.suggestionRegistry = registryContainer.getSuggestionRegistry(); + this.argumentRegistry = registryContainer.getArgumentRegistry(); + } + + /** + * Process all annotations for the specific {@link AnnotatedElement}. + * + * @param extensions The main extensions to get the processors from. + * @param element The annotated element to process its annotations. + * @param target The target of the annotation. + * @param meta The meta builder that'll be passed to processors. + */ + public static void processAnnotations( + final @NotNull CommandExtensions extensions, + final @NotNull AnnotatedElement element, + final @NotNull AnnotationTarget target, + final @NotNull CommandMeta.Builder meta + ) { + final Map, AnnotationProcessor> processors + = extensions.getAnnotationProcessors(); + + for (final Annotation annotation : element.getAnnotations()) { + @SuppressWarnings("rawtypes") final AnnotationProcessor annotationProcessor + = processors.get(annotation.annotationType()); + + // No processors available + if (annotationProcessor == null) continue; + + annotationProcessor.process(annotation, target, meta); + } + } + + protected @NotNull CommandMeta getParentMeta() { + return parentMeta; + } + + @Contract("_ -> new") + @NotNull + public SubCommandRegistrationException createException(final @NotNull String message) { + return new SubCommandRegistrationException(message, annotatedElement, baseCommand.getClass()); + } + + private @Nullable String nameOf() { + final Command commandAnnotation = annotatedElement.getAnnotation(Command.class); + + // Not a command element + if (commandAnnotation == null) return null; + + return commandAnnotation.value(); + } + + public @Nullable String getName() { + return name; + } + + // TODO COMMENTS + protected @NotNull InternalArgument createArgument( + final @NotNull Parameter parameter, + final @NotNull List argDescriptions, + final @NotNull Map> suggestions, + final int position + ) { + final Class type = parameter.getType(); + final String argumentName = getArgName(parameter); + final String argumentDescription = getArgumentDescription(argDescriptions, parameter, position); + final boolean optional = parameter.isAnnotationPresent(Optional.class); + + // Handles collection internalArgument. + // TODO: Add more collection types. + if (SUPPORTED_COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { + final Class collectionType = getGenericType(parameter); + final InternalArgument argument = createSimpleArgument( + collectionType, + argumentName, + argumentDescription, + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + true + ); + + // Throw exception on unknown arguments for collection parameter type + if (argument instanceof UnknownInternalArgument) { + throw createException("No internalArgument of type \"" + argument.getType().getName() + "\" registered"); + } + + if (parameter.isAnnotationPresent(Split.class)) { + final Split splitAnnotation = parameter.getAnnotation(Split.class); + return new SplitStringInternalArgument<>( + argumentName, + argumentDescription, + splitAnnotation.value(), + argument, + type, + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + optional + ); + } + + return new CollectionInternalArgument<>( + argumentName, + argumentDescription, + argument, + type, + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + optional + ); + } + + // Handler for using String with `@Join`. + if (type == String.class && parameter.isAnnotationPresent(Join.class)) { + final Join joinAnnotation = parameter.getAnnotation(Join.class); + return new JoinedStringInternalArgument<>( + argumentName, + argumentDescription, + joinAnnotation.value(), + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + optional + ); + } + + // Handler for flags. + // TODO RE-ADD FLAGS AND NAMED ARGUMENTS AS A SINGLE TYPE + /*if (type == Flags.class) { + if (flagGroup.isEmpty()) { + throw createException("Flags internalArgument detected but no flag annotation declared"); + } + + return new FlagInternalArgument<>( + argumentName, + argumentDescription, + flagGroup, + optional + ); + } + + // Handler for named arguments + if (type == Arguments.class) { + final NamedArguments namedArguments = annotatedElement.getAnnotation(NamedArguments.class); + if (namedArguments == null) { + throw createException("TODO"); + } + + return new NamedInternalArgument<>( + argumentName, + argumentDescription, + collectNamedArgs(namedArguments.value()), + optional + ); + }*/ + + return createSimpleArgument( + type, + argumentName, + argumentDescription, + suggestions.getOrDefault(position, suggestionFromParam(parameter)), + optional + ); + } + + protected @NotNull InternalArgument createSimpleArgument( + final @NotNull Class type, + final @NotNull String parameterName, + final @NotNull String argumentDescription, + final @NotNull Suggestion suggestion, + final boolean optional + ) { + // All other types default to the resolver. + final ArgumentResolver resolver = argumentRegistry.getResolver(type); + if (resolver == null) { + // Handler for using any Enum. + if (Enum.class.isAssignableFrom(type)) { + //noinspection unchecked + return new EnumInternalArgument<>( + parameterName, + argumentDescription, + (Class>) type, + suggestion, + optional + ); + } + + return new UnknownInternalArgument<>(type); + } + return new ResolverInternalArgument<>( + parameterName, + argumentDescription, + type, + resolver, + suggestion, + optional + ); + } + + /** + * Gets the internalArgument name, either from the parameter or from the annotation. + * If the parameter is not annotated, turn the name from Camel Case to "lower-hyphen". + * + * @param parameter The parameter to get data from. + * @return The final internalArgument name. + */ + private @NotNull String getArgName(final @NotNull Parameter parameter) { + if (parameter.isAnnotationPresent(ArgName.class)) { + return parameter.getAnnotation(ArgName.class).value(); + } + + return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, parameter.getName()); + } + + /** + * Gets the internalArgument description. + * + * @param argDescriptions List with collected method annotation instead of argument annotation. + * @param parameter The parameter to get data from. + * @param index The index of the internalArgument. + * @return The final internalArgument description. + */ + private @NotNull String getArgumentDescription( + final List argDescriptions, + final @NotNull Parameter parameter, + final int index + ) { + final Description description = parameter.getAnnotation(Description.class); + if (description != null) { + return description.value(); + } + + if (index < argDescriptions.size()) return argDescriptions.get(index); + return ""; + } + + private @NotNull Class getGenericType(final @NotNull Parameter parameter) { + final Class type = parameter.getType(); + if (SUPPORTED_COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { + final ParameterizedType parameterizedType = (ParameterizedType) parameter.getParameterizedType(); + final Type[] types = parameterizedType.getActualTypeArguments(); + + if (types.length != 1) { + throw createException("Unsupported collection type \"" + type + "\""); + } + + final Type genericType = types[0]; + return (Class) (genericType instanceof WildcardType ? ((WildcardType) genericType).getUpperBounds()[0] : genericType); + } + + return type; + } + + protected @Nullable Suggestion createSuggestion(final @Nullable SuggestionKey suggestionKey, final @NotNull Class type) { + if (suggestionKey == null) { + if (Enum.class.isAssignableFrom(type)) return new EnumSuggestion<>((Class>) type); + + final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(type); + if (resolver != null) return new SimpleSuggestion<>(resolver); + + return null; + } + + final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(suggestionKey); + if (resolver == null) { + throw createException("Cannot find the suggestion key `" + suggestionKey + "`"); + } + return new SimpleSuggestion<>(resolver); + } + + private @NotNull Suggestion suggestionFromParam(final @NotNull Parameter parameter) { + final dev.triumphteam.cmd.core.annotations.Suggestion parameterAnnotation = parameter.getAnnotation(dev.triumphteam.cmd.core.annotations.Suggestion.class); + final SuggestionKey suggestionKey = parameterAnnotation == null ? null : SuggestionKey.of(parameterAnnotation.value()); + + final Class type = getGenericType(parameter); + final Suggestion suggestion = createSuggestion(suggestionKey, type); + + if (suggestion == null) return new EmptySuggestion<>(); + + return suggestion; + } + + protected @NotNull CommandExtensions getCommandExtensions() { + return commandExtensions; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java index 61e6dae8..4ae9debe 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java @@ -29,24 +29,24 @@ import dev.triumphteam.cmd.core.command.SubCommand; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.CommandExtensions; -import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.annotation.AnnotationTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.lang.annotation.Annotation; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.stream.Collectors; +import static dev.triumphteam.cmd.core.processor.AbstractCommandProcessor.processAnnotations; + @SuppressWarnings("unchecked") -public abstract class AbstractRootCommandProcessor { +public abstract class AbstractRootCommandProcessor implements CommandProcessor { private final BaseCommand baseCommand; @@ -84,21 +84,13 @@ public String getDescription() { return description; } - public CommandMeta createMeta() { + @Contract(" -> new") + @Override + public @NotNull CommandMeta createMeta() { final CommandMeta.Builder meta = new CommandMeta.Builder(null); - final Map, AnnotationProcessor> processors - = commandExtensions.getAnnotationProcessors(); - - for (final Annotation annotation : baseCommand.getClass().getAnnotations()) { - @SuppressWarnings("rawtypes") final AnnotationProcessor annotationProcessor - = processors.get(annotation.annotationType()); - - // No processors available - if (annotationProcessor == null) continue; - - annotationProcessor.process(annotation, AnnotationTarget.COMMAND, meta); - } - + // Process all the class annotations + processAnnotations(commandExtensions, baseCommand.getClass(), AnnotationTarget.COMMAND, meta); + // Return modified meta return meta.build(); } @@ -116,37 +108,23 @@ public CommandMeta createMeta() { final @NotNull CommandMeta parentMeta, final @NotNull Method[] methods ) { - final Map, AnnotationProcessor> annotationProcessors - = commandExtensions.getAnnotationProcessors(); - return Arrays.stream(methods).map(method -> { // Ignore non-public methods if (!Modifier.isPublic(method.getModifiers())) return null; - final CommandMeta.Builder meta = new CommandMeta.Builder(parentMeta); - final SubCommandProcessor processor = new SubCommandProcessor<>( name, baseCommand, method, registryContainer, - commandExtensions + commandExtensions, + parentMeta ); // Not a command, ignore the method if (processor.getName() == null) return null; - // Process annotations - for (final Annotation annotation : method.getAnnotations()) { - @SuppressWarnings("rawtypes") final AnnotationProcessor annotationProcessor - = annotationProcessors.get(annotation.annotationType()); - if (annotationProcessor == null) continue; - annotationProcessor.process(annotation, AnnotationTarget.SUB_COMMAND, meta); - } - - processor.senderType(); - System.out.println(processor.arguments()); - return new SubCommand(null); + return new SubCommand<>(processor); }).filter(Objects::nonNull).collect(Collectors.toList()); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index ffc8e2d4..7121070a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -1,350 +1,9 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ package dev.triumphteam.cmd.core.processor; -import com.google.common.base.CaseFormat; -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.annotations.ArgName; -import dev.triumphteam.cmd.core.annotations.Command; -import dev.triumphteam.cmd.core.annotations.Description; -import dev.triumphteam.cmd.core.annotations.Join; -import dev.triumphteam.cmd.core.annotations.Optional; -import dev.triumphteam.cmd.core.annotations.Split; -import dev.triumphteam.cmd.core.extention.CommandExtensions; -import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; -import dev.triumphteam.cmd.core.argument.ArgumentResolver; -import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; -import dev.triumphteam.cmd.core.argument.EnumInternalArgument; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; -import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; -import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; -import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; -import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; -import dev.triumphteam.cmd.core.suggestion.EnumSuggestion; -import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; -import dev.triumphteam.cmd.core.suggestion.Suggestion; -import dev.triumphteam.cmd.core.suggestion.SuggestionKey; -import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; -import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; -import org.jetbrains.annotations.Contract; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Parameter; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.WildcardType; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; +public interface CommandProcessor { -/** - * Abstracts most of the "extracting" from sub command annotations, allows for extending. - *
- * I know this could be done better, but couldn't think of a better way. - * If you do please PR or let me know on my discord! - * - * @param The sender type. - */ -@SuppressWarnings("unchecked") -public abstract class CommandProcessor { - - private static final Set> SUPPORTED_COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); - - private final String parentName; - private final BaseCommand baseCommand; - private final String name; - private final AnnotatedElement annotatedElement; - - private final SuggestionRegistry suggestionRegistry; - private final ArgumentRegistry argumentRegistry; - - private final CommandExtensions commandExtensions; - - CommandProcessor( - final @NotNull String parentName, - final @NotNull BaseCommand baseCommand, - final @NotNull AnnotatedElement annotatedElement, - final @NotNull RegistryContainer registryContainer, - final @NotNull CommandExtensions commandExtensions - ) { - this.parentName = parentName; - this.baseCommand = baseCommand; - this.annotatedElement = annotatedElement; - this.name = nameOf(); - - this.commandExtensions = commandExtensions; - this.suggestionRegistry = registryContainer.getSuggestionRegistry(); - this.argumentRegistry = registryContainer.getArgumentRegistry(); - } - - @Contract("_ -> new") - @NotNull - public SubCommandRegistrationException createException(final @NotNull String message) { - return new SubCommandRegistrationException(message, annotatedElement, baseCommand.getClass()); - } - - private @Nullable String nameOf() { - final Command commandAnnotation = annotatedElement.getAnnotation(Command.class); - - // Not a command element - if (commandAnnotation == null) return null; - - return commandAnnotation.value(); - } - - public @Nullable String getName() { - return name; - } - - // TODO COMMENTS - protected @NotNull InternalArgument createArgument( - final @NotNull Parameter parameter, - final @NotNull List argDescriptions, - final @NotNull Map> suggestions, - final int position - ) { - final Class type = parameter.getType(); - final String argumentName = getArgName(parameter); - final String argumentDescription = getArgumentDescription(argDescriptions, parameter, position); - final boolean optional = parameter.isAnnotationPresent(Optional.class); - - // Handles collection internalArgument. - // TODO: Add more collection types. - if (SUPPORTED_COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { - final Class collectionType = getGenericType(parameter); - final InternalArgument argument = createSimpleArgument( - collectionType, - argumentName, - argumentDescription, - suggestions.getOrDefault(position, suggestionFromParam(parameter)), - true - ); - - // Throw exception on unknown arguments for collection parameter type - if (argument instanceof UnknownInternalArgument) { - throw createException("No internalArgument of type \"" + argument.getType().getName() + "\" registered"); - } - - if (parameter.isAnnotationPresent(Split.class)) { - final Split splitAnnotation = parameter.getAnnotation(Split.class); - return new SplitStringInternalArgument<>( - argumentName, - argumentDescription, - splitAnnotation.value(), - argument, - type, - suggestions.getOrDefault(position, suggestionFromParam(parameter)), - optional - ); - } - - return new CollectionInternalArgument<>( - argumentName, - argumentDescription, - argument, - type, - suggestions.getOrDefault(position, suggestionFromParam(parameter)), - optional - ); - } - - // Handler for using String with `@Join`. - if (type == String.class && parameter.isAnnotationPresent(Join.class)) { - final Join joinAnnotation = parameter.getAnnotation(Join.class); - return new JoinedStringInternalArgument<>( - argumentName, - argumentDescription, - joinAnnotation.value(), - suggestions.getOrDefault(position, suggestionFromParam(parameter)), - optional - ); - } - - // Handler for flags. - // TODO RE-ADD FLAGS AND NAMED ARGUMENTS AS A SINGLE TYPE - /*if (type == Flags.class) { - if (flagGroup.isEmpty()) { - throw createException("Flags internalArgument detected but no flag annotation declared"); - } - - return new FlagInternalArgument<>( - argumentName, - argumentDescription, - flagGroup, - optional - ); - } - - // Handler for named arguments - if (type == Arguments.class) { - final NamedArguments namedArguments = annotatedElement.getAnnotation(NamedArguments.class); - if (namedArguments == null) { - throw createException("TODO"); - } - - return new NamedInternalArgument<>( - argumentName, - argumentDescription, - collectNamedArgs(namedArguments.value()), - optional - ); - }*/ - - return createSimpleArgument( - type, - argumentName, - argumentDescription, - suggestions.getOrDefault(position, suggestionFromParam(parameter)), - optional - ); - } - - protected @NotNull InternalArgument createSimpleArgument( - final @NotNull Class type, - final @NotNull String parameterName, - final @NotNull String argumentDescription, - final @NotNull Suggestion suggestion, - final boolean optional - ) { - // All other types default to the resolver. - final ArgumentResolver resolver = argumentRegistry.getResolver(type); - if (resolver == null) { - // Handler for using any Enum. - if (Enum.class.isAssignableFrom(type)) { - //noinspection unchecked - return new EnumInternalArgument<>( - parameterName, - argumentDescription, - (Class>) type, - suggestion, - optional - ); - } - - return new UnknownInternalArgument<>(type); - } - return new ResolverInternalArgument<>( - parameterName, - argumentDescription, - type, - resolver, - suggestion, - optional - ); - } - - /** - * Gets the internalArgument name, either from the parameter or from the annotation. - * If the parameter is not annotated, turn the name from Camel Case to "lower-hyphen". - * - * @param parameter The parameter to get data from. - * @return The final internalArgument name. - */ - private @NotNull String getArgName(final @NotNull Parameter parameter) { - if (parameter.isAnnotationPresent(ArgName.class)) { - return parameter.getAnnotation(ArgName.class).value(); - } - - return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, parameter.getName()); - } - - /** - * Gets the internalArgument description. - * - * @param argDescriptions List with collected method annotation instead of argument annotation. - * @param parameter The parameter to get data from. - * @param index The index of the internalArgument. - * @return The final internalArgument description. - */ - private @NotNull String getArgumentDescription( - final List argDescriptions, - final @NotNull Parameter parameter, - final int index - ) { - final Description description = parameter.getAnnotation(Description.class); - if (description != null) { - return description.value(); - } - - if (index < argDescriptions.size()) return argDescriptions.get(index); - return ""; - } - - private @NotNull Class getGenericType(final @NotNull Parameter parameter) { - final Class type = parameter.getType(); - if (SUPPORTED_COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { - final ParameterizedType parameterizedType = (ParameterizedType) parameter.getParameterizedType(); - final Type[] types = parameterizedType.getActualTypeArguments(); - - if (types.length != 1) { - throw createException("Unsupported collection type \"" + type + "\""); - } - - final Type genericType = types[0]; - return (Class) (genericType instanceof WildcardType ? ((WildcardType) genericType).getUpperBounds()[0] : genericType); - } - - return type; - } - - protected @Nullable Suggestion createSuggestion(final @Nullable SuggestionKey suggestionKey, final @NotNull Class type) { - if (suggestionKey == null) { - if (Enum.class.isAssignableFrom(type)) return new EnumSuggestion<>((Class>) type); - - final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(type); - if (resolver != null) return new SimpleSuggestion<>(resolver); - - return null; - } - - final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(suggestionKey); - if (resolver == null) { - throw createException("Cannot find the suggestion key `" + suggestionKey + "`"); - } - return new SimpleSuggestion<>(resolver); - } - - private @NotNull Suggestion suggestionFromParam(final @NotNull Parameter parameter) { - final dev.triumphteam.cmd.core.annotations.Suggestion parameterAnnotation = parameter.getAnnotation(dev.triumphteam.cmd.core.annotations.Suggestion.class); - final SuggestionKey suggestionKey = parameterAnnotation == null ? null : SuggestionKey.of(parameterAnnotation.value()); - - final Class type = getGenericType(parameter); - final Suggestion suggestion = createSuggestion(suggestionKey, type); - - if (suggestion == null) return new EmptySuggestion<>(); - - return suggestion; - } - - protected @NotNull CommandExtensions getCommandExtensions() { - return commandExtensions; - } + @NotNull CommandMeta createMeta(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index 81c1209c..eb48c686 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -28,6 +28,8 @@ import dev.triumphteam.cmd.core.annotations.Suggestions; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.annotation.AnnotationTarget; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; @@ -58,7 +60,7 @@ * @param The sender type. */ @SuppressWarnings("unchecked") -public final class SubCommandProcessor extends CommandProcessor { +public final class SubCommandProcessor extends AbstractCommandProcessor { private final Method method; @@ -67,13 +69,23 @@ public final class SubCommandProcessor extends CommandProcessor { final @NotNull BaseCommand baseCommand, final @NotNull Method method, final @NotNull RegistryContainer registryContainer, - final @NotNull CommandExtensions commandExtensions + final @NotNull CommandExtensions commandExtensions, + final @NotNull CommandMeta parentMeta ) { - super(parentName, baseCommand, method, registryContainer, commandExtensions); + super(parentName, baseCommand, method, registryContainer, commandExtensions, parentMeta); this.method = method; } + @Override + public @NotNull CommandMeta createMeta() { + final CommandMeta.Builder meta = new CommandMeta.Builder(getParentMeta()); + // Process all the class annotations + processAnnotations(getCommandExtensions(), method, AnnotationTarget.SUB_COMMAND, meta); + // Return modified meta + return meta.build(); + } + /** * Gets the correct sender type for the command. * It'll validate the sender with a {@link SenderExtension}. @@ -103,9 +115,17 @@ public Class senderType() { return (Class) type; } - public List> arguments() { + public List> arguments(final @NotNull CommandMeta parentMeta) { final Parameter[] parameters = method.getParameters(); + // First thing is to process the parameter annotations + final Map parameterMetas = new HashMap<>(); + for (final Parameter parameter : parameters) { + final CommandMeta.Builder meta = new CommandMeta.Builder(parentMeta); + processAnnotations(getCommandExtensions(), parameter, AnnotationTarget.ARGUMENT, meta); + parameterMetas.put(parameter, meta.build()); + } + // Ignore everything if command doesn't have arguments. if (parameters.length <= 1) return Collections.emptyList(); From b1fb357143930aacbc7355e0c1fa6e08be79fcbf Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Mon, 26 Dec 2022 01:21:12 +0000 Subject: [PATCH 030/101] chore: Modifying annotation target structure --- .../cmd/core/command/SubCommand.java | 2 + .../annotation/AnnotationTarget.java | 65 ++++++++++++++++++- .../defaults/AsyncAnnotationProcessor.java | 3 +- .../extention/meta/ImmutableCommandMeta.java | 7 ++ .../AbstractRootCommandProcessor.java | 2 +- .../core/processor/SubCommandProcessor.java | 2 +- 6 files changed, 76 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 1c85fa49..87497ae3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -20,6 +20,8 @@ public SubCommand( this.meta = processor.createMeta(); this.senderType = processor.senderType(); this.arguments = processor.arguments(meta); + + System.out.println(meta); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationTarget.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationTarget.java index 0f0981ae..09ca1a2b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationTarget.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationTarget.java @@ -1,8 +1,71 @@ package dev.triumphteam.cmd.core.extention.annotation; +import dev.triumphteam.cmd.core.BaseCommand; + +import java.lang.reflect.Method; + +/** + * The target for the custom annotation processing. + */ public enum AnnotationTarget { + /** + * The original command, normally the {@link Class} that extends {@link BaseCommand} or a child of it. + *

{@code
+     * @Command("foo")
+     * @ExampleCustomAnnotation
+     * abstract class ParentClass extends BaseCommand {}
+     *
+     * // Refers to this class, which when registering will also use the annotations from ParentClass.
+     * class MyCommand extends ParentClass() {}
+     * }
+ */ + ROOT_COMMAND, + /** + * A command "holder". the "sub-command" {@link Class}, normally does not extend {@link BaseCommand} or anything. + *
{@code
+     * @Command("foo")
+     * class MyCommand extends BaseCommand() {
+     *
+     *     // Refers to this class, which has many method commands inside
+     *     @Command("bar")
+     *     @ExampleCustomAnnotation
+     *     class InnerCommand {
+     *         // Method commands would be here
+     *     }
+     * }
+     * }
+ */ + PARENT_COMMAND, + /** + * The traditional "sub-command", command {@link Method}. + *
{@code
+     * @Command("foo")
+     * class MyCommand extends BaseCommand() {
+     *
+     *     @Command("bar")
+     *     class InnerCommand {
+     *         // Refers to either this
+     *         @Command("baz")
+     *         @ExampleCustomAnnotation
+     *         void baz(Sender sender) {}
+     *     }
+     *
+     *      // Or this
+     *      @Command("baz")
+     *      @ExampleCustomAnnotation
+     *      void baz(Sender sender) {}
+     * }
+     * }
+ */ COMMAND, - SUB_COMMAND, + /** + * The arguments are always the parameters, either from a command {@link Method} or {@link Class}. + *
{@code
+     *  // Refers to the parameters of the method, aka the arguments
+     *  @Command("baz")
+     *  void baz(Sender sender, @ExampleCustomAnnotation String argument) {}
+     * }
+ */ ARGUMENT; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java index 6d18da23..698c26b4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java @@ -14,8 +14,7 @@ public void process( final @NotNull AnnotationTarget target, final @NotNull CommandMeta.@NotNull Builder meta ) { - System.out.println(target); - if (target != AnnotationTarget.SUB_COMMAND) return; + if (target != AnnotationTarget.COMMAND) return; meta.add(Async.META_KEY); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java index c692c32c..5eb19277 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java @@ -23,4 +23,11 @@ public ImmutableCommandMeta(final @NotNull Map, Object> meta) { public boolean isPresent(final @NotNull MetaKey metaKey) { return meta.containsKey(metaKey); } + + @Override + public String toString() { + return "ImmutableCommandMeta{" + + "meta=" + meta + + '}'; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java index 4ae9debe..ad92ebf7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java @@ -89,7 +89,7 @@ public String getDescription() { public @NotNull CommandMeta createMeta() { final CommandMeta.Builder meta = new CommandMeta.Builder(null); // Process all the class annotations - processAnnotations(commandExtensions, baseCommand.getClass(), AnnotationTarget.COMMAND, meta); + processAnnotations(commandExtensions, baseCommand.getClass(), AnnotationTarget.ROOT_COMMAND, meta); // Return modified meta return meta.build(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index eb48c686..68b3a79a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -81,7 +81,7 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { public @NotNull CommandMeta createMeta() { final CommandMeta.Builder meta = new CommandMeta.Builder(getParentMeta()); // Process all the class annotations - processAnnotations(getCommandExtensions(), method, AnnotationTarget.SUB_COMMAND, meta); + processAnnotations(getCommandExtensions(), method, AnnotationTarget.COMMAND, meta); // Return modified meta return meta.build(); } From 6cbbe15178c8509542c0b131da438ef8a5c40bce Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Tue, 27 Dec 2022 00:32:18 +0000 Subject: [PATCH 031/101] feature: Kotlin suspending commands, new command options, and extensions --- .../triumphteam/cmd/core/CommandManager.java | 18 ++--- .../cmd/core/extention/CommandExtensions.java | 21 +++--- .../cmd/core/extention/CommandOptions.java | 42 +++++++++++ .../cmd/core/extention/ExtensionBuilder.java | 55 +++++++------- .../argument/ArgumentValidationResult.java | 23 ++++++ .../extention/argument/ArgumentValidator.java | 18 ++++- ...essor.java => CommandMethodProcessor.java} | 6 +- .../defaults/DefaultArgumentValidator.java | 15 ++-- .../cmd/core/extention/meta/CommandMeta.java | 4 +- .../extention/meta/ImmutableCommandMeta.java | 12 +++- .../extention/sender/SenderExtension.java | 4 +- .../core/extention/sender/SenderMapper.java | 6 +- .../processor/AbstractCommandProcessor.java | 19 +++-- .../core/processor/SubCommandProcessor.java | 19 ++++- {kotlin-extras => kotlin}/build.gradle.kts | 4 +- .../cmds/CoroutinesCommandExtension.kt | 72 +++++++++++++++++++ .../kotlin/dev/triumphteam/cmds/FlagsExt.kt | 2 +- .../kotlin/dev/triumphteam/cmds/OptionsExt.kt | 9 +++ settings.gradle.kts | 4 +- .../cmds/simple/SimpleCommandManager.java | 13 ++-- .../cmds/simple/SimpleCommandOptions.java | 27 +++++++ .../cmds/simple/SimpleExtensionBuilder.java | 22 ------ 22 files changed, 305 insertions(+), 110 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidationResult.java rename core/src/main/java/dev/triumphteam/cmd/core/extention/argument/{ArgumentProcessor.java => CommandMethodProcessor.java} (66%) rename {kotlin-extras => kotlin}/build.gradle.kts (81%) create mode 100644 kotlin/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt rename kotlin-extras/src/main/kotlin/dev/triumphteam/cmds/kotlin/Flags.kt => kotlin/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt (97%) create mode 100644 kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt create mode 100644 simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java delete mode 100644 simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index e1a95ddb..a2670b42 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -26,7 +26,7 @@ import dev.triumphteam.cmd.core.argument.ArgumentResolver; import dev.triumphteam.cmd.core.argument.named.Argument; import dev.triumphteam.cmd.core.argument.named.ArgumentKey; -import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.message.ContextualKey; import dev.triumphteam.cmd.core.message.MessageResolver; @@ -43,16 +43,16 @@ /** * Base command manager for all platforms. * - * @param The default sender type. - * @param The sender type. + * @param The default sender type. + * @param The sender type. */ @SuppressWarnings("unchecked") -public abstract class CommandManager { +public abstract class CommandManager { - private final CommandExtensions commandExtensions; + private final CommandOptions commandOptions; - public CommandManager(final @NotNull CommandExtensions commandExtensions) { - this.commandExtensions = commandExtensions; + public CommandManager(final @NotNull CommandOptions commandOptions) { + this.commandOptions = commandOptions; } /** @@ -148,7 +148,7 @@ public final void registerRequirement( protected abstract @NotNull RegistryContainer getRegistryContainer(); - protected @NotNull CommandExtensions getCommandExtensions() { - return commandExtensions; + protected @NotNull CommandOptions getCommandOptions() { + return commandOptions; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java index 091ee918..f4c4e976 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java @@ -1,30 +1,31 @@ package dev.triumphteam.cmd.core.extention; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; -import dev.triumphteam.cmd.core.extention.argument.ArgumentProcessor; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; +import dev.triumphteam.cmd.core.extention.argument.CommandMethodProcessor; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.NotNull; import java.lang.annotation.Annotation; +import java.util.List; import java.util.Map; -public final class CommandExtensions { +public final class CommandExtensions { private final Map, AnnotationProcessor> annotationProcessors; - private final Map, ArgumentProcessor> argumentProcessors; + private final List commandMethodProcessors; - private final SenderExtension senderExtension; + private final SenderExtension senderExtension; private final ArgumentValidator argumentValidator; public CommandExtensions( final @NotNull Map, AnnotationProcessor> annotationProcessors, - final @NotNull Map, ArgumentProcessor> argumentProcessors, - final @NotNull SenderExtension senderExtension, + final @NotNull List commandMethodProcessors, + final @NotNull SenderExtension senderExtension, final @NotNull ArgumentValidator argumentValidator ) { this.annotationProcessors = annotationProcessors; - this.argumentProcessors = argumentProcessors; + this.commandMethodProcessors = commandMethodProcessors; this.senderExtension = senderExtension; this.argumentValidator = argumentValidator; } @@ -33,11 +34,11 @@ public CommandExtensions( return annotationProcessors; } - public @NotNull Map, ArgumentProcessor> getArgumentProcessors() { - return argumentProcessors; + public @NotNull List getCommandMethodProcessors() { + return commandMethodProcessors; } - public @NotNull SenderExtension getSenderExtension() { + public @NotNull SenderExtension getSenderExtension() { return senderExtension; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java new file mode 100644 index 00000000..29031fd9 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java @@ -0,0 +1,42 @@ +package dev.triumphteam.cmd.core.extention; + +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; + +@SuppressWarnings("unchecked") +public class CommandOptions { + + private final CommandExtensions commandExtensions; + + public CommandOptions( + final @NotNull CommandExtensions commandExtensions + ) { + this.commandExtensions = commandExtensions; + } + + public @NotNull CommandExtensions getCommandExtensions() { + return commandExtensions; + } + + public static abstract class Builder, B extends Builder> { + + private final ExtensionBuilder extensionBuilder = new ExtensionBuilder<>(); + + public Builder(final @NotNull Consumer> defaultExtensions) { + // Adding all defaults first so they can be overridden + defaultExtensions.accept(extensionBuilder); + } + + public @NotNull B extensions(final @NotNull Consumer> consumer) { + consumer.accept(extensionBuilder); + return (B) this; + } + + public abstract @NotNull O build(); + + protected @NotNull CommandExtensions getCommandExtensions() { + return extensionBuilder.build(); + } + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java index 6e4e1926..1488e6c4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java @@ -2,28 +2,28 @@ import dev.triumphteam.cmd.core.exceptions.TriumphCmdException; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; -import dev.triumphteam.cmd.core.extention.argument.ArgumentProcessor; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; +import dev.triumphteam.cmd.core.extention.argument.CommandMethodProcessor; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.lang.annotation.Annotation; -import java.util.Collections; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; -public abstract class ExtensionBuilder { +public final class ExtensionBuilder { private final Map, AnnotationProcessor> annotationProcessors = new HashMap<>(); - private final Map, ArgumentProcessor> argumentProcessors = new HashMap<>(); + private final List commandMethodProcessors = new ArrayList<>(); - private SenderExtension senderExtension; + private SenderExtension senderExtension; private ArgumentValidator argumentValidator; @Contract("_, _ -> this") - public
ExtensionBuilder addAnnotationProcessor( + public @NotNull ExtensionBuilder addAnnotationProcessor( final Class annotation, final @NotNull AnnotationProcessor annotationProcessor ) { @@ -31,45 +31,38 @@ public ExtensionBuilder addAnnotationProcessor( return this; } - @Contract("_, _ -> this") - public ExtensionBuilder addArgumentProcessor( - final Class argumentType, - final @NotNull ArgumentProcessor argumentProcessor - ) { - argumentProcessors.put(argumentType, argumentProcessor); + @Contract("_ -> this") + public @NotNull ExtensionBuilder addCommandMethodProcessor(final @NotNull CommandMethodProcessor commandMethodProcessor) { + commandMethodProcessors.add(commandMethodProcessor); return this; } @Contract("_ -> this") - public ExtensionBuilder setSenderExtension(final @NotNull SenderExtension senderExtension) { + public @NotNull ExtensionBuilder setSenderExtension(final @NotNull SenderExtension senderExtension) { this.senderExtension = senderExtension; return this; } @Contract("_ -> this") - public ExtensionBuilder setArgumentValidator(final @NotNull ArgumentValidator argumentValidator) { + public @NotNull ExtensionBuilder setArgumentValidator(final @NotNull ArgumentValidator argumentValidator) { this.argumentValidator = argumentValidator; return this; } - protected abstract @NotNull CommandExtensions build(); - - protected @NotNull Map, AnnotationProcessor> getAnnotationProcessors() { - return Collections.unmodifiableMap(annotationProcessors); - } - - protected @NotNull Map, ArgumentProcessor> getArgumentProcessors() { - return Collections.unmodifiableMap(argumentProcessors); - } - - protected @NotNull SenderExtension getSenderExtension(final @Nullable SenderExtension def) { - if (senderExtension == null && def == null) { + public @NotNull CommandExtensions build() { + if (senderExtension == null) { throw new TriumphCmdException("No sender extension was added to Command Manager."); } - return senderExtension == null ? def : senderExtension; - } - protected @NotNull ArgumentValidator getArgumentValidator(final @NotNull ArgumentValidator def) { - return argumentValidator == null ? def : argumentValidator; + if (argumentValidator == null) { + throw new TriumphCmdException("No argument validator was added to Command Manager."); + } + + return new CommandExtensions<>( + annotationProcessors, + commandMethodProcessors, + senderExtension, + argumentValidator + ); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidationResult.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidationResult.java new file mode 100644 index 00000000..5544ee51 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidationResult.java @@ -0,0 +1,23 @@ +package dev.triumphteam.cmd.core.extention.argument; + +import org.jetbrains.annotations.NotNull; + +public interface ArgumentValidationResult { + + class Valid implements ArgumentValidationResult {} + + class Ignore implements ArgumentValidationResult {} + + class Invalid implements ArgumentValidationResult { + + private final String message; + + public Invalid(final @NotNull String message) { + this.message = message; + } + + public @NotNull String getMessage() { + return message; + } + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java index c06d904c..95271efa 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java @@ -1,15 +1,27 @@ package dev.triumphteam.cmd.core.extention.argument; import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.processor.SubCommandProcessor; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; public interface ArgumentValidator { - boolean validate( - final @NotNull SubCommandProcessor subCommandProcessor, + ArgumentValidationResult validate( + final @NotNull CommandMeta meta, final @NotNull InternalArgument argument, final int position, final int last ); + + default ArgumentValidationResult invalid(final @NotNull String message) { + return new ArgumentValidationResult.Invalid(message); + } + + default ArgumentValidationResult valid() { + return new ArgumentValidationResult.Valid(); + } + + default ArgumentValidationResult ignore() { + return new ArgumentValidationResult.Ignore(); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMethodProcessor.java similarity index 66% rename from core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentProcessor.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMethodProcessor.java index 2758f4dd..ef0ede67 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMethodProcessor.java @@ -3,10 +3,12 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; -public interface ArgumentProcessor { +import java.lang.reflect.Method; + +public interface CommandMethodProcessor { void process( - final @NotNull Class annotation, + final @NotNull Method method, final @NotNull CommandMeta.Builder meta ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java index 75403786..79f54473 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java @@ -3,34 +3,35 @@ import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; +import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; -import dev.triumphteam.cmd.core.processor.SubCommandProcessor; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; public class DefaultArgumentValidator implements ArgumentValidator { @Override - public boolean validate( - final @NotNull SubCommandProcessor processor, + public ArgumentValidationResult validate( + final @NotNull CommandMeta data, final @NotNull InternalArgument argument, final int position, final int last ) { // Validation for optionals if (position != last && argument.isOptional()) { - throw processor.createException("Optional internalArgument is only allowed as the last internalArgument"); + return invalid("Optional internalArgument is only allowed as the last internalArgument"); } // Validation for limitless if (position != last && argument instanceof LimitlessInternalArgument) { - throw processor.createException("Limitless internalArgument is only allowed as the last internalArgument"); + return invalid("Limitless internalArgument is only allowed as the last internalArgument"); } // Unknown types by default throw if (argument instanceof UnknownInternalArgument) { - throw processor.createException("No internalArgument of type \"" + argument.getType().getName() + "\" registered"); + return invalid("No internalArgument of type \"" + argument.getType().getName() + "\" registered"); } - return true; + return valid(); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java index 65effa8e..4d3f3641 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java @@ -14,6 +14,8 @@ public interface CommandMeta { boolean isPresent(final @NotNull MetaKey metaKey); + public @Nullable CommandMeta getParentMeta(); + final class Builder { private final Map, Object> dataMap = new HashMap<>(); @@ -36,7 +38,7 @@ public void add(final @NotNull MetaKey metaKey) { } public CommandMeta build() { - return new ImmutableCommandMeta(Collections.unmodifiableMap(dataMap)); + return new ImmutableCommandMeta(parentMeta, Collections.unmodifiableMap(dataMap)); } } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java index 5eb19277..907a176a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java @@ -7,9 +7,14 @@ final class ImmutableCommandMeta implements CommandMeta { + private final CommandMeta parentMeta; private final Map, Object> meta; - public ImmutableCommandMeta(final @NotNull Map, Object> meta) { + public ImmutableCommandMeta( + final @Nullable CommandMeta parentMeta, + final @NotNull Map, Object> meta + ) { + this.parentMeta = parentMeta; this.meta = meta; } @@ -24,6 +29,11 @@ public boolean isPresent(final @NotNull MetaKey metaKey) { return meta.containsKey(metaKey); } + @Override + public @Nullable CommandMeta getParentMeta() { + return parentMeta; + } + @Override public String toString() { return "ImmutableCommandMeta{" + diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java index ca718d91..9ec17977 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java @@ -7,7 +7,7 @@ import java.util.Set; -public interface SenderExtension { +public interface SenderExtension { @NotNull Set> getAllowedSenders(); @@ -17,5 +17,5 @@ boolean validate( final @NotNull S sender ); - @Nullable S map(final @NotNull DS defaultSender); + @Nullable S map(final @NotNull D defaultSender); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java index 5027c5c3..e93f2b42 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java @@ -29,13 +29,13 @@ /** * Interface for mapping a default send into a custom sender. * - * @param The type of the default sender. + * @param The type of the default sender. * @param The type of the custom sender. */ @FunctionalInterface -public interface SenderMapper { +public interface SenderMapper { - @Nullable S map(final @NotNull DS defaultSender); + @Nullable S map(final @NotNull D defaultSender); static @NotNull SenderMapper defaultMapper() { return defaultMapper -> defaultMapper; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index ed03a544..7bc0f751 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -31,11 +31,6 @@ import dev.triumphteam.cmd.core.annotations.Join; import dev.triumphteam.cmd.core.annotations.Optional; import dev.triumphteam.cmd.core.annotations.Split; -import dev.triumphteam.cmd.core.extention.CommandExtensions; -import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; -import dev.triumphteam.cmd.core.extention.annotation.AnnotationTarget; -import dev.triumphteam.cmd.core.extention.meta.CommandMeta; -import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; import dev.triumphteam.cmd.core.argument.ArgumentResolver; import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; import dev.triumphteam.cmd.core.argument.EnumInternalArgument; @@ -45,6 +40,11 @@ import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; +import dev.triumphteam.cmd.core.extention.annotation.AnnotationTarget; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.EnumSuggestion; @@ -59,6 +59,7 @@ import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; @@ -140,6 +141,14 @@ public static void processAnnotations( } } + public static void processCommandMethod( + final @NotNull CommandExtensions extensions, + final @NotNull Method method, + final @NotNull CommandMeta.Builder meta + ) { + extensions.getCommandMethodProcessors().forEach(it -> it.process(method, meta)); + } + protected @NotNull CommandMeta getParentMeta() { return parentMeta; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index 68b3a79a..2b410094 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -29,6 +29,7 @@ import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.annotation.AnnotationTarget; +import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; @@ -82,6 +83,7 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { final CommandMeta.Builder meta = new CommandMeta.Builder(getParentMeta()); // Process all the class annotations processAnnotations(getCommandExtensions(), method, AnnotationTarget.COMMAND, meta); + processCommandMethod(getCommandExtensions(), method, meta); // Return modified meta return meta.build(); } @@ -148,9 +150,22 @@ public Class senderType() { i ); - // If validation is false ignore it - if (!getCommandExtensions().getArgumentValidator().validate(this, argument, i, last)) continue; + // Validating the argument + final CommandMeta meta = parameterMetas.get(parameter); + if (meta == null) { + throw createException("An error occurred while getting parameter meta data for parameter " + parameter.getName()); + } + final ArgumentValidationResult result = getCommandExtensions().getArgumentValidator().validate(meta, argument, i, last); + + // If the result is invalid we throw the exception with the passed message + if (result instanceof ArgumentValidationResult.Invalid) { + throw createException(((ArgumentValidationResult.Invalid) result).getMessage()); + } + + // If it's ignorable we ignore it and don't add to the argument list + if (result instanceof ArgumentValidationResult.Ignore) continue; + // If valid argument then add to list arguments.add(argument); } diff --git a/kotlin-extras/build.gradle.kts b/kotlin/build.gradle.kts similarity index 81% rename from kotlin-extras/build.gradle.kts rename to kotlin/build.gradle.kts index 9fe2dfd1..3a1bf17a 100644 --- a/kotlin-extras/build.gradle.kts +++ b/kotlin/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } dependencies { - api(project(":triumph-cmd-core")) + api(projects.triumphCmdCore) api(kotlin("stdlib")) } @@ -12,4 +12,4 @@ tasks { kotlin { explicitApi() } -} \ No newline at end of file +} diff --git a/kotlin/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt b/kotlin/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt new file mode 100644 index 00000000..2c4e342d --- /dev/null +++ b/kotlin/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt @@ -0,0 +1,72 @@ +package dev.triumphteam.cmds + +import dev.triumphteam.cmd.core.argument.InternalArgument +import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument +import dev.triumphteam.cmd.core.argument.UnknownInternalArgument +import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult +import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator +import dev.triumphteam.cmd.core.extention.argument.CommandMethodProcessor +import dev.triumphteam.cmd.core.extention.meta.CommandMeta +import dev.triumphteam.cmd.core.extention.meta.MetaKey +import java.lang.reflect.Method +import kotlin.coroutines.Continuation + +public class CoroutinesCommandExtension : CommandMethodProcessor, ArgumentValidator { + + private companion object { + /** The key that'll represent a suspending function. */ + private val SUSPEND_META_KEY: MetaKey = MetaKey.of("suspend", Unit::class.java) + } + + /** Simply processing if the [method] contains a [Continuation], if so, we're dealing with a suspend function. */ + override fun process(method: Method, meta: CommandMeta.Builder) { + if (method.parameterTypes.none(Continuation::class.java::equals)) return + // Marks the function as suspending + // We don't really care about the value it passes + meta.add(SUSPEND_META_KEY, Unit) + } + + /** Validation uses the same as the defaults but with an addition modification to allow [Continuation]. */ + override fun validate( + meta: CommandMeta, + argument: InternalArgument, + position: Int, + last: Int, + ): ArgumentValidationResult { + // If we're dealing with a suspending function, the meta will be present + val suspend = meta.parentMeta?.isPresent(SUSPEND_META_KEY) ?: false + + // If we're dealing with a suspending function, the visible "last" argument is one position less, because + // the last one is always a Continuation + val suspendLast = if (suspend) last - 1 else last + + // Validation for optionals + if (position != suspendLast && argument.isOptional) { + return invalid("Optional internalArgument is only allowed as the last internalArgument") + } + + // Validation for limitless + if (position != suspendLast && argument is LimitlessInternalArgument<*>) { + return invalid("Limitless internalArgument is only allowed as the last internalArgument") + } + + // A continuation found + if (argument.type == Continuation::class.java) { + // Continuation is not allowed as an argument + if (position != last) { + return invalid("Kotlin continuation is not allowed as an argument, make the function suspend instead") + } + + // We ignore this type for execution later + return ignore() + } + + // Could not find the type registered + if (argument is UnknownInternalArgument<*>) { + return invalid("No internalArgument of type \"" + argument.getType().name + "\" registered") + } + + // If everything goes well, we now have valid argument + return valid() + } +} diff --git a/kotlin-extras/src/main/kotlin/dev/triumphteam/cmds/kotlin/Flags.kt b/kotlin/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt similarity index 97% rename from kotlin-extras/src/main/kotlin/dev/triumphteam/cmds/kotlin/Flags.kt rename to kotlin/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt index 5be27bdd..4174a686 100644 --- a/kotlin-extras/src/main/kotlin/dev/triumphteam/cmds/kotlin/Flags.kt +++ b/kotlin/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmds.kotlin +package dev.triumphteam.cmds import dev.triumphteam.cmd.core.flag.Flags diff --git a/kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt b/kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt new file mode 100644 index 00000000..9256dbbe --- /dev/null +++ b/kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt @@ -0,0 +1,9 @@ +package dev.triumphteam.cmds + +import dev.triumphteam.cmd.core.extention.ExtensionBuilder + +public fun > B.useCoroutines() { + val kotlinArgumentExtension = CoroutinesCommandExtension() + addCommandMethodProcessor(kotlinArgumentExtension) + setArgumentValidator(kotlinArgumentExtension) +} diff --git a/settings.gradle.kts b/settings.gradle.kts index f6a38440..bee034c1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,14 +9,14 @@ rootProject.name = "triumph-cmd" listOf( "core", - "kotlin-extras", + "kotlin", "simple" ).forEach(::includeProject) listOf( // "minecraft/bukkit", "discord/jda-common", - "discord/jda-prefixed", + // "discord/jda-prefixed", // "discord/jda-slash", ).forEach { val (folder, name) = it.split('/') diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 1f7171f8..ef1e3727 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -28,8 +28,7 @@ import dev.triumphteam.cmd.core.execution.AsyncExecutionProvider; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.execution.SyncExecutionProvider; -import dev.triumphteam.cmd.core.extention.CommandExtensions; -import dev.triumphteam.cmd.core.extention.ExtensionBuilder; +import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; @@ -50,13 +49,13 @@ public final class SimpleCommandManager extends CommandManager { private final ExecutionProvider syncExecutionProvider = new SyncExecutionProvider(); private final ExecutionProvider asyncExecutionProvider = new AsyncExecutionProvider(); - private SimpleCommandManager(final @NotNull CommandExtensions commandExtensions) { - super(commandExtensions); + private SimpleCommandManager(final @NotNull CommandOptions commandOptions) { + super(commandOptions); } @Contract("_ -> new") - public static @NotNull SimpleCommandManager create(final @NotNull Consumer> builder) { - final SimpleExtensionBuilder extensionBuilder = new SimpleExtensionBuilder<>(); + public static @NotNull SimpleCommandManager create(final @NotNull Consumer> builder) { + final SimpleCommandOptions.Builder extensionBuilder = new SimpleCommandOptions.Builder<>(); builder.accept(extensionBuilder); return new SimpleCommandManager<>(extensionBuilder.build()); } @@ -66,7 +65,7 @@ public void registerCommand(final @NotNull BaseCommand baseCommand) { final SimpleCommandProcessor processor = new SimpleCommandProcessor<>( baseCommand, getRegistryContainer(), - getCommandExtensions() + getCommandOptions().getCommandExtensions() ); final String name = processor.getName(); diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java new file mode 100644 index 00000000..244bfdac --- /dev/null +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java @@ -0,0 +1,27 @@ +package dev.triumphteam.cmds.simple; + +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.CommandOptions; +import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; +import org.jetbrains.annotations.NotNull; + +public final class SimpleCommandOptions extends CommandOptions { + + public SimpleCommandOptions(final @NotNull CommandExtensions commandExtensions) { + super(commandExtensions); + } + + public static final class Builder extends CommandOptions.Builder, Builder> { + + public Builder() { + super(builder -> { + builder.setArgumentValidator(new DefaultArgumentValidator<>()); + }); + } + + @Override + public @NotNull SimpleCommandOptions build() { + return new SimpleCommandOptions<>(getCommandExtensions()); + } + } +} diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java deleted file mode 100644 index 3a15f4b8..00000000 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleExtensionBuilder.java +++ /dev/null @@ -1,22 +0,0 @@ -package dev.triumphteam.cmds.simple; - -import dev.triumphteam.cmd.core.annotations.Async; -import dev.triumphteam.cmd.core.extention.CommandExtensions; -import dev.triumphteam.cmd.core.extention.defaults.AsyncAnnotationProcessor; -import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; -import dev.triumphteam.cmd.core.extention.ExtensionBuilder; -import org.jetbrains.annotations.NotNull; - -final class SimpleExtensionBuilder extends ExtensionBuilder { - - @Override - public @NotNull CommandExtensions build() { - addAnnotationProcessor(Async.class, new AsyncAnnotationProcessor()); - return new CommandExtensions<>( - getAnnotationProcessors(), - getArgumentProcessors(), - getSenderExtension(null), - getArgumentValidator(new DefaultArgumentValidator<>()) - ); - } -} From ef5340987d8d893ea926f5f12fd7ab2365e652b3 Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Tue, 27 Dec 2022 01:30:17 +0000 Subject: [PATCH 032/101] chore: Make command processor extension available for all types --- .../triumphteam/cmd/core/command/Command.java | 3 +- .../cmd/core/command/ParentCommand.java | 8 +- .../cmd/core/command/ParentSubCommand.java | 20 +++-- .../cmd/core/command/SubCommand.java | 7 ++ .../cmd/core/extention/CommandExtensions.java | 12 +-- .../cmd/core/extention/ExtensionBuilder.java | 10 +-- .../annotation/AnnotationProcessor.java | 2 +- ...tationTarget.java => ProcessorTarget.java} | 2 +- .../argument/CommandMetaProcessor.java | 16 ++++ .../argument/CommandMethodProcessor.java | 14 ---- .../defaults/AsyncAnnotationProcessor.java | 6 +- .../processor/AbstractCommandProcessor.java | 40 ---------- .../AbstractRootCommandProcessor.java | 52 ++++++++----- .../cmd/core/processor/CommandProcessor.java | 44 +++++++++++ .../processor/ParentCommandProcessor.java | 73 +++++++++++++++++++ .../core/processor/SubCommandProcessor.java | 37 +++------- .../cmds/CoroutinesCommandExtension.kt | 16 ++-- .../kotlin/dev/triumphteam/cmds/OptionsExt.kt | 2 +- .../cmds/simple/SimpleCommand.java | 13 ++-- 19 files changed, 236 insertions(+), 141 deletions(-) rename core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/{AnnotationTarget.java => ProcessorTarget.java} (98%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMetaProcessor.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMethodProcessor.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index d3b3c74e..39d2e789 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -24,8 +24,9 @@ package dev.triumphteam.cmd.core.command; import dev.triumphteam.cmd.core.extention.meta.CommandMetaContainer; +import org.jetbrains.annotations.NotNull; public interface Command extends CommandMetaContainer { - + @NotNull String getName(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index 0433a548..5196fb13 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -36,15 +36,13 @@ */ public interface ParentCommand extends Command { + @NotNull String getName(); + @NotNull Map> getCommands(); @NotNull Map> getCommandAliases(); - void addSubCommand( - final @NotNull String name, - final @NotNull Command subCommand, - final boolean isAlias - ); + void addSubCommand(final @NotNull Command subCommand, final boolean isAlias); default @Nullable Command getSubCommand(final @NotNull List args) { Command subCommand = getDefaultSubCommand(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 38c725ea..5ab848b3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -1,6 +1,7 @@ package dev.triumphteam.cmd.core.command; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.processor.ParentCommandProcessor; import org.jetbrains.annotations.NotNull; import java.util.HashMap; @@ -11,17 +12,24 @@ public class ParentSubCommand implements ParentCommand { private final Map> commands = new HashMap<>(); private final Map> commandAliases = new HashMap<>(); + private final String name; private final CommandMeta meta; - public ParentSubCommand(final @NotNull CommandMeta meta) {this.meta = meta;} + public ParentSubCommand( + final @NotNull ParentCommandProcessor processor + ) { + this.name = processor.getName(); + this.meta = processor.createMeta(); + } @Override - public void addSubCommand( - final @NotNull String name, - final @NotNull Command subCommand, - final boolean isAlias - ) { + public void addSubCommand(final @NotNull Command subCommand, final boolean isAlias) { + commands.put(subCommand.getName(), subCommand); + } + @Override + public @NotNull String getName() { + return name; } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 87497ae3..a76266ff 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -12,11 +12,13 @@ public class SubCommand implements Command { private final List> arguments; private final Class senderType; + private final String name; private final CommandMeta meta; public SubCommand( final @NotNull SubCommandProcessor processor ) { + this.name = processor.getName(); this.meta = processor.createMeta(); this.senderType = processor.senderType(); this.arguments = processor.arguments(meta); @@ -28,4 +30,9 @@ public SubCommand( public @NotNull CommandMeta getMeta() { return meta; } + + @Override + public @NotNull String getName() { + return name; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java index f4c4e976..7a2b4aa6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java @@ -2,7 +2,7 @@ import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; -import dev.triumphteam.cmd.core.extention.argument.CommandMethodProcessor; +import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.NotNull; @@ -13,19 +13,19 @@ public final class CommandExtensions { private final Map, AnnotationProcessor> annotationProcessors; - private final List commandMethodProcessors; + private final List commandMetaProcessors; private final SenderExtension senderExtension; private final ArgumentValidator argumentValidator; public CommandExtensions( final @NotNull Map, AnnotationProcessor> annotationProcessors, - final @NotNull List commandMethodProcessors, + final @NotNull List commandMetaProcessors, final @NotNull SenderExtension senderExtension, final @NotNull ArgumentValidator argumentValidator ) { this.annotationProcessors = annotationProcessors; - this.commandMethodProcessors = commandMethodProcessors; + this.commandMetaProcessors = commandMetaProcessors; this.senderExtension = senderExtension; this.argumentValidator = argumentValidator; } @@ -34,8 +34,8 @@ public CommandExtensions( return annotationProcessors; } - public @NotNull List getCommandMethodProcessors() { - return commandMethodProcessors; + public @NotNull List getCommandMetaProcessors() { + return commandMetaProcessors; } public @NotNull SenderExtension getSenderExtension() { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java index 1488e6c4..314ef620 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java @@ -3,7 +3,7 @@ import dev.triumphteam.cmd.core.exceptions.TriumphCmdException; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; -import dev.triumphteam.cmd.core.extention.argument.CommandMethodProcessor; +import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -17,7 +17,7 @@ public final class ExtensionBuilder { private final Map, AnnotationProcessor> annotationProcessors = new HashMap<>(); - private final List commandMethodProcessors = new ArrayList<>(); + private final List commandMetaProcessors = new ArrayList<>(); private SenderExtension senderExtension; private ArgumentValidator argumentValidator; @@ -32,8 +32,8 @@ public final class ExtensionBuilder { } @Contract("_ -> this") - public @NotNull ExtensionBuilder addCommandMethodProcessor(final @NotNull CommandMethodProcessor commandMethodProcessor) { - commandMethodProcessors.add(commandMethodProcessor); + public @NotNull ExtensionBuilder addCommandMetaProcessor(final @NotNull CommandMetaProcessor commandMetaProcessor) { + commandMetaProcessors.add(commandMetaProcessor); return this; } @@ -60,7 +60,7 @@ public final class ExtensionBuilder { return new CommandExtensions<>( annotationProcessors, - commandMethodProcessors, + commandMetaProcessors, senderExtension, argumentValidator ); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java index 64a57f72..c533d99b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java @@ -9,7 +9,7 @@ public interface AnnotationProcessor { void process( final @NotNull A annotation, - final @NotNull AnnotationTarget target, + final @NotNull ProcessorTarget target, final @NotNull CommandMeta.Builder meta ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationTarget.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/ProcessorTarget.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationTarget.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/ProcessorTarget.java index 09ca1a2b..b44b51d3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationTarget.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/ProcessorTarget.java @@ -7,7 +7,7 @@ /** * The target for the custom annotation processing. */ -public enum AnnotationTarget { +public enum ProcessorTarget { /** * The original command, normally the {@link Class} that extends {@link BaseCommand} or a child of it. diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMetaProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMetaProcessor.java new file mode 100644 index 00000000..c8a0532c --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMetaProcessor.java @@ -0,0 +1,16 @@ +package dev.triumphteam.cmd.core.extention.argument; + +import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.AnnotatedElement; + +public interface CommandMetaProcessor { + + void process( + final @NotNull AnnotatedElement method, + final @NotNull ProcessorTarget target, + final @NotNull CommandMeta.Builder meta + ); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMethodProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMethodProcessor.java deleted file mode 100644 index ef0ede67..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMethodProcessor.java +++ /dev/null @@ -1,14 +0,0 @@ -package dev.triumphteam.cmd.core.extention.argument; - -import dev.triumphteam.cmd.core.extention.meta.CommandMeta; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Method; - -public interface CommandMethodProcessor { - - void process( - final @NotNull Method method, - final @NotNull CommandMeta.Builder meta - ); -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java index 698c26b4..6b622746 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java @@ -2,7 +2,7 @@ import dev.triumphteam.cmd.core.annotations.Async; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; -import dev.triumphteam.cmd.core.extention.annotation.AnnotationTarget; +import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; @@ -11,10 +11,10 @@ public final class AsyncAnnotationProcessor implements AnnotationProcessor implements CommandProcessor { this.argumentRegistry = registryContainer.getArgumentRegistry(); } - /** - * Process all annotations for the specific {@link AnnotatedElement}. - * - * @param extensions The main extensions to get the processors from. - * @param element The annotated element to process its annotations. - * @param target The target of the annotation. - * @param meta The meta builder that'll be passed to processors. - */ - public static void processAnnotations( - final @NotNull CommandExtensions extensions, - final @NotNull AnnotatedElement element, - final @NotNull AnnotationTarget target, - final @NotNull CommandMeta.Builder meta - ) { - final Map, AnnotationProcessor> processors - = extensions.getAnnotationProcessors(); - - for (final Annotation annotation : element.getAnnotations()) { - @SuppressWarnings("rawtypes") final AnnotationProcessor annotationProcessor - = processors.get(annotation.annotationType()); - - // No processors available - if (annotationProcessor == null) continue; - - annotationProcessor.process(annotation, target, meta); - } - } - - public static void processCommandMethod( - final @NotNull CommandExtensions extensions, - final @NotNull Method method, - final @NotNull CommandMeta.Builder meta - ) { - extensions.getCommandMethodProcessors().forEach(it -> it.process(method, meta)); - } - protected @NotNull CommandMeta getParentMeta() { return parentMeta; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java index ad92ebf7..36b7b4b9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java @@ -26,10 +26,11 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.annotations.Description; import dev.triumphteam.cmd.core.command.Command; +import dev.triumphteam.cmd.core.command.ParentSubCommand; import dev.triumphteam.cmd.core.command.SubCommand; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.CommandExtensions; -import dev.triumphteam.cmd.core.extention.annotation.AnnotationTarget; +import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import org.jetbrains.annotations.Contract; @@ -40,10 +41,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import static dev.triumphteam.cmd.core.processor.AbstractCommandProcessor.processAnnotations; @SuppressWarnings("unchecked") public abstract class AbstractRootCommandProcessor implements CommandProcessor { @@ -89,7 +86,9 @@ public String getDescription() { public @NotNull CommandMeta createMeta() { final CommandMeta.Builder meta = new CommandMeta.Builder(null); // Process all the class annotations - processAnnotations(commandExtensions, baseCommand.getClass(), AnnotationTarget.ROOT_COMMAND, meta); + final Class klass = baseCommand.getClass(); + processAnnotations(commandExtensions, klass, ProcessorTarget.ROOT_COMMAND, meta); + processCommandMeta(commandExtensions, klass, ProcessorTarget.PARENT_COMMAND, meta); // Return modified meta return meta.build(); } @@ -108,9 +107,10 @@ public String getDescription() { final @NotNull CommandMeta parentMeta, final @NotNull Method[] methods ) { - return Arrays.stream(methods).map(method -> { + final List> commands = new ArrayList<>(); + for (final Method method : methods) { // Ignore non-public methods - if (!Modifier.isPublic(method.getModifiers())) return null; + if (!Modifier.isPublic(method.getModifiers())) continue; final SubCommandProcessor processor = new SubCommandProcessor<>( name, @@ -122,33 +122,47 @@ public String getDescription() { ); // Not a command, ignore the method - if (processor.getName() == null) return null; + if (processor.getName() == null) continue; + + // Add new command + commands.add(new SubCommand<>(processor)); + } - return new SubCommand<>(processor); - }).filter(Objects::nonNull).collect(Collectors.toList()); + return commands; } private @NotNull List> classCommands( final @NotNull CommandMeta parentMeta, final @NotNull Class[] classes ) { - final List> subCommands = new ArrayList<>(); + final List> commands = new ArrayList<>(); for (final Class klass : classes) { // Ignore non-public methods if (!Modifier.isPublic(klass.getModifiers())) continue; - final String name = ""; + final ParentCommandProcessor processor = new ParentCommandProcessor<>( + name, + baseCommand, + klass, + registryContainer, + commandExtensions, + parentMeta + ); + // Not a command, ignore the method - if (name == null) continue; + if (processor.getName() == null) continue; + + final ParentSubCommand parent = new ParentSubCommand<>(processor); - System.out.println("Sub boy -> " + name); + // Add children commands to parent + methodCommands(parent.getMeta(), klass.getDeclaredMethods()).forEach(it -> parent.addSubCommand(it, false)); + classCommands(parent.getMeta(), klass.getDeclaredClasses()).forEach(it -> parent.addSubCommand(it, false)); - // TODO THIS NEEDS TO BE A NEW META FROM PARENT, NOT CURRENT PARENT - subCommands.addAll(methodCommands(parentMeta, klass.getDeclaredMethods())); - subCommands.addAll(classCommands(parentMeta, klass.getDeclaredClasses())); + // Add parent command to main list + commands.add(parent); } - return subCommands; + return commands; } private @NotNull String nameOf() { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index 7121070a..18dd4b3e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -1,9 +1,53 @@ package dev.triumphteam.cmd.core.processor; +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; +import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; +import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; +import java.util.Map; + public interface CommandProcessor { @NotNull CommandMeta createMeta(); + + /** + * Process all annotations for the specific {@link AnnotatedElement}. + * + * @param extensions The main extensions to get the processors from. + * @param element The annotated element to process its annotations. + * @param target The target of the annotation. + * @param meta The meta builder that'll be passed to processors. + */ + default void processAnnotations( + final @NotNull CommandExtensions extensions, + final @NotNull AnnotatedElement element, + final @NotNull ProcessorTarget target, + final @NotNull CommandMeta.Builder meta + ) { + final Map, AnnotationProcessor> processors + = extensions.getAnnotationProcessors(); + + for (final Annotation annotation : element.getAnnotations()) { + @SuppressWarnings("rawtypes") final AnnotationProcessor annotationProcessor + = processors.get(annotation.annotationType()); + + // No processors available + if (annotationProcessor == null) continue; + + annotationProcessor.process(annotation, target, meta); + } + } + + default void processCommandMeta( + final @NotNull CommandExtensions extensions, + final @NotNull AnnotatedElement element, + final @NotNull ProcessorTarget target, + final @NotNull CommandMeta.Builder meta + ) { + extensions.getCommandMetaProcessors().forEach(it -> it.process(element, target, meta)); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java new file mode 100644 index 00000000..ca1b28e6 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java @@ -0,0 +1,73 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.processor; + +import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import org.jetbrains.annotations.NotNull; + +/** + * Abstracts most of the "extracting" from sub command annotations, allows for extending. + *
+ * I know this could be done better, but couldn't think of a better way. + * If you do please PR or let me know on my discord! + * + * @param The sender type. + */ +@SuppressWarnings("unchecked") +public final class ParentCommandProcessor extends AbstractCommandProcessor { + + private final Class klass; + + ParentCommandProcessor( + final @NotNull String parentName, + final @NotNull BaseCommand baseCommand, + final @NotNull Class klass, + final @NotNull RegistryContainer registryContainer, + final @NotNull CommandExtensions commandExtensions, + final @NotNull CommandMeta parentMeta + ) { + super(parentName, baseCommand, klass, registryContainer, commandExtensions, parentMeta); + + this.klass = klass; + } + + @Override + public @NotNull CommandMeta createMeta() { + final CommandMeta.Builder meta = new CommandMeta.Builder(getParentMeta()); + // Process all the class annotations + processAnnotations(getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); + processCommandMeta(getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); + // Return modified meta + return meta.build(); + } + + public InternalArgument argument(final @NotNull CommandMeta parentMeta) { + return null; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index 2b410094..538ac4f0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -28,7 +28,7 @@ import dev.triumphteam.cmd.core.annotations.Suggestions; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.extention.CommandExtensions; -import dev.triumphteam.cmd.core.extention.annotation.AnnotationTarget; +import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; @@ -82,8 +82,8 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { public @NotNull CommandMeta createMeta() { final CommandMeta.Builder meta = new CommandMeta.Builder(getParentMeta()); // Process all the class annotations - processAnnotations(getCommandExtensions(), method, AnnotationTarget.COMMAND, meta); - processCommandMethod(getCommandExtensions(), method, meta); + processAnnotations(getCommandExtensions(), method, ProcessorTarget.COMMAND, meta); + processCommandMeta(getCommandExtensions(), method, ProcessorTarget.COMMAND, meta); // Return modified meta return meta.build(); } @@ -94,7 +94,7 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { * * @return The validated sender type. */ - public Class senderType() { + public @NotNull Class senderType() { final Parameter[] parameters = method.getParameters(); if (parameters.length == 0) { throw createException("Sender parameter missing"); @@ -117,14 +117,14 @@ public Class senderType() { return (Class) type; } - public List> arguments(final @NotNull CommandMeta parentMeta) { + public @NotNull List> arguments(final @NotNull CommandMeta parentMeta) { final Parameter[] parameters = method.getParameters(); // First thing is to process the parameter annotations final Map parameterMetas = new HashMap<>(); for (final Parameter parameter : parameters) { final CommandMeta.Builder meta = new CommandMeta.Builder(parentMeta); - processAnnotations(getCommandExtensions(), parameter, AnnotationTarget.ARGUMENT, meta); + processAnnotations(getCommandExtensions(), parameter, ProcessorTarget.ARGUMENT, meta); parameterMetas.put(parameter, meta.build()); } @@ -177,16 +177,16 @@ public Class senderType() { * * @return A list with the descriptions ordered by parameter order. */ - private List argDescriptionFromMethodAnnotation() { + private @NotNull List argDescriptionFromMethodAnnotation() { final ArgDescriptions argDescriptions = method.getAnnotation(ArgDescriptions.class); if (argDescriptions == null) return Collections.emptyList(); return Arrays.asList(argDescriptions.value()); } - public Map> suggestionsFromMethodAnnotation() { + public @NotNull Map> suggestionsFromMethodAnnotation() { final Map> map = new HashMap<>(); - @NotNull List suggestionsFromAnnotations = getSuggestionsFromAnnotations(); + final List suggestionsFromAnnotations = getSuggestionsFromAnnotations(); for (int i = 0; i < suggestionsFromAnnotations.size(); i++) { final dev.triumphteam.cmd.core.annotations.Suggestion suggestion = suggestionsFromAnnotations.get(i); final String key = suggestion.value(); @@ -203,25 +203,6 @@ public Map> suggestionsFromMethodAnnotation() { return map; } - /** - * Extract all suggestions from the parameters. - * Adds the suggestions to the passed list. - */ - private void extractSuggestionFromParams() { - // TODO SUGGESTIONS - /*final Parameter[] parameters = annotatedElement.getParameters(); - for (int i = 1; i < parameters.length; i++) { - final Parameter parameter = parameters[i]; - - final dev.triumphteam.cmd.core.annotation.Suggestion suggestion = parameter.getAnnotation(dev.triumphteam.cmd.core.annotation.Suggestion.class); - final SuggestionKey suggestionKey = suggestion == null ? null : SuggestionKey.of(suggestion.value()); - - final Class type = getGenericType(parameter); - final int addIndex = i - 1; - setOrAddSuggestion(addIndex, createSuggestion(suggestionKey, type)); - }*/ - } - private @NotNull List getSuggestionsFromAnnotations() { final Suggestions requirements = method.getAnnotation(Suggestions.class); if (requirements != null) return Arrays.asList(requirements.value()); diff --git a/kotlin/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt b/kotlin/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt index 2c4e342d..b264fd64 100644 --- a/kotlin/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt +++ b/kotlin/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt @@ -3,24 +3,30 @@ package dev.triumphteam.cmds import dev.triumphteam.cmd.core.argument.InternalArgument import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument import dev.triumphteam.cmd.core.argument.UnknownInternalArgument +import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator -import dev.triumphteam.cmd.core.extention.argument.CommandMethodProcessor +import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor import dev.triumphteam.cmd.core.extention.meta.CommandMeta import dev.triumphteam.cmd.core.extention.meta.MetaKey +import java.lang.reflect.AnnotatedElement import java.lang.reflect.Method import kotlin.coroutines.Continuation -public class CoroutinesCommandExtension : CommandMethodProcessor, ArgumentValidator { +public class CoroutinesCommandExtension : CommandMetaProcessor, ArgumentValidator { private companion object { /** The key that'll represent a suspending function. */ private val SUSPEND_META_KEY: MetaKey = MetaKey.of("suspend", Unit::class.java) } - /** Simply processing if the [method] contains a [Continuation], if so, we're dealing with a suspend function. */ - override fun process(method: Method, meta: CommandMeta.Builder) { - if (method.parameterTypes.none(Continuation::class.java::equals)) return + /** Simply processing if the [element] contains a [Continuation], if so, we're dealing with a suspend function. */ + override fun process(element: AnnotatedElement, target: ProcessorTarget, meta: CommandMeta.Builder) { + if (element !is Method) return + // Not really necessary but doesn't hurt to check + if (target != ProcessorTarget.COMMAND) return + + if (element.parameterTypes.none(Continuation::class.java::equals)) return // Marks the function as suspending // We don't really care about the value it passes meta.add(SUSPEND_META_KEY, Unit) diff --git a/kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt b/kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt index 9256dbbe..19252f6c 100644 --- a/kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt +++ b/kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt @@ -4,6 +4,6 @@ import dev.triumphteam.cmd.core.extention.ExtensionBuilder public fun > B.useCoroutines() { val kotlinArgumentExtension = CoroutinesCommandExtension() - addCommandMethodProcessor(kotlinArgumentExtension) + addCommandMetaProcessor(kotlinArgumentExtension) setArgumentValidator(kotlinArgumentExtension) } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index 61140bf8..dc5552cf 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -75,12 +75,8 @@ public void execute( } @Override - public void addSubCommand( - final @NotNull String name, - final @NotNull Command subCommand, - final boolean isAlias - ) { - subCommands.put(name, subCommand); + public @NotNull String getName() { + return null; } @Override @@ -93,6 +89,11 @@ public void addSubCommand( return subCommandAliases; } + @Override + public void addSubCommand(final @NotNull Command subCommand, final boolean isAlias) { + + } + @Override public @NotNull CommandMeta getMeta() { return meta; From e347fb06807d8b9e09422ca4142f2a02a9a3cee3 Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Tue, 27 Dec 2022 12:37:32 +0000 Subject: [PATCH 033/101] chore: Reorganizing kotlin modules --- gradle/libs.versions.toml | 6 ++++++ kotlin/{ => coroutines}/build.gradle.kts | 8 ++------ .../cmds/CoroutinesCommandExtension.kt | 7 +++++++ kotlin/extensions/build.gradle.kts | 9 +++++++++ .../kotlin/dev/triumphteam/cmds/FlagsExt.kt | 0 .../kotlin/dev/triumphteam/cmds/OptionsExt.kt | 9 --------- settings.gradle.kts | 18 +++++++++--------- 7 files changed, 33 insertions(+), 24 deletions(-) rename kotlin/{ => coroutines}/build.gradle.kts (75%) rename kotlin/{ => coroutines}/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt (92%) create mode 100644 kotlin/extensions/build.gradle.kts rename kotlin/{ => extensions}/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt (100%) delete mode 100644 kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9577c8ca..a1572510 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,8 @@ [versions] +# kotlin kotlin = "1.7.21" +coroutines = "1.6.4" + license = "0.16.1" # Core @@ -37,6 +40,9 @@ spigot = { module = "org.spigotmc:spigot-api", version.ref = "spigot" } # Discord jda = { module = "net.dv8tion:JDA", version.ref = "jda" } +# Kotlin +coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" } + # build build-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } build-license = { module = "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin", version.ref = "license" } diff --git a/kotlin/build.gradle.kts b/kotlin/coroutines/build.gradle.kts similarity index 75% rename from kotlin/build.gradle.kts rename to kotlin/coroutines/build.gradle.kts index 3a1bf17a..9a0a39f2 100644 --- a/kotlin/build.gradle.kts +++ b/kotlin/coroutines/build.gradle.kts @@ -6,10 +6,6 @@ plugins { dependencies { api(projects.triumphCmdCore) api(kotlin("stdlib")) -} - -tasks { - kotlin { - explicitApi() - } + api(kotlin("reflect")) + api(libs.coroutines) } diff --git a/kotlin/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt similarity index 92% rename from kotlin/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt rename to kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt index b264fd64..cf805bac 100644 --- a/kotlin/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt +++ b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt @@ -3,6 +3,7 @@ package dev.triumphteam.cmds import dev.triumphteam.cmd.core.argument.InternalArgument import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument import dev.triumphteam.cmd.core.argument.UnknownInternalArgument +import dev.triumphteam.cmd.core.extention.ExtensionBuilder import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator @@ -13,6 +14,12 @@ import java.lang.reflect.AnnotatedElement import java.lang.reflect.Method import kotlin.coroutines.Continuation +public fun > B.useCoroutines() { + val kotlinArgumentExtension = CoroutinesCommandExtension() + addCommandMetaProcessor(kotlinArgumentExtension) + setArgumentValidator(kotlinArgumentExtension) +} + public class CoroutinesCommandExtension : CommandMetaProcessor, ArgumentValidator { private companion object { diff --git a/kotlin/extensions/build.gradle.kts b/kotlin/extensions/build.gradle.kts new file mode 100644 index 00000000..386ca84a --- /dev/null +++ b/kotlin/extensions/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + id("cmds.base-conventions") + id("cmds.library-conventions") +} + +dependencies { + api(projects.triumphCmdCore) + api(kotlin("stdlib")) +} diff --git a/kotlin/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt b/kotlin/extensions/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt similarity index 100% rename from kotlin/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt rename to kotlin/extensions/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt diff --git a/kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt b/kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt deleted file mode 100644 index 19252f6c..00000000 --- a/kotlin/src/main/kotlin/dev/triumphteam/cmds/OptionsExt.kt +++ /dev/null @@ -1,9 +0,0 @@ -package dev.triumphteam.cmds - -import dev.triumphteam.cmd.core.extention.ExtensionBuilder - -public fun > B.useCoroutines() { - val kotlinArgumentExtension = CoroutinesCommandExtension() - addCommandMetaProcessor(kotlinArgumentExtension) - setArgumentValidator(kotlinArgumentExtension) -} diff --git a/settings.gradle.kts b/settings.gradle.kts index bee034c1..e8cf35e2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -9,18 +9,18 @@ rootProject.name = "triumph-cmd" listOf( "core", - "kotlin", "simple" ).forEach(::includeProject) listOf( - // "minecraft/bukkit", - "discord/jda-common", - // "discord/jda-prefixed", - // "discord/jda-slash", + // "minecraft/bukkit" to "bukkit", + "discord/jda-common" to "jda-common", + // "discord/jda-prefixed" to "jda-prefixed", + // "discord/jda-slash" to "jda-slash", + "kotlin/coroutines" to "kotlin-coroutines", + "kotlin/extensions" to "kotlin-extensions" ).forEach { - val (folder, name) = it.split('/') - includeProject(name, folder) + includeProjectFolders(it.first, it.second) } include("test-module") @@ -31,10 +31,10 @@ fun includeProject(name: String) { } } -fun includeProject(name: String, folder: String) { +fun includeProjectFolders(folder: String, name: String) { include(name) { this.name = "${rootProject.name}-$name" - this.projectDir = file("$folder/$name") + this.projectDir = file(folder) } } From 2b1442d296cb611d259ac9686d98c7d7d02d4dab Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Tue, 27 Dec 2022 12:41:09 +0000 Subject: [PATCH 034/101] chore: Hmm --- .../java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java index 21b6b7c3..c8aaf99c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java @@ -59,8 +59,6 @@ public FlagParser(final @NotNull FlagGroup flagGroup) { return new FlagsResult<>(sender, parsed.getKey(), parsed.getValue()); } - private List hi; - private Map.@NotNull Entry<@NotNull Map<@NotNull FlagOptions, @NotNull String>, @NotNull List<@NotNull String>> parseInternal(final @NotNull List<@NotNull String> toParse) { final FlagScanner tokens = new FlagScanner(toParse); From ab30b598074135bc79294a24a76406ab340c8f17 Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Tue, 27 Dec 2022 23:56:08 +0000 Subject: [PATCH 035/101] feature: New flags + argument parser --- .../core/argument/FlagInternalArgument.java | 8 +- .../core/argument/NamedInternalArgument.java | 6 +- .../cmd/core/{ => argument}/flag/FlagKey.java | 2 +- .../cmd/core/{ => argument}/flag/Flags.java | 2 +- .../internal/ArgFlagValue.java | 2 +- .../internal/EmptyFlagValue.java | 2 +- .../internal/FlagGroup.java | 2 +- .../internal/FlagOptions.java | 2 +- .../internal/FlagParser.java | 12 +- .../internal/FlagValidator.java | 2 +- .../internal/FlagValue.java | 2 +- .../internal/FlagsResult.java | 10 +- .../internal/ParserScanner.java} | 6 +- .../core/argument/named/ArgumentParser.java | 280 ++++++++++++++++++ .../cmd/core/argument/named/Arguments.java | 3 +- .../core/argument/named/FlagsContainer.java | 39 +++ .../argument/named/NamedArgumentParser.java | 95 ------ .../argument/named/NamedArgumentResult.java | 4 +- .../core/extention/registry/FlagRegistry.java | 2 +- .../OldAbstractSubCommandProcessor.java | 8 +- .../kotlin/dev/triumphteam/cmds/FlagsExt.kt | 2 +- 21 files changed, 358 insertions(+), 133 deletions(-) rename core/src/main/java/dev/triumphteam/cmd/core/{ => argument}/flag/FlagKey.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => argument}/flag/Flags.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{flag => argument}/internal/ArgFlagValue.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/{flag => argument}/internal/EmptyFlagValue.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{flag => argument}/internal/FlagGroup.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{flag => argument}/internal/FlagOptions.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{flag => argument}/internal/FlagParser.java (89%) rename core/src/main/java/dev/triumphteam/cmd/core/{flag => argument}/internal/FlagValidator.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/{flag => argument}/internal/FlagValue.java (95%) rename core/src/main/java/dev/triumphteam/cmd/core/{flag => argument}/internal/FlagsResult.java (92%) rename core/src/main/java/dev/triumphteam/cmd/core/{flag/internal/FlagScanner.java => argument/internal/ParserScanner.java} (93%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentParser.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/named/FlagsContainer.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java index 9b157767..5f9696d6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java @@ -23,10 +23,10 @@ */ package dev.triumphteam.cmd.core.argument; -import dev.triumphteam.cmd.core.flag.Flags; -import dev.triumphteam.cmd.core.flag.internal.FlagGroup; -import dev.triumphteam.cmd.core.flag.internal.FlagOptions; -import dev.triumphteam.cmd.core.flag.internal.FlagParser; +import dev.triumphteam.cmd.core.argument.flag.Flags; +import dev.triumphteam.cmd.core.argument.internal.FlagGroup; +import dev.triumphteam.cmd.core.argument.internal.FlagOptions; +import dev.triumphteam.cmd.core.argument.internal.FlagParser; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java index 03fbe7d9..54719a08 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.argument.named.Arguments; -import dev.triumphteam.cmd.core.argument.named.NamedArgumentParser; +import dev.triumphteam.cmd.core.argument.named.ArgumentParser; import dev.triumphteam.cmd.core.argument.named.NamedArgumentResult; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; @@ -54,7 +54,7 @@ public NamedInternalArgument( @Override public @NotNull Object resolve(final @NotNull S sender, final @NotNull List<@NotNull String> value) { - final Map parsedArgs = NamedArgumentParser.parse(String.join(" ", value)); + final Map parsedArgs = ArgumentParser.parse(String.join(" ", value)); final Map mapped = new HashMap<>(parsedArgs.size()); for (final Map.Entry entry : parsedArgs.entrySet()) { @@ -74,7 +74,7 @@ public NamedInternalArgument( final @NotNull List<@NotNull String> trimmed, final @NotNull SuggestionContext context ) { - final Map parsedArgs = NamedArgumentParser.parse(String.join(" ", trimmed)); + final Map parsedArgs = ArgumentParser.parse(String.join(" ", trimmed)); final String current = trimmed.get(trimmed.size() - 1); final List notUsed = arguments.keySet() diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/flag/FlagKey.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/flag/FlagKey.java index 9acd63cc..8eed0fe2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/FlagKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/flag/FlagKey.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag; +package dev.triumphteam.cmd.core.argument.flag; import dev.triumphteam.cmd.core.extention.StringKey; import org.jetbrains.annotations.Contract; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/Flags.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/flag/Flags.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/Flags.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/flag/Flags.java index d93d276a..1e21a565 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/Flags.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/flag/Flags.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag; +package dev.triumphteam.cmd.core.argument.flag; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ArgFlagValue.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ArgFlagValue.java index 1b51a418..90b8e735 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/ArgFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ArgFlagValue.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag.internal; +package dev.triumphteam.cmd.core.argument.internal; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/EmptyFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/EmptyFlagValue.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/internal/EmptyFlagValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/internal/EmptyFlagValue.java index e80786da..e31c3e8e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/EmptyFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/EmptyFlagValue.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag.internal; +package dev.triumphteam.cmd.core.argument.internal; public final class EmptyFlagValue implements FlagValue { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagGroup.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagGroup.java index bd988aa1..536e27d3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagGroup.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag.internal; +package dev.triumphteam.cmd.core.argument.internal; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagOptions.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagOptions.java index f908c5d1..d862c11c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagOptions.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag.internal; +package dev.triumphteam.cmd.core.argument.internal; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagParser.java similarity index 89% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagParser.java index c8aaf99c..21f868f1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagParser.java @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag.internal; +package dev.triumphteam.cmd.core.argument.internal; import com.google.common.collect.Maps; -import dev.triumphteam.cmd.core.flag.Flags; +import dev.triumphteam.cmd.core.argument.flag.Flags; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -50,17 +50,17 @@ public FlagParser(final @NotNull FlagGroup flagGroup) { this.flagGroup = flagGroup; } - public @NotNull Map<@NotNull FlagOptions, @NotNull String> parseFlags(final @NotNull List<@NotNull String> toParse) { + public @NotNull Map, String> parseFlags(final @NotNull List toParse) { return parseInternal(toParse).getKey(); } - public @NotNull Flags parse(final @NotNull S sender, final @NotNull List<@NotNull String> toParse) { + public @NotNull Flags parse(final @NotNull S sender, final @NotNull List toParse) { final Map.Entry, String>, List> parsed = parseInternal(toParse); return new FlagsResult<>(sender, parsed.getKey(), parsed.getValue()); } - private Map.@NotNull Entry<@NotNull Map<@NotNull FlagOptions, @NotNull String>, @NotNull List<@NotNull String>> parseInternal(final @NotNull List<@NotNull String> toParse) { - final FlagScanner tokens = new FlagScanner(toParse); + private Map.Entry, String>, List> parseInternal(final @NotNull List toParse) { + final ParserScanner tokens = new ParserScanner(toParse); final Map, String> flags = new LinkedHashMap<>(); final List args = new ArrayList<>(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValidator.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValidator.java index 4e6a2684..0ece16ac 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValidator.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag.internal; +package dev.triumphteam.cmd.core.argument.internal; import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValue.java similarity index 95% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValue.java index ae3994e3..76eb1b91 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValue.java @@ -21,6 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag.internal; +package dev.triumphteam.cmd.core.argument.internal; public interface FlagValue {} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagsResult.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagsResult.java similarity index 92% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagsResult.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagsResult.java index 26e312e5..eb04ff66 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagsResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagsResult.java @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag.internal; +package dev.triumphteam.cmd.core.argument.internal; -import dev.triumphteam.cmd.core.flag.Flags; +import dev.triumphteam.cmd.core.argument.flag.Flags; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,15 +45,15 @@ class FlagsResult implements Flags { FlagsResult( final @NotNull S sender, - final @NotNull Map<@NotNull FlagOptions, @NotNull String> flags, - final @NotNull List<@NotNull String> args + final @NotNull Map, String> flags, + final @NotNull List args ) { this.sender = sender; flags.forEach(this::addFlag); this.args = args; } - void addFlag(final @NotNull FlagOptions flag, final @Nullable String value) { + public void addFlag(final @NotNull FlagOptions flag, final @Nullable String value) { final String shortFlag = flag.getFlag(); final String longFlag = flag.getLongFlag(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagScanner.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ParserScanner.java similarity index 93% rename from core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagScanner.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ParserScanner.java index 22c312e2..4fa6dbda 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/flag/internal/FlagScanner.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ParserScanner.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.flag.internal; +package dev.triumphteam.cmd.core.argument.internal; import org.jetbrains.annotations.NotNull; @@ -30,14 +30,14 @@ /** * Simple util scanner for easier looping through the tokens. */ -public final class FlagScanner { +public final class ParserScanner { private final List tokens; private int pointer = -1; private String current = null; - public FlagScanner(final @NotNull List<@NotNull String> tokens) { + public ParserScanner(final @NotNull List<@NotNull String> tokens) { this.tokens = tokens; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentParser.java new file mode 100644 index 00000000..d8ee349f --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentParser.java @@ -0,0 +1,280 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.argument.named; + +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.argument.internal.FlagGroup; +import dev.triumphteam.cmd.core.argument.internal.FlagOptions; +import dev.triumphteam.cmd.core.argument.internal.ParserScanner; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.PrimitiveIterator; +import java.util.Set; + +public final class ArgumentParser { + + private static final int SPACE = ' '; + private static final int ESCAPE_CHAR = '\\'; + private static final int HYPHEN = '-'; + + private static final String LONG = "--"; + private static final String SHORT = "-"; + private static final String ESCAPE = "\\"; + + private static final int ARGUMENT_SEPARATOR = ':'; + private static final int FLAG_SEPARATOR = '='; + + private static final Set ESCAPABLE_CHARS = + Collections.unmodifiableSet(new HashSet<>(Arrays.asList(HYPHEN, ARGUMENT_SEPARATOR, FLAG_SEPARATOR))); + + private final FlagGroup flagGroup; + private final Map> namedArguments; + + public ArgumentParser( + final @NotNull FlagGroup flagGroup, + final @NotNull Map> namedArguments + ) { + this.flagGroup = flagGroup; + this.namedArguments = namedArguments; + } + + public static Map parse(final @NotNull String literal) { + final PrimitiveIterator.OfInt iterator = literal.chars().iterator(); + + final Map args = new LinkedHashMap<>(); + final StringBuilder builder = new StringBuilder(); + + // Control variables + boolean escape = false; + String argument = ""; + + while (iterator.hasNext()) { + final int current = iterator.next(); + + // Marks next character to be escaped + if (current == ESCAPE_CHAR && !argument.isEmpty()) { + escape = true; + continue; + } + + // Found a separator + if (current == ARGUMENT_SEPARATOR && argument.isEmpty()) { + argument = builder.toString(); + builder.setLength(0); + continue; + } + + // Handling for spaces + // TODO: Scape + if (current == SPACE) { + // If no argument is found, discard values + if (argument.isEmpty()) { + builder.setLength(0); + continue; + } + + // If argument is found, accept as value + args.put(argument, builder.toString()); + builder.setLength(0); + argument = ""; + continue; + } + + // If no escapable token was found, aka :, re-append the backslash + if (escape) { + builder.appendCodePoint(ESCAPE_CHAR); + escape = false; + } + + // Normal append character + builder.appendCodePoint(current); + } + + // If end of string is reached and value was not closed, close it + if (!argument.isEmpty()) args.put(argument, builder.toString()); + + return args; + } + + public void newParse(final @NotNull List arguments) { + final ParserScanner tokens = new ParserScanner(arguments); + + final Result result = new Result(); + + while (tokens.hasNext()) { + final String token = tokens.next(); + + // If escaping the flag then just, skip + if (token.startsWith(ESCAPE)) { + result.addNonToken(token); + continue; + } + + // Checks if it's a flag, if not then skip + if ((!token.startsWith(LONG) || LONG.equals(token)) && (!token.startsWith(SHORT) || SHORT.equals(token))) { + final int separator = token.indexOf(ARGUMENT_SEPARATOR); + + // Not a flag nor a named argument, so just ignore + if (separator == -1) { + result.addNonToken(token); + continue; + } + + // Splits the flag from `name:arg` + final String namedToken = token.substring(0, separator); + final String argToken = token.substring(separator + 1); + + final InternalArgument internalArgument = namedArguments.get(namedToken); + // If there is no valid argument we ignore it + if (internalArgument == null) { + result.addNonToken(token); + continue; + } + + result.addNamedArgument(namedToken, argToken); + result.setWaitingArgument(argToken.isEmpty()); + continue; + } + + final int equals = token.indexOf(FLAG_SEPARATOR); + // No equals char was found + if (equals == -1) { + handleNoEquals(tokens, result, token); + continue; + } + + // Handling of arguments with equals + handleWithEquals(result, token, equals); + } + + result.test(); + } + + private void handleNoEquals( + final @NotNull ParserScanner tokens, + final @NotNull Result result, + final @NotNull String token + + ) { + final FlagOptions flag = flagGroup.getMatchingFlag(token); + // No valid flag with the name, skip + if (flag == null) { + result.addNonToken(token); + return; + } + + // Checks if the flag needs argument + if (flag.hasArgument()) { + // If an argument is needed and no more tokens present, then just append empty as value + if (!tokens.hasNext()) { + result.addFlag(flag); + result.setWaitingArgument(true); + return; + } + + // Value found so append + result.addFlag(flag, tokens.next()); + result.setWaitingArgument(false); + return; + } + + // No argument needed just add flag + result.addFlag(flag); + } + + private void handleWithEquals( + final @NotNull Result result, + final @NotNull String token, + final int equals + ) { + // Splits the flag from `flag=arg` + final String flagToken = token.substring(0, equals); + final String argToken = token.substring(equals + 1); + + final FlagOptions flag = flagGroup.getMatchingFlag(flagToken); + // No valid flag with the name, skip + if (flag == null) { + result.addNonToken(token); + return; + } + + // Flag with equals should always have argument, so we ignore if it doesn't + if (!flag.hasArgument()) { + result.addNonToken(token); + return; + } + + // Add flag normally + result.addFlag(flag, argToken); + result.setWaitingArgument(argToken.isEmpty()); + } + + public class Result { + + private final Map, String> flags = new HashMap<>(); + private final Map namedArguments = new HashMap<>(); + private final List nonTokens = new ArrayList<>(); + + private boolean waitingArgument = false; + + public void addNamedArgument(final @NotNull String name) { + namedArguments.put(name, ""); + } + + public void addNamedArgument(final @NotNull String name, final @NotNull String value) { + namedArguments.put(name, value); + } + + public void addFlag(final @NotNull FlagOptions flagOptions) { + flags.put(flagOptions, ""); + } + + public void addFlag(final @NotNull FlagOptions flagOptions, final @NotNull String value) { + flags.put(flagOptions, value); + } + + public void addNonToken(final @NotNull String token) { + nonTokens.add(token); + } + + public void setWaitingArgument(final boolean value) { + this.waitingArgument = value; + } + + public void test() { + System.out.println(flags); + System.out.println(namedArguments); + System.out.println(nonTokens); + System.out.println(waitingArgument); + } + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java index 5046e470..3ffe98a7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.argument.named; +import dev.triumphteam.cmd.core.argument.flag.Flags; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -30,7 +31,7 @@ import java.util.Optional; import java.util.Set; -public interface Arguments { +public interface Arguments extends Flags { /** * Gets an argument by name. diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/FlagsContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/FlagsContainer.java new file mode 100644 index 00000000..f232d034 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/FlagsContainer.java @@ -0,0 +1,39 @@ +package dev.triumphteam.cmd.core.argument.named; + +import org.jetbrains.annotations.NotNull; + +import java.util.List; +import java.util.Optional; + +public abstract class FlagsContainer implements Arguments { + + @Override + public boolean hasFlag(final @NotNull String flag) { + return false; + } + + @Override + public @NotNull Optional getValue(final @NotNull String flag, final @NotNull Class type) { + return Optional.empty(); + } + + @Override + public @NotNull Optional getValue(final @NotNull String flag) { + return Optional.empty(); + } + + @Override + public @NotNull String getText() { + return null; + } + + @Override + public @NotNull String getText(final @NotNull String delimiter) { + return null; + } + + @Override + public @NotNull List<@NotNull String> getArgs() { + return null; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java deleted file mode 100644 index 663a7efc..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentParser.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.argument.named; - -import org.jetbrains.annotations.NotNull; - -import java.util.LinkedHashMap; -import java.util.Map; -import java.util.PrimitiveIterator; - -public final class NamedArgumentParser { - - private static final char SPACE = ' '; - private static final char ESCAPE = '\\'; - private static final char SEPARATOR = ':'; - - public static Map parse(final @NotNull String literal) { - final PrimitiveIterator.OfInt iterator = literal.chars().iterator(); - - final Map args = new LinkedHashMap<>(); - final StringBuilder builder = new StringBuilder(); - - // Control variables - boolean escape = false; - String argument = ""; - - while (iterator.hasNext()) { - final int current = iterator.next(); - - // Marks next character to be escaped - if (current == ESCAPE && !argument.isEmpty()) { - escape = true; - continue; - } - - // Found a separator - if (current == SEPARATOR && argument.isEmpty()) { - argument = builder.toString(); - builder.setLength(0); - continue; - } - - // Handling for spaces - // TODO: Scape - if (current == SPACE) { - // If no argument is found, discard values - if (argument.isEmpty()) { - builder.setLength(0); - continue; - } - - // If argument is found, accept as value - args.put(argument, builder.toString()); - builder.setLength(0); - argument = ""; - continue; - } - - // If no escapable token was found, aka :, re-append the backslash - if (escape) { - builder.appendCodePoint(ESCAPE); - escape = false; - } - - // Normal append character - builder.appendCodePoint(current); - } - - // If end of string is reached and value was not closed, close it - if (!argument.isEmpty()) args.put(argument, builder.toString()); - - return args; - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java index 09f0e347..3eee4388 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java @@ -32,11 +32,11 @@ import java.util.Set; @SuppressWarnings("unchecked") -public final class NamedArgumentResult implements Arguments { +public final class NamedArgumentResult extends FlagsContainer { private final Map values; - public NamedArgumentResult(final @NotNull Map<@NotNull String, @NotNull Object> values) { + public NamedArgumentResult(final @NotNull Map values) { this.values = values; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java index 37257329..278223c3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.extention.registry; -import dev.triumphteam.cmd.core.flag.FlagKey; +import dev.triumphteam.cmd.core.argument.flag.FlagKey; import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java index 0f7a8e07..c7dbd9e9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java @@ -57,10 +57,10 @@ import dev.triumphteam.cmd.core.argument.named.ListArgument; import dev.triumphteam.cmd.core.extention.registry.NamedArgumentRegistry; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.flag.Flags; -import dev.triumphteam.cmd.core.flag.internal.FlagGroup; -import dev.triumphteam.cmd.core.flag.internal.FlagOptions; -import dev.triumphteam.cmd.core.flag.internal.FlagValidator; +import dev.triumphteam.cmd.core.argument.flag.Flags; +import dev.triumphteam.cmd.core.argument.internal.FlagGroup; +import dev.triumphteam.cmd.core.argument.internal.FlagOptions; +import dev.triumphteam.cmd.core.argument.internal.FlagValidator; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; diff --git a/kotlin/extensions/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt b/kotlin/extensions/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt index 4174a686..bcd284af 100644 --- a/kotlin/extensions/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt +++ b/kotlin/extensions/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmds -import dev.triumphteam.cmd.core.flag.Flags +import dev.triumphteam.cmd.core.argument.flag.Flags /** * Checks if the flag key is present or not using operator function. From 0a1d9ab7d74a33c32855f023e82586ec61dcf15f Mon Sep 17 00:00:00 2001 From: Mateus Moreira Date: Wed, 28 Dec 2022 18:08:47 +0000 Subject: [PATCH 036/101] feature: Rewritten flags and named arguments system --- .../triumphteam/cmd/core/CommandManager.java | 6 +- .../cmd/core/annotations/CommandFlags.java | 10 +- .../core/argument/FlagInternalArgument.java | 40 +-- .../core/argument/NamedInternalArgument.java | 9 +- .../core/argument/internal/FlagParser.java | 134 --------- .../core/argument/internal/ParserScanner.java | 88 ------ .../{named => keyed}/ArgumentKey.java | 2 +- .../argument/{named => keyed}/Arguments.java | 4 +- .../argument/{flag => keyed}/FlagKey.java | 2 +- .../core/argument/{flag => keyed}/Flags.java | 2 +- .../{ => keyed}/internal/ArgFlagValue.java | 2 +- .../argument/keyed/internal/Argument.java | 278 ++++++++++++++++++ .../keyed/internal/ArgumentGroup.java | 63 ++++ .../internal}/ArgumentParser.java | 176 +++++------ .../{ => keyed}/internal/EmptyFlagValue.java | 2 +- .../core/argument/keyed/internal/Flag.java | 165 +++++++++++ .../{ => keyed}/internal/FlagGroup.java | 52 +--- .../{ => keyed}/internal/FlagOptions.java | 77 ++--- .../{ => keyed}/internal/FlagValidator.java | 31 +- .../{ => keyed}/internal/FlagValue.java | 2 +- .../internal}/FlagsContainer.java | 3 +- .../{ => keyed}/internal/FlagsResult.java | 13 +- .../internal}/ListArgument.java | 4 +- .../internal}/NamedArgumentResult.java | 2 +- .../internal/NamedGroup.java} | 53 ++-- .../internal}/SimpleArgument.java | 4 +- .../named/AbstractArgumentBuilder.java | 102 ------- .../cmd/core/argument/named/Argument.java | 105 ------- .../core/argument/named/ArgumentBuilder.java | 33 --- .../core/extention/registry/FlagRegistry.java | 2 +- .../registry/NamedArgumentRegistry.java | 9 +- .../OldAbstractSubCommandProcessor.java | 34 +-- .../kotlin/dev/triumphteam/cmds/FlagsExt.kt | 2 +- 33 files changed, 745 insertions(+), 766 deletions(-) delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagParser.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ParserScanner.java rename core/src/main/java/dev/triumphteam/cmd/core/argument/{named => keyed}/ArgumentKey.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{named => keyed}/Arguments.java (95%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{flag => keyed}/FlagKey.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{flag => keyed}/Flags.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{ => keyed}/internal/ArgFlagValue.java (97%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Argument.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java rename core/src/main/java/dev/triumphteam/cmd/core/argument/{named => keyed/internal}/ArgumentParser.java (55%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{ => keyed}/internal/EmptyFlagValue.java (95%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Flag.java rename core/src/main/java/dev/triumphteam/cmd/core/argument/{ => keyed}/internal/FlagGroup.java (62%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{ => keyed}/internal/FlagOptions.java (58%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{ => keyed}/internal/FlagValidator.java (68%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{ => keyed}/internal/FlagValue.java (95%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{named => keyed/internal}/FlagsContainer.java (87%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{ => keyed}/internal/FlagsResult.java (90%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{named => keyed/internal}/ListArgument.java (94%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{named => keyed/internal}/NamedArgumentResult.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{named/ListArgumentBuilder.java => keyed/internal/NamedGroup.java} (52%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/{named => keyed/internal}/SimpleArgument.java (93%) delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index a2670b42..fcf644ec 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -24,8 +24,8 @@ package dev.triumphteam.cmd.core; import dev.triumphteam.cmd.core.argument.ArgumentResolver; -import dev.triumphteam.cmd.core.argument.named.Argument; -import dev.triumphteam.cmd.core.argument.named.ArgumentKey; +import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; +import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.message.ContextualKey; @@ -116,7 +116,7 @@ public final void registerNamedArguments(final @NotNull ArgumentKey key, final @ registerNamedArguments(key, Arrays.asList(arguments)); } - public final void registerNamedArguments(final @NotNull ArgumentKey key, final @NotNull List<@NotNull Argument> arguments) { + public final void registerNamedArguments(final @NotNull ArgumentKey key, final @NotNull List arguments) { getRegistryContainer().getNamedArgumentRegistry().register(key, arguments); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/CommandFlags.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/CommandFlags.java index 3b673f54..c0d531a4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/CommandFlags.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/CommandFlags.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.annotations; +import dev.triumphteam.cmd.core.argument.keyed.FlagKey; import org.jetbrains.annotations.NotNull; import java.lang.annotation.ElementType; @@ -42,5 +43,12 @@ * * @return Array of flags. */ - @NotNull Flag[] value(); + @NotNull Flag[] value() default {}; + + /** + * key to use flags from the registry instead of method declared. + * + * @return The {@link FlagKey} value. + */ + @NotNull String key() default ""; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java index 5f9696d6..af424fd4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java @@ -23,17 +23,15 @@ */ package dev.triumphteam.cmd.core.argument; -import dev.triumphteam.cmd.core.argument.flag.Flags; -import dev.triumphteam.cmd.core.argument.internal.FlagGroup; -import dev.triumphteam.cmd.core.argument.internal.FlagOptions; -import dev.triumphteam.cmd.core.argument.internal.FlagParser; +import dev.triumphteam.cmd.core.argument.keyed.Flags; +import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; +import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; @@ -48,18 +46,18 @@ */ public final class FlagInternalArgument extends LimitlessInternalArgument { - private final FlagGroup flagGroup; - private final FlagParser flagParser; + private final ArgumentGroup flagGroup; + // private final FlagParser flagParser; public FlagInternalArgument( final @NotNull String name, final @NotNull String description, - final @NotNull FlagGroup flagGroup, + final @NotNull ArgumentGroup flagGroup, final boolean isOptional ) { super(name, description, Flags.class, new EmptySuggestion<>(), isOptional); this.flagGroup = flagGroup; - this.flagParser = new FlagParser<>(flagGroup); + // this.flagParser = new FlagParser<>(flagGroup); } /** @@ -71,7 +69,7 @@ public FlagInternalArgument( */ @Override public @NotNull Object resolve(final @NotNull S sender, final @NotNull List<@NotNull String> value) { - return flagParser.parse(sender, value.size() == 1 ? Arrays.asList(value.get(0).split(" ")) : value); + return null;// flagParser.parse(sender, value.size() == 1 ? Arrays.asList(value.get(0).split(" ")) : value); } @Override @@ -84,16 +82,17 @@ public FlagInternalArgument( final String current = trimmed.get(size - 1); // TODO: Show flags before long flags. - final List flags = flagGroup.getAllFlags(); + final List flags = flagGroup.getAllNames(); // Parses all the arguments to get the flags that have been used - final List, String>> parsed = new ArrayList<>(flagParser.parseFlags(trimmed).entrySet()); + // flagParser.parseFlags(trimmed).entrySet() + final List> parsed = new ArrayList<>(); final List used = new ArrayList<>(); // Due to long flags and normal flags being together, loop through them to collect the used ones // Could have been done with stream but too complex for my brain right now - for (final Map.Entry, String> entry : parsed) { - final FlagOptions options = entry.getKey(); + for (final Map.Entry entry : parsed) { + final Flag options = entry.getKey(); final String flag = options.getFlag(); final String longFlag = options.getLongFlag(); @@ -104,8 +103,8 @@ public FlagInternalArgument( // If something was parsed we enter to check for arguments if (!parsed.isEmpty()) { // Get the last used flag - final Map.Entry, String> last = parsed.get(parsed.size() - 1); - final FlagOptions flagOptions = last.getKey(); + final Map.Entry last = parsed.get(parsed.size() - 1); + final Flag flagOptions = last.getKey(); // Checking for arguments that doesn't use `=` if (!current.contains("=")) { @@ -113,7 +112,8 @@ public FlagInternalArgument( if (size > 1) { // If the flag has arguments and the previous arg was a flag we get its suggestion if (flagOptions.hasArgument() && flags.contains(trimmed.get(size - 2))) { - return flagOptions.getArgument().suggestions(sender, Collections.singletonList(current), context); + // TODO + return Collections.emptyList();// flagOptions.getArgument().suggestions(sender, Collections.singletonList(current), context); } } } else { @@ -127,12 +127,14 @@ public FlagInternalArgument( // If the flag has arguments we get suggestions and append the flag and `=` to the suggestion if (flagOptions.hasArgument()) { - return flagOptions + // TODO + return Collections.emptyList(); + /*return flagOptions .getArgument() .suggestions(sender, Collections.singletonList(arg), context) .stream() .map(it -> flag + "=" + it) - .collect(Collectors.toList()); + .collect(Collectors.toList());*/ } } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java index 54719a08..1b1dc241 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java @@ -23,9 +23,8 @@ */ package dev.triumphteam.cmd.core.argument; -import dev.triumphteam.cmd.core.argument.named.Arguments; -import dev.triumphteam.cmd.core.argument.named.ArgumentParser; -import dev.triumphteam.cmd.core.argument.named.NamedArgumentResult; +import dev.triumphteam.cmd.core.argument.keyed.internal.NamedArgumentResult; +import dev.triumphteam.cmd.core.argument.keyed.Arguments; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; @@ -54,7 +53,7 @@ public NamedInternalArgument( @Override public @NotNull Object resolve(final @NotNull S sender, final @NotNull List<@NotNull String> value) { - final Map parsedArgs = ArgumentParser.parse(String.join(" ", value)); + final Map parsedArgs = Collections.emptyMap();// ArgumentParser.parse(String.join(" ", value)); final Map mapped = new HashMap<>(parsedArgs.size()); for (final Map.Entry entry : parsedArgs.entrySet()) { @@ -74,7 +73,7 @@ public NamedInternalArgument( final @NotNull List<@NotNull String> trimmed, final @NotNull SuggestionContext context ) { - final Map parsedArgs = ArgumentParser.parse(String.join(" ", trimmed)); + final Map parsedArgs = Collections.emptyMap();// ArgumentParser.parse(String.join(" ", trimmed)); final String current = trimmed.get(trimmed.size() - 1); final List notUsed = arguments.keySet() diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagParser.java deleted file mode 100644 index 21f868f1..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagParser.java +++ /dev/null @@ -1,134 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.argument.internal; - -import com.google.common.collect.Maps; -import dev.triumphteam.cmd.core.argument.flag.Flags; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.LinkedHashMap; -import java.util.List; -import java.util.Map; - -/** - * Basic flag parser. - * - * @param The sender type. - */ -public final class FlagParser { - - private final FlagGroup flagGroup; - - private static final String ESCAPE = "\\"; - private static final String LONG = "--"; - private static final String SHORT = "-"; - private static final int EQUALS = '='; - - public FlagParser(final @NotNull FlagGroup flagGroup) { - this.flagGroup = flagGroup; - } - - public @NotNull Map, String> parseFlags(final @NotNull List toParse) { - return parseInternal(toParse).getKey(); - } - - public @NotNull Flags parse(final @NotNull S sender, final @NotNull List toParse) { - final Map.Entry, String>, List> parsed = parseInternal(toParse); - return new FlagsResult<>(sender, parsed.getKey(), parsed.getValue()); - } - - private Map.Entry, String>, List> parseInternal(final @NotNull List toParse) { - final ParserScanner tokens = new ParserScanner(toParse); - - final Map, String> flags = new LinkedHashMap<>(); - final List args = new ArrayList<>(); - - while (tokens.hasNext()) { - final String token = tokens.next(); - - // If escaping the flag then just, skip - if (token.startsWith(ESCAPE)) { - args.add(token); - continue; - } - - // Checks if it's a flag, if not then skip - if ((!token.startsWith(LONG) || LONG.equals(token)) && (!token.startsWith(SHORT) || SHORT.equals(token))) { - args.add(token); - continue; - } - - final int equals = token.indexOf(EQUALS); - // No equals char was found - if (equals == -1) { - final FlagOptions flag = flagGroup.getMatchingFlag(token); - // No valid flag with the name, skip - if (flag == null) { - args.add(token); - continue; - } - - // Checks if the flag needs argument - if (flag.hasArgument()) { - // If an argument is needed and no more tokens present, then just append empty as value - if (!tokens.hasNext()) { - flags.put(flag, ""); - continue; - } - - // Value found so append - flags.put(flag, tokens.next()); - continue; - } - - // No argument needed just add flag - flags.put(flag, null); - continue; - } - - // Splits the flag from `flag=arg` - final String flagToken = token.substring(0, equals); - final String argToken = token.substring(equals + 1); - - final FlagOptions flag = flagGroup.getMatchingFlag(flagToken); - // No valid flag with the name, skip - if (flag == null) { - args.add(token); - continue; - } - - // Flag with equals should always have argument, so we ignore if it doesn't - if (!flag.hasArgument()) { - args.add(token); - continue; - } - - // Add flag normally - flags.put(flag, argToken); - } - - return Maps.immutableEntry(flags, args); - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ParserScanner.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ParserScanner.java deleted file mode 100644 index 4fa6dbda..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ParserScanner.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.argument.internal; - -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -/** - * Simple util scanner for easier looping through the tokens. - */ -public final class ParserScanner { - - private final List tokens; - private int pointer = -1; - - private String current = null; - - public ParserScanner(final @NotNull List<@NotNull String> tokens) { - this.tokens = tokens; - } - - /** - * Allows peeking into the current token without moving the pointer. - * - * @return The current token. - */ - public @NotNull String peek() { - return current; - } - - /** - * Checks if there are more tokens in the list. - * - * @return Whether the pointer has reached the list end. - */ - public boolean hasNext() { - return pointer < tokens.size() - 1; - } - - /** - * Points the pointer to the next token. - */ - public @NotNull String next() { - if (pointer < tokens.size()) pointer++; - setToken(tokens.get(pointer)); - return peek(); - } - - /** - * Points the pointer to the previous token. - */ - public void previous() { - if (pointer > 0) pointer--; - setToken(tokens.get(pointer)); - } - - /** - * Sets the current token. - * - * @param token The new token to set. - */ - private void setToken(final @NotNull String token) { - this.current = token; - } - -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentKey.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentKey.java index 25a6c6e9..45ee362a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentKey.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.argument.keyed; import dev.triumphteam.cmd.core.extention.StringKey; import org.jetbrains.annotations.Contract; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Arguments.java similarity index 95% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Arguments.java index 3ffe98a7..01b2a97a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Arguments.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Arguments.java @@ -21,9 +21,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.argument.keyed; -import dev.triumphteam.cmd.core.argument.flag.Flags; import org.jetbrains.annotations.NotNull; import java.util.List; @@ -44,7 +43,6 @@ public interface Arguments extends Flags { */ @NotNull Optional get(final @NotNull String name, final @NotNull Class type); - @NotNull Optional> getAsList(final @NotNull String name, final @NotNull Class type); @NotNull Optional> getAsSet(final @NotNull String name, final @NotNull Class type); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/flag/FlagKey.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagKey.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/flag/FlagKey.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagKey.java index 8eed0fe2..e51a0822 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/flag/FlagKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagKey.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.flag; +package dev.triumphteam.cmd.core.argument.keyed; import dev.triumphteam.cmd.core.extention.StringKey; import org.jetbrains.annotations.Contract; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/flag/Flags.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flags.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/flag/Flags.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flags.java index 1e21a565..da235149 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/flag/Flags.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flags.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.flag; +package dev.triumphteam.cmd.core.argument.keyed; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ArgFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgFlagValue.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ArgFlagValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgFlagValue.java index 90b8e735..bf2e778c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/ArgFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgFlagValue.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.internal; +package dev.triumphteam.cmd.core.argument.keyed.internal; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Argument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Argument.java new file mode 100644 index 00000000..30cf1177 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Argument.java @@ -0,0 +1,278 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.argument.keyed.internal; + +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; +import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; +import dev.triumphteam.cmd.core.suggestion.SuggestionKey; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Set; + +/** + * An argument or "named" argument, is separate from the {@link InternalArgument}, as they are used within one. + * This is used for explicit name to value arguments, for example name:John. + */ +public interface Argument { + + /** + * Creates a builder for a {@link String} argument. + * + * @return A {@link Builder} for a {@link String} argument. + */ + @Contract(" -> new") + static @NotNull Argument.Builder forString() { + return new Builder(String.class); + } + + /** + * Creates a builder for a {@link Integer} argument. + * + * @return A {@link Builder} for a {@link Integer} argument. + */ + @Contract(" -> new") + static @NotNull Argument.Builder forInt() { + return new Builder(int.class); + } + + /** + * Creates a builder for a {@link Float} argument. + * + * @return A {@link Builder} for a {@link Float} argument. + */ + @Contract(" -> new") + static @NotNull Argument.Builder forFloat() { + return new Builder(float.class); + } + + /** + * Creates a builder for a {@link Double} argument. + * + * @return A {@link Builder} for a {@link Double} argument. + */ + @Contract(" -> new") + static @NotNull Argument.Builder forDouble() { + return new Builder(double.class); + } + + /** + * Creates a builder for a {@link Boolean} argument. + * + * @return A {@link Builder} for a {@link Boolean} argument. + */ + @Contract(" -> new") + static @NotNull Argument.Builder forBoolean() { + return new Builder(boolean.class); + } + + /** + * Creates a builder for a custom type argument. + * + * @return A {@link Builder} for a custom type argument. + */ + @Contract("_ -> new") + static @NotNull Argument.Builder forType(final @NotNull Class type) { + return new Builder(type); + } + + /** + * Creates a {@link List} builder of a custom type argument. + * + * @param type The type of the argument. + * @return A {@link CollectionBuilder} for a custom type argument. + */ + @Contract("_ -> new") + static @NotNull Argument.CollectionBuilder listOf(final @NotNull Class type) { + return new CollectionBuilder(List.class, type); + } + + /** + * Creates a {@link Set} builder of a custom type argument. + * + * @param type The type of the argument. + * @return A {@link CollectionBuilder} for a custom type argument. + */ + @Contract("_ -> new") + static @NotNull Argument.CollectionBuilder setOf(final @NotNull Class type) { + return new CollectionBuilder(Set.class, type); + } + + /** + * @return The type of the argument. + */ + @NotNull Class getType(); + + /** + * @return The name of the argument. + */ + @NotNull String getName(); + + /** + * @return The description of the argument. + */ + @NotNull String getDescription(); + + /** + * @return The {@link SuggestionKey} to be used. + */ + @Nullable SuggestionKey getSuggestion(); + + /** + * The default builder, simply extends the functionality of {@link AbstractBuilder}. + */ + class Builder extends AbstractBuilder { + public Builder(final @NotNull Class type) { + super(type); + } + } + + /** + * A builder for specific collections. + * Adds the collection type and the separator to be used during execution. + */ + final class CollectionBuilder extends AbstractBuilder { + + private final Class collectionType; + private String separator = ","; + + public CollectionBuilder(final @NotNull Class collectionType, final @NotNull Class type) { + super(type); + this.collectionType = collectionType; + } + + /** + * Set the separator to be used to split an argument into a collection. + * + * @param separator The char or string to use as separator, supports regex. + * @return This builder. + */ + @Contract("_ -> this") + public @NotNull Argument.CollectionBuilder separator(final @NotNull String separator) { + this.separator = separator; + return this; + } + + /** + * Builds the argument. + * + * @return A new {@link Argument} with the data from this builder. + */ + @Contract(" -> new") + public @NotNull Argument build() { + return new ListArgument(this); + } + + @NotNull Class getCollectionType() { + return collectionType; + } + + @NotNull String getSeparator() { + return separator; + } + } + + @SuppressWarnings("unchecked") + abstract class AbstractBuilder> { + + private final Class type; + + private String name; + private String description; + private SuggestionKey suggestionKey; + + private AbstractBuilder(final @NotNull Class type) { + this.type = type; + } + + /** + * Sets the name of the argument. + * + * @param name The name of the argument. + * @return This builder. + */ + @Contract("_ -> this") + public @NotNull T name(final @NotNull String name) { + this.name = name; + return (T) this; + } + + /** + * Sets the description of the argument. + * + * @param description The description of the argument. + * @return This builder. + */ + @Contract("_ -> this") + public @NotNull T description(final @NotNull String description) { + this.description = description; + return (T) this; + } + + /** + * Sets the suggestion key to be used by the argument. + * If not are supplied the argument will use {@link EmptySuggestion} instead. + * + * @param suggestionKey The registered suggestion key. + * @return This builder. + */ + @Contract("_ -> this") + public @NotNull T suggestion(final @NotNull SuggestionKey suggestionKey) { + this.suggestionKey = suggestionKey; + return (T) this; + } + + /** + * Builds the argument. + * + * @return A new {@link Argument} with the data from this builder. + */ + @Contract(" -> new") + public @NotNull Argument build() { + return new SimpleArgument(this); + } + + @NotNull Class getType() { + return type; + } + + @NotNull String getName() { + if (name == null || name.isEmpty()) { + throw new CommandRegistrationException("Argument is missing a name!"); + } + return name; + } + + @NotNull String getDescription() { + return description; + } + + @Nullable SuggestionKey getSuggestionKey() { + return suggestionKey; + } + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java new file mode 100644 index 00000000..9323d204 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java @@ -0,0 +1,63 @@ +package dev.triumphteam.cmd.core.argument.keyed.internal; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +/** + * A group of argument data. + * Example implementations are, flags and named arguments. + * + * @param The type of argument of the group. + */ +public interface ArgumentGroup { + + /** + * Static factory for creating a new flag {@link ArgumentGroup} of type {@link Flag}. + * + * @return A {@link FlagGroup} instance. + */ + static ArgumentGroup flags() { + return new FlagGroup<>(); + } + + /** + * Static factory for creating a new arguments {@link ArgumentGroup} of type {@link Argument}. + * + * @param arguments The {@link List} of {@link Argument}s. + * @return A {@link NamedGroup} instance. + */ + static ArgumentGroup named(final @NotNull List arguments) { + return new NamedGroup(arguments); + } + + /** + * Adds a new argument to the group. + * + * @param argument The argument {@link T} that should be added to the group. + */ + void addArgument(final @NotNull T argument); + + /** + * Gets the argument that matches the current token. + * + * @param token The current token, an argument name or not. + * @return The argument if found or null if not a valid argument name. + */ + @Nullable T getMatchingArgument(final @NotNull String token); + + /** + * Gets a list with all possible argument names. + * + * @return A {@link List} of names. + */ + @NotNull List getAllNames(); + + /** + * Checks if the group is empty. + * + * @return Whether the group is empty. + */ + boolean isEmpty(); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentParser.java similarity index 55% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentParser.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentParser.java index d8ee349f..a14b8e31 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentParser.java @@ -21,30 +21,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.argument.keyed.internal; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.argument.internal.FlagGroup; -import dev.triumphteam.cmd.core.argument.internal.FlagOptions; -import dev.triumphteam.cmd.core.argument.internal.ParserScanner; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashMap; +import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.PrimitiveIterator; -import java.util.Set; -public final class ArgumentParser { - - private static final int SPACE = ' '; - private static final int ESCAPE_CHAR = '\\'; - private static final int HYPHEN = '-'; +public final class ArgumentParser { private static final String LONG = "--"; private static final String SHORT = "-"; @@ -53,80 +40,25 @@ public final class ArgumentParser { private static final int ARGUMENT_SEPARATOR = ':'; private static final int FLAG_SEPARATOR = '='; - private static final Set ESCAPABLE_CHARS = - Collections.unmodifiableSet(new HashSet<>(Arrays.asList(HYPHEN, ARGUMENT_SEPARATOR, FLAG_SEPARATOR))); - - private final FlagGroup flagGroup; - private final Map> namedArguments; + private final ArgumentGroup flagGroup; + private final ArgumentGroup namedGroup; public ArgumentParser( - final @NotNull FlagGroup flagGroup, - final @NotNull Map> namedArguments + final @NotNull ArgumentGroup flagGroup, + final @NotNull ArgumentGroup namedGroup ) { this.flagGroup = flagGroup; - this.namedArguments = namedArguments; + this.namedGroup = namedGroup; } - public static Map parse(final @NotNull String literal) { - final PrimitiveIterator.OfInt iterator = literal.chars().iterator(); - - final Map args = new LinkedHashMap<>(); - final StringBuilder builder = new StringBuilder(); - - // Control variables - boolean escape = false; - String argument = ""; - - while (iterator.hasNext()) { - final int current = iterator.next(); - - // Marks next character to be escaped - if (current == ESCAPE_CHAR && !argument.isEmpty()) { - escape = true; - continue; - } - - // Found a separator - if (current == ARGUMENT_SEPARATOR && argument.isEmpty()) { - argument = builder.toString(); - builder.setLength(0); - continue; - } - - // Handling for spaces - // TODO: Scape - if (current == SPACE) { - // If no argument is found, discard values - if (argument.isEmpty()) { - builder.setLength(0); - continue; - } - - // If argument is found, accept as value - args.put(argument, builder.toString()); - builder.setLength(0); - argument = ""; - continue; - } - - // If no escapable token was found, aka :, re-append the backslash - if (escape) { - builder.appendCodePoint(ESCAPE_CHAR); - escape = false; - } - - // Normal append character - builder.appendCodePoint(current); - } - - // If end of string is reached and value was not closed, close it - if (!argument.isEmpty()) args.put(argument, builder.toString()); - - return args; - } - - public void newParse(final @NotNull List arguments) { - final ParserScanner tokens = new ParserScanner(arguments); + /** + * Parse the current {@link List} of raw arguments for {@link Flag}s and {@link Argument}. + * + * @param arguments A {@link List} of raw arguments. + * @return A {@link Result} object containing the raw results of the parse. + */ + public Result parse(final @NotNull List arguments) { + final Iterator tokens = arguments.iterator(); final Result result = new Result(); @@ -149,19 +81,8 @@ public void newParse(final @NotNull List arguments) { continue; } - // Splits the flag from `name:arg` - final String namedToken = token.substring(0, separator); - final String argToken = token.substring(separator + 1); - - final InternalArgument internalArgument = namedArguments.get(namedToken); - // If there is no valid argument we ignore it - if (internalArgument == null) { - result.addNonToken(token); - continue; - } - - result.addNamedArgument(namedToken, argToken); - result.setWaitingArgument(argToken.isEmpty()); + // Handling of named arguments + handleNamed(result, token, separator); continue; } @@ -176,16 +97,51 @@ public void newParse(final @NotNull List arguments) { handleWithEquals(result, token, equals); } - result.test(); + return result; } + /** + * Parser handler for named arguments. + * + * @param result The results instance to add to. + * @param token The current named argument token. + * @param separator The position of the separator. + */ + private void handleNamed( + final @NotNull Result result, + final @NotNull String token, + final int separator + ) { + // Splits the flag from `name:arg` + final String namedToken = token.substring(0, separator); + final String argToken = token.substring(separator + 1); + + final Argument argument = namedGroup.getMatchingArgument(namedToken); + // If there is no valid argument we ignore it + if (argument == null) { + result.addNonToken(token); + return; + } + + result.addNamedArgument(namedToken, argToken); + result.setWaitingArgument(argToken.isEmpty()); + } + + /** + * Parser handler for flags without an equals. + * The argument would be the next iteration. + * + * @param tokens The tokens {@link Iterator} from the loop. + * @param result The results instance to add to. + * @param token The current flag token. + */ private void handleNoEquals( - final @NotNull ParserScanner tokens, + final @NotNull Iterator tokens, final @NotNull Result result, final @NotNull String token ) { - final FlagOptions flag = flagGroup.getMatchingFlag(token); + final Flag flag = flagGroup.getMatchingArgument(token); // No valid flag with the name, skip if (flag == null) { result.addNonToken(token); @@ -211,6 +167,12 @@ private void handleNoEquals( result.addFlag(flag); } + /** + * Parser handler for flags with an equals. + * + * @param result The results instance to add to. + * @param token The current flag token. + */ private void handleWithEquals( final @NotNull Result result, final @NotNull String token, @@ -220,7 +182,7 @@ private void handleWithEquals( final String flagToken = token.substring(0, equals); final String argToken = token.substring(equals + 1); - final FlagOptions flag = flagGroup.getMatchingFlag(flagToken); + final Flag flag = flagGroup.getMatchingArgument(flagToken); // No valid flag with the name, skip if (flag == null) { result.addNonToken(token); @@ -238,27 +200,23 @@ private void handleWithEquals( result.setWaitingArgument(argToken.isEmpty()); } - public class Result { + public static class Result { - private final Map, String> flags = new HashMap<>(); + private final Map flags = new HashMap<>(); private final Map namedArguments = new HashMap<>(); private final List nonTokens = new ArrayList<>(); private boolean waitingArgument = false; - public void addNamedArgument(final @NotNull String name) { - namedArguments.put(name, ""); - } - public void addNamedArgument(final @NotNull String name, final @NotNull String value) { namedArguments.put(name, value); } - public void addFlag(final @NotNull FlagOptions flagOptions) { + public void addFlag(final @NotNull Flag flagOptions) { flags.put(flagOptions, ""); } - public void addFlag(final @NotNull FlagOptions flagOptions, final @NotNull String value) { + public void addFlag(final @NotNull Flag flagOptions, final @NotNull String value) { flags.put(flagOptions, value); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/EmptyFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyFlagValue.java similarity index 95% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/internal/EmptyFlagValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyFlagValue.java index e31c3e8e..9a61b3a5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/EmptyFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyFlagValue.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.internal; +package dev.triumphteam.cmd.core.argument.keyed.internal; public final class EmptyFlagValue implements FlagValue { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Flag.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Flag.java new file mode 100644 index 00000000..544851d1 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Flag.java @@ -0,0 +1,165 @@ +package dev.triumphteam.cmd.core.argument.keyed.internal; + +import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; +import dev.triumphteam.cmd.core.suggestion.SuggestionKey; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface Flag { + + /** + * Creates a {@link Flag} builder. + * + * @param flag The flag value to start with. + * @return A {@link Argument.Builder} to create a new {@link Flag}. + */ + @Contract("_ -> new") + static @NotNull Builder flag(final @NotNull String flag) { + return new Builder().flag(flag); + } + + /** + * Creates a {@link Flag} builder. + * + * @param longFlag The long flag value to start with. + * @return A {@link Argument.Builder} to create a new {@link Flag}. + */ + @Contract("_ -> new") + static @NotNull Builder longFlag(final @NotNull String longFlag) { + return new Builder().longFlag(longFlag); + } + + /** + * @return The flag identifier. + */ + @Nullable String getFlag(); + + /** + * @return The long flag identifier. + */ + @Nullable String getLongFlag(); + + /** + * @return Either be the {@link Flag#getFlag()} or the {@link Flag#getLongFlag()}.. + */ + @NotNull String getKey(); + + /** + * @return The description of the flag. + */ + @NotNull String getDescription(); + + /** + * @return The {@link SuggestionKey} to be used. + */ + @Nullable SuggestionKey getSuggestion(); + + /** + * @return Whether the flag contains arguments. + */ + boolean hasArgument(); + + /** + * Simple builder for creating new {@link Flag}s. + */ + final class Builder { + + private String flag; + private String longFlag; + private String description; + private Class argument; + private SuggestionKey suggestionKey; + + /** + * Sets the flag name. + * + * @param flag The flag to be used. + * @return This builder. + */ + @Contract("_ -> this") + public @NotNull Builder flag(final @NotNull String flag) { + this.flag = flag; + return this; + } + + /** + * Sets the long flag name. + * + * @param longFlag The long flag to be used. + * @return This builder. + */ + @Contract("_ -> this") + public @NotNull Builder longFlag(final @NotNull String longFlag) { + this.longFlag = longFlag; + return this; + } + + /** + * Sets the description of the Flag. + * + * @param description The description of the Flag. + * @return This builder. + */ + @Contract("_ -> this") + public @NotNull Builder description(final @NotNull String description) { + this.description = description; + return this; + } + + /** + * Sets the argument type of the Flag. + * + * @param argumentType The argument type of the Flag. + * @return This builder. + */ + @Contract("_ -> this") + public @NotNull Builder argument(final @NotNull Class argumentType) { + this.argument = argumentType; + return this; + } + + /** + * Sets the suggestion key to be used by the Flag. + * If not are supplied the Flag will use {@link EmptySuggestion} instead. + * + * @param suggestionKey The registered suggestion key. + * @return This builder. + */ + @Contract("_ -> this") + public @NotNull Builder suggestion(final @NotNull SuggestionKey suggestionKey) { + this.suggestionKey = suggestionKey; + return this; + } + + /** + * Builds the flag. + * + * @return A new {@link Flag} with the data from this builder. + */ + @Contract(" -> new") + public @NotNull Flag build() { + return new FlagOptions(this); + } + + @NotNull Class getArgument() { + return argument; + } + + @NotNull String getFlag() { + return flag; + } + + @NotNull String getLongFlag() { + return longFlag; + } + + @NotNull String getDescription() { + return description; + } + + @Nullable SuggestionKey getSuggestionKey() { + return suggestionKey; + } + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java similarity index 62% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagGroup.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java index 536e27d3..4f13d492 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.internal; +package dev.triumphteam.cmd.core.argument.keyed.internal; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,62 +36,42 @@ * * @param The sender type. */ -public final class FlagGroup { +final class FlagGroup implements ArgumentGroup { - private final Map> flags = new HashMap<>(); - private final Map> longFlags = new HashMap<>(); + private final Map flags = new HashMap<>(); + private final Map longFlags = new HashMap<>(); private final List allFlags = new ArrayList<>(); - public @NotNull Map<@Nullable String, @NotNull FlagOptions> getFlags() { - return flags; - } - - public @NotNull Map<@NotNull String, @NotNull FlagOptions> getLongFlags() { - return longFlags; - } - - /** - * Adds a new flag to the group. - * - * @param flagOptions The {@link FlagOptions} that should be added to the lis. - */ - public void addFlag(final @NotNull FlagOptions flagOptions) { - final String key = flagOptions.getKey(); + @Override + public void addArgument(final @NotNull Flag argument) { + final String key = argument.getKey(); - final String longFlag = flagOptions.getLongFlag(); + final String longFlag = argument.getLongFlag(); if (longFlag != null) { allFlags.add("--" + longFlag); - longFlags.put(longFlag, flagOptions); + longFlags.put(longFlag, argument); } allFlags.add("-" + key); - flags.put(key, flagOptions); + flags.put(key, argument); } - public @NotNull List<@NotNull String> getAllFlags() { + @Override + public @NotNull List getAllNames() { return allFlags; } - /** - * Checks if the flags are empty. - * - * @return Whether the flag lists are empty. - */ + @Override public boolean isEmpty() { return flags.isEmpty() && longFlags.isEmpty(); } - /** - * Gets the flag that matches the current token. - * - * @param token The current token, a flag name or not. - * @return The flag if found or null if not a valid flag. - */ - public @Nullable FlagOptions getMatchingFlag(final @NotNull String token) { + @Override + public @Nullable Flag getMatchingArgument(final @NotNull String token) { final String stripped = stripLeadingHyphens(token); - final FlagOptions flag = flags.get(stripped); + final Flag flag = flags.get(stripped); return flag != null ? flag : longFlags.get(stripped); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagOptions.java similarity index 58% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagOptions.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagOptions.java index d862c11c..d418567f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagOptions.java @@ -21,78 +21,81 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.internal; +package dev.triumphteam.cmd.core.argument.keyed.internal; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; +import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; /** * Contains all the "settings" for the flag. - * - * @param The sender type. */ -public final class FlagOptions { +final class FlagOptions implements Flag { private final String flag; private final String longFlag; + private final String description; + private final Class argument; + private final SuggestionKey suggestionKey; + + FlagOptions(final @NotNull Flag.Builder builder) { + + final String flag = builder.getFlag(); + final String longFlag = builder.getLongFlag(); - // TODO: 9/16/2021 Check if flag description is needed. - private final StringInternalArgument argument; - - public FlagOptions( - final @Nullable String flag, - final @Nullable String longFlag, - final @Nullable StringInternalArgument argument - ) { - this.flag = flag; - this.longFlag = longFlag; - this.argument = argument; + this.flag = flag.isEmpty() ? null : flag; + this.longFlag = longFlag.isEmpty() ? null : longFlag; + + this.description = builder.getDescription(); + this.argument = builder.getArgument(); + this.suggestionKey = builder.getSuggestionKey(); + + if (this.flag == null && this.longFlag == null) { + throw new CommandRegistrationException("Flag can't have both normal and long flag empty!"); + } + + FlagValidator.validate(flag); + FlagValidator.validate(longFlag); } - /** - * Gets the flag identifier. - * - * @return The flag identifier. - */ + @Override public @Nullable String getFlag() { return flag; } - /** - * Gets the long flag identifier. - * - * @return The long flag identifier. - */ + @Override public @Nullable String getLongFlag() { return longFlag; } - // TODO: Comments - public @Nullable StringInternalArgument getArgument() { - return argument; - } - - /** - * They key will either be the {@link FlagOptions#getFlag()} or the {@link FlagOptions#getLongFlag()}. - * - * @return The key that identifies the flag. - */ + @Override public @NotNull String getKey() { // Will never happen. if (flag == null && longFlag == null) { - throw new CommandExecutionException("Both options can't be null."); + throw new CommandExecutionException("Both flag and long flag can't be null."); } return (flag == null) ? longFlag : flag; } + @Override + public @NotNull String getDescription() { + return description; + } + + @Override + public @Nullable SuggestionKey getSuggestion() { + return suggestionKey; + } + /** * Checks if the flag has argument or not. * * @return Whether it has an argument. */ + @Override public boolean hasArgument() { return argument != null; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValidator.java similarity index 68% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValidator.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValidator.java index 0ece16ac..a4955fea 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValidator.java @@ -21,20 +21,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.internal; +package dev.triumphteam.cmd.core.argument.keyed.internal; -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import org.jetbrains.annotations.NotNull; +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import org.jetbrains.annotations.Nullable; -import java.lang.reflect.AnnotatedElement; - /** * Modified from commons-cli. * https://github.com/apache/commons-cli */ -public final class FlagValidator { +final class FlagValidator { private FlagValidator() { throw new AssertionError("Util class must not be initialized."); @@ -43,14 +39,9 @@ private FlagValidator() { /** * Checks whether the flag contains illegal characters. * - * @param flag The {@link String} flag. - * @param annotatedElement The method from the registration so that better error message can be thrown. + * @param flag The {@link String} flag. */ - public static void validate( - final @Nullable String flag, - final @NotNull AnnotatedElement annotatedElement, - final @NotNull BaseCommand baseCommand - ) { + static void validate(final @Nullable String flag) { if (flag == null) return; // handle the single character flag @@ -58,11 +49,7 @@ public static void validate( char character = flag.charAt(0); if (!isValidFlag(character)) { - throw new SubCommandRegistrationException( - "Illegal flag name \"" + character + "\"", - annotatedElement, - baseCommand.getClass() - ); + throw new CommandRegistrationException("Illegal flag name \"" + character + "\" on flag \"" + flag + "\"."); } return; @@ -71,11 +58,7 @@ public static void validate( // handle the multi character flag for (char character : flag.toCharArray()) { if (!isValidChar(character)) { - throw new SubCommandRegistrationException( - "The flag \"" + flag + "\" contains an illegal character \"" + character + "\"", - annotatedElement, - baseCommand.getClass() - ); + throw new CommandRegistrationException("The flag \"" + flag + "\" contains an illegal character \"" + character + "\"."); } } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValue.java similarity index 95% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValue.java index 76eb1b91..33d20a80 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValue.java @@ -21,6 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.internal; +package dev.triumphteam.cmd.core.argument.keyed.internal; public interface FlagValue {} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/FlagsContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java similarity index 87% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/FlagsContainer.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java index f232d034..e8db2d83 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/FlagsContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java @@ -1,5 +1,6 @@ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.argument.keyed.internal; +import dev.triumphteam.cmd.core.argument.keyed.Arguments; import org.jetbrains.annotations.NotNull; import java.util.List; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagsResult.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java similarity index 90% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagsResult.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java index eb04ff66..2fbde7a8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/internal/FlagsResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.internal; +package dev.triumphteam.cmd.core.argument.keyed.internal; -import dev.triumphteam.cmd.core.argument.flag.Flags; +import dev.triumphteam.cmd.core.argument.keyed.Flags; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -45,7 +45,7 @@ class FlagsResult implements Flags { FlagsResult( final @NotNull S sender, - final @NotNull Map, String> flags, + final @NotNull Map flags, final @NotNull List args ) { this.sender = sender; @@ -53,11 +53,12 @@ class FlagsResult implements Flags { this.args = args; } - public void addFlag(final @NotNull FlagOptions flag, final @Nullable String value) { + public void addFlag(final @NotNull Flag flag, final @Nullable String value) { final String shortFlag = flag.getFlag(); final String longFlag = flag.getLongFlag(); - final FlagValue flagValue = value == null ? EmptyFlagValue.INSTANCE : new ArgFlagValue<>(value, flag.getArgument()); + // TODO + /* final FlagValue flagValue = value == null ? EmptyFlagValue.INSTANCE : new ArgFlagValue<>(value, flag.getArgument()); if (shortFlag != null) { flags.put(shortFlag, flagValue); @@ -65,7 +66,7 @@ public void addFlag(final @NotNull FlagOptions flag, final @Nullable String v if (longFlag != null) { flags.put(longFlag, flagValue); - } + }*/ } void addArg(final @NotNull String arg) { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java similarity index 94% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java index 4d6952e4..fbf5a1e1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.argument.keyed.internal; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; @@ -37,7 +37,7 @@ public final class ListArgument implements Argument { private final SuggestionKey suggestionKey; - public ListArgument(final @NotNull ListArgumentBuilder argumentBuilder) { + public ListArgument(final @NotNull Argument.CollectionBuilder argumentBuilder) { this.type = argumentBuilder.getType(); this.name = argumentBuilder.getName(); this.description = argumentBuilder.getDescription(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedArgumentResult.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedArgumentResult.java index 3eee4388..b8c11ac8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/NamedArgumentResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedArgumentResult.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.argument.keyed.internal; import com.google.common.collect.ImmutableMap; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java similarity index 52% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java index c2c34cd8..daf4fe91 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ListArgumentBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java @@ -21,42 +21,47 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.argument.keyed.internal; -import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -public final class ListArgumentBuilder extends AbstractArgumentBuilder { +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; - private final Class collectionType; - private String separator = ","; +/** + * Basically a holder that contains all the needed arguments for the command. + */ +final class NamedGroup implements ArgumentGroup { + + private final Map arguments = new HashMap<>(); + private final List allArgumentNames = new ArrayList<>(); - public ListArgumentBuilder(final @NotNull Class collectionType, final @NotNull Class type) { - super(type); - this.collectionType = collectionType; + NamedGroup(final @NotNull List arguments) { + arguments.forEach(this::addArgument); } - @Contract("_ -> this") - public @NotNull ListArgumentBuilder separator(final @NotNull String separator) { - this.separator = separator; - return this; + @Override + public void addArgument(final @NotNull Argument argument) { + final String name = argument.getName(); + allArgumentNames.add(name); + arguments.put(name, argument); } - /** - * Builds the argument. - * - * @return A new {@link Argument} with the data from this builder. - */ - @Contract(" -> new") - public @NotNull Argument build() { - return new ListArgument(this); + @Override + public @NotNull List getAllNames() { + return allArgumentNames; } - @NotNull Class getCollectionType() { - return collectionType; + @Override + public boolean isEmpty() { + return arguments.isEmpty(); } - @NotNull String getSeparator() { - return separator; + @Override + public @Nullable Argument getMatchingArgument(final @NotNull String token) { + return arguments.get(token); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java similarity index 93% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java index ea6d4a7a..91010eaa 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/SimpleArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.named; +package dev.triumphteam.cmd.core.argument.keyed.internal; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; @@ -35,7 +35,7 @@ public final class SimpleArgument implements Argument { private final SuggestionKey suggestionKey; - public SimpleArgument(final @NotNull AbstractArgumentBuilder argumentBuilder) { + public SimpleArgument(final @NotNull Argument.AbstractBuilder argumentBuilder) { this.type = argumentBuilder.getType(); this.name = argumentBuilder.getName(); this.description = argumentBuilder.getDescription(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java deleted file mode 100644 index fc87a18a..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/AbstractArgumentBuilder.java +++ /dev/null @@ -1,102 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.argument.named; - -import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; -import dev.triumphteam.cmd.core.suggestion.SuggestionKey; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -@SuppressWarnings("unchecked") -abstract class AbstractArgumentBuilder> { - - private final Class type; - private String name; - private String description = "Description!"; - private SuggestionKey suggestionKey; - - public AbstractArgumentBuilder(final @NotNull Class type) { - this.type = type; - } - - /** - * Sets the name of the argument. - * - * @param name The name of the argument. - * @return This builder. - */ - @Contract("_ -> this") - public @NotNull T name(final @NotNull String name) { - this.name = name; - return (T) this; - } - - /** - * Sets the description of the argument. - * - * @param description The description of the argument. - * @return This builder. - */ - @Contract("_ -> this") - public @NotNull T description(final @NotNull String description) { - this.description = description; - return (T) this; - } - - @Contract("_ -> this") - public @NotNull T suggestion(final @NotNull SuggestionKey suggestionKey) { - this.suggestionKey = suggestionKey; - return (T) this; - } - - /** - * Builds the argument. - * - * @return A new {@link Argument} with the data from this builder. - */ - @Contract(" -> new") - public @NotNull Argument build() { - return new SimpleArgument(this); - } - - @NotNull Class getType() { - return type; - } - - @NotNull String getName() { - if (name == null || name.isEmpty()) { - throw new CommandRegistrationException("Argument is missing a name!"); - } - return name; - } - - @NotNull String getDescription() { - return description; - } - - @Nullable SuggestionKey getSuggestionKey() { - return suggestionKey; - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java deleted file mode 100644 index 351e0508..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/Argument.java +++ /dev/null @@ -1,105 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.argument.named; - -import dev.triumphteam.cmd.core.suggestion.SuggestionKey; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.Set; - -public interface Argument { - - /** - * Creates a builder for a {@link String} argument. - * - * @return A {@link ArgumentBuilder} for a {@link String} argument. - */ - static @NotNull ArgumentBuilder forString() { - return new ArgumentBuilder(String.class); - } - - /** - * Creates a builder for a {@link Integer} argument. - * - * @return A {@link ArgumentBuilder} for a {@link Integer} argument. - */ - static @NotNull ArgumentBuilder forInt() { - return new ArgumentBuilder(int.class); - } - - /** - * Creates a builder for a {@link Float} argument. - * - * @return A {@link ArgumentBuilder} for a {@link Float} argument. - */ - static @NotNull ArgumentBuilder forFloat() { - return new ArgumentBuilder(float.class); - } - - /** - * Creates a builder for a {@link Double} argument. - * - * @return A {@link ArgumentBuilder} for a {@link Double} argument. - */ - static @NotNull ArgumentBuilder forDouble() { - return new ArgumentBuilder(double.class); - } - - /** - * Creates a builder for a {@link Boolean} argument. - * - * @return A {@link ArgumentBuilder} for a {@link Boolean} argument. - */ - static @NotNull ArgumentBuilder forBoolean() { - return new ArgumentBuilder(boolean.class); - } - - /** - * Creates a builder for a custom type argument. - * - * @return A {@link ArgumentBuilder} for a custom type argument. - */ - static @NotNull ArgumentBuilder forType(final @NotNull Class type) { - return new ArgumentBuilder(type); - } - - static @NotNull ListArgumentBuilder listOf(final @NotNull Class type) { - return new ListArgumentBuilder(List.class, type); - } - - static @NotNull ListArgumentBuilder setOf(final @NotNull Class type) { - return new ListArgumentBuilder(Set.class, type); - } - - // TODO: Comments - @NotNull Class getType(); - - @NotNull String getName(); - - @NotNull String getDescription(); - - @Nullable SuggestionKey getSuggestion(); -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java deleted file mode 100644 index 4783756c..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/named/ArgumentBuilder.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.argument.named; - -import org.jetbrains.annotations.NotNull; - -public final class ArgumentBuilder extends AbstractArgumentBuilder { - - public ArgumentBuilder(final @NotNull Class type) { - super(type); - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java index 278223c3..8ac01aea 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.extention.registry; -import dev.triumphteam.cmd.core.argument.flag.FlagKey; +import dev.triumphteam.cmd.core.argument.keyed.FlagKey; import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java index 1908bde9..e16fc7b6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java @@ -23,8 +23,8 @@ */ package dev.triumphteam.cmd.core.extention.registry; -import dev.triumphteam.cmd.core.argument.named.Argument; -import dev.triumphteam.cmd.core.argument.named.ArgumentKey; +import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; +import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -36,12 +36,11 @@ public final class NamedArgumentRegistry implements Registry { private final Map> namedArguments = new HashMap<>(); - public void register(final @NotNull ArgumentKey key, final @NotNull List<@NotNull Argument> arguments) { + public void register(final @NotNull ArgumentKey key, final @NotNull List arguments) { namedArguments.put(key, arguments); } - public @Nullable List<@NotNull Argument> getResolver(final @NotNull ArgumentKey key) { + public @Nullable List getResolver(final @NotNull ArgumentKey key) { return namedArguments.get(key); } - } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java index c7dbd9e9..8eb0763a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java @@ -39,7 +39,6 @@ import dev.triumphteam.cmd.core.annotations.Requirements; import dev.triumphteam.cmd.core.annotations.Split; import dev.triumphteam.cmd.core.annotations.Suggestions; -import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; import dev.triumphteam.cmd.core.argument.ArgumentResolver; import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; import dev.triumphteam.cmd.core.argument.EnumInternalArgument; @@ -51,26 +50,25 @@ import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; import dev.triumphteam.cmd.core.argument.StringInternalArgument; -import dev.triumphteam.cmd.core.argument.named.Argument; -import dev.triumphteam.cmd.core.argument.named.ArgumentKey; -import dev.triumphteam.cmd.core.argument.named.Arguments; -import dev.triumphteam.cmd.core.argument.named.ListArgument; -import dev.triumphteam.cmd.core.extention.registry.NamedArgumentRegistry; +import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; +import dev.triumphteam.cmd.core.argument.keyed.Arguments; +import dev.triumphteam.cmd.core.argument.keyed.Flags; +import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; +import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; +import dev.triumphteam.cmd.core.argument.keyed.internal.ListArgument; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.argument.flag.Flags; -import dev.triumphteam.cmd.core.argument.internal.FlagGroup; -import dev.triumphteam.cmd.core.argument.internal.FlagOptions; -import dev.triumphteam.cmd.core.argument.internal.FlagValidator; -import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.registry.NamedArgumentRegistry; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry; +import dev.triumphteam.cmd.core.extention.sender.SenderValidator; +import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import dev.triumphteam.cmd.core.message.context.MessageContext; -import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.requirement.Requirement; import dev.triumphteam.cmd.core.requirement.RequirementKey; -import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry; import dev.triumphteam.cmd.core.requirement.RequirementResolver; -import dev.triumphteam.cmd.core.extention.sender.SenderValidator; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.EnumSuggestion; import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; @@ -119,7 +117,7 @@ public abstract class OldAbstractSubCommandProcessor { private final List argDescriptions = new ArrayList<>(); private final List alias = new ArrayList<>(); private final boolean isAsync; - private final FlagGroup flagGroup = new FlagGroup<>(); + private final ArgumentGroup flagGroup = ArgumentGroup.flags(); private final List> suggestionList = new ArrayList<>(); private final List> internalArguments = new ArrayList<>(); private final Set> requirements = new HashSet<>(); @@ -602,7 +600,6 @@ private void extractFlags() { for (final Flag flagAnnotation : flags) { String flag = flagAnnotation.flag(); if (flag.isEmpty()) flag = null; - FlagValidator.validate(flag, annotatedElement, baseCommand); String longFlag = flagAnnotation.longFlag(); if (longFlag.contains(" ")) { @@ -644,13 +641,14 @@ private void extractFlags() { } } - flagGroup.addFlag( + // TODO + /*flagGroup.addArgument( new FlagOptions<>( flag, longFlag, internalArgument ) - ); + );*/ } } diff --git a/kotlin/extensions/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt b/kotlin/extensions/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt index bcd284af..ccd9766b 100644 --- a/kotlin/extensions/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt +++ b/kotlin/extensions/src/main/kotlin/dev/triumphteam/cmds/FlagsExt.kt @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmds -import dev.triumphteam.cmd.core.argument.flag.Flags +import dev.triumphteam.cmd.core.argument.keyed.Flags /** * Checks if the flag key is present or not using operator function. From 26e42f67bf15c4187ce1da7df4449d41cb8bd80d Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 28 Dec 2022 18:50:12 +0000 Subject: [PATCH 037/101] feature: Flags registration --- .../triumphteam/cmd/core/CommandManager.java | 65 ++++++++++++++++--- .../core/extention/registry/FlagRegistry.java | 14 ++-- .../registry/NamedArgumentRegistry.java | 4 +- .../extention/registry/RegistryContainer.java | 9 ++- .../OldAbstractSubCommandProcessor.java | 2 +- 5 files changed, 72 insertions(+), 22 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index fcf644ec..5e809aa4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -24,8 +24,12 @@ package dev.triumphteam.cmd.core; import dev.triumphteam.cmd.core.argument.ArgumentResolver; +import dev.triumphteam.cmd.core.argument.keyed.Arguments; +import dev.triumphteam.cmd.core.argument.keyed.FlagKey; +import dev.triumphteam.cmd.core.argument.keyed.Flags; import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; +import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.message.ContextualKey; @@ -92,34 +96,75 @@ public final void unregisterCommands(final @NotNull BaseCommand @NotNull ... com } /** - * Registers a custom internalArgument. + * Registers a custom argument. * - * @param clazz The class of the internalArgument to be registered. - * @param resolver The {@link ArgumentResolver} with the internalArgument resolution. + * @param clazz The class of the argument to be registered. + * @param resolver The {@link ArgumentResolver} with the argument resolution. */ public final void registerArgument(final @NotNull Class clazz, final @NotNull ArgumentResolver resolver) { getRegistryContainer().getArgumentRegistry().register(clazz, resolver); } - // TODO: Comments - public void registerSuggestion(final @NotNull SuggestionKey key, final @NotNull SuggestionResolver suggestionResolver) { - getRegistryContainer().getSuggestionRegistry().register(key, suggestionResolver); + /** + * Registers a suggestion to be used for specific arguments. + * + * @param key The {@link SuggestionKey} that identifies the registered suggestion. + * @param resolver The {@link SuggestionResolver} with the suggestion resolution. + */ + public void registerSuggestion(final @NotNull SuggestionKey key, final @NotNull SuggestionResolver resolver) { + getRegistryContainer().getSuggestionRegistry().register(key, resolver); } - // TODO: Comments - public void registerSuggestion(final @NotNull Class type, final @NotNull SuggestionResolver suggestionResolver) { - getRegistryContainer().getSuggestionRegistry().register(type, suggestionResolver); + /** + * Registers a suggestion to be used for all arguments of a specific type. + * + * @param type Using specific {@link Class} types as target for suggestions instead of keys. + * @param resolver The {@link SuggestionResolver} with the suggestion resolution. + */ + public void registerSuggestion(final @NotNull Class type, final @NotNull SuggestionResolver resolver) { + getRegistryContainer().getSuggestionRegistry().register(type, resolver); } - // TODO: Comments + /** + * Registers a list of arguments to be used as named arguments in a command. + * + * @param key The {@link ArgumentKey} to represent the list. + * @param arguments The list of arguments. + */ public final void registerNamedArguments(final @NotNull ArgumentKey key, final @NotNull Argument @NotNull ... arguments) { registerNamedArguments(key, Arrays.asList(arguments)); } + /** + * Registers a list of arguments to be used on a {@link Arguments} argument in a command. + * + * @param key The {@link ArgumentKey} to represent the list. + * @param arguments The {@link List} of arguments. + */ public final void registerNamedArguments(final @NotNull ArgumentKey key, final @NotNull List arguments) { getRegistryContainer().getNamedArgumentRegistry().register(key, arguments); } + /** + * Registers a list of flags to be used on a {@link Flags} argument or {@link Arguments} argument, in a command. + * + * @param key The {@link FlagKey} to represent the list. + * @param flags The list of flags. + */ + public final void registerFlags(final @NotNull FlagKey key, final @NotNull Flag @NotNull ... flags) { + registerFlags(key, Arrays.asList(flags)); + } + + /** + * Registers a list of flags to be used on a {@link Flags} argument or {@link Arguments} argument, in a command. + * + * @param key The {@link FlagKey} to represent the list. + * @param flags The {@link List} of flags. + */ + public final void registerFlags(final @NotNull FlagKey key, final @NotNull List flags) { + getRegistryContainer().getFlagRegistry().register(key, flags); + } + /** * Registers a custom message. * diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java index 8ac01aea..8180544b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java @@ -24,23 +24,23 @@ package dev.triumphteam.cmd.core.extention.registry; import dev.triumphteam.cmd.core.argument.keyed.FlagKey; -import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; +import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.HashMap; +import java.util.List; import java.util.Map; -public final class FlagRegistry implements Registry { +public final class FlagRegistry implements Registry { - private final Map> suggestions = new HashMap<>(); + private final Map> suggestions = new HashMap<>(); - - public void register(final @NotNull FlagKey key, final @NotNull SuggestionResolver resolver) { - suggestions.put(key, resolver); + public void register(final @NotNull FlagKey key, final @NotNull List flags) { + suggestions.put(key, flags); } - public @Nullable SuggestionResolver getSuggestionResolver(final @NotNull FlagKey key) { + public @Nullable List getFlags(final @NotNull FlagKey key) { return suggestions.get(key); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java index e16fc7b6..10d9fcec 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java @@ -32,7 +32,7 @@ import java.util.List; import java.util.Map; -public final class NamedArgumentRegistry implements Registry { +public final class NamedArgumentRegistry implements Registry { private final Map> namedArguments = new HashMap<>(); @@ -40,7 +40,7 @@ public void register(final @NotNull ArgumentKey key, final @NotNull List getResolver(final @NotNull ArgumentKey key) { + public @Nullable List getArguments(final @NotNull ArgumentKey key) { return namedArguments.get(key); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RegistryContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RegistryContainer.java index f8144379..9fecfc55 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RegistryContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RegistryContainer.java @@ -29,7 +29,8 @@ public class RegistryContainer { private final ArgumentRegistry argumentRegistry = new ArgumentRegistry<>(); - private final NamedArgumentRegistry namedArgumentRegistry = new NamedArgumentRegistry<>(); + private final NamedArgumentRegistry namedArgumentRegistry = new NamedArgumentRegistry(); + private final FlagRegistry flagRegistry = new FlagRegistry(); private final RequirementRegistry requirementRegistry = new RequirementRegistry<>(); private final MessageRegistry messageRegistry = new MessageRegistry<>(); private final SuggestionRegistry suggestionRegistry = new SuggestionRegistry<>(); @@ -38,10 +39,14 @@ public class RegistryContainer { return argumentRegistry; } - public @NotNull NamedArgumentRegistry getNamedArgumentRegistry() { + public @NotNull NamedArgumentRegistry getNamedArgumentRegistry() { return namedArgumentRegistry; } + public FlagRegistry getFlagRegistry() { + return flagRegistry; + } + public @NotNull RequirementRegistry getRequirementRegistry() { return requirementRegistry; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java index 8eb0763a..7da8adcc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java @@ -427,7 +427,7 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi } private @NotNull Map<@NotNull String, @NotNull InternalArgument> collectNamedArgs(final @NotNull String key) { - final List arguments = namedArgumentRegistry.getResolver(ArgumentKey.of(key)); + final List arguments = namedArgumentRegistry.getArguments(ArgumentKey.of(key)); if (arguments == null || arguments.isEmpty()) { throw createException("No registered named arguments found for key \"" + key + "\""); } From b9b75e044d4f8e4487ca9c0079a7f04521bae76c Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 28 Dec 2022 22:57:24 +0000 Subject: [PATCH 038/101] feature: Finalizing named arguments and most of command registration --- .../cmd/core/annotations/Flag.java | 12 ++- .../core/argument/EnumInternalArgument.java | 4 - .../core/argument/KeyedInternalArgument.java | 84 ++++++++++++++++++ .../cmd/core/argument/keyed/ArgumentKey.java | 14 +++ .../cmd/core/argument/keyed/FlagKey.java | 15 +--- .../keyed/internal/ArgumentGroup.java | 12 +-- .../argument/keyed/internal/FlagGroup.java | 16 +++- .../keyed/internal/FlagsContainer.java | 2 +- .../argument/keyed/internal/ListArgument.java | 2 +- .../argument/keyed/internal/NamedGroup.java | 8 +- .../keyed/internal/SimpleArgument.java | 3 +- .../cmd/core/extention/StringKey.java | 1 - .../cmd/core/extention/meta/MetaKey.java | 16 ++++ .../cmd/core/message/ContextualKey.java | 16 ---- .../processor/AbstractCommandProcessor.java | 47 +++++----- .../cmd/core/processor/CommandProcessor.java | 1 + .../OldAbstractSubCommandProcessor.java | 30 +------ .../core/processor/SubCommandProcessor.java | 85 +++++++++++++++++++ .../cmd/core/requirement/RequirementKey.java | 17 ---- .../cmd/core/suggestion/SuggestionKey.java | 17 ---- 20 files changed, 262 insertions(+), 140 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Flag.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Flag.java index ab99ed1e..42dd518a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Flag.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Flag.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.annotations; +import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; import java.lang.annotation.ElementType; @@ -64,6 +65,15 @@ */ @NotNull Class argument() default void.class; - // TODO: Comments + /** + * The value for the {@link SuggestionKey} of a registered suggestion. + * + * @return The string key of a suggestion. + */ @NotNull String suggestion() default ""; + + /** + * @return The flag's description. + */ + @NotNull String description() default ""; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java index bf35e1ea..3ae295aa 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java @@ -57,10 +57,6 @@ public EnumInternalArgument( populateCache(type); } - public @NotNull Class> getEnumType() { - return enumType; - } - /** * Resolves the argument type. * diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java new file mode 100644 index 00000000..f4a3798a --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java @@ -0,0 +1,84 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.argument; + +import dev.triumphteam.cmd.core.argument.keyed.Flags; +import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; +import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; +import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentParser; +import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; +import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; +import dev.triumphteam.cmd.core.suggestion.SuggestionContext; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.List; + + +public final class KeyedInternalArgument extends LimitlessInternalArgument { + + private final ArgumentGroup argumentGroup; + private final ArgumentGroup flagGroup; + private final ArgumentParser argumentParser; + + public KeyedInternalArgument( + final @NotNull String name, + final @NotNull String description, + final @NotNull ArgumentGroup flagGroup, + final @NotNull ArgumentGroup argumentGroup + ) { + super(name, description, Flags.class, new EmptySuggestion<>(), true); + this.flagGroup = flagGroup; + this.argumentGroup = argumentGroup; + this.argumentParser = new ArgumentParser(flagGroup, argumentGroup); + } + + /** + * Resolves the argument type. + * + * @param sender The sender to resolve to. + * @param value The arguments {@link List}. + * @return A {@link Flags} which contains the flags and leftovers. + */ + @Override + public @NotNull Object resolve(final @NotNull S sender, final @NotNull List<@NotNull String> value) { + return null;// flagParser.parse(sender, value.size() == 1 ? Arrays.asList(value.get(0).split(" ")) : value); + } + + @Override + public @NotNull List<@NotNull String> suggestions( + final @NotNull S sender, + final @NotNull List<@NotNull String> trimmed, + final @NotNull SuggestionContext context + ) { + return Collections.emptyList(); + } + + @Override + public @NotNull String toString() { + return "FlagArgument{" + + "flagGroup=" + flagGroup + + ", super=" + super.toString() + "}"; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentKey.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentKey.java index 45ee362a..68167d73 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentKey.java @@ -27,14 +27,28 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +/** + * Identifier for a list of registered named arguments. + */ public class ArgumentKey extends StringKey { private ArgumentKey(final @NotNull String key) { super(key); } + /** + * Factory method for creating a {@link ArgumentKey}. + * + * @param key The value of the key, normally separated by .. + * @return A new {@link ArgumentKey}. + */ @Contract("_ -> new") public static @NotNull ArgumentKey of(final @NotNull String key) { return new ArgumentKey(key); } + + @Override + public @NotNull String toString() { + return "ArgumentKey{super=" + super.toString() + "}"; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagKey.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagKey.java index e51a0822..e8bd6ae9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagKey.java @@ -27,18 +27,13 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - +/** + * Identifier for a list of registered flags. + */ public final class FlagKey extends StringKey { - // Holds all registered keys, default and custom ones - private static final Set REGISTERED_KEYS = new HashSet<>(); - private FlagKey(final @NotNull String key) { super(key); - REGISTERED_KEYS.add(this); } /** @@ -52,10 +47,6 @@ private FlagKey(final @NotNull String key) { return new FlagKey(key); } - public static @NotNull Set<@NotNull FlagKey> getRegisteredKeys() { - return Collections.unmodifiableSet(REGISTERED_KEYS); - } - @Override public @NotNull String toString() { return "FlagKey{super=" + super.toString() + "}"; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java index 9323d204..0ecec743 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java @@ -16,10 +16,11 @@ public interface ArgumentGroup { /** * Static factory for creating a new flag {@link ArgumentGroup} of type {@link Flag}. * + * @param flags The {@link List} of {@link Flag}s. * @return A {@link FlagGroup} instance. */ - static ArgumentGroup flags() { - return new FlagGroup<>(); + static ArgumentGroup flags(final @NotNull List flags) { + return new FlagGroup(flags); } /** @@ -32,13 +33,6 @@ static ArgumentGroup named(final @NotNull List arguments) { return new NamedGroup(arguments); } - /** - * Adds a new argument to the group. - * - * @param argument The argument {@link T} that should be added to the group. - */ - void addArgument(final @NotNull T argument); - /** * Gets the argument that matches the current token. * diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java index 4f13d492..1c952417 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java @@ -33,17 +33,18 @@ /** * Basically a holder that contains all the needed flags for the command. - * - * @param The sender type. */ -final class FlagGroup implements ArgumentGroup { +final class FlagGroup implements ArgumentGroup { private final Map flags = new HashMap<>(); private final Map longFlags = new HashMap<>(); private final List allFlags = new ArrayList<>(); - @Override + public FlagGroup(final @NotNull List flags) { + flags.forEach(this::addArgument); + } + public void addArgument(final @NotNull Flag argument) { final String key = argument.getKey(); @@ -86,4 +87,11 @@ public boolean isEmpty() { if (token.startsWith("-")) return token.substring(1); return token; } + + @Override + public String toString() { + return "FlagGroup{" + + "allFlags=" + allFlags + + '}'; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java index e8db2d83..e627c118 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java @@ -6,7 +6,7 @@ import java.util.List; import java.util.Optional; -public abstract class FlagsContainer implements Arguments { +abstract class FlagsContainer implements Arguments { @Override public boolean hasFlag(final @NotNull String flag) { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java index fbf5a1e1..f4fcadcf 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java @@ -27,7 +27,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public final class ListArgument implements Argument { +final class ListArgument implements Argument { private final Class collectionType; private final String separator; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java index daf4fe91..ab6c6842 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java @@ -43,7 +43,6 @@ final class NamedGroup implements ArgumentGroup { arguments.forEach(this::addArgument); } - @Override public void addArgument(final @NotNull Argument argument) { final String name = argument.getName(); allArgumentNames.add(name); @@ -64,4 +63,11 @@ public boolean isEmpty() { public @Nullable Argument getMatchingArgument(final @NotNull String token) { return arguments.get(token); } + + @Override + public String toString() { + return "NamedGroup{" + + "allArgumentNames=" + allArgumentNames + + '}'; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java index 91010eaa..8098e9ed 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java @@ -27,14 +27,13 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public final class SimpleArgument implements Argument { +final class SimpleArgument implements Argument { private final Class type; private final String name; private final String description; private final SuggestionKey suggestionKey; - public SimpleArgument(final @NotNull Argument.AbstractBuilder argumentBuilder) { this.type = argumentBuilder.getType(); this.name = argumentBuilder.getName(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/StringKey.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/StringKey.java index 6326a960..2c04230b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/StringKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/StringKey.java @@ -67,5 +67,4 @@ public int hashCode() { "key='" + key + '\'' + '}'; } - } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java index 230edc4d..77ee10a6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java @@ -4,6 +4,11 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +/** + * Identifier for a specific meta value. + * + * @param The type of the meta value. + */ public final class MetaKey extends StringKey { private final Class valueType; @@ -17,8 +22,19 @@ private MetaKey( this.valueType = valueType; } + /** + * Factory method for creating a {@link MetaKey}. + * + * @param key The value of the key, normally separated by .. + * @return A new {@link MetaKey}. + */ @Contract("_, _ -> new") public static @NotNull MetaKey of(final @NotNull String key, final @NotNull Class valueType) { return new MetaKey<>(key, valueType); } + + @Override + public @NotNull String toString() { + return "MetaKey{super=" + super.toString() + "}"; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java b/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java index aef5527c..8e06a2ac 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/ContextualKey.java @@ -28,25 +28,18 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.HashSet; import java.util.Objects; -import java.util.Set; /** * Registry key, for more organized way of registering and getting things from the registries. */ public abstract class ContextualKey extends StringKey { - // Holds all registered keys, default and custom ones - private static final Set> REGISTERED_KEYS = new HashSet<>(); - private final Class type; protected ContextualKey(final @NotNull String key, final @NotNull Class type) { super(key); this.type = type; - REGISTERED_KEYS.add(this); } /** @@ -58,15 +51,6 @@ protected ContextualKey(final @NotNull String key, final @NotNull Class type) return type; } - /** - * Gets an immutable {@link Set} with all the registered keys. - * - * @return The keys {@link Set}. - */ - public static @NotNull Set<@NotNull ContextualKey> getRegisteredKeys() { - return Collections.unmodifiableSet(REGISTERED_KEYS); - } - @Override public boolean equals(final @Nullable Object o) { if (this == o) return true; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 366d32ec..116728cd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -36,9 +36,15 @@ import dev.triumphteam.cmd.core.argument.EnumInternalArgument; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; +import dev.triumphteam.cmd.core.argument.KeyedInternalArgument; import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; +import dev.triumphteam.cmd.core.argument.keyed.Arguments; +import dev.triumphteam.cmd.core.argument.keyed.Flags; +import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; +import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; +import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; @@ -137,6 +143,8 @@ public SubCommandRegistrationException createException(final @NotNull String mes final @NotNull Parameter parameter, final @NotNull List argDescriptions, final @NotNull Map> suggestions, + final @NotNull ArgumentGroup flagGroup, + final @NotNull ArgumentGroup argumentGroup, final int position ) { final Class type = parameter.getType(); @@ -196,36 +204,23 @@ public SubCommandRegistrationException createException(final @NotNull String mes ); } - // Handler for flags. - // TODO RE-ADD FLAGS AND NAMED ARGUMENTS AS A SINGLE TYPE - /*if (type == Flags.class) { - if (flagGroup.isEmpty()) { - throw createException("Flags internalArgument detected but no flag annotation declared"); + // Handle flags and named arguments + if (Flags.class.isAssignableFrom(type)) { + + if (type == Arguments.class) { + if (argumentGroup.isEmpty()) { + throw createException("No named arguments found, if you want only Flags use the \"" + Flags.class.getSimpleName() + "\" argument instead"); + } + } else if (type == Flags.class) { + if (flagGroup.isEmpty()) { + throw createException("No declared flags found, make sure you have registered or declared some, or make sure the key is correct."); + } } - return new FlagInternalArgument<>( - argumentName, - argumentDescription, - flagGroup, - optional - ); + return new KeyedInternalArgument<>(argumentName, argumentDescription, flagGroup, argumentGroup); } - // Handler for named arguments - if (type == Arguments.class) { - final NamedArguments namedArguments = annotatedElement.getAnnotation(NamedArguments.class); - if (namedArguments == null) { - throw createException("TODO"); - } - - return new NamedInternalArgument<>( - argumentName, - argumentDescription, - collectNamedArgs(namedArguments.value()), - optional - ); - }*/ - + // No more exceptions found so now just create simple argument return createSimpleArgument( type, argumentName, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index 18dd4b3e..ffdd397e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -22,6 +22,7 @@ public interface CommandProcessor { * @param target The target of the annotation. * @param meta The meta builder that'll be passed to processors. */ + @SuppressWarnings("unchecked") default void processAnnotations( final @NotNull CommandExtensions extensions, final @NotNull AnnotatedElement element, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java index 7da8adcc..e501f21d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java @@ -55,7 +55,6 @@ import dev.triumphteam.cmd.core.argument.keyed.Flags; import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; -import dev.triumphteam.cmd.core.argument.keyed.internal.ListArgument; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; @@ -117,14 +116,14 @@ public abstract class OldAbstractSubCommandProcessor { private final List argDescriptions = new ArrayList<>(); private final List alias = new ArrayList<>(); private final boolean isAsync; - private final ArgumentGroup flagGroup = ArgumentGroup.flags(); + private final ArgumentGroup flagGroup = ArgumentGroup.flags(emptyList()); private final List> suggestionList = new ArrayList<>(); private final List> internalArguments = new ArrayList<>(); private final Set> requirements = new HashSet<>(); private final RegistryContainer registryContainer; private final SuggestionRegistry suggestionRegistry; private final ArgumentRegistry argumentRegistry; - private final NamedArgumentRegistry namedArgumentRegistry; + private final NamedArgumentRegistry namedArgumentRegistry; private final RequirementRegistry requirementRegistry; private final MessageRegistry messageRegistry; private final SenderValidator senderValidator; @@ -436,31 +435,6 @@ protected void createArgument(final @NotNull Parameter parameter, final int posi return arguments.stream().map(argument -> { final Suggestion suggestion = createSuggestion(argument.getSuggestion(), argument.getType()); - if (argument instanceof ListArgument) { - final ListArgument listArgument = (ListArgument) argument; - - final InternalArgument internalArgument = createSimpleArgument( - listArgument.getType(), - listArgument.getName(), - listArgument.getDescription(), - suggestion, - true - ); - - return Maps.immutableEntry( - listArgument.getName(), - new SplitStringInternalArgument<>( - listArgument.getName(), - listArgument.getDescription(), - listArgument.getSeparator(), - internalArgument, - listArgument.getType(), - suggestion, - true - ) - ); - } - return Maps.immutableEntry( argument.getName(), createSimpleArgument( diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index 538ac4f0..4551692e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -25,12 +25,21 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.annotations.ArgDescriptions; +import dev.triumphteam.cmd.core.annotations.CommandFlags; +import dev.triumphteam.cmd.core.annotations.NamedArguments; import dev.triumphteam.cmd.core.annotations.Suggestions; import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; +import dev.triumphteam.cmd.core.argument.keyed.FlagKey; +import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; +import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; +import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.FlagRegistry; +import dev.triumphteam.cmd.core.extention.registry.NamedArgumentRegistry; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; @@ -64,6 +73,8 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { private final Method method; + private final NamedArgumentRegistry namedArgumentRegistry; + private final FlagRegistry flagRegistry; SubCommandProcessor( final @NotNull String parentName, @@ -76,6 +87,8 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { super(parentName, baseCommand, method, registryContainer, commandExtensions, parentMeta); this.method = method; + this.namedArgumentRegistry = registryContainer.getNamedArgumentRegistry(); + this.flagRegistry = registryContainer.getFlagRegistry(); } @Override @@ -117,6 +130,12 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { return (Class) type; } + /** + * Create all arguments necessary for the command to function. + * + * @param parentMeta The {@link CommandMeta} inherited from the parent command. + * @return A {@link List} of validated arguments. + */ public @NotNull List> arguments(final @NotNull CommandMeta parentMeta) { final Parameter[] parameters = method.getParameters(); @@ -133,6 +152,8 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { final List argDescriptions = argDescriptionFromMethodAnnotation(); final Map> suggestions = suggestionsFromMethodAnnotation(); + final ArgumentGroup flagGroup = flagGroupFromMethod(method); + final ArgumentGroup argumentGroup = argumentGroupFromMethod(method); // Position of the last argument. final int last = parameters.length - 1; @@ -147,6 +168,8 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { parameter, argDescriptions, suggestions, + flagGroup, + argumentGroup, i ); @@ -172,6 +195,68 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { return arguments; } + /** + * Create a named argument group from the values passed by the annotation. + * + * @param method The method to extract annotations from. + * @return The final group of named arguments or null if none was available. + */ + private @NotNull ArgumentGroup argumentGroupFromMethod(final @NotNull Method method) { + final NamedArguments namedAnnotation = method.getAnnotation(NamedArguments.class); + if (namedAnnotation == null) return ArgumentGroup.named(emptyList()); + + final List argumentsFromRegistry = namedArgumentRegistry.getArguments(ArgumentKey.of(namedAnnotation.value())); + if (argumentsFromRegistry == null) return ArgumentGroup.named(emptyList()); + + return ArgumentGroup.named(argumentsFromRegistry); + } + + /** + * Create a flag group from the values passed by the annotation. + * + * @param method The method to extract annotations from. + * @return The final group of flags or null if none was available. + */ + private @NotNull ArgumentGroup flagGroupFromMethod(final @NotNull Method method) { + final CommandFlags flagsAnnotation = method.getAnnotation(CommandFlags.class); + + if (flagsAnnotation != null) { + final String key = flagsAnnotation.key(); + // We give priority to keyed value from the registry + if (!key.isEmpty()) { + final List flagsFromRegistry = flagRegistry.getFlags(FlagKey.of(key)); + if (flagsFromRegistry != null) return ArgumentGroup.flags(flagsFromRegistry); + } + + // If key not present, parse annotations into usable flag data + final List flags = flagsFromRawFlags(Arrays.asList(flagsAnnotation.value())); + return ArgumentGroup.flags(flags); + } + + final dev.triumphteam.cmd.core.annotations.Flag flagAnnotation = method.getAnnotation(dev.triumphteam.cmd.core.annotations.Flag.class); + if (flagAnnotation == null) return ArgumentGroup.flags(emptyList()); + // Parse single annotation into usable flag data + final List flags = flagsFromRawFlags(singletonList(flagAnnotation)); + return ArgumentGroup.flags(flags); + } + + /** + * Converts a flag annotation into usable flag data just like the one from the registry. + * + * @param rawFlags The raw flag annotations. + * @return The converted flag data. + */ + private @NotNull List flagsFromRawFlags(final @NotNull List rawFlags) { + return rawFlags.stream().map(it -> Flag.flag(it.flag()) + .longFlag(it.longFlag()) + .argument(it.argument()) + .description(it.description()) + .suggestion(SuggestionKey.of(it.suggestion())) + .build() + ).collect(Collectors.toList()); + + } + /** * Extracts the {@link ArgDescriptions} Annotation from the Method. * diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java index e10a91b5..50b1872e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementKey.java @@ -28,21 +28,13 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - /** * Key used to identify the {@link RequirementResolver} in the {@link RequirementRegistry}. */ public final class RequirementKey extends StringKey { - // Holds all registered keys, default and custom ones - private static final Set REGISTERED_KEYS = new HashSet<>(); - private RequirementKey(final @NotNull String key) { super(key); - REGISTERED_KEYS.add(this); } /** @@ -56,15 +48,6 @@ private RequirementKey(final @NotNull String key) { return new RequirementKey(key); } - /** - * Gets an immutable {@link Set} with all the registered keys. - * - * @return The keys {@link Set}. - */ - public static @NotNull Set<@NotNull RequirementKey> getRegisteredKeys() { - return Collections.unmodifiableSet(REGISTERED_KEYS); - } - @Override public @NotNull String toString() { return "RequirementKey{super=" + super.toString() + "}"; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java index dc2199dd..54306133 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java @@ -27,21 +27,13 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - /** * Key used to identify the {@link } in the {@link }. */ public final class SuggestionKey extends StringKey { - // Holds all registered keys, default and custom ones - private static final Set REGISTERED_KEYS = new HashSet<>(); - private SuggestionKey(final @NotNull String key) { super(key); - REGISTERED_KEYS.add(this); } /** @@ -55,15 +47,6 @@ private SuggestionKey(final @NotNull String key) { return new SuggestionKey(key); } - /** - * Gets an immutable {@link Set} with all the registered keys. - * - * @return The keys {@link Set}. - */ - public static @NotNull Set<@NotNull SuggestionKey> getRegisteredKeys() { - return Collections.unmodifiableSet(REGISTERED_KEYS); - } - @Override public @NotNull String toString() { return "SuggestionKey{super=" + super.toString() + "}"; From 28df64ca247160fa950387152049c5e51fc850d6 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 29 Dec 2022 00:16:39 +0000 Subject: [PATCH 039/101] chore: Cleanup and polishing --- .../argument/AbstractInternalArgument.java | 15 --- .../argument/CollectionInternalArgument.java | 16 --- .../core/argument/EnumInternalArgument.java | 15 --- .../JoinedStringInternalArgument.java | 16 --- .../argument/ResolverInternalArgument.java | 16 --- .../argument/UnknownInternalArgument.java | 7 + .../cmd/core/command/SubCommand.java | 2 - .../cmd/core/extention/meta/CommandMeta.java | 122 ++++++++++++++++-- .../extention/meta/ImmutableCommandMeta.java | 2 +- .../cmd/core/processor/CommandProcessor.java | 5 + 10 files changed, 127 insertions(+), 89 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java index 319d2afa..fe765a3c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java @@ -26,10 +26,8 @@ import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.Objects; /** * Command internalArgument. @@ -111,19 +109,6 @@ public boolean isOptional() { return suggestion; } - @Override - public boolean equals(final @Nullable Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final AbstractInternalArgument internalArgument = (AbstractInternalArgument) o; - return optional == internalArgument.optional && name.equals(internalArgument.name) && type.equals(internalArgument.type); - } - - @Override - public int hashCode() { - return Objects.hash(name, type, optional); - } - @Override public @NotNull String toString() { return "AbstractInternalArgument{" + diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java index 9684ce42..d2ee707b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java @@ -25,10 +25,8 @@ import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.Objects; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -71,20 +69,6 @@ public CollectionInternalArgument( return stream.collect(Collectors.toList()); } - @Override - public boolean equals(final @Nullable Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - final CollectionInternalArgument that = (CollectionInternalArgument) o; - return collectionType.equals(that.collectionType); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), collectionType); - } - @Override public @NotNull String toString() { return "CollectionArgument{" + diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java index 3ae295aa..205f657a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java @@ -28,7 +28,6 @@ import org.jetbrains.annotations.Nullable; import java.lang.ref.WeakReference; -import java.util.Objects; import static dev.triumphteam.cmd.core.util.EnumUtils.getEnumConstants; import static dev.triumphteam.cmd.core.util.EnumUtils.populateCache; @@ -71,20 +70,6 @@ public EnumInternalArgument( return reference.get(); } - @Override - public boolean equals(final @Nullable Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - final EnumInternalArgument that = (EnumInternalArgument) o; - return enumType.equals(that.enumType); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), enumType); - } - @Override public @NotNull String toString() { return "EnumArgument{" + diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java index 9c4e6fc2..f53edf26 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java @@ -25,10 +25,8 @@ import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.List; -import java.util.Objects; /** * Joined string argument, a {@link LimitlessInternalArgument}. @@ -63,20 +61,6 @@ public JoinedStringInternalArgument( return String.join(delimiter, value); } - @Override - public boolean equals(final @Nullable Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - final JoinedStringInternalArgument that = (JoinedStringInternalArgument) o; - return delimiter.equals(that.delimiter); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), delimiter); - } - @Override public @NotNull String toString() { return "JoinedStringArgument{" + diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java index f0050359..9a68fabd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java @@ -28,8 +28,6 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Objects; - /** * Normal {@link StringInternalArgument}. * Basically the main implementation. @@ -66,20 +64,6 @@ public ResolverInternalArgument( return resolver.resolve(sender, value); } - @Override - public boolean equals(final @Nullable Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - final ResolverInternalArgument that = (ResolverInternalArgument) o; - return resolver.equals(that.resolver); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), resolver); - } - @Override public @NotNull String toString() { return "ResolverArgument{" + diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index d4861c7d..80b071e6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -48,4 +48,11 @@ public boolean isOptional() { public @NotNull List<@NotNull String> suggestions(@NotNull final S sender, final @NotNull List<@NotNull String> trimmed, final @NotNull SuggestionContext context) { return Collections.emptyList(); } + + @Override + public String toString() { + return "UnknownInternalArgument{" + + "type=" + type + + '}'; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index a76266ff..455f1b79 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -22,8 +22,6 @@ public SubCommand( this.meta = processor.createMeta(); this.senderType = processor.senderType(); this.arguments = processor.arguments(meta); - - System.out.println(meta); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java index 4d3f3641..e9a9813f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java @@ -1,44 +1,150 @@ package dev.triumphteam.cmd.core.extention.meta; +import dev.triumphteam.cmd.core.command.Command; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.HashMap; import java.util.Map; +import java.util.Optional; +/** + * Storage for custom data stored in a {@link Command} or argument. + * Meta is only mutable during its {@link Builder} state, once it's fully built it'll be fully immutable. + */ public interface CommandMeta { - @SuppressWarnings("unchecked") - @Nullable V get(final @NotNull MetaKey metaKey); + /** + * Get the value of the meta associated with the passed {@link MetaKey}. + * + * @param metaKey The {@link MetaKey} associated with the value. + * @param The type of the value to cast to. + * @return An {@link Optional} value as {@link V}. + */ + @NotNull Optional get(final @NotNull MetaKey metaKey); + + /** + * Get the value of the meta associated with the passed {@link MetaKey}. + * + * @param metaKey The {@link MetaKey} associated with the value. + * @param The type of the value to cast to. + * @return A nullable value as {@link V}. + */ + @Nullable V getNullable(final @NotNull MetaKey metaKey); + + /** + * Get the value of the meta associated with the passed {@link MetaKey}. + * + * @param metaKey The {@link MetaKey} associated with the value. + * @param def The default value to return in case the stored value doesn't exist. + * @param The type of the value to cast to. + * @return The value as {@link V} or default {@link V} if it doesn't exist, the return is null if the default value is null. + */ + @Contract("_, null -> null; _, !null -> !null") + V getOrDefault(final @NotNull MetaKey metaKey, final @Nullable V def); + /** + * Checks if there is any value associated with the passed {@link MetaKey}. + * + * @param metaKey The {@link MetaKey} associated with the value. + * @param The type of the value to cast to. + * @return True if the value exists. + */ boolean isPresent(final @NotNull MetaKey metaKey); - public @Nullable CommandMeta getParentMeta(); + /** + * Get the immutable parent {@link CommandMeta} of this instance. + * + * @return The parent meta of this instance. + */ + @Nullable CommandMeta getParentMeta(); - final class Builder { - private final Map, Object> dataMap = new HashMap<>(); + /** + * Simple builder to add to or get from the original meta map because it becomes immutable. + */ + @SuppressWarnings("unchecked") + final class Builder implements CommandMeta { + private final Map, Object> metaMap = new HashMap<>(); private final CommandMeta parentMeta; public Builder(final @Nullable CommandMeta parentMeta) { this.parentMeta = parentMeta; } + /** + * Add the value {@link V} to the map associated by the {@link MetaKey}. + * + * @param metaKey The {@link MetaKey} to be the key of the internal map. + * @param value The nullable value {@link V} to be stored. + * @param The type of value that'll be stored. + */ public void add(final @NotNull MetaKey metaKey, final @Nullable V value) { - dataMap.put(metaKey, value); + metaMap.put(metaKey, value); } + /** + * Add the value {@link V} to the map associated by the {@link MetaKey}. + * Defaults the value to null. + * + * @param metaKey The {@link MetaKey} to be the key of the internal map. + * @param The type of value that'll be stored. + */ public void add(final @NotNull MetaKey metaKey) { add(metaKey, null); } + /** + * {@inheritDoc} + */ + @Override + public @NotNull Optional get(final @NotNull MetaKey metaKey) { + return Optional.ofNullable(getNullable(metaKey)); + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable V getNullable(final @NotNull MetaKey metaKey) { + return (V) metaMap.get(metaKey); + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable V getOrDefault(final @NotNull MetaKey metaKey, @Nullable final V def) { + return (V) metaMap.getOrDefault(metaKey, def); + } + + /** + * {@inheritDoc} + */ + @Override + public boolean isPresent(final @NotNull MetaKey metaKey) { + return metaMap.containsKey(metaKey); + } + + /** + * {@inheritDoc} + */ + @Override public @Nullable CommandMeta getParentMeta() { return parentMeta; } - public CommandMeta build() { - return new ImmutableCommandMeta(parentMeta, Collections.unmodifiableMap(dataMap)); + /** + * Creates the final immutable meta. + * This should not be used externally, but if you need a copy of the current meta state, sure. + * + * @return A new {@link CommandMeta} with the current meta map immutable. + */ + @Contract(" -> new") + public @NotNull CommandMeta build() { + return new ImmutableCommandMeta(parentMeta, Collections.unmodifiableMap(metaMap)); } } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java index 907a176a..d70baad2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java @@ -20,7 +20,7 @@ public ImmutableCommandMeta( @SuppressWarnings("unchecked") @Override - public @Nullable V get(final @NotNull MetaKey metaKey) { + public @Nullable V getNullable(final @NotNull MetaKey metaKey) { return (V) meta.get(metaKey); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index ffdd397e..d1b39581 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -12,6 +12,11 @@ public interface CommandProcessor { + /** + * Create a new meta and handle some processing before it's fully created. + * + * @return The immutable {@link CommandMeta} instance. + */ @NotNull CommandMeta createMeta(); /** From aefc0d6843f24ce4e3d77818dcdcf47020a86624 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 30 Dec 2022 00:35:52 +0000 Subject: [PATCH 040/101] feature: Argument-as-subcommand, multi-level sub command declaration --- .../triumphteam/cmd/core/command/Command.java | 20 ++- .../cmd/core/command/ExecutableCommand.java | 36 +++++ .../cmd/core/command/ParentCommand.java | 78 +++++++--- .../cmd/core/command/ParentSubCommand.java | 137 +++++++++++++++++- .../cmd/core/command/SubCommand.java | 43 +++++- .../execution/AsyncExecutionProvider.java | 2 +- .../core/command/execution/ExecutionData.java | 25 ++++ .../execution/ExecutionProvider.java | 2 +- .../execution/SyncExecutionProvider.java | 2 +- .../CommandRegistrationException.java | 3 +- .../extention/meta/CommandMetaContainer.java | 6 + .../extention/meta/ImmutableCommandMeta.java | 13 +- .../extention/sender/SenderExtension.java | 4 +- .../processor/AbstractCommandProcessor.java | 7 + .../AbstractRootCommandProcessor.java | 67 +++++++-- .../OldAbstractCommandProcessor.java | 2 +- .../processor/ParentCommandProcessor.java | 5 - .../cmd/core/subcommand/OldSubCommand.java | 2 +- .../cmds/simple/SimpleCommand.java | 59 +++++--- .../cmds/simple/SimpleCommandManager.java | 10 +- .../cmds/simple/SimpleSubCommand.java | 2 +- 21 files changed, 448 insertions(+), 77 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/execution/AsyncExecutionProvider.java (96%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionData.java rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/execution/ExecutionProvider.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/{ => command}/execution/SyncExecutionProvider.java (96%) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 39d2e789..4f4e2fe7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -26,7 +26,25 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMetaContainer; import org.jetbrains.annotations.NotNull; -public interface Command extends CommandMetaContainer { +/** + * Representation of a command. + * Not all commands are executable directly. + * Some implementations will have listeners inside that'll trigger the execution. + */ +public interface Command extends CommandMetaContainer { + /** + * @return The name of the comamnd. + */ @NotNull String getName(); + + /** + * @return Whether this is a "default" command, meaning it represents the class itself and is not separate. + */ + boolean isDefault(); + + /** + * @return Whether the command has arguments. + */ + boolean hasArguments(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java new file mode 100644 index 00000000..4eeaade6 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java @@ -0,0 +1,36 @@ +package dev.triumphteam.cmd.core.command; + +import dev.triumphteam.cmd.core.BaseCommand; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.function.Supplier; + +/** + * An executable command is not just a holder that has its own triggers for commands but one that needs external execution trigger. + * + * @param The type of sender to be used. + */ +public interface ExecutableCommand extends Command { + + /** + * Executes this command. + * + * @param sender The sender of the command. + * @param command The command typed. + * @param instanceSupplier The instance supplier for execution. + * @param arguments The list of arguments passed. + */ + void execute( + final @NotNull S sender, + final @NotNull String command, + final @Nullable Supplier instanceSupplier, + final @NotNull List arguments + ); + + /** + * @return The instance of the original base command class where the command belongs to. + */ + @NotNull BaseCommand getBaseCommand(); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index 5196fb13..1e19532a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -30,43 +30,83 @@ import java.util.Map; /** - * Command interface which all platforms will implement. + * A parent command means it's a simple holder of other commands. + * The commands can either be a parent as well or simple sub commands. * * @param The sender type. */ -public interface ParentCommand extends Command { +public interface ParentCommand extends Command { - @NotNull String getName(); + /** + * @return The map with all the commands it holds. + */ + @NotNull Map> getCommands(); - @NotNull Map> getCommands(); + /** + * @return The map with all the command alias it holds. + */ + @NotNull Map> getCommandAliases(); - @NotNull Map> getCommandAliases(); + /** + * @return A parent command with arguments as a sub command. Null if none exists. + */ + @Nullable ExecutableCommand getParentCommandWithArgument(); - void addSubCommand(final @NotNull Command subCommand, final boolean isAlias); + /** + * Add a new command to the maps. + * + * @param subCommand The sub command to be added. + * @param isAlias Whether it is an alias. + */ + void addSubCommand(final @NotNull ExecutableCommand subCommand, final boolean isAlias); - default @Nullable Command getSubCommand(final @NotNull List args) { - Command subCommand = getDefaultSubCommand(); + @Override + default boolean isDefault() { + return false; + } + + @Override + default boolean hasArguments() { + return !getCommands().isEmpty(); + } + + /** + * Small abstraction to reduce repetition in the execution. + * + * @param name The name of the command, normally from {@link #nameFromArguments}. + * @param size The size of arguments passed to the execution. + * @return The default command, a sub command, or a parent command with arguments, and lastly null if none exist. + */ + default @Nullable ExecutableCommand getSubCommand(final @NotNull String name, final int size) { + ExecutableCommand subCommand = getDefaultSubCommand(); - String subCommandName = ""; - if (args.size() > 0) subCommandName = args.get(0).toLowerCase(); - if (subCommand == null || subCommandExists(subCommandName)) { - subCommand = getSubCommand(subCommandName); + if (subCommand == null || subCommandExists(name)) { + subCommand = getSubCommand(name); } - // TODO - /*if (subCommand == null || (args.size() > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { - return null; - }*/ + if (subCommand == null || (size > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { + return getParentCommandWithArgument(); + } return subCommand; } - default @Nullable Command getDefaultSubCommand() { + /** + * Gets the name of the command from the arguments given. + * + * @param arguments The list of arguments. + * @return The name or an empty string if there are no arguments. + */ + default @NotNull String nameFromArguments(final @NotNull List arguments) { + return arguments.size() > 0 ? arguments.get(0) : ""; + } + + default @Nullable ExecutableCommand getDefaultSubCommand() { return getCommands().get(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); } - default @Nullable Command getSubCommand(final @NotNull String key) { - final Command subCommand = getCommands().get(key); + default @Nullable ExecutableCommand getSubCommand(final @NotNull String key) { + final ExecutableCommand subCommand = getCommands().get(key); if (subCommand != null) return subCommand; return getCommandAliases().get(key); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 5ab848b3..ae889f3f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -1,44 +1,167 @@ package dev.triumphteam.cmd.core.command; +import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import dev.triumphteam.cmd.core.processor.ParentCommandProcessor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.function.Supplier; -public class ParentSubCommand implements ParentCommand { - - private final Map> commands = new HashMap<>(); - private final Map> commandAliases = new HashMap<>(); +/** + * A parent sub command is basically a holder of other sub commands. + * This normally represents an inner class of a main command. + * It can contain arguments which will turn it into an argument-as-subcommand type. + * + * @param The sender type to be used. + */ +public class ParentSubCommand implements ParentCommand, ExecutableCommand { + private final Map> commands = new HashMap<>(); + private final Map> commandAliases = new HashMap<>(); private final String name; private final CommandMeta meta; + private final BaseCommand baseCommand; + private final Constructor constructor; + private final boolean isStatic; + private final StringInternalArgument argument; + private final boolean hasArgument; + private final MessageRegistry messageRegistry; + + // Single parent command with argument + private ExecutableCommand parentCommandWithArgument; public ParentSubCommand( + final @NotNull BaseCommand baseCommand, + final @NotNull Constructor constructor, + final boolean isStatic, + final @Nullable StringInternalArgument argument, final @NotNull ParentCommandProcessor processor ) { + this.baseCommand = baseCommand; + this.constructor = constructor; + this.isStatic = isStatic; + this.argument = argument; + this.hasArgument = argument != null; + this.name = processor.getName(); this.meta = processor.createMeta(); + this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); } @Override - public void addSubCommand(final @NotNull Command subCommand, final boolean isAlias) { + public void addSubCommand(final @NotNull ExecutableCommand subCommand, final boolean isAlias) { + // If it's a parent command with argument we add it + if (subCommand instanceof ParentSubCommand && subCommand.hasArguments()) { + if (parentCommandWithArgument != null) { + throw new CommandRegistrationException("Only one inner command with argument is allowed per command", baseCommand.getClass()); + } + + parentCommandWithArgument = subCommand; + return; + } + + // Normal commands are added here commands.put(subCommand.getName(), subCommand); } + @Override + public void execute( + final @NotNull S sender, + final @NotNull String command, + final @Nullable Supplier instanceSupplier, + final @NotNull List arguments + ) { + final int argumentSize = arguments.size(); + + final String commandName = nameFromArguments(arguments); + final ExecutableCommand subCommand = getSubCommand(commandName, argumentSize); + + if (subCommand == null) { + messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new DefaultMessageContext(name, commandName)); + return; + } + + try { + final Object argumentValue; + if (hasArgument) argumentValue = argument.resolve(sender, command); + else argumentValue = null; + + if (hasArgument && argumentValue == null) { + // TODO INVALID ARGUMENT HERE + return; + } + + final Object instance = createInstance(instanceSupplier, argumentValue); + subCommand.execute(sender, commandName, () -> instance, !subCommand.isDefault() ? arguments.subList(1, argumentSize) : arguments); + } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + /** + * Creates a new instance to be passed down to the child commands. + * + * @param instanceSupplier The instance supplier from parents. + * @param argumentValue The value of the argument to pass if there is an argument. + * @return An instance of this command for execution. + */ + private @NotNull Object createInstance( + final @Nullable Supplier instanceSupplier, + final @Nullable Object argumentValue + ) throws InvocationTargetException, InstantiationException, IllegalAccessException { + // Non-static classes required parent instance + if (!isStatic) { + // If there is no argument don't pass anything + // A bit annoying but if the method has no parameters, "null" is a valid parameter so this check is needed + if (!hasArgument) { + return constructor.newInstance(instanceSupplier == null ? baseCommand : instanceSupplier.get()); + } + + return constructor.newInstance(instanceSupplier == null ? baseCommand : instanceSupplier.get(), argumentValue); + } + + if (!hasArgument) constructor.newInstance(); + return constructor.newInstance(argumentValue); + } + @Override public @NotNull String getName() { return name; } @Override - public @NotNull Map> getCommands() { + public @NotNull BaseCommand getBaseCommand() { + return baseCommand; + } + + @Override + public @Nullable ExecutableCommand getParentCommandWithArgument() { + return parentCommandWithArgument; + } + + @Override + public boolean hasArguments() { + return argument != null; + } + + @Override + public @NotNull Map> getCommands() { return commands; } @Override - public @NotNull Map> getCommandAliases() { + public @NotNull Map> getCommandAliases() { return commandAliases; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 455f1b79..90ef5f14 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -1,13 +1,18 @@ package dev.triumphteam.cmd.core.command; +import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.processor.SubCommandProcessor; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; import java.util.List; +import java.util.function.Supplier; -public class SubCommand implements Command { +public class SubCommand implements ExecutableCommand { private final List> arguments; private final Class senderType; @@ -15,15 +20,36 @@ public class SubCommand implements Command { private final String name; private final CommandMeta meta; + private final BaseCommand baseCommand; + private final Method method; + public SubCommand( + final @NotNull BaseCommand baseCommand, + final @NotNull Method method, final @NotNull SubCommandProcessor processor ) { + this.baseCommand = baseCommand; + this.method = method; this.name = processor.getName(); this.meta = processor.createMeta(); this.senderType = processor.senderType(); this.arguments = processor.arguments(meta); } + @Override + public void execute( + final @NotNull S sender, + final @NotNull String command, + final @Nullable Supplier instanceSupplier, + final @NotNull List arguments + ) { + try { + method.invoke(instanceSupplier == null ? baseCommand : instanceSupplier.get(), sender); + } catch (IllegalAccessException | InvocationTargetException e) { + throw new RuntimeException(e); + } + } + @Override public @NotNull CommandMeta getMeta() { return meta; @@ -33,4 +59,19 @@ public SubCommand( public @NotNull String getName() { return name; } + + @Override + public @NotNull BaseCommand getBaseCommand() { + return baseCommand; + } + + @Override + public boolean isDefault() { + return name.equals(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); + } + + @Override + public boolean hasArguments() { + return !arguments.isEmpty(); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/execution/AsyncExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/AsyncExecutionProvider.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/execution/AsyncExecutionProvider.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/execution/AsyncExecutionProvider.java index dffbede5..40bee8e8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/execution/AsyncExecutionProvider.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/AsyncExecutionProvider.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.execution; +package dev.triumphteam.cmd.core.command.execution; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionData.java b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionData.java new file mode 100644 index 00000000..57e9dca8 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionData.java @@ -0,0 +1,25 @@ +package dev.triumphteam.cmd.core.command.execution; + +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Method; +import java.util.function.Supplier; + +public final class ExecutionData { + + private final Supplier instanceSupplier; + private final Method method; + + public ExecutionData(final @NotNull Supplier instanceSupplier, final @NotNull Method method) { + this.instanceSupplier = instanceSupplier; + this.method = method; + } + + public @NotNull Supplier getInstanceSupplier() { + return instanceSupplier; + } + + public @NotNull Method getMethod() { + return method; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/execution/ExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionProvider.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/execution/ExecutionProvider.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionProvider.java index cb5c6fb0..422a4f07 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/execution/ExecutionProvider.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionProvider.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.execution; +package dev.triumphteam.cmd.core.command.execution; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/execution/SyncExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/SyncExecutionProvider.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/execution/SyncExecutionProvider.java rename to core/src/main/java/dev/triumphteam/cmd/core/command/execution/SyncExecutionProvider.java index 2b1e2b0d..a434e717 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/execution/SyncExecutionProvider.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/SyncExecutionProvider.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.execution; +package dev.triumphteam.cmd.core.command.execution; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java index d57a6045..2e873d37 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/CommandRegistrationException.java @@ -23,7 +23,6 @@ */ package dev.triumphteam.cmd.core.exceptions; -import dev.triumphteam.cmd.core.BaseCommand; import org.jetbrains.annotations.NotNull; /** @@ -37,7 +36,7 @@ public CommandRegistrationException(final @NotNull String message) { public CommandRegistrationException( final @NotNull String message, - final @NotNull Class commandClass + final @NotNull Class commandClass ) { super(message + ". In Class \"" + commandClass.getName() + "\""); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java index dba7d432..37676e39 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java @@ -2,7 +2,13 @@ import org.jetbrains.annotations.NotNull; +/** + * Something that can hold a {@link CommandMeta} instance. + */ public interface CommandMetaContainer { + /** + * @return the {@link CommandMeta} of the container. + */ @NotNull CommandMeta getMeta(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java index d70baad2..638a6301 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java @@ -4,7 +4,9 @@ import org.jetbrains.annotations.Nullable; import java.util.Map; +import java.util.Optional; +@SuppressWarnings("unchecked") final class ImmutableCommandMeta implements CommandMeta { private final CommandMeta parentMeta; @@ -18,12 +20,21 @@ public ImmutableCommandMeta( this.meta = meta; } - @SuppressWarnings("unchecked") + @Override + public @NotNull Optional get(final @NotNull MetaKey metaKey) { + return Optional.ofNullable(getNullable(metaKey)); + } + @Override public @Nullable V getNullable(final @NotNull MetaKey metaKey) { return (V) meta.get(metaKey); } + @Override + public V getOrDefault(final @NotNull MetaKey metaKey, @Nullable final V def) { + return (V) meta.getOrDefault(metaKey, def); + } + @Override public boolean isPresent(final @NotNull MetaKey metaKey) { return meta.containsKey(metaKey); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java index 9ec17977..f967cda4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java @@ -1,6 +1,6 @@ package dev.triumphteam.cmd.core.extention.sender; -import dev.triumphteam.cmd.core.command.Command; +import dev.triumphteam.cmd.core.command.ExecutableCommand; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -13,7 +13,7 @@ public interface SenderExtension { boolean validate( final @NotNull MessageRegistry messageRegistry, - final @NotNull Command command, + final @NotNull ExecutableCommand command, final @NotNull S sender ); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 116728cd..dbb830a0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -90,6 +90,8 @@ abstract class AbstractCommandProcessor implements CommandProcessor { private final String name; private final AnnotatedElement annotatedElement; + private final RegistryContainer registryContainer; + private final SuggestionRegistry suggestionRegistry; private final ArgumentRegistry argumentRegistry; @@ -111,10 +113,15 @@ abstract class AbstractCommandProcessor implements CommandProcessor { this.parentMeta = parentMeta; this.commandExtensions = commandExtensions; + this.registryContainer = registryContainer; this.suggestionRegistry = registryContainer.getSuggestionRegistry(); this.argumentRegistry = registryContainer.getArgumentRegistry(); } + public @NotNull RegistryContainer getRegistryContainer() { + return registryContainer; + } + protected @NotNull CommandMeta getParentMeta() { return parentMeta; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java index 36b7b4b9..41286330 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java @@ -24,8 +24,12 @@ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.core.annotations.Description; -import dev.triumphteam.cmd.core.command.Command; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; +import dev.triumphteam.cmd.core.command.ExecutableCommand; import dev.triumphteam.cmd.core.command.ParentSubCommand; import dev.triumphteam.cmd.core.command.SubCommand; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; @@ -36,12 +40,17 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.lang.reflect.Parameter; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import static java.util.Collections.emptyList; +import static java.util.Collections.emptyMap; + @SuppressWarnings("unchecked") public abstract class AbstractRootCommandProcessor implements CommandProcessor { @@ -93,21 +102,21 @@ public String getDescription() { return meta.build(); } - public @NotNull List> commands(final @NotNull CommandMeta parentMeta) { + public @NotNull List> commands(final @NotNull CommandMeta parentMeta) { final Class klass = baseCommand.getClass(); - final List> subCommands = new ArrayList<>(); + final List> subCommands = new ArrayList<>(); subCommands.addAll(methodCommands(parentMeta, klass.getDeclaredMethods())); subCommands.addAll(classCommands(parentMeta, klass.getDeclaredClasses())); return subCommands; } - private @NotNull List> methodCommands( + private @NotNull List> methodCommands( final @NotNull CommandMeta parentMeta, final @NotNull Method[] methods ) { - final List> commands = new ArrayList<>(); + final List> commands = new ArrayList<>(); for (final Method method : methods) { // Ignore non-public methods if (!Modifier.isPublic(method.getModifiers())) continue; @@ -125,17 +134,17 @@ public String getDescription() { if (processor.getName() == null) continue; // Add new command - commands.add(new SubCommand<>(processor)); + commands.add(new SubCommand<>(baseCommand, method, processor)); } return commands; } - private @NotNull List> classCommands( + private @NotNull List> classCommands( final @NotNull CommandMeta parentMeta, final @NotNull Class[] classes ) { - final List> commands = new ArrayList<>(); + final List> commands = new ArrayList<>(); for (final Class klass : classes) { // Ignore non-public methods if (!Modifier.isPublic(klass.getModifiers())) continue; @@ -152,7 +161,47 @@ public String getDescription() { // Not a command, ignore the method if (processor.getName() == null) continue; - final ParentSubCommand parent = new ParentSubCommand<>(processor); + // Validation for allowed constructor + final Constructor[] constructors = klass.getConstructors(); + if (constructors.length != 1) { + throw new CommandRegistrationException("Inner command class can only have a single constructor, " + constructors.length + " found", klass); + } + + // Validation for allowed arguments + final Constructor constructor = constructors[0]; + final Parameter[] parameters = constructor.getParameters(); + + final boolean isStatic = Modifier.isStatic(klass.getModifiers()); + final int arguments = (isStatic ? parameters.length : parameters.length - 1); + final boolean hasArgument = arguments != 0; + + if (arguments > 1) { + throw new CommandRegistrationException("Inner command class can only have a maximum of 1 argument, " + arguments + " found", klass); + } + + final InternalArgument argument; + if (!hasArgument) argument = null; + else { + if (!Command.DEFAULT_CMD_NAME.equals(processor.getName())) { + throw new CommandRegistrationException("Inner command class with argument must not have a name", klass); + } + + final Parameter parameter = isStatic ? parameters[0] : parameters[1]; + argument = processor.createArgument( + parameter, + emptyList(), + emptyMap(), + ArgumentGroup.flags(emptyList()), + ArgumentGroup.named(emptyList()), + 0 + ); + + if (!(argument instanceof StringInternalArgument)) { + throw new CommandRegistrationException("Inner command class with argument must not be limitless, only single string argument is allowed", klass); + } + } + + final ParentSubCommand parent = new ParentSubCommand<>(baseCommand, constructor, isStatic, (StringInternalArgument) argument, processor); // Add children commands to parent methodCommands(parent.getMeta(), klass.getDeclaredMethods()).forEach(it -> parent.addSubCommand(it, false)); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java index d37109a8..5c2ea84f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java @@ -29,7 +29,7 @@ import dev.triumphteam.cmd.core.annotations.Description; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; +import dev.triumphteam.cmd.core.command.execution.ExecutionProvider; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderMapper; import dev.triumphteam.cmd.core.extention.sender.SenderValidator; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java index ca1b28e6..abf5d8fd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java @@ -24,7 +24,6 @@ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; @@ -66,8 +65,4 @@ public final class ParentCommandProcessor extends AbstractCommandProcessor // Return modified meta return meta.build(); } - - public InternalArgument argument(final @NotNull CommandMeta parentMeta) { - return null; - } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java index 9f307b0a..91ace876 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java @@ -29,7 +29,7 @@ import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; +import dev.triumphteam.cmd.core.command.execution.ExecutionProvider; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index dc5552cf..37e8f897 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -23,11 +23,16 @@ */ package dev.triumphteam.cmds.simple; -import dev.triumphteam.cmd.core.command.Command; +import dev.triumphteam.cmd.core.command.ExecutableCommand; import dev.triumphteam.cmd.core.command.ParentCommand; +import dev.triumphteam.cmd.core.command.ParentSubCommand; +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.HashMap; import java.util.List; @@ -39,10 +44,11 @@ public final class SimpleCommand implements ParentCommand { private final MessageRegistry messageRegistry; - private final Map> subCommands = new HashMap<>(); - private final Map> subCommandAliases = new HashMap<>(); + private final Map> subCommands = new HashMap<>(); + private final Map> subCommandAliases = new HashMap<>(); private final CommandMeta meta; + private ExecutableCommand parentCommandWithArgument; @SuppressWarnings("unchecked") public SimpleCommand( @@ -55,43 +61,58 @@ public SimpleCommand( this.messageRegistry = messageRegistry; } - // TODO: Comments + @Override + public void addSubCommand(final @NotNull ExecutableCommand subCommand, final boolean isAlias) { + // If it's a parent command with argument we add it + if (subCommand instanceof ParentSubCommand && subCommand.hasArguments()) { + if (parentCommandWithArgument != null) { + throw new CommandRegistrationException("Only one inner command with argument is allowed per command.", subCommand.getBaseCommand().getClass()); + } + + parentCommandWithArgument = subCommand; + return; + } + + // Normal commands are added here + + subCommands.put(subCommand.getName(), subCommand); + // TODO ALIAS + } + public void execute( final @NotNull S sender, - final @NotNull List<@NotNull String> arguments + final @NotNull List arguments ) { - final int argumentSize = arguments.size(); - final Command subCommand = getSubCommand(arguments); + final String commandName = nameFromArguments(arguments); + final ExecutableCommand subCommand = getSubCommand(commandName, arguments.size()); - // TODO - /*if (subCommand == null || (argumentSize > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { - final String name = argumentSize == 0 ? dev.triumphteam.cmd.core.annotation.Command.DEFAULT_CMD_NAME : arguments.get(0); - messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new DefaultMessageContext(this.name, name)); + if (subCommand == null) { + messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new DefaultMessageContext(name, commandName)); return; } - subCommand.execute(sender, !subCommand.isDefault() ? arguments.subList(1, argumentSize) : arguments);*/ + subCommand.execute(sender, commandName, null, !subCommand.isDefault() ? arguments.subList(1, arguments.size()) : arguments); } @Override public @NotNull String getName() { - return null; + return name; } @Override - public @NotNull Map> getCommands() { - return subCommands; + public @Nullable ExecutableCommand getParentCommandWithArgument() { + return parentCommandWithArgument; } @Override - public @NotNull Map> getCommandAliases() { - return subCommandAliases; + public @NotNull Map> getCommands() { + return subCommands; } @Override - public void addSubCommand(final @NotNull Command subCommand, final boolean isAlias) { - + public @NotNull Map> getCommandAliases() { + return subCommandAliases; } @Override diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index ef1e3727..e4cf9ad1 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -25,9 +25,9 @@ import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.CommandManager; -import dev.triumphteam.cmd.core.execution.AsyncExecutionProvider; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.execution.SyncExecutionProvider; +import dev.triumphteam.cmd.core.command.execution.AsyncExecutionProvider; +import dev.triumphteam.cmd.core.command.execution.ExecutionProvider; +import dev.triumphteam.cmd.core.command.execution.SyncExecutionProvider; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.message.MessageKey; @@ -78,12 +78,12 @@ public void registerCommand(final @NotNull BaseCommand baseCommand) { // Command does not exist, proceed to add new! final SimpleCommand newCommand = commands.computeIfAbsent(processor.getName(), it -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); - processor.commands(newCommand.getMeta()); + processor.commands(newCommand.getMeta()).forEach(it -> newCommand.addSubCommand(it, false)); processor.getAlias().forEach(it -> { final SimpleCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); // Adding sub commands. - // TODO: ADD SUBCOMMANDS + processor.commands(newCommand.getMeta()).forEach(sub -> aliasCommand.addSubCommand(sub, false)); }); } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java index 1f15f9ae..7bb77082 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmds.simple; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; +import dev.triumphteam.cmd.core.command.execution.ExecutionProvider; import dev.triumphteam.cmd.core.subcommand.OldSubCommand; import org.jetbrains.annotations.NotNull; From aca41bbc7893f7ec174a3cd2b9a3ec5f4207f093 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 30 Dec 2022 14:00:49 +0000 Subject: [PATCH 041/101] feature: Make annotations documented and some cleanups --- .../cmd/core/annotations/ArgDescriptions.java | 8 +++ .../cmd/core/annotations/ArgName.java | 2 + .../cmd/core/annotations/Async.java | 2 + .../cmd/core/annotations/Choices.java | 45 ---------------- .../cmd/core/annotations/Command.java | 2 + .../cmd/core/annotations/CommandFlags.java | 2 + .../cmd/core/annotations/Default.java | 49 ----------------- .../cmd/core/annotations/Description.java | 9 ++++ .../cmd/core/annotations/Flag.java | 2 + .../cmd/core/annotations/Join.java | 2 + .../cmd/core/annotations/NamedArguments.java | 14 ++++- .../cmd/core/annotations/Optional.java | 2 + .../cmd/core/annotations/Requirement.java | 2 + .../cmd/core/annotations/Requirements.java | 6 ++- .../cmd/core/annotations/Split.java | 2 + .../cmd/core/annotations/SubCommand.java | 54 ------------------- .../cmd/core/annotations/Suggestion.java | 16 +++++- .../cmd/core/annotations/Suggestions.java | 12 ++++- 18 files changed, 79 insertions(+), 152 deletions(-) delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/annotations/Choices.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/annotations/Default.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/annotations/SubCommand.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgDescriptions.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgDescriptions.java index aff5b2dc..d7090111 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgDescriptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgDescriptions.java @@ -25,14 +25,22 @@ import org.jetbrains.annotations.NotNull; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Sets descriptions for arguments in a method. + */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface ArgDescriptions { + /** + * @return An array indexed based on the argument's position. + */ @NotNull String[] value(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgName.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgName.java index 9a4360cd..c3ad8a2b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgName.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/ArgName.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.annotations; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -31,6 +32,7 @@ /** * Allows to specify the name of the argument instead of just using the parameter name. */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) public @interface ArgName { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java index 087a65f4..c249e6cd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Async.java @@ -25,6 +25,7 @@ import dev.triumphteam.cmd.core.extention.meta.MetaKey; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -33,6 +34,7 @@ /** * Marks the sub-command to be executed asynchronously. */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Async { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Choices.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Choices.java deleted file mode 100644 index 2932918b..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Choices.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Provides the Option to add custom Choices to Command Parameters in order to add Auto-Complete. - * Argument must be nullable in Kotlin. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface Choices { - - /** - * An array of possible Choices for this Command Argument. - * - * @return An array of Choices. - */ - String[] value(); -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Command.java index e55200ab..d98b5bcc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Command.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; @@ -34,6 +35,7 @@ /** * Command annotation, marks the class or method as a command. */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD}) @Inherited diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/CommandFlags.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/CommandFlags.java index c0d531a4..7f3a0e9a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/CommandFlags.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/CommandFlags.java @@ -26,6 +26,7 @@ import dev.triumphteam.cmd.core.argument.keyed.FlagKey; import org.jetbrains.annotations.NotNull; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -34,6 +35,7 @@ /** * Annotation for declaring all the {@link Flag}s needed for the command. */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface CommandFlags { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Default.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Default.java deleted file mode 100644 index 38971247..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Default.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.annotations; - -import org.jetbrains.annotations.NotNull; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Marks the method to be run without any subcommands. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) -public @interface Default { - - // Default sub commands use this name. - String DEFAULT_CMD_NAME = "TH_DEFAULT"; - - /** - * Gets the list of alias for the default sub command. - * - * @return An array with command aliases. - */ - @NotNull String[] alias() default {}; -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Description.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Description.java index b04d1d51..10281b41 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Description.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Description.java @@ -25,16 +25,25 @@ import org.jetbrains.annotations.NotNull; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * The description of an element. + * Can be used for class, method, or parameter. Aka, command, sub command, or argument. + */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER}) @Inherited public @interface Description { + /** + * @return The description of the element. + */ @NotNull String value(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Flag.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Flag.java index 42dd518a..a6e58c95 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Flag.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Flag.java @@ -26,6 +26,7 @@ import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; @@ -36,6 +37,7 @@ * Flag annotation. Contains all the "data" for the flag. * To be used inside the {@link CommandFlags} annotation. */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @Repeatable(CommandFlags.class) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Join.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Join.java index a380abfc..f9daa8be 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Join.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Join.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -33,6 +34,7 @@ /** * Join annotation is to be used in a String parameter to join all the arguments into one continuous string. */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) public @interface Join { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/NamedArguments.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/NamedArguments.java index 5204b9f8..f65c550d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/NamedArguments.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/NamedArguments.java @@ -23,14 +23,26 @@ */ package dev.triumphteam.cmd.core.annotations; +import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; +import dev.triumphteam.cmd.core.argument.keyed.Arguments; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * An annotation to target a method and set which {@link Arguments} list will be used. + */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface NamedArguments { - String value(); + /** + * @return The {@link ArgumentKey} value to be used internally. + */ + @NotNull String value(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Optional.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Optional.java index 5b7d6711..c6c4034d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Optional.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Optional.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.annotations; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -32,6 +33,7 @@ * Marks the argument as optional, so if a user doesn't type it, it'll be null. * Argument must be nullable in Kotlin. */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) public @interface Optional {} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java index f8872a2d..d4f7276c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; @@ -35,6 +36,7 @@ * Requirement annotation. Holds all the requirement's data. * To be used inside {@link Requirements}. */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) @Repeatable(Requirements.class) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirements.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirements.java index c93e2267..bd5bfb0a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirements.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirements.java @@ -23,6 +23,9 @@ */ package dev.triumphteam.cmd.core.annotations; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -31,6 +34,7 @@ /** * Annotation to hold all the command requirements. */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Requirements { @@ -40,5 +44,5 @@ * * @return An array of {@link Requirement}s. */ - Requirement[] value(); + @NotNull Requirement[] value(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Split.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Split.java index b99a74b2..72d0852d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Split.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Split.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; @@ -35,6 +36,7 @@ * For example: diamond;stone;iron;gold, into [diamond, stone, iron, gold]. * The splitting is type safe. */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) public @interface Split { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/SubCommand.java deleted file mode 100644 index 8836d292..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/SubCommand.java +++ /dev/null @@ -1,54 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.annotations; - -import org.jetbrains.annotations.NotNull; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Sets the method to be a sub command. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.TYPE}) -public @interface SubCommand { - - /** - * Main sub command name. - * Must not contain spaces. - * - * @return The sub command name. - */ - @NotNull String value(); - - /** - * List with all the valid aliases for the command. - * - * @return An array with command aliases. - */ - @NotNull String[] alias() default {}; -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestion.java index 5c5229aa..04af62f5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestion.java @@ -23,18 +23,32 @@ */ package dev.triumphteam.cmd.core.annotations; +import dev.triumphteam.cmd.core.suggestion.SuggestionKey; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Sets which suggestion to use for specific arguments. + */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.PARAMETER}) @Repeatable(Suggestions.class) public @interface Suggestion { - String value(); + /** + * @return The {@link SuggestionKey} value to be used internally. + */ + @NotNull String value(); + /** + * @return If strict then only suggested values are allowed as valid arguments. + */ boolean strict() default false; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestions.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestions.java index 25745286..9cece25e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Suggestions.java @@ -23,14 +23,24 @@ */ package dev.triumphteam.cmd.core.annotations; +import org.jetbrains.annotations.NotNull; + +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +/** + * Annotation to hold all the command suggestions. + */ +@Documented @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.PARAMETER}) public @interface Suggestions { - Suggestion[] value(); + /** + * @return An array of {@link Suggestion}s. + */ + @NotNull Suggestion[] value(); } From a31858d649775be8a2162d1d71cb7cdcc6d0057b Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 30 Dec 2022 15:18:18 +0000 Subject: [PATCH 042/101] feature: Goodbye BaseCommand --- ...BaseCommand.java => AnnotatedCommand.java} | 14 ++-- .../triumphteam/cmd/core/CommandManager.java | 26 +++---- .../cmd/core/annotations/Command.java | 2 +- .../cmd/core/command/ExecutableCommand.java | 5 +- .../cmd/core/command/ParentSubCommand.java | 17 ++-- .../cmd/core/command/SubCommand.java | 13 ++-- .../extention/annotation/ProcessorTarget.java | 6 +- .../processor/AbstractCommandProcessor.java | 11 ++- .../AbstractRootCommandProcessor.java | 77 ++++++++++++------- .../OldAbstractCommandProcessor.java | 14 ++-- .../OldAbstractSubCommandProcessor.java | 34 +++----- .../processor/ParentCommandProcessor.java | 5 +- .../core/processor/SubCommandProcessor.java | 5 +- .../cmd/core/subcommand/OldSubCommand.java | 13 ++-- .../core/subcommand/invoker/ClassInvoker.java | 6 +- .../subcommand/invoker/MethodInvoker.java | 6 +- .../cmds/simple/SimpleCommand.java | 2 +- .../cmds/simple/SimpleCommandManager.java | 17 ++-- .../cmds/simple/SimpleCommandProcessor.java | 5 +- .../simple/SimpleSubCommandProcessor.java | 6 +- .../fail/command registration fail test.kt | 8 +- 21 files changed, 144 insertions(+), 148 deletions(-) rename core/src/main/java/dev/triumphteam/cmd/core/{BaseCommand.java => AnnotatedCommand.java} (86%) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java similarity index 86% rename from core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java rename to core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java index c2457295..68a3e35f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/BaseCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java @@ -32,32 +32,32 @@ /** * Class in which all commands need to extend. */ -public abstract class BaseCommand { +public abstract class AnnotatedCommand { private final String command; private final List alias = new ArrayList<>(); private final String description; - public BaseCommand() { + public AnnotatedCommand() { this(null, null, null); } - public BaseCommand(final @Nullable List<@NotNull String> alias) { + public AnnotatedCommand(final @Nullable List alias) { this(null, alias, null); } - public BaseCommand(final @Nullable String command) { + public AnnotatedCommand(final @Nullable String command) { this(command, null, null); } - public BaseCommand(final @Nullable String command, final @Nullable String description) { + public AnnotatedCommand(final @Nullable String command, final @Nullable String description) { this(command, null, description); } - public BaseCommand( + public AnnotatedCommand( final @Nullable String command, - final @Nullable List<@NotNull String> alias, + final @Nullable List alias, final @Nullable String description ) { this.command = command; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index 5e809aa4..c9a1107c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -60,19 +60,19 @@ public CommandManager(final @NotNull CommandOptions commandOptions) { } /** - * Registers a {@link BaseCommand} into the manager. + * Registers a command into the manager. * - * @param baseCommand The {@link BaseCommand} to be registered. + * @param command The instance of the command to be registered. */ - public abstract void registerCommand(final @NotNull BaseCommand baseCommand); + public abstract void registerCommand(final @NotNull Object command); /** - * Registers {@link BaseCommand}s. + * Registers commands. * - * @param baseCommands A list of baseCommands to be registered. + * @param commands A list of commands to be registered. */ - public final void registerCommand(final @NotNull BaseCommand @NotNull ... baseCommands) { - for (final BaseCommand command : baseCommands) { + public final void registerCommand(final @NotNull Object @NotNull ... commands) { + for (final Object command : commands) { registerCommand(command); } } @@ -80,17 +80,17 @@ public final void registerCommand(final @NotNull BaseCommand @NotNull ... baseCo /** * Main method for unregistering commands to be implemented in other platform command managers. * - * @param command The {@link BaseCommand} to be unregistered. + * @param command The command to be unregistered. */ - public abstract void unregisterCommand(final @NotNull BaseCommand command); + public abstract void unregisterCommand(final @NotNull Object command); /** * Method to unregister commands with vararg. * * @param commands A list of commands to be unregistered. */ - public final void unregisterCommands(final @NotNull BaseCommand @NotNull ... commands) { - for (final BaseCommand command : commands) { + public final void unregisterCommands(final @NotNull Object @NotNull ... commands) { + for (final Object command : commands) { unregisterCommand(command); } } @@ -148,7 +148,7 @@ public final void registerNamedArguments(final @NotNull ArgumentKey key, final @ /** * Registers a list of flags to be used on a {@link Flags} argument or {@link Arguments} argument, in a command. * - * @param key The {@link FlagKey} to represent the list. + * @param key The {@link FlagKey} to represent the list. * @param flags The list of flags. */ public final void registerFlags(final @NotNull FlagKey key, final @NotNull Flag @NotNull ... flags) { @@ -158,7 +158,7 @@ public final void registerFlags(final @NotNull FlagKey key, final @NotNull Flag /** * Registers a list of flags to be used on a {@link Flags} argument or {@link Arguments} argument, in a command. * - * @param key The {@link FlagKey} to represent the list. + * @param key The {@link FlagKey} to represent the list. * @param flags The {@link List} of flags. */ public final void registerFlags(final @NotNull FlagKey key, final @NotNull List flags) { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Command.java index d98b5bcc..e95cbf03 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Command.java @@ -42,7 +42,7 @@ public @interface Command { // Default commands use this name. - String DEFAULT_CMD_NAME = "TH_DEFAULT"; + String DEFAULT_CMD_NAME = "th-default"; /** * Command's name. diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java index 4eeaade6..3b5fbc2e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java @@ -1,6 +1,5 @@ package dev.triumphteam.cmd.core.command; -import dev.triumphteam.cmd.core.BaseCommand; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,7 +29,7 @@ void execute( ); /** - * @return The instance of the original base command class where the command belongs to. + * @return The instance of the original command instance where the command belongs to. */ - @NotNull BaseCommand getBaseCommand(); + @NotNull Object getInvocationInstance(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index ae889f3f..7d570bda 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -1,6 +1,5 @@ package dev.triumphteam.cmd.core.command; -import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; @@ -31,7 +30,7 @@ public class ParentSubCommand implements ParentCommand, ExecutableCommand< private final Map> commandAliases = new HashMap<>(); private final String name; private final CommandMeta meta; - private final BaseCommand baseCommand; + private final Object invocationInstance; private final Constructor constructor; private final boolean isStatic; private final StringInternalArgument argument; @@ -42,13 +41,13 @@ public class ParentSubCommand implements ParentCommand, ExecutableCommand< private ExecutableCommand parentCommandWithArgument; public ParentSubCommand( - final @NotNull BaseCommand baseCommand, + final @NotNull Object invocationInstance, final @NotNull Constructor constructor, final boolean isStatic, final @Nullable StringInternalArgument argument, final @NotNull ParentCommandProcessor processor ) { - this.baseCommand = baseCommand; + this.invocationInstance = invocationInstance; this.constructor = constructor; this.isStatic = isStatic; this.argument = argument; @@ -64,7 +63,7 @@ public void addSubCommand(final @NotNull ExecutableCommand subCommand, final // If it's a parent command with argument we add it if (subCommand instanceof ParentSubCommand && subCommand.hasArguments()) { if (parentCommandWithArgument != null) { - throw new CommandRegistrationException("Only one inner command with argument is allowed per command", baseCommand.getClass()); + throw new CommandRegistrationException("Only one inner command with argument is allowed per command", invocationInstance.getClass()); } parentCommandWithArgument = subCommand; @@ -125,10 +124,10 @@ public void execute( // If there is no argument don't pass anything // A bit annoying but if the method has no parameters, "null" is a valid parameter so this check is needed if (!hasArgument) { - return constructor.newInstance(instanceSupplier == null ? baseCommand : instanceSupplier.get()); + return constructor.newInstance(instanceSupplier == null ? invocationInstance : instanceSupplier.get()); } - return constructor.newInstance(instanceSupplier == null ? baseCommand : instanceSupplier.get(), argumentValue); + return constructor.newInstance(instanceSupplier == null ? invocationInstance : instanceSupplier.get(), argumentValue); } if (!hasArgument) constructor.newInstance(); @@ -141,8 +140,8 @@ public void execute( } @Override - public @NotNull BaseCommand getBaseCommand() { - return baseCommand; + public @NotNull Object getInvocationInstance() { + return invocationInstance; } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 90ef5f14..e51f8bb1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -1,6 +1,5 @@ package dev.triumphteam.cmd.core.command; -import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.processor.SubCommandProcessor; @@ -20,15 +19,15 @@ public class SubCommand implements ExecutableCommand { private final String name; private final CommandMeta meta; - private final BaseCommand baseCommand; + private final Object invocationInstance; private final Method method; public SubCommand( - final @NotNull BaseCommand baseCommand, + final @NotNull Object invocationInstance, final @NotNull Method method, final @NotNull SubCommandProcessor processor ) { - this.baseCommand = baseCommand; + this.invocationInstance = invocationInstance; this.method = method; this.name = processor.getName(); this.meta = processor.createMeta(); @@ -44,7 +43,7 @@ public void execute( final @NotNull List arguments ) { try { - method.invoke(instanceSupplier == null ? baseCommand : instanceSupplier.get(), sender); + method.invoke(instanceSupplier == null ? invocationInstance : instanceSupplier.get(), sender); } catch (IllegalAccessException | InvocationTargetException e) { throw new RuntimeException(e); } @@ -61,8 +60,8 @@ public void execute( } @Override - public @NotNull BaseCommand getBaseCommand() { - return baseCommand; + public @NotNull Object getInvocationInstance() { + return invocationInstance; } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/ProcessorTarget.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/ProcessorTarget.java index b44b51d3..e809738c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/ProcessorTarget.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/ProcessorTarget.java @@ -1,6 +1,6 @@ package dev.triumphteam.cmd.core.extention.annotation; -import dev.triumphteam.cmd.core.BaseCommand; +import dev.triumphteam.cmd.core.AnnotatedCommand; import java.lang.reflect.Method; @@ -10,7 +10,7 @@ public enum ProcessorTarget { /** - * The original command, normally the {@link Class} that extends {@link BaseCommand} or a child of it. + * The original command, normally the {@link Class} that extends {@link AnnotatedCommand} or a child of it. *
{@code
      * @Command("foo")
      * @ExampleCustomAnnotation
@@ -22,7 +22,7 @@ public enum ProcessorTarget {
      */
     ROOT_COMMAND,
     /**
-     * A command "holder". the "sub-command" {@link Class}, normally does not extend {@link BaseCommand} or anything.
+     * A command "holder". the "sub-command" {@link Class}, normally does not extend {@link AnnotatedCommand} or anything.
      * 
{@code
      * @Command("foo")
      * class MyCommand extends BaseCommand() {
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java
index dbb830a0..9f3ba758 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java
@@ -24,7 +24,6 @@
 package dev.triumphteam.cmd.core.processor;
 
 import com.google.common.base.CaseFormat;
-import dev.triumphteam.cmd.core.BaseCommand;
 import dev.triumphteam.cmd.core.annotations.ArgName;
 import dev.triumphteam.cmd.core.annotations.Command;
 import dev.triumphteam.cmd.core.annotations.Description;
@@ -86,7 +85,7 @@ abstract class AbstractCommandProcessor implements CommandProcessor {
     private static final Set> SUPPORTED_COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class));
 
     private final String parentName;
-    private final BaseCommand baseCommand;
+    private final Object invocationInstance;
     private final String name;
     private final AnnotatedElement annotatedElement;
 
@@ -100,14 +99,14 @@ abstract class AbstractCommandProcessor implements CommandProcessor {
 
     AbstractCommandProcessor(
             final @NotNull String parentName,
-            final @NotNull BaseCommand baseCommand,
+            final @NotNull Object invocationInstance,
             final @NotNull AnnotatedElement annotatedElement,
             final @NotNull RegistryContainer registryContainer,
             final @NotNull CommandExtensions commandExtensions,
             final @NotNull CommandMeta parentMeta
     ) {
         this.parentName = parentName;
-        this.baseCommand = baseCommand;
+        this.invocationInstance = invocationInstance;
         this.annotatedElement = annotatedElement;
         this.name = nameOf();
         this.parentMeta = parentMeta;
@@ -129,7 +128,7 @@ abstract class AbstractCommandProcessor implements CommandProcessor {
     @Contract("_ -> new")
     @NotNull
     public SubCommandRegistrationException createException(final @NotNull String message) {
-        return new SubCommandRegistrationException(message, annotatedElement, baseCommand.getClass());
+        return new SubCommandRegistrationException(message, annotatedElement, invocationInstance.getClass());
     }
 
     private @Nullable String nameOf() {
@@ -138,7 +137,7 @@ public SubCommandRegistrationException createException(final @NotNull String mes
         // Not a command element
         if (commandAnnotation == null) return null;
 
-        return commandAnnotation.value();
+        return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, commandAnnotation.value());
     }
 
     public @Nullable String getName() {
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java
index 41286330..5f1bb6b2 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java
@@ -23,7 +23,8 @@
  */
 package dev.triumphteam.cmd.core.processor;
 
-import dev.triumphteam.cmd.core.BaseCommand;
+import com.google.common.base.CaseFormat;
+import dev.triumphteam.cmd.core.AnnotatedCommand;
 import dev.triumphteam.cmd.core.annotations.Command;
 import dev.triumphteam.cmd.core.annotations.Description;
 import dev.triumphteam.cmd.core.argument.InternalArgument;
@@ -47,6 +48,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 import static java.util.Collections.emptyList;
 import static java.util.Collections.emptyMap;
@@ -54,7 +56,7 @@
 @SuppressWarnings("unchecked")
 public abstract class AbstractRootCommandProcessor implements CommandProcessor {
 
-    private final BaseCommand baseCommand;
+    private final Object invocationInstance;
 
     private final String name;
     private final List alias;
@@ -64,11 +66,11 @@ public abstract class AbstractRootCommandProcessor implements CommandProcesso
     private final RegistryContainer registryContainer;
 
     public AbstractRootCommandProcessor(
-            final @NotNull BaseCommand baseCommand,
+            final @NotNull Object invocationInstance,
             final @NotNull RegistryContainer registryContainer,
             final @NotNull CommandExtensions commandExtensions
     ) {
-        this.baseCommand = baseCommand;
+        this.invocationInstance = invocationInstance;
 
         this.name = nameOf();
         this.alias = aliasOf();
@@ -95,7 +97,7 @@ public String getDescription() {
     public @NotNull CommandMeta createMeta() {
         final CommandMeta.Builder meta = new CommandMeta.Builder(null);
         // Process all the class annotations
-        final Class klass = baseCommand.getClass();
+        final Class klass = invocationInstance.getClass();
         processAnnotations(commandExtensions, klass, ProcessorTarget.ROOT_COMMAND, meta);
         processCommandMeta(commandExtensions, klass, ProcessorTarget.PARENT_COMMAND, meta);
         // Return modified meta
@@ -103,7 +105,7 @@ public String getDescription() {
     }
 
     public @NotNull List> commands(final @NotNull CommandMeta parentMeta) {
-        final Class klass = baseCommand.getClass();
+        final Class klass = invocationInstance.getClass();
 
         final List> subCommands = new ArrayList<>();
         subCommands.addAll(methodCommands(parentMeta, klass.getDeclaredMethods()));
@@ -123,7 +125,7 @@ public String getDescription() {
 
             final SubCommandProcessor processor = new SubCommandProcessor<>(
                     name,
-                    baseCommand,
+                    invocationInstance,
                     method,
                     registryContainer,
                     commandExtensions,
@@ -134,7 +136,7 @@ public String getDescription() {
             if (processor.getName() == null) continue;
 
             // Add new command
-            commands.add(new SubCommand<>(baseCommand, method, processor));
+            commands.add(new SubCommand<>(invocationInstance, method, processor));
         }
 
         return commands;
@@ -151,7 +153,7 @@ public String getDescription() {
 
             final ParentCommandProcessor processor = new ParentCommandProcessor<>(
                     name,
-                    baseCommand,
+                    invocationInstance,
                     klass,
                     registryContainer,
                     commandExtensions,
@@ -201,7 +203,7 @@ public String getDescription() {
                 }
             }
 
-            final ParentSubCommand parent = new ParentSubCommand<>(baseCommand, constructor, isStatic, (StringInternalArgument) argument, processor);
+            final ParentSubCommand parent = new ParentSubCommand<>(invocationInstance, constructor, isStatic, (StringInternalArgument) argument, processor);
 
             // Add children commands to parent
             methodCommands(parent.getMeta(), klass.getDeclaredMethods()).forEach(it -> parent.addSubCommand(it, false));
@@ -215,35 +217,54 @@ public String getDescription() {
     }
 
     private @NotNull String nameOf() {
-        final Class commandClass = baseCommand.getClass();
-        final dev.triumphteam.cmd.core.annotations.Command commandAnnotation = commandClass.getAnnotation(dev.triumphteam.cmd.core.annotations.Command.class);
-
-        final String name;
-        if (commandAnnotation == null) {
-            final String commandName = baseCommand.getCommand();
-            if (commandName == null) {
-                throw new CommandRegistrationException("Command name or \"@" + dev.triumphteam.cmd.core.annotations.Command.class.getSimpleName() + "\" annotation missing", baseCommand.getClass());
-            }
+        final Class commandClass = invocationInstance.getClass();
+        final Command commandAnnotation = commandClass.getAnnotation(Command.class);
 
-            name = commandName;
-        } else {
+        String name = null;
+        if (commandAnnotation != null) {
             name = commandAnnotation.value();
+        } else if (AnnotatedCommand.class.isAssignableFrom(commandClass)) {
+            name = ((AnnotatedCommand) invocationInstance).getCommand();
         }
 
-        if (name.isEmpty() || name.equals(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME)) {
-            throw new CommandRegistrationException("Command name must not be empty", baseCommand.getClass());
+        if (name == null) {
+            throw new CommandRegistrationException("No \"@" + Command.class.getSimpleName() + "\" annotation found or class doesn't extend \"" + AnnotatedCommand.class.getSimpleName() + "\"", invocationInstance.getClass());
         }
 
-        return name;
+        if (name.isEmpty() || name.equals(Command.DEFAULT_CMD_NAME)) {
+            throw new CommandRegistrationException("Command name must not be empty", invocationInstance.getClass());
+        }
+
+        return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, name);
     }
 
     private @NotNull List aliasOf() {
-        final dev.triumphteam.cmd.core.annotations.Command commandAnnotation = baseCommand.getClass().getAnnotation(dev.triumphteam.cmd.core.annotations.Command.class);
-        return commandAnnotation == null ? baseCommand.getAlias() : Arrays.asList(commandAnnotation.alias());
+        final Class commandClass = invocationInstance.getClass();
+        final Command commandAnnotation = commandClass.getAnnotation(Command.class);
+
+        List aliases = null;
+        if (commandAnnotation != null) {
+            aliases = Arrays.asList(commandAnnotation.alias());
+        } else if (AnnotatedCommand.class.isAssignableFrom(commandClass)) {
+            aliases = ((AnnotatedCommand) invocationInstance).getAlias();
+        }
+
+        return aliases == null ? emptyList() : aliases.stream()
+                .map(name -> CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, name))
+                .collect(Collectors.toList());
     }
 
     private @NotNull String descriptionOf() {
-        final Description commandAnnotation = baseCommand.getClass().getAnnotation(Description.class);
-        return commandAnnotation == null ? baseCommand.getDescription() : commandAnnotation.value();
+        final Class commandClass = invocationInstance.getClass();
+        final Description descriptionAnnotation = commandClass.getAnnotation(Description.class);
+
+        String description = "";
+        if (descriptionAnnotation != null) {
+            description = descriptionAnnotation.value();
+        } else if (AnnotatedCommand.class.isAssignableFrom(commandClass)) {
+            description = ((AnnotatedCommand) invocationInstance).getDescription();
+        }
+
+        return description;
     }
 }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
index 5c2ea84f..3e91644a 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
@@ -23,7 +23,7 @@
  */
 package dev.triumphteam.cmd.core.processor;
 
-import dev.triumphteam.cmd.core.BaseCommand;
+import dev.triumphteam.cmd.core.AnnotatedCommand;
 import dev.triumphteam.cmd.core.command.ParentCommand;
 import dev.triumphteam.cmd.core.annotations.Command;
 import dev.triumphteam.cmd.core.annotations.Description;
@@ -67,8 +67,8 @@ public abstract class OldAbstractCommandProcessor subCommands = new HashMap<>();
     private final Map subCommandsAlias = new HashMap<>();
 
-    private final Class commandClass;
-    private final Supplier instanceSupplier;
+    private final Class commandClass;
+    private final Supplier instanceSupplier;
     private final RegistryContainer registryContainer;
     private final SenderMapper senderMapper;
     private final SenderValidator senderValidator;
@@ -77,8 +77,8 @@ public abstract class OldAbstractCommandProcessor commandClass,
-            final @NotNull Supplier instanceSupplier,
+            final @NotNull Class commandClass,
+            final @NotNull Supplier instanceSupplier,
             final @NotNull RegistryContainer registryContainer,
             final @NotNull SenderMapper senderMapper,
             final @NotNull SenderValidator senderValidator,
@@ -156,7 +156,7 @@ private void collectMethodSubCommands(
 
             if (subCommandName.isEmpty()) {
                 throw new SubCommandRegistrationException(
-                        "@" + dev.triumphteam.cmd.core.annotations.SubCommand.class.getSimpleName() + " name must not be empty",
+                        "@ name must not be empty",
                         method,
                         klass
                 );
@@ -250,7 +250,7 @@ private void extractCommandNames() {
 
         alias.addAll(baseCommand.getAlias());*/
         if (name.isEmpty()) {
-            throw new CommandRegistrationException("Command name must not be empty", BaseCommand.class);
+            throw new CommandRegistrationException("Command name must not be empty", AnnotatedCommand.class);
         }
     }
 
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java
index e501f21d..691e4a50 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java
@@ -25,12 +25,11 @@
 
 import com.google.common.base.CaseFormat;
 import com.google.common.collect.Maps;
-import dev.triumphteam.cmd.core.BaseCommand;
+import dev.triumphteam.cmd.core.AnnotatedCommand;
 import dev.triumphteam.cmd.core.annotations.ArgDescriptions;
 import dev.triumphteam.cmd.core.annotations.ArgName;
 import dev.triumphteam.cmd.core.annotations.Async;
 import dev.triumphteam.cmd.core.annotations.CommandFlags;
-import dev.triumphteam.cmd.core.annotations.Default;
 import dev.triumphteam.cmd.core.annotations.Description;
 import dev.triumphteam.cmd.core.annotations.Flag;
 import dev.triumphteam.cmd.core.annotations.Join;
@@ -110,7 +109,7 @@
 public abstract class OldAbstractSubCommandProcessor {
 
     private static final Set> COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class));
-    private final BaseCommand baseCommand;
+    private final AnnotatedCommand annotatedCommand;
     private final String parentName;
     private final AnnotatedElement annotatedElement;
     private final List argDescriptions = new ArrayList<>();
@@ -135,13 +134,13 @@ public abstract class OldAbstractSubCommandProcessor {
     private Class senderType;
 
     protected OldAbstractSubCommandProcessor(
-            final @NotNull BaseCommand baseCommand,
+            final @NotNull AnnotatedCommand annotatedCommand,
             final @NotNull String parentName,
             final @NotNull AnnotatedElement annotatedElement,
             final @NotNull RegistryContainer registryContainer,
             final @NotNull SenderValidator senderValidator
     ) {
-        this.baseCommand = baseCommand;
+        this.annotatedCommand = annotatedCommand;
         this.parentName = parentName;
 
         this.annotatedElement = annotatedElement;
@@ -188,7 +187,7 @@ protected void extractArguments(final @NotNull AnnotatedElement annotatedElement
 
     /**
      * Used for the child factories to get the sub command name.
-     * It's nullable because a method might not have a {@link dev.triumphteam.cmd.core.annotations.SubCommand} or {@link Default} annotation.
+     * It's nullable because a method might not have a annotation.
      *
      * @return The sub command name.
      */
@@ -238,12 +237,12 @@ public boolean isAsync() {
     }
 
     /**
-     * Gets the {@link BaseCommand} instance, so it can be used later to invoke.
+     * Gets the {@link AnnotatedCommand} instance, so it can be used later to invoke.
      *
      * @return The base command instance.
      */
-    public @NotNull BaseCommand getBaseCommand() {
-        return baseCommand;
+    public @NotNull AnnotatedCommand getBaseCommand() {
+        return annotatedCommand;
     }
 
     // TODO comments
@@ -286,7 +285,7 @@ public boolean isAsync() {
      */
     @Contract("_ -> new")
     protected @NotNull SubCommandRegistrationException createException(final @NotNull String message) {
-        return new SubCommandRegistrationException(message, annotatedElement, baseCommand.getClass());
+        return new SubCommandRegistrationException(message, annotatedElement, annotatedCommand.getClass());
     }
 
     /**
@@ -546,22 +545,7 @@ private void addArgument(final @NotNull InternalArgument internalArgument)
      * Extracts the data from the method to retrieve the sub command name or the default name.
      */
     private void extractSubCommandNames() {
-        final Default defaultAnnotation = annotatedElement.getAnnotation(Default.class);
-        final dev.triumphteam.cmd.core.annotations.SubCommand subCommandAnnotation = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.SubCommand.class);
 
-        if (defaultAnnotation == null && subCommandAnnotation == null) {
-            return;
-        }
-
-        if (defaultAnnotation != null) {
-            name = Default.DEFAULT_CMD_NAME;
-            alias.addAll(Arrays.stream(defaultAnnotation.alias()).map(String::toLowerCase).collect(Collectors.toList()));
-            isDefault = true;
-            return;
-        }
-
-        name = subCommandAnnotation.value().toLowerCase();
-        alias.addAll(Arrays.stream(subCommandAnnotation.alias()).map(String::toLowerCase).collect(Collectors.toList()));
     }
 
     /**
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java
index abf5d8fd..86d298c7 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java
@@ -23,7 +23,6 @@
  */
 package dev.triumphteam.cmd.core.processor;
 
-import dev.triumphteam.cmd.core.BaseCommand;
 import dev.triumphteam.cmd.core.extention.CommandExtensions;
 import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget;
 import dev.triumphteam.cmd.core.extention.meta.CommandMeta;
@@ -45,13 +44,13 @@ public final class ParentCommandProcessor extends AbstractCommandProcessor
 
     ParentCommandProcessor(
             final @NotNull String parentName,
-            final @NotNull BaseCommand baseCommand,
+            final @NotNull Object invocationInstance,
             final @NotNull Class klass,
             final @NotNull RegistryContainer registryContainer,
             final @NotNull CommandExtensions commandExtensions,
             final @NotNull CommandMeta parentMeta
     ) {
-        super(parentName, baseCommand, klass, registryContainer, commandExtensions, parentMeta);
+        super(parentName, invocationInstance, klass, registryContainer, commandExtensions, parentMeta);
 
         this.klass = klass;
     }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java
index 4551692e..d1948c6a 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java
@@ -23,7 +23,6 @@
  */
 package dev.triumphteam.cmd.core.processor;
 
-import dev.triumphteam.cmd.core.BaseCommand;
 import dev.triumphteam.cmd.core.annotations.ArgDescriptions;
 import dev.triumphteam.cmd.core.annotations.CommandFlags;
 import dev.triumphteam.cmd.core.annotations.NamedArguments;
@@ -78,13 +77,13 @@ public final class SubCommandProcessor extends AbstractCommandProcessor {
 
     SubCommandProcessor(
             final @NotNull String parentName,
-            final @NotNull BaseCommand baseCommand,
+            final @NotNull Object invocationInstance,
             final @NotNull Method method,
             final @NotNull RegistryContainer registryContainer,
             final @NotNull CommandExtensions commandExtensions,
             final @NotNull CommandMeta parentMeta
     ) {
-        super(parentName, baseCommand, method, registryContainer, commandExtensions, parentMeta);
+        super(parentName, invocationInstance, method, registryContainer, commandExtensions, parentMeta);
 
         this.method = method;
         this.namedArgumentRegistry = registryContainer.getNamedArgumentRegistry();
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java
index 91ace876..bdeaa52f 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java
@@ -23,8 +23,7 @@
  */
 package dev.triumphteam.cmd.core.subcommand;
 
-import dev.triumphteam.cmd.core.BaseCommand;
-import dev.triumphteam.cmd.core.annotations.Default;
+import dev.triumphteam.cmd.core.AnnotatedCommand;
 import dev.triumphteam.cmd.core.argument.InternalArgument;
 import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument;
 import dev.triumphteam.cmd.core.argument.StringInternalArgument;
@@ -57,7 +56,7 @@
  */
 public abstract class OldSubCommand {
 
-    private final BaseCommand baseCommand;
+    private final AnnotatedCommand annotatedCommand;
     private final Method method = null;
 
     private final String parentName;
@@ -83,7 +82,7 @@ public OldSubCommand(
             @NotNull final String parentName,
             @NotNull final ExecutionProvider executionProvider
     ) {
-        this.baseCommand = processor.getBaseCommand();
+        this.annotatedCommand = processor.getBaseCommand();
         // this.method = processor.getAnnotatedElement();
         this.name = processor.getName();
         this.alias = processor.getAlias();
@@ -105,7 +104,7 @@ public OldSubCommand(
 
     /**
      * Checks if the sub command is default.
-     * Can also just check if the name is {@link Default#DEFAULT_CMD_NAME}.
+     * Can also just check if the name is .
      *
      * @return Whether the sub command is default.
      */
@@ -174,7 +173,7 @@ public void execute(@NotNull final S sender, @NotNull final List args) {
 
         executionProvider.execute(() -> {
             try {
-                method.invoke(baseCommand, invokeArguments.toArray());
+                method.invoke(annotatedCommand, invokeArguments.toArray());
             } catch (IllegalAccessException | InvocationTargetException exception) {
                 throw new CommandExecutionException("An error occurred while executing the command", parentName, name)
                         .initCause(exception instanceof InvocationTargetException ? exception.getCause() : exception);
@@ -329,7 +328,7 @@ private boolean meetRequirements(@NotNull final S sender) {
     @NotNull @Override
     public String toString() {
         return "SimpleSubCommand{" +
-                "baseCommand=" + baseCommand +
+                "baseCommand=" + annotatedCommand +
                 ", method=" + method +
                 ", name='" + name + '\'' +
                 ", alias=" + alias +
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java
index c82ca665..9c91e1e3 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java
@@ -23,7 +23,7 @@
  */
 package dev.triumphteam.cmd.core.subcommand.invoker;
 
-import dev.triumphteam.cmd.core.BaseCommand;
+import dev.triumphteam.cmd.core.AnnotatedCommand;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -33,13 +33,13 @@
 
 public class ClassInvoker implements Invoker {
 
-    private final BaseCommand parent;
+    private final AnnotatedCommand parent;
     private final Constructor constructor;
     private final Method method;
     private final boolean isStatic;
 
     public ClassInvoker(
-            final @NotNull BaseCommand parent,
+            final @NotNull AnnotatedCommand parent,
             final @NotNull Constructor constructor,
             final @NotNull Method method,
             final boolean isStatic
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java
index 6e240a30..7cc73955 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java
@@ -23,7 +23,7 @@
  */
 package dev.triumphteam.cmd.core.subcommand.invoker;
 
-import dev.triumphteam.cmd.core.BaseCommand;
+import dev.triumphteam.cmd.core.AnnotatedCommand;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -33,10 +33,10 @@
 
 public class MethodInvoker implements Invoker {
 
-    private final Supplier instanceSupplier;
+    private final Supplier instanceSupplier;
     private final Method method;
 
-    public MethodInvoker(final @NotNull Supplier instanceSupplier, final @NotNull Method method) {
+    public MethodInvoker(final @NotNull Supplier instanceSupplier, final @NotNull Method method) {
         this.instanceSupplier = instanceSupplier;
         this.method = method;
     }
diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java
index 37e8f897..da3c7779 100644
--- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java
+++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java
@@ -66,7 +66,7 @@ public void addSubCommand(final @NotNull ExecutableCommand subCommand, final
         // If it's a parent command with argument we add it
         if (subCommand instanceof ParentSubCommand && subCommand.hasArguments()) {
             if (parentCommandWithArgument != null) {
-                throw new CommandRegistrationException("Only one inner command with argument is allowed per command.", subCommand.getBaseCommand().getClass());
+                throw new CommandRegistrationException("Only one inner command with argument is allowed per command.", subCommand.getInvocationInstance().getClass());
             }
 
             parentCommandWithArgument = subCommand;
diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java
index e4cf9ad1..cb0ae9ef 100644
--- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java
+++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java
@@ -23,7 +23,6 @@
  */
 package dev.triumphteam.cmds.simple;
 
-import dev.triumphteam.cmd.core.BaseCommand;
 import dev.triumphteam.cmd.core.CommandManager;
 import dev.triumphteam.cmd.core.command.execution.AsyncExecutionProvider;
 import dev.triumphteam.cmd.core.command.execution.ExecutionProvider;
@@ -61,29 +60,29 @@ private SimpleCommandManager(final @NotNull CommandOptions commandOptions)
     }
 
     @Override
-    public void registerCommand(final @NotNull BaseCommand baseCommand) {
+    public void registerCommand(final @NotNull Object command) {
         final SimpleCommandProcessor processor = new SimpleCommandProcessor<>(
-                baseCommand,
+                command,
                 getRegistryContainer(),
                 getCommandOptions().getCommandExtensions()
         );
 
         final String name = processor.getName();
 
-        final SimpleCommand command = commands.get(name);
-        if (command != null) {
+        final SimpleCommand simpleCommand = commands.get(name);
+        if (simpleCommand != null) {
             // TODO: Command exists, only care about adding subs
             return;
         }
 
         // Command does not exist, proceed to add new!
-        final SimpleCommand newCommand = commands.computeIfAbsent(processor.getName(), it -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry()));
-        processor.commands(newCommand.getMeta()).forEach(it -> newCommand.addSubCommand(it, false));
+        final SimpleCommand newSimpleCommand = commands.computeIfAbsent(processor.getName(), it -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry()));
+        processor.commands(newSimpleCommand.getMeta()).forEach(it -> newSimpleCommand.addSubCommand(it, false));
 
         processor.getAlias().forEach(it -> {
             final SimpleCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry()));
             // Adding sub commands.
-            processor.commands(newCommand.getMeta()).forEach(sub -> aliasCommand.addSubCommand(sub, false));
+            processor.commands(newSimpleCommand.getMeta()).forEach(sub -> aliasCommand.addSubCommand(sub, false));
         });
     }
 
@@ -96,7 +95,7 @@ public void registerCommand(final @NotNull BaseCommand baseCommand) {
     }
 
     @Override
-    public void unregisterCommand(final @NotNull BaseCommand command) {
+    public void unregisterCommand(final @NotNull Object command) {
         // TODO add a remove functionality
     }
 
diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java
index 74f851fe..17232119 100644
--- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java
+++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java
@@ -23,7 +23,6 @@
  */
 package dev.triumphteam.cmds.simple;
 
-import dev.triumphteam.cmd.core.BaseCommand;
 import dev.triumphteam.cmd.core.extention.CommandExtensions;
 import dev.triumphteam.cmd.core.extention.registry.RegistryContainer;
 import dev.triumphteam.cmd.core.processor.AbstractRootCommandProcessor;
@@ -32,10 +31,10 @@
 public final class SimpleCommandProcessor extends AbstractRootCommandProcessor {
 
     public SimpleCommandProcessor(
-            final @NotNull BaseCommand baseCommand,
+            final @NotNull Object invocationInstance,
             final @NotNull RegistryContainer registryContainer,
             final @NotNull CommandExtensions commandExtensions
     ) {
-        super(baseCommand, registryContainer, commandExtensions);
+        super(invocationInstance, registryContainer, commandExtensions);
     }
 }
diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java
index 2c54b75e..ae2516c9 100644
--- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java
+++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java
@@ -23,7 +23,7 @@
  */
 package dev.triumphteam.cmds.simple;
 
-import dev.triumphteam.cmd.core.BaseCommand;
+import dev.triumphteam.cmd.core.AnnotatedCommand;
 import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor;
 import dev.triumphteam.cmd.core.extention.registry.RegistryContainer;
 import dev.triumphteam.cmd.core.extention.sender.SenderValidator;
@@ -34,12 +34,12 @@
 final class SimpleSubCommandProcessor extends OldAbstractSubCommandProcessor {
 
     public SimpleSubCommandProcessor(
-            final @NotNull BaseCommand baseCommand,
+            final @NotNull AnnotatedCommand annotatedCommand,
             final @NotNull String parentName,
             final @NotNull Method method,
             final @NotNull RegistryContainer registries,
             final @NotNull SenderValidator senderValidator
     ) {
-        super(baseCommand, parentName, method, registries, senderValidator);
+        super(annotatedCommand, parentName, method, registries, senderValidator);
     }
 }
diff --git a/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt b/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt
index 76436591..f929680c 100644
--- a/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt	
+++ b/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt	
@@ -23,7 +23,7 @@
  */
 package dev.triumphteam.tests.fail
 
-import dev.triumphteam.cmd.core.BaseCommand
+import dev.triumphteam.cmd.core.AnnotatedCommand
 import dev.triumphteam.cmd.core.annotations.Command
 import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException
 import dev.triumphteam.cmds.simple.SimpleCommandManager
@@ -67,9 +67,9 @@ class `command registration fail test` {
     }
 }
 
-class NoCommand : BaseCommand()
+class NoCommand : AnnotatedCommand()
 
 @Command
-class EmptyCommandAnnotation : BaseCommand()
+class EmptyCommandAnnotation : AnnotatedCommand()
 
-class EmptyCommandSuper : BaseCommand("")
+class EmptyCommandSuper : AnnotatedCommand("")

From 4a6f4c427638a86f9a03ef0006a7eb35f0b98977 Mon Sep 17 00:00:00 2001
From: Matt 
Date: Fri, 30 Dec 2022 16:39:24 +0000
Subject: [PATCH 043/101] feature: Re-add arguments to commands

---
 .../cmd/core/command/SubCommand.java          | 119 +++++++++++++++++-
 .../processor/AbstractCommandProcessor.java   |  12 +-
 2 files changed, 124 insertions(+), 7 deletions(-)

diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
index e51f8bb1..88095f29 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
@@ -1,13 +1,23 @@
 package dev.triumphteam.cmd.core.command;
 
 import dev.triumphteam.cmd.core.argument.InternalArgument;
+import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument;
+import dev.triumphteam.cmd.core.argument.StringInternalArgument;
+import dev.triumphteam.cmd.core.exceptions.CommandExecutionException;
 import dev.triumphteam.cmd.core.extention.meta.CommandMeta;
+import dev.triumphteam.cmd.core.extention.registry.MessageRegistry;
+import dev.triumphteam.cmd.core.extention.sender.SenderExtension;
+import dev.triumphteam.cmd.core.message.MessageKey;
+import dev.triumphteam.cmd.core.message.context.DefaultMessageContext;
+import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext;
 import dev.triumphteam.cmd.core.processor.SubCommandProcessor;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.function.Supplier;
 
@@ -22,6 +32,9 @@ public class SubCommand implements ExecutableCommand {
     private final Object invocationInstance;
     private final Method method;
 
+    private final SenderExtension senderExtension;
+    private final MessageRegistry messageRegistry;
+
     public SubCommand(
             final @NotNull Object invocationInstance,
             final @NotNull Method method,
@@ -33,6 +46,9 @@ public SubCommand(
         this.meta = processor.createMeta();
         this.senderType = processor.senderType();
         this.arguments = processor.arguments(meta);
+
+        this.messageRegistry = processor.getRegistryContainer().getMessageRegistry();
+        this.senderExtension = processor.getCommandExtensions().getSenderExtension();
     }
 
     @Override
@@ -42,8 +58,19 @@ public void execute(
             final @Nullable Supplier instanceSupplier,
             final @NotNull List arguments
     ) {
+        if (!senderExtension.validate(messageRegistry, this, sender)) return;
+        // if (!meetRequirements(sender)) return;
+
+        // Creates the invoking arguments list
+        final List invokeArguments = new ArrayList<>();
+        invokeArguments.add(sender);
+
+        if (!validateAndCollectArguments(sender, invokeArguments, arguments)) {
+            return;
+        }
+
         try {
-            method.invoke(instanceSupplier == null ? invocationInstance : instanceSupplier.get(), sender);
+            method.invoke(instanceSupplier == null ? invocationInstance : instanceSupplier.get(), invokeArguments.toArray());
         } catch (IllegalAccessException | InvocationTargetException e) {
             throw new RuntimeException(e);
         }
@@ -73,4 +100,94 @@ public boolean isDefault() {
     public boolean hasArguments() {
         return !arguments.isEmpty();
     }
+
+    /**
+     * Used for checking if the arguments are valid and adding them to the `invokeArguments`.
+     *
+     * @param sender          The sender of the command.
+     * @param invokeArguments A list with the arguments that'll be used on the `invoke` of the command method.
+     * @param commandArgs     The command arguments type.
+     * @return False if any internalArgument fails to pass.
+     */
+    @SuppressWarnings("unchecked")
+    private boolean validateAndCollectArguments(
+            @NotNull final S sender,
+            @NotNull final List invokeArguments,
+            @NotNull final List commandArgs
+    ) {
+        for (int i = 0; i < arguments.size(); i++) {
+            final InternalArgument internalArgument = arguments.get(i);
+
+            if (internalArgument instanceof LimitlessInternalArgument) {
+                final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument;
+                final List leftOvers = leftOvers(commandArgs, i);
+
+                final java.lang.Object result = limitlessArgument.resolve(sender, leftOvers);
+
+                if (result == null) {
+                    return false;
+                }
+
+                invokeArguments.add(result);
+                return true;
+            }
+
+            if (!(internalArgument instanceof StringInternalArgument)) {
+                throw new CommandExecutionException("Found unsupported internalArgument", "", name);
+            }
+
+            final StringInternalArgument stringArgument = (StringInternalArgument) internalArgument;
+            final String arg = valueOrNull(commandArgs, i);
+
+            if (arg == null || arg.isEmpty()) {
+                if (internalArgument.isOptional()) {
+                    invokeArguments.add(null);
+                    continue;
+                }
+
+                messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new DefaultMessageContext("", name));
+                return false;
+            }
+
+            final java.lang.Object result = stringArgument.resolve(sender, arg);
+            if (result == null) {
+                messageRegistry.sendMessage(
+                        MessageKey.INVALID_ARGUMENT,
+                        sender,
+                        new InvalidArgumentContext("", name, arg, internalArgument.getName(), internalArgument.getType())
+                );
+                return false;
+            }
+
+            invokeArguments.add(result);
+        }
+
+        return true;
+    }
+
+    /**
+     * Gets an internalArgument value or null.
+     *
+     * @param list  The list to check from.
+     * @param index The current index of the internalArgument.
+     * @return The internalArgument name or null.
+     */
+    @Nullable
+    private String valueOrNull(@NotNull final List list, final int index) {
+        if (index >= list.size()) return null;
+        return list.get(index);
+    }
+
+    /**
+     * Gets the left over of the arguments.
+     *
+     * @param list The list with all the arguments.
+     * @param from The index from which should start removing.
+     * @return A list with the leftover arguments.
+     */
+    @NotNull
+    private List leftOvers(@NotNull final List list, final int from) {
+        if (from > list.size()) return Collections.emptyList();
+        return list.subList(from, list.size());
+    }
 }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java
index 9f3ba758..20151fc5 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java
@@ -121,13 +121,17 @@ abstract class AbstractCommandProcessor implements CommandProcessor {
         return registryContainer;
     }
 
+    public @NotNull CommandExtensions getCommandExtensions() {
+        return commandExtensions;
+    }
+
     protected @NotNull CommandMeta getParentMeta() {
         return parentMeta;
     }
 
     @Contract("_ -> new")
     @NotNull
-    public SubCommandRegistrationException createException(final @NotNull String message) {
+    protected SubCommandRegistrationException createException(final @NotNull String message) {
         return new SubCommandRegistrationException(message, annotatedElement, invocationInstance.getClass());
     }
 
@@ -143,8 +147,8 @@ public SubCommandRegistrationException createException(final @NotNull String mes
     public @Nullable String getName() {
         return name;
     }
-
     // TODO COMMENTS
+
     protected @NotNull InternalArgument createArgument(
             final @NotNull Parameter parameter,
             final @NotNull List argDescriptions,
@@ -352,8 +356,4 @@ public SubCommandRegistrationException createException(final @NotNull String mes
 
         return suggestion;
     }
-
-    protected @NotNull CommandExtensions getCommandExtensions() {
-        return commandExtensions;
-    }
 }

From 3f36b55b79b8cab8e4c33e1543e136a14c8298db Mon Sep 17 00:00:00 2001
From: Matt 
Date: Fri, 30 Dec 2022 16:42:53 +0000
Subject: [PATCH 044/101] chore: Spotless

---
 .../dev/triumphteam/cmd/core/command/SubCommand.java | 12 +++++-------
 .../cmd/core/processor/AbstractCommandProcessor.java |  3 +--
 2 files changed, 6 insertions(+), 9 deletions(-)

diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
index 88095f29..69084d31 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
@@ -111,9 +111,9 @@ public boolean hasArguments() {
      */
     @SuppressWarnings("unchecked")
     private boolean validateAndCollectArguments(
-            @NotNull final S sender,
-            @NotNull final List invokeArguments,
-            @NotNull final List commandArgs
+            final @NotNull S sender,
+            final @NotNull List invokeArguments,
+            final @NotNull List commandArgs
     ) {
         for (int i = 0; i < arguments.size(); i++) {
             final InternalArgument internalArgument = arguments.get(i);
@@ -172,8 +172,7 @@ private boolean validateAndCollectArguments(
      * @param index The current index of the internalArgument.
      * @return The internalArgument name or null.
      */
-    @Nullable
-    private String valueOrNull(@NotNull final List list, final int index) {
+    private @Nullable String valueOrNull(final @NotNull List list, final int index) {
         if (index >= list.size()) return null;
         return list.get(index);
     }
@@ -185,8 +184,7 @@ private String valueOrNull(@NotNull final List list, final int index) {
      * @param from The index from which should start removing.
      * @return A list with the leftover arguments.
      */
-    @NotNull
-    private List leftOvers(@NotNull final List list, final int from) {
+    private @NotNull List leftOvers(final @NotNull List list, final int from) {
         if (from > list.size()) return Collections.emptyList();
         return list.subList(from, list.size());
     }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java
index 20151fc5..d32e9274 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java
@@ -130,8 +130,7 @@ abstract class AbstractCommandProcessor implements CommandProcessor {
     }
 
     @Contract("_ -> new")
-    @NotNull
-    protected SubCommandRegistrationException createException(final @NotNull String message) {
+    protected @NotNull SubCommandRegistrationException createException(final @NotNull String message) {
         return new SubCommandRegistrationException(message, annotatedElement, invocationInstance.getClass());
     }
 

From be6da7033fe8a703de72111076879c40d360d30d Mon Sep 17 00:00:00 2001
From: Matt 
Date: Fri, 30 Dec 2022 18:33:35 +0000
Subject: [PATCH 045/101] feature: Re-added requirements

---
 .../cmd/core/command/SubCommand.java          | 30 ++++++++--
 .../OldAbstractCommandProcessor.java          | 12 +---
 .../core/processor/SubCommandProcessor.java   | 48 +++++++++++++++
 .../core/subcommand/invoker/ClassInvoker.java | 58 -------------------
 .../cmd/core/subcommand/invoker/Invoker.java  | 38 ------------
 .../subcommand/invoker/MethodInvoker.java     | 48 ---------------
 6 files changed, 76 insertions(+), 158 deletions(-)
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java

diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
index 69084d31..05f11a4b 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
@@ -11,6 +11,7 @@
 import dev.triumphteam.cmd.core.message.context.DefaultMessageContext;
 import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext;
 import dev.triumphteam.cmd.core.processor.SubCommandProcessor;
+import dev.triumphteam.cmd.core.requirement.Requirement;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -23,8 +24,9 @@
 
 public class SubCommand implements ExecutableCommand {
 
-    private final List> arguments;
     private final Class senderType;
+    private final List> arguments;
+    private final List> requirements;
 
     private final String name;
     private final CommandMeta meta;
@@ -46,6 +48,7 @@ public SubCommand(
         this.meta = processor.createMeta();
         this.senderType = processor.senderType();
         this.arguments = processor.arguments(meta);
+        this.requirements = processor.requirements();
 
         this.messageRegistry = processor.getRegistryContainer().getMessageRegistry();
         this.senderExtension = processor.getCommandExtensions().getSenderExtension();
@@ -59,7 +62,7 @@ public void execute(
             final @NotNull List arguments
     ) {
         if (!senderExtension.validate(messageRegistry, this, sender)) return;
-        // if (!meetRequirements(sender)) return;
+        if (!meetRequirements(sender)) return;
 
         // Creates the invoking arguments list
         final List invokeArguments = new ArrayList<>();
@@ -122,7 +125,7 @@ private boolean validateAndCollectArguments(
                 final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument;
                 final List leftOvers = leftOvers(commandArgs, i);
 
-                final java.lang.Object result = limitlessArgument.resolve(sender, leftOvers);
+                final Object result = limitlessArgument.resolve(sender, leftOvers);
 
                 if (result == null) {
                     return false;
@@ -133,7 +136,7 @@ private boolean validateAndCollectArguments(
             }
 
             if (!(internalArgument instanceof StringInternalArgument)) {
-                throw new CommandExecutionException("Found unsupported internalArgument", "", name);
+                throw new CommandExecutionException("Found unsupported argument", "", name);
             }
 
             final StringInternalArgument stringArgument = (StringInternalArgument) internalArgument;
@@ -149,7 +152,7 @@ private boolean validateAndCollectArguments(
                 return false;
             }
 
-            final java.lang.Object result = stringArgument.resolve(sender, arg);
+            final Object result = stringArgument.resolve(sender, arg);
             if (result == null) {
                 messageRegistry.sendMessage(
                         MessageKey.INVALID_ARGUMENT,
@@ -165,6 +168,23 @@ private boolean validateAndCollectArguments(
         return true;
     }
 
+    /**
+     * Checks if the requirements to run the command are met.
+     *
+     * @param sender The sender of the command.
+     * @return Whether all requirements are met.
+     */
+    private boolean meetRequirements(@NotNull final S sender) {
+        for (final Requirement requirement : requirements) {
+            if (!requirement.isMet(sender)) {
+                requirement.sendMessage(messageRegistry, sender, "", name);
+                return false;
+            }
+        }
+
+        return true;
+    }
+
     /**
      * Gets an internalArgument value or null.
      *
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
index 3e91644a..efe0fcc1 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
@@ -24,18 +24,16 @@
 package dev.triumphteam.cmd.core.processor;
 
 import dev.triumphteam.cmd.core.AnnotatedCommand;
-import dev.triumphteam.cmd.core.command.ParentCommand;
 import dev.triumphteam.cmd.core.annotations.Command;
 import dev.triumphteam.cmd.core.annotations.Description;
+import dev.triumphteam.cmd.core.command.ParentCommand;
+import dev.triumphteam.cmd.core.command.execution.ExecutionProvider;
 import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException;
 import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException;
-import dev.triumphteam.cmd.core.command.execution.ExecutionProvider;
 import dev.triumphteam.cmd.core.extention.registry.RegistryContainer;
 import dev.triumphteam.cmd.core.extention.sender.SenderMapper;
 import dev.triumphteam.cmd.core.extention.sender.SenderValidator;
 import dev.triumphteam.cmd.core.subcommand.OldSubCommand;
-import dev.triumphteam.cmd.core.subcommand.invoker.Invoker;
-import dev.triumphteam.cmd.core.subcommand.invoker.MethodInvoker;
 import org.jetbrains.annotations.NotNull;
 
 import java.lang.reflect.AnnotatedElement;
@@ -47,7 +45,6 @@
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.function.Function;
 import java.util.function.Supplier;
 
 /**
@@ -100,7 +97,6 @@ protected OldAbstractCommandProcessor(
     // TODO: Comments
     public void addSubCommands(final @NotNull ParentCommand command) {
         // Method sub commands
-        collectMethodSubCommands(command, commandClass, method -> new MethodInvoker(instanceSupplier, method));
 
         // Classes sub commands
         for (final Class klass : commandClass.getDeclaredClasses()) {
@@ -139,15 +135,13 @@ public void addSubCommands(final @NotNull ParentCommand command) {
 
     private void collectMethodSubCommands(
             final @NotNull ParentCommand command,
-            final @NotNull Class klass,
-            final @NotNull Function invokerFunction
+            final @NotNull Class klass
     ) {
         // Method sub commands
         for (final Method method : klass.getDeclaredMethods()) {
             // TODO: ALLOW PRIVATE
             if (Modifier.isPrivate(method.getModifiers())) continue;
 
-            final Invoker invoker = invokerFunction.apply(method);
 
             final P processor = createSubProcessor(method);
             final String subCommandName = processor.getName();
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java
index d1948c6a..834b8be1 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java
@@ -26,6 +26,7 @@
 import dev.triumphteam.cmd.core.annotations.ArgDescriptions;
 import dev.triumphteam.cmd.core.annotations.CommandFlags;
 import dev.triumphteam.cmd.core.annotations.NamedArguments;
+import dev.triumphteam.cmd.core.annotations.Requirements;
 import dev.triumphteam.cmd.core.annotations.Suggestions;
 import dev.triumphteam.cmd.core.argument.InternalArgument;
 import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey;
@@ -40,7 +41,14 @@
 import dev.triumphteam.cmd.core.extention.registry.FlagRegistry;
 import dev.triumphteam.cmd.core.extention.registry.NamedArgumentRegistry;
 import dev.triumphteam.cmd.core.extention.registry.RegistryContainer;
+import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry;
 import dev.triumphteam.cmd.core.extention.sender.SenderExtension;
+import dev.triumphteam.cmd.core.message.MessageKey;
+import dev.triumphteam.cmd.core.message.context.DefaultMessageContext;
+import dev.triumphteam.cmd.core.message.context.MessageContext;
+import dev.triumphteam.cmd.core.requirement.Requirement;
+import dev.triumphteam.cmd.core.requirement.RequirementKey;
+import dev.triumphteam.cmd.core.requirement.RequirementResolver;
 import dev.triumphteam.cmd.core.suggestion.EmptySuggestion;
 import dev.triumphteam.cmd.core.suggestion.Suggestion;
 import dev.triumphteam.cmd.core.suggestion.SuggestionKey;
@@ -73,6 +81,7 @@ public final class SubCommandProcessor extends AbstractCommandProcessor {
 
     private final Method method;
     private final NamedArgumentRegistry namedArgumentRegistry;
+    private final RequirementRegistry requirementRegistry;
     private final FlagRegistry flagRegistry;
 
     SubCommandProcessor(
@@ -87,6 +96,7 @@ public final class SubCommandProcessor extends AbstractCommandProcessor {
 
         this.method = method;
         this.namedArgumentRegistry = registryContainer.getNamedArgumentRegistry();
+        this.requirementRegistry = registryContainer.getRequirementRegistry();
         this.flagRegistry = registryContainer.getFlagRegistry();
     }
 
@@ -194,6 +204,44 @@ public final class SubCommandProcessor extends AbstractCommandProcessor {
         return arguments;
     }
 
+    /**
+     * Get all the requirements for the class.
+     *
+     * @return A {@link List} of requirements needed to run the command.
+     */
+    public @NotNull List> requirements() {
+        final List> requirements = new ArrayList<>();
+        for (final dev.triumphteam.cmd.core.annotations.Requirement requirementAnnotation : getRequirementsFromAnnotations()) {
+            final RequirementKey requirementKey = RequirementKey.of(requirementAnnotation.value());
+            final String messageKeyValue = requirementAnnotation.messageKey();
+
+            final MessageKey messageKey;
+            if (messageKeyValue.isEmpty()) messageKey = null;
+            else messageKey = MessageKey.of(messageKeyValue, MessageContext.class);
+
+            final RequirementResolver resolver = requirementRegistry.getRequirement(requirementKey);
+            if (resolver == null) {
+                throw createException("Could not find Requirement Key \"" + requirementKey.getKey() + "\"");
+            }
+
+            requirements.add(new Requirement<>(resolver, messageKey, DefaultMessageContext::new, requirementAnnotation.invert()));
+        }
+
+        return Collections.unmodifiableList(requirements);
+    }
+
+    /**
+     * @return The list of requirements annotations.
+     */
+    private @NotNull List getRequirementsFromAnnotations() {
+        final Requirements requirements = method.getAnnotation(Requirements.class);
+        if (requirements != null) return Arrays.asList(requirements.value());
+
+        final dev.triumphteam.cmd.core.annotations.Requirement requirement = method.getAnnotation(dev.triumphteam.cmd.core.annotations.Requirement.class);
+        if (requirement == null) return Collections.emptyList();
+        return Collections.singletonList(requirement);
+    }
+
     /**
      * Create a named argument group from the values passed by the annotation.
      *
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java
deleted file mode 100644
index 9c91e1e3..00000000
--- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/ClassInvoker.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/**
- * MIT License
- *
- * Copyright (c) 2019-2021 Matt
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package dev.triumphteam.cmd.core.subcommand.invoker;
-
-import dev.triumphteam.cmd.core.AnnotatedCommand;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-
-public class ClassInvoker implements Invoker {
-
-    private final AnnotatedCommand parent;
-    private final Constructor constructor;
-    private final Method method;
-    private final boolean isStatic;
-
-    public ClassInvoker(
-            final @NotNull AnnotatedCommand parent,
-            final @NotNull Constructor constructor,
-            final @NotNull Method method,
-            final boolean isStatic
-    ) {
-        this.parent = parent;
-        this.constructor = constructor;
-        this.method = method;
-        this.isStatic = isStatic;
-    }
-
-    @Override
-    public void invoke(final @Nullable Object arg, final @NotNull Object[] arguments) throws InvocationTargetException, InstantiationException, IllegalAccessException {
-        final Object instance = isStatic ? constructor.newInstance(arg) : constructor.newInstance(parent, arg);
-        method.invoke(instance, arguments);
-    }
-}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java
deleted file mode 100644
index e05b7e7c..00000000
--- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/Invoker.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * MIT License
- *
- * Copyright (c) 2019-2021 Matt
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package dev.triumphteam.cmd.core.subcommand.invoker;
-
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.lang.reflect.InvocationTargetException;
-
-public interface Invoker {
-
-    void invoke(final @Nullable Object arg, final @NotNull Object[] arguments) throws
-            InstantiationException,
-            IllegalAccessException,
-            IllegalArgumentException,
-            InvocationTargetException;
-}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java
deleted file mode 100644
index 7cc73955..00000000
--- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/invoker/MethodInvoker.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/**
- * MIT License
- *
- * Copyright (c) 2019-2021 Matt
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package dev.triumphteam.cmd.core.subcommand.invoker;
-
-import dev.triumphteam.cmd.core.AnnotatedCommand;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.function.Supplier;
-
-public class MethodInvoker implements Invoker {
-
-    private final Supplier instanceSupplier;
-    private final Method method;
-
-    public MethodInvoker(final @NotNull Supplier instanceSupplier, final @NotNull Method method) {
-        this.instanceSupplier = instanceSupplier;
-        this.method = method;
-    }
-
-    @Override
-    public void invoke(final @Nullable Object arg, final @NotNull Object[] arguments) throws InvocationTargetException, IllegalAccessException {
-        method.invoke(instanceSupplier.get(), arguments);
-    }
-}

From 6bc26bb12eea312a616f586bd265b74c8353fb30 Mon Sep 17 00:00:00 2001
From: Matt 
Date: Sun, 1 Jan 2023 17:55:40 +0000
Subject: [PATCH 046/101] chore: Small rewrite of message context

---
 .../triumphteam/cmd/core/CommandManager.java  |  1 -
 .../cmd/core/command/ExecutableCommand.java   |  4 +-
 .../cmd/core/command/ParentSubCommand.java    | 45 +++++++++-----
 .../cmd/core/command/SubCommand.java          | 36 +++++++----
 .../command/execution/ExecutionProvider.java  |  1 -
 .../extention/sender/SenderExtension.java     |  2 +
 .../cmd/core/message/MessageKey.java          |  8 +--
 ...eContext.java => BasicMessageContext.java} | 55 ++++++-----------
 .../context/InvalidArgumentContext.java       | 61 +++----------------
 ...ontext.java => InvalidCommandContext.java} | 19 +++---
 .../message/context/InvalidInputContext.java  | 49 +++++++++++++++
 .../core/message/context/MessageContext.java  | 19 ++----
 .../context/MessageContextFactory.java        |  1 -
 .../OldAbstractSubCommandProcessor.java       |  3 +-
 .../core/processor/SubCommandProcessor.java   |  4 +-
 .../cmd/core/requirement/Requirement.java     | 25 +++-----
 .../cmd/core/subcommand/OldSubCommand.java    | 16 +----
 .../cmds/simple/SimpleCommand.java            | 27 +++++++-
 .../cmds/simple/SimpleCommandManager.java     |  6 +-
 19 files changed, 195 insertions(+), 187 deletions(-)
 rename core/src/main/java/dev/triumphteam/cmd/core/message/context/{AbstractMessageContext.java => BasicMessageContext.java} (51%)
 rename core/src/main/java/dev/triumphteam/cmd/core/message/context/{DefaultMessageContext.java => InvalidCommandContext.java} (74%)
 create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java

diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java
index c9a1107c..dfa8bf41 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java
@@ -50,7 +50,6 @@
  * @param  The default sender type.
  * @param  The sender type.
  */
-@SuppressWarnings("unchecked")
 public abstract class CommandManager {
 
     private final CommandOptions commandOptions;
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java
index 3b5fbc2e..15a3c4ca 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java
@@ -3,6 +3,7 @@
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import java.lang.reflect.InvocationTargetException;
 import java.util.List;
 import java.util.function.Supplier;
 
@@ -25,8 +26,9 @@ void execute(
             final @NotNull S sender,
             final @NotNull String command,
             final @Nullable Supplier instanceSupplier,
+            final @NotNull List commandPath,
             final @NotNull List arguments
-    );
+    ) throws InvocationTargetException, InstantiationException, IllegalAccessException;
 
     /**
      * @return The instance of the original command instance where the command belongs to.
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java
index 7d570bda..daceb031 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java
@@ -5,7 +5,8 @@
 import dev.triumphteam.cmd.core.extention.meta.CommandMeta;
 import dev.triumphteam.cmd.core.extention.registry.MessageRegistry;
 import dev.triumphteam.cmd.core.message.MessageKey;
-import dev.triumphteam.cmd.core.message.context.DefaultMessageContext;
+import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext;
+import dev.triumphteam.cmd.core.message.context.InvalidCommandContext;
 import dev.triumphteam.cmd.core.processor.ParentCommandProcessor;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
@@ -17,6 +18,9 @@
 import java.util.Map;
 import java.util.function.Supplier;
 
+import static java.util.Collections.emptyList;
+import static java.util.Collections.singletonList;
+
 /**
  * A parent sub command is basically a holder of other sub commands.
  * This normally represents an inner class of a main command.
@@ -79,33 +83,44 @@ public void execute(
             final @NotNull S sender,
             final @NotNull String command,
             final @Nullable Supplier instanceSupplier,
+            final @NotNull List commandPath,
             final @NotNull List arguments
-    ) {
+    ) throws InvocationTargetException, InstantiationException, IllegalAccessException {
         final int argumentSize = arguments.size();
 
         final String commandName = nameFromArguments(arguments);
         final ExecutableCommand subCommand = getSubCommand(commandName, argumentSize);
 
         if (subCommand == null) {
-            messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new DefaultMessageContext(name, commandName));
+            messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(commandPath, emptyList(), commandName));
             return;
         }
 
-        try {
-            final Object argumentValue;
-            if (hasArgument) argumentValue = argument.resolve(sender, command);
-            else argumentValue = null;
+        commandPath.add(subCommand.getName());
 
-            if (hasArgument && argumentValue == null) {
-                // TODO INVALID ARGUMENT HERE
-                return;
-            }
+        final Object argumentValue;
+        if (hasArgument) argumentValue = argument.resolve(sender, command);
+        else argumentValue = null;
 
-            final Object instance = createInstance(instanceSupplier, argumentValue);
-            subCommand.execute(sender, commandName, () -> instance, !subCommand.isDefault() ? arguments.subList(1, argumentSize) : arguments);
-        } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
-            throw new RuntimeException(e);
+        if (hasArgument && argumentValue == null) {
+            messageRegistry.sendMessage(MessageKey.INVALID_ARGUMENT, sender, new InvalidArgumentContext(
+                    commandPath,
+                    singletonList(commandName),
+                    commandName,
+                    argument.getName(),
+                    argument.getType()
+            ));
+            return;
         }
+
+        final Object instance = createInstance(instanceSupplier, argumentValue);
+
+        subCommand.execute(
+                sender, commandName,
+                () -> instance,
+                commandPath,
+                !subCommand.isDefault() ? arguments.subList(1, arguments.size()) : arguments
+        );
     }
 
     /**
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
index 05f11a4b..1a342e47 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
@@ -8,7 +8,7 @@
 import dev.triumphteam.cmd.core.extention.registry.MessageRegistry;
 import dev.triumphteam.cmd.core.extention.sender.SenderExtension;
 import dev.triumphteam.cmd.core.message.MessageKey;
-import dev.triumphteam.cmd.core.message.context.DefaultMessageContext;
+import dev.triumphteam.cmd.core.message.context.BasicMessageContext;
 import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext;
 import dev.triumphteam.cmd.core.processor.SubCommandProcessor;
 import dev.triumphteam.cmd.core.requirement.Requirement;
@@ -30,6 +30,7 @@ public class SubCommand implements ExecutableCommand {
 
     private final String name;
     private final CommandMeta meta;
+    private final boolean containsLimitless;
 
     private final Object invocationInstance;
     private final Method method;
@@ -50,6 +51,8 @@ public SubCommand(
         this.arguments = processor.arguments(meta);
         this.requirements = processor.requirements();
 
+        this.containsLimitless = arguments.stream().anyMatch(LimitlessInternalArgument.class::isInstance);
+
         this.messageRegistry = processor.getRegistryContainer().getMessageRegistry();
         this.senderExtension = processor.getCommandExtensions().getSenderExtension();
     }
@@ -59,24 +62,26 @@ public void execute(
             final @NotNull S sender,
             final @NotNull String command,
             final @Nullable Supplier instanceSupplier,
+            final @NotNull List commandPath,
             final @NotNull List arguments
-    ) {
+    ) throws InvocationTargetException, IllegalAccessException {
         if (!senderExtension.validate(messageRegistry, this, sender)) return;
-        if (!meetRequirements(sender)) return;
+        if (!meetRequirements(sender, commandPath, arguments)) return;
 
         // Creates the invoking arguments list
         final List invokeArguments = new ArrayList<>();
         invokeArguments.add(sender);
 
-        if (!validateAndCollectArguments(sender, invokeArguments, arguments)) {
+        if (!validateAndCollectArguments(sender, commandPath, invokeArguments, arguments)) {
             return;
         }
 
-        try {
-            method.invoke(instanceSupplier == null ? invocationInstance : instanceSupplier.get(), invokeArguments.toArray());
-        } catch (IllegalAccessException | InvocationTargetException e) {
-            throw new RuntimeException(e);
+        if ((!containsLimitless) && arguments.size() >= invokeArguments.size()) {
+            messageRegistry.sendMessage(MessageKey.TOO_MANY_ARGUMENTS, sender, new BasicMessageContext(commandPath, arguments));
+            return;
         }
+
+        method.invoke(instanceSupplier == null ? invocationInstance : instanceSupplier.get(), invokeArguments.toArray());
     }
 
     @Override
@@ -115,7 +120,8 @@ public boolean hasArguments() {
     @SuppressWarnings("unchecked")
     private boolean validateAndCollectArguments(
             final @NotNull S sender,
-            final @NotNull List invokeArguments,
+            final @NotNull List commandPath,
+            final @NotNull List invokeArguments,
             final @NotNull List commandArgs
     ) {
         for (int i = 0; i < arguments.size(); i++) {
@@ -148,7 +154,7 @@ private boolean validateAndCollectArguments(
                     continue;
                 }
 
-                messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new DefaultMessageContext("", name));
+                messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new BasicMessageContext(commandPath, commandArgs));
                 return false;
             }
 
@@ -157,7 +163,7 @@ private boolean validateAndCollectArguments(
                 messageRegistry.sendMessage(
                         MessageKey.INVALID_ARGUMENT,
                         sender,
-                        new InvalidArgumentContext("", name, arg, internalArgument.getName(), internalArgument.getType())
+                        new InvalidArgumentContext(commandPath, commandArgs, arg, internalArgument.getName(), internalArgument.getType())
                 );
                 return false;
             }
@@ -174,10 +180,14 @@ private boolean validateAndCollectArguments(
      * @param sender The sender of the command.
      * @return Whether all requirements are met.
      */
-    private boolean meetRequirements(@NotNull final S sender) {
+    private boolean meetRequirements(
+            final @NotNull S sender,
+            final @NotNull List commandPath,
+            final @NotNull List argumentPath
+    ) {
         for (final Requirement requirement : requirements) {
             if (!requirement.isMet(sender)) {
-                requirement.sendMessage(messageRegistry, sender, "", name);
+                requirement.sendMessage(messageRegistry, sender, commandPath, argumentPath);
                 return false;
             }
         }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionProvider.java
index 422a4f07..c709fe97 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionProvider.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionProvider.java
@@ -38,5 +38,4 @@ public interface ExecutionProvider {
      * @param command The command to execute.
      */
     void execute(final @NotNull Runnable command);
-
 }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java
index f967cda4..b3aca817 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java
@@ -18,4 +18,6 @@ boolean validate(
     );
 
     @Nullable S map(final @NotNull D defaultSender);
+
+    @Nullable D reMap(final @NotNull S defaultSender);
 }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java
index b8cba3e5..d063c63d 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/message/MessageKey.java
@@ -23,8 +23,8 @@
  */
 package dev.triumphteam.cmd.core.message;
 
-import dev.triumphteam.cmd.core.message.context.DefaultMessageContext;
 import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext;
+import dev.triumphteam.cmd.core.message.context.InvalidCommandContext;
 import dev.triumphteam.cmd.core.message.context.MessageContext;
 import org.jetbrains.annotations.Contract;
 import org.jetbrains.annotations.NotNull;
@@ -37,9 +37,9 @@
 public class MessageKey extends ContextualKey {
 
     // Default keys
-    public static final MessageKey UNKNOWN_COMMAND = of("unknown.command", MessageContext.class);
-    public static final MessageKey TOO_MANY_ARGUMENTS = of("too.many.arguments", DefaultMessageContext.class);
-    public static final MessageKey NOT_ENOUGH_ARGUMENTS = of("not.enough.arguments", DefaultMessageContext.class);
+    public static final MessageKey UNKNOWN_COMMAND = of("unknown.command", InvalidCommandContext.class);
+    public static final MessageKey TOO_MANY_ARGUMENTS = of("too.many.arguments", MessageContext.class);
+    public static final MessageKey NOT_ENOUGH_ARGUMENTS = of("not.enough.arguments", MessageContext.class);
     public static final MessageKey INVALID_ARGUMENT = of("invalid.argument", InvalidArgumentContext.class);
 
     protected MessageKey(final @NotNull String key, final @NotNull Class type) {
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/AbstractMessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java
similarity index 51%
rename from core/src/main/java/dev/triumphteam/cmd/core/message/context/AbstractMessageContext.java
rename to core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java
index 7a70c649..05e19f0d 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/AbstractMessageContext.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java
@@ -24,61 +24,46 @@
 package dev.triumphteam.cmd.core.message.context;
 
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
 
-import java.util.Objects;
+import java.util.List;
 
 /**
  * The default most keys will use, only contains the most basic data.
  */
-public abstract class AbstractMessageContext implements MessageContext {
+public class BasicMessageContext implements MessageContext {
 
-    private final String command;
-    private final String subCommand;
+    private final List commandPath;
+    private final List argumentPath;
 
-    public AbstractMessageContext(final @NotNull String command, final @NotNull String subCommand) {
-        this.command = command;
-        this.subCommand = subCommand;
+    public BasicMessageContext(
+            final @NotNull List commandPath,
+            final @NotNull List argumentPath
+    ) {
+        this.commandPath = commandPath;
+        this.argumentPath = argumentPath;
     }
 
     /**
-     * Gets the command in which the error occurred.
-     *
-     * @return The command name.
+     * {@inheritDoc}
      */
     @Override
-    public @NotNull String getCommand() {
-        return command;
+    public @NotNull List getCommandPath() {
+        return commandPath;
     }
 
     /**
-     * Gets the sub command in which the error occurred.
-     *
-     * @return The sub command name.
+     * {@inheritDoc}
      */
     @Override
-    public @NotNull String getSubCommand() {
-        return subCommand;
+    public @NotNull List getArgumentPath() {
+        return argumentPath;
     }
 
     @Override
-    public boolean equals(final @Nullable Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-        final AbstractMessageContext that = (AbstractMessageContext) o;
-        return command.equals(that.command) && Objects.equals(subCommand, that.subCommand);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(command, subCommand);
-    }
-
-    @Override
-    public @NotNull String toString() {
-        return "AbstractMessageContext{" +
-                "command='" + command + '\'' +
-                ", subCommand='" + subCommand + '\'' +
+    public String toString() {
+        return "BasicMessageContext{" +
+                "commandPath=" + commandPath +
+                ", argumentPath=" + argumentPath +
                 '}';
     }
 }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java
index e36c1210..ebfb2eee 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java
@@ -24,81 +24,34 @@
 package dev.triumphteam.cmd.core.message.context;
 
 import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
 
-import java.util.Objects;
+import java.util.List;
 
 /**
  * Context for when user types an invalid argument based on its type.
  */
-public final class InvalidArgumentContext extends AbstractMessageContext {
+public final class InvalidArgumentContext extends InvalidInputContext {
 
-    private final String argument;
     private final String name;
     private final Class type;
 
     public InvalidArgumentContext(
-            final @NotNull String command,
-            final @NotNull String subCommand,
-            final @NotNull String argument,
+            final @NotNull List commandPath,
+            final @NotNull List argumentPath,
+            final @NotNull String invalidInput,
             final @NotNull String name,
             final @NotNull Class type
     ) {
-        super(command, subCommand);
-        this.argument = argument;
+        super(commandPath, argumentPath, invalidInput);
         this.name = name;
         this.type = type;
     }
 
-    /**
-     * Gets the invalid argument the user typed.
-     *
-     * @return The invalid argument.
-     */
-    public @NotNull String getTypedArgument() {
-        return argument;
-    }
-
-    /**
-     * Gets the name of the argument.
-     * If compiled with -parameters argument, it'll show the actual parameter name.
-     * If not compiled with it, names will look like arg1, arg2, arg3, etc.
-     *
-     * @return The argument name, should be equal to the parameter name.
-     */
-    public @NotNull String getName() {
+    public @NotNull String getArgumentName() {
         return name;
     }
 
-    /**
-     * Gets the expected argument type.
-     *
-     * @return The argument type the user should have used.
-     */
     public @NotNull Class getArgumentType() {
         return type;
     }
-
-    @Override
-    public boolean equals(final @Nullable Object o) {
-        if (this == o) return true;
-        if (o == null || getClass() != o.getClass()) return false;
-        if (!super.equals(o)) return false;
-        final InvalidArgumentContext that = (InvalidArgumentContext) o;
-        return argument.equals(that.argument) && name.equals(that.name) && type.equals(that.type);
-    }
-
-    @Override
-    public int hashCode() {
-        return Objects.hash(super.hashCode(), argument, name, type);
-    }
-
-    @Override
-    public @NotNull String toString() {
-        return "InvalidArgumentContext{" +
-                "argument='" + argument + '\'' +
-                ", name='" + name + '\'' +
-                ", type=" + type +
-                ", super=" + super.toString() + "}";
-    }
 }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/DefaultMessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidCommandContext.java
similarity index 74%
rename from core/src/main/java/dev/triumphteam/cmd/core/message/context/DefaultMessageContext.java
rename to core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidCommandContext.java
index 7094332d..02b25ea7 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/DefaultMessageContext.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidCommandContext.java
@@ -25,17 +25,18 @@
 
 import org.jetbrains.annotations.NotNull;
 
+import java.util.List;
+
 /**
- * The default most keys will use, only contains the most basic data.
+ * Context for when user types an invalid argument based on its type.
  */
-public final class DefaultMessageContext extends AbstractMessageContext {
-
-    public DefaultMessageContext(final @NotNull String command, final @NotNull String subCommand) {
-        super(command, subCommand);
-    }
+public final class InvalidCommandContext extends InvalidInputContext {
 
-    @Override
-    public @NotNull String toString() {
-        return "DefaultMessageContext{super=" + super.toString() + "}";
+    public InvalidCommandContext(
+            final @NotNull List commandPath,
+            final @NotNull List argumentPath,
+            final @NotNull String invalidInput
+    ) {
+        super(commandPath, argumentPath, invalidInput);
     }
 }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java
new file mode 100644
index 00000000..eb22e0dd
--- /dev/null
+++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java
@@ -0,0 +1,49 @@
+/**
+ * MIT License
+ *
+ * Copyright (c) 2019-2021 Matt
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+package dev.triumphteam.cmd.core.message.context;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
+/**
+ * Context with an invalid input.
+ */
+public abstract class InvalidInputContext extends BasicMessageContext {
+
+    private final String invalidInput;
+
+    public InvalidInputContext(
+            final @NotNull List commandPath,
+            final @NotNull List argumentPath,
+            final @NotNull String invalidInput
+    ) {
+        super(commandPath, argumentPath);
+        this.invalidInput = invalidInput;
+    }
+
+    public @NotNull String getInvalidInput() {
+        return invalidInput;
+    }
+}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java
index 846e0a1f..d21cb8bd 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java
@@ -23,27 +23,16 @@
  */
 package dev.triumphteam.cmd.core.message.context;
 
-import dev.triumphteam.cmd.core.annotations.Default;
 import org.jetbrains.annotations.NotNull;
 
+import java.util.List;
+
 /**
  * Contains specific data for error handling.
  */
 public interface MessageContext {
 
-    /**
-     * Gets the command in which the error occurred.
-     *
-     * @return The command name.
-     */
-    @NotNull String getCommand();
-
-    /**
-     * Gets the sub command in which the error occurred.
-     * If the command is default its value will be {@link Default#DEFAULT_CMD_NAME}.
-     *
-     * @return The sub command name.
-     */
-    @NotNull String getSubCommand();
+    @NotNull List getCommandPath();
 
+    @NotNull List getArgumentPath();
 }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java
index 41d08434..13fb4f09 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java
@@ -31,5 +31,4 @@ public interface MessageContextFactory {
 
     @Contract("_, _ -> new")
     @NotNull C create(final @NotNull String command, final @NotNull String subCommand);
-
 }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java
index 691e4a50..16b51be0 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java
@@ -62,7 +62,6 @@
 import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry;
 import dev.triumphteam.cmd.core.extention.sender.SenderValidator;
 import dev.triumphteam.cmd.core.message.MessageKey;
-import dev.triumphteam.cmd.core.message.context.DefaultMessageContext;
 import dev.triumphteam.cmd.core.message.context.MessageContext;
 import dev.triumphteam.cmd.core.requirement.Requirement;
 import dev.triumphteam.cmd.core.requirement.RequirementKey;
@@ -641,7 +640,7 @@ public void extractRequirements() {
                 throw createException("Could not find Requirement Key \"" + requirementKey.getKey() + "\"");
             }
 
-            addRequirement(new Requirement<>(resolver, messageKey, DefaultMessageContext::new, requirementAnnotation.invert()));
+            // addRequirement(new Requirement<>(resolver, messageKey, DefaultMessageContext::new, requirementAnnotation.invert()));
         }
     }
 
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java
index 834b8be1..5634ef08 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java
@@ -44,7 +44,7 @@
 import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry;
 import dev.triumphteam.cmd.core.extention.sender.SenderExtension;
 import dev.triumphteam.cmd.core.message.MessageKey;
-import dev.triumphteam.cmd.core.message.context.DefaultMessageContext;
+import dev.triumphteam.cmd.core.message.context.BasicMessageContext;
 import dev.triumphteam.cmd.core.message.context.MessageContext;
 import dev.triumphteam.cmd.core.requirement.Requirement;
 import dev.triumphteam.cmd.core.requirement.RequirementKey;
@@ -224,7 +224,7 @@ public final class SubCommandProcessor extends AbstractCommandProcessor {
                 throw createException("Could not find Requirement Key \"" + requirementKey.getKey() + "\"");
             }
 
-            requirements.add(new Requirement<>(resolver, messageKey, DefaultMessageContext::new, requirementAnnotation.invert()));
+            requirements.add(new Requirement<>(resolver, messageKey, BasicMessageContext::new, requirementAnnotation.invert()));
         }
 
         return Collections.unmodifiableList(requirements);
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java
index 780fcc48..39362eae 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java
@@ -23,14 +23,15 @@
  */
 package dev.triumphteam.cmd.core.requirement;
 
-import dev.triumphteam.cmd.core.message.ContextualKey;
 import dev.triumphteam.cmd.core.extention.registry.MessageRegistry;
+import dev.triumphteam.cmd.core.message.ContextualKey;
 import dev.triumphteam.cmd.core.message.context.MessageContext;
-import dev.triumphteam.cmd.core.message.context.MessageContextFactory;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import java.util.List;
 import java.util.Objects;
+import java.util.function.BiFunction;
 
 /**
  * Contains the data for the requirement.
@@ -41,13 +42,13 @@ public final class Requirement {
 
     private final RequirementResolver resolver;
     private final ContextualKey messageKey;
-    private final MessageContextFactory contextFactory;
+    private final BiFunction, List, C> contextFactory;
     private final boolean invert;
 
     public Requirement(
             final @NotNull RequirementResolver resolver,
             final @Nullable ContextualKey messageKey,
-            final @NotNull MessageContextFactory contextFactory,
+            final @NotNull BiFunction, List, C> contextFactory,
             final boolean invert
     ) {
         this.resolver = resolver;
@@ -65,23 +66,15 @@ public Requirement(
         return messageKey;
     }
 
-    /**
-     * Sends the message to the sender.
-     *
-     * @param registry   The registry which contains the message.
-     * @param sender     The sender which will receive the message.
-     * @param command    The command which is being executed.
-     * @param subCommand The sub command which is being executed.
-     * @param        The sender type.
-     */
+    // TODO
     public  void sendMessage(
             final @NotNull MessageRegistry registry,
             final @NotNull ST sender,
-            final @NotNull String command,
-            final @NotNull String subCommand
+            final @NotNull List commandPath,
+            final @NotNull List argumentPath
     ) {
         if (messageKey == null) return;
-        registry.sendMessage(messageKey, sender, contextFactory.create(command, subCommand));
+        registry.sendMessage(messageKey, sender, contextFactory.apply(commandPath, argumentPath));
     }
 
     /**
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java
index bdeaa52f..873629b1 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java
@@ -27,15 +27,12 @@
 import dev.triumphteam.cmd.core.argument.InternalArgument;
 import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument;
 import dev.triumphteam.cmd.core.argument.StringInternalArgument;
-import dev.triumphteam.cmd.core.exceptions.CommandExecutionException;
 import dev.triumphteam.cmd.core.command.execution.ExecutionProvider;
-import dev.triumphteam.cmd.core.message.MessageKey;
+import dev.triumphteam.cmd.core.exceptions.CommandExecutionException;
 import dev.triumphteam.cmd.core.extention.registry.MessageRegistry;
-import dev.triumphteam.cmd.core.message.context.DefaultMessageContext;
-import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext;
+import dev.triumphteam.cmd.core.extention.sender.SenderValidator;
 import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor;
 import dev.triumphteam.cmd.core.requirement.Requirement;
-import dev.triumphteam.cmd.core.extention.sender.SenderValidator;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -167,7 +164,6 @@ public void execute(@NotNull final S sender, @NotNull final List args) {
         }
 
         if ((!containsLimitless) && args.size() >= invokeArguments.size()) {
-            messageRegistry.sendMessage(MessageKey.TOO_MANY_ARGUMENTS, sender, new DefaultMessageContext(parentName, name));
             return;
         }
 
@@ -264,17 +260,12 @@ private boolean validateAndCollectArguments(
                     continue;
                 }
 
-                messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new DefaultMessageContext(parentName, name));
                 return false;
             }
 
             final java.lang.Object result = stringArgument.resolve(sender, arg);
             if (result == null) {
-                messageRegistry.sendMessage(
-                        MessageKey.INVALID_ARGUMENT,
-                        sender,
-                        new InvalidArgumentContext(parentName, name, arg, internalArgument.getName(), internalArgument.getType())
-                );
+
                 return false;
             }
 
@@ -293,7 +284,6 @@ private boolean validateAndCollectArguments(
     private boolean meetRequirements(@NotNull final S sender) {
         for (final Requirement requirement : requirements) {
             if (!requirement.isMet(sender)) {
-                requirement.sendMessage(messageRegistry, sender, parentName, name);
                 return false;
             }
         }
diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java
index da3c7779..6b5961f5 100644
--- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java
+++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java
@@ -26,18 +26,23 @@
 import dev.triumphteam.cmd.core.command.ExecutableCommand;
 import dev.triumphteam.cmd.core.command.ParentCommand;
 import dev.triumphteam.cmd.core.command.ParentSubCommand;
+import dev.triumphteam.cmd.core.exceptions.CommandExecutionException;
 import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException;
 import dev.triumphteam.cmd.core.extention.meta.CommandMeta;
 import dev.triumphteam.cmd.core.extention.registry.MessageRegistry;
 import dev.triumphteam.cmd.core.message.MessageKey;
-import dev.triumphteam.cmd.core.message.context.DefaultMessageContext;
+import dev.triumphteam.cmd.core.message.context.InvalidCommandContext;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
+import java.lang.reflect.InvocationTargetException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
+import static java.util.Collections.emptyList;
+
 public final class SimpleCommand implements ParentCommand {
 
     private final String name;
@@ -87,12 +92,28 @@ public void execute(
         final String commandName = nameFromArguments(arguments);
         final ExecutableCommand subCommand = getSubCommand(commandName, arguments.size());
 
+        final List commandPath = new ArrayList<>();
+
         if (subCommand == null) {
-            messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new DefaultMessageContext(name, commandName));
+            messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(commandPath, emptyList(), commandName));
             return;
         }
 
-        subCommand.execute(sender, commandName, null, !subCommand.isDefault() ? arguments.subList(1, arguments.size()) : arguments);
+        // Add itself as beginning of path
+        commandPath.add(subCommand.getName());
+
+        // Executing the subcommand.
+        try {
+            subCommand.execute(
+                    sender, commandName,
+                    null,
+                    commandPath,
+                    !subCommand.isDefault() ? arguments.subList(1, arguments.size()) : arguments
+            );
+        } catch (final @NotNull Throwable exception) {
+            throw new CommandExecutionException("An error occurred while executing the command")
+                    .initCause(exception instanceof InvocationTargetException ? exception.getCause() : exception);
+        }
     }
 
     @Override
diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java
index cb0ae9ef..22342af8 100644
--- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java
+++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java
@@ -30,7 +30,7 @@
 import dev.triumphteam.cmd.core.extention.CommandOptions;
 import dev.triumphteam.cmd.core.extention.registry.RegistryContainer;
 import dev.triumphteam.cmd.core.message.MessageKey;
-import dev.triumphteam.cmd.core.message.context.DefaultMessageContext;
+import dev.triumphteam.cmd.core.message.context.InvalidCommandContext;
 import org.jetbrains.annotations.Contract;
 import org.jetbrains.annotations.NotNull;
 
@@ -39,6 +39,8 @@
 import java.util.Map;
 import java.util.function.Consumer;
 
+import static java.util.Collections.emptyList;
+
 public final class SimpleCommandManager extends CommandManager {
 
     private final Map> commands = new HashMap<>();
@@ -114,7 +116,7 @@ public void executeCommand(final @NotNull S sender, final @NotNull List<@NotNull
             registryContainer.getMessageRegistry().sendMessage(
                     MessageKey.UNKNOWN_COMMAND,
                     sender,
-                    new DefaultMessageContext(commandName, "")
+                    new InvalidCommandContext(emptyList(), emptyList(), commandName)
             );
             return;
         }

From 6606d2a78601ce8fd2f07d2ade0e12bdc1dd7dd3 Mon Sep 17 00:00:00 2001
From: Matt 
Date: Sun, 1 Jan 2023 18:44:01 +0000
Subject: [PATCH 047/101] feature: Draft executor extension

---
 .../cmd/core/command/ExecutableCommand.java   |  3 +-
 .../cmd/core/command/ParentSubCommand.java    |  2 +-
 .../cmd/core/command/SubCommand.java          | 13 ++++--
 .../execution/AsyncExecutionProvider.java     | 42 -------------------
 .../command/execution/CommandExecutor.java    | 17 ++++++++
 .../core/command/execution/ExecutionData.java | 25 -----------
 .../command/execution/ExecutionProvider.java  | 41 ------------------
 .../execution/SyncExecutionProvider.java      | 34 ---------------
 .../core/exceptions/TriumphCmdException.java  | 10 -----
 .../cmd/core/extention/CommandExtensions.java | 10 ++++-
 .../cmd/core/extention/ExtensionBuilder.java  | 26 +++++++++---
 .../defaults/DefaultCommandExecutor.java      | 21 ++++++++++
 .../OldAbstractCommandProcessor.java          | 23 +---------
 .../cmd/core/subcommand/OldSubCommand.java    | 16 +------
 .../cmds/simple/SimpleCommandManager.java     |  6 ---
 .../cmds/simple/SimpleCommandOptions.java     |  2 +
 .../cmds/simple/SimpleSubCommand.java         |  6 +--
 17 files changed, 86 insertions(+), 211 deletions(-)
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/execution/AsyncExecutionProvider.java
 create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/execution/CommandExecutor.java
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionData.java
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionProvider.java
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/execution/SyncExecutionProvider.java
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/exceptions/TriumphCmdException.java
 create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java

diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java
index 15a3c4ca..9933ab86 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java
@@ -3,7 +3,6 @@
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.lang.reflect.InvocationTargetException;
 import java.util.List;
 import java.util.function.Supplier;
 
@@ -28,7 +27,7 @@ void execute(
             final @Nullable Supplier instanceSupplier,
             final @NotNull List commandPath,
             final @NotNull List arguments
-    ) throws InvocationTargetException, InstantiationException, IllegalAccessException;
+    ) throws Throwable;
 
     /**
      * @return The instance of the original command instance where the command belongs to.
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java
index daceb031..cb80e268 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java
@@ -85,7 +85,7 @@ public void execute(
             final @Nullable Supplier instanceSupplier,
             final @NotNull List commandPath,
             final @NotNull List arguments
-    ) throws InvocationTargetException, InstantiationException, IllegalAccessException {
+    ) throws Throwable {
         final int argumentSize = arguments.size();
 
         final String commandName = nameFromArguments(arguments);
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
index 1a342e47..4c624635 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
@@ -3,6 +3,7 @@
 import dev.triumphteam.cmd.core.argument.InternalArgument;
 import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument;
 import dev.triumphteam.cmd.core.argument.StringInternalArgument;
+import dev.triumphteam.cmd.core.command.execution.CommandExecutor;
 import dev.triumphteam.cmd.core.exceptions.CommandExecutionException;
 import dev.triumphteam.cmd.core.extention.meta.CommandMeta;
 import dev.triumphteam.cmd.core.extention.registry.MessageRegistry;
@@ -15,7 +16,6 @@
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -34,6 +34,7 @@ public class SubCommand implements ExecutableCommand {
 
     private final Object invocationInstance;
     private final Method method;
+    private final CommandExecutor commandExecutor;
 
     private final SenderExtension senderExtension;
     private final MessageRegistry messageRegistry;
@@ -55,6 +56,7 @@ public SubCommand(
 
         this.messageRegistry = processor.getRegistryContainer().getMessageRegistry();
         this.senderExtension = processor.getCommandExtensions().getSenderExtension();
+        this.commandExecutor = processor.getCommandExtensions().getCommandExecutor();
     }
 
     @Override
@@ -64,7 +66,7 @@ public void execute(
             final @Nullable Supplier instanceSupplier,
             final @NotNull List commandPath,
             final @NotNull List arguments
-    ) throws InvocationTargetException, IllegalAccessException {
+    ) throws Throwable {
         if (!senderExtension.validate(messageRegistry, this, sender)) return;
         if (!meetRequirements(sender, commandPath, arguments)) return;
 
@@ -81,7 +83,12 @@ public void execute(
             return;
         }
 
-        method.invoke(instanceSupplier == null ? invocationInstance : instanceSupplier.get(), invokeArguments.toArray());
+        commandExecutor.execute(
+                meta,
+                instanceSupplier == null ? invocationInstance : instanceSupplier.get(),
+                method,
+                invokeArguments
+        );
     }
 
     @Override
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/AsyncExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/AsyncExecutionProvider.java
deleted file mode 100644
index 40bee8e8..00000000
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/AsyncExecutionProvider.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/**
- * MIT License
- *
- * Copyright (c) 2019-2021 Matt
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package dev.triumphteam.cmd.core.command.execution;
-
-import org.jetbrains.annotations.NotNull;
-
-import java.util.concurrent.CompletableFuture;
-
-/**
- * Implementation of asynchronous execution, not necessarily used in all platforms.
- */
-public final class AsyncExecutionProvider implements ExecutionProvider {
-
-    /**
-     * {@inheritDoc}
-     */
-    @Override
-    public void execute(final @NotNull Runnable command) {
-        CompletableFuture.runAsync(command);
-    }
-}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/CommandExecutor.java b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/CommandExecutor.java
new file mode 100644
index 00000000..fae721f8
--- /dev/null
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/CommandExecutor.java
@@ -0,0 +1,17 @@
+package dev.triumphteam.cmd.core.command.execution;
+
+import dev.triumphteam.cmd.core.extention.meta.CommandMeta;
+import org.jetbrains.annotations.NotNull;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+public interface CommandExecutor {
+
+    void execute(
+            final @NotNull CommandMeta meta,
+            final @NotNull Object instance,
+            final @NotNull Method method,
+            final @NotNull List arguments
+    ) throws Throwable;
+}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionData.java b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionData.java
deleted file mode 100644
index 57e9dca8..00000000
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionData.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package dev.triumphteam.cmd.core.command.execution;
-
-import org.jetbrains.annotations.NotNull;
-
-import java.lang.reflect.Method;
-import java.util.function.Supplier;
-
-public final class ExecutionData {
-
-    private final Supplier instanceSupplier;
-    private final Method method;
-
-    public ExecutionData(final @NotNull Supplier instanceSupplier, final @NotNull Method method) {
-        this.instanceSupplier = instanceSupplier;
-        this.method = method;
-    }
-
-    public @NotNull Supplier getInstanceSupplier() {
-        return instanceSupplier;
-    }
-
-    public @NotNull Method getMethod() {
-        return method;
-    }
-}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionProvider.java
deleted file mode 100644
index c709fe97..00000000
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/ExecutionProvider.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/**
- * MIT License
- *
- * Copyright (c) 2019-2021 Matt
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package dev.triumphteam.cmd.core.command.execution;
-
-import org.jetbrains.annotations.NotNull;
-
-/**
- * Provides different ways to execute the command.
- */
-public interface ExecutionProvider {
-
-    /**
-     * Executes the command.
-     * This can be done in many forms, such as synchronous or asynchronous.
-     * This also allows for different asynchronous implementations, for example, BukkitScheduler or CompletableFuture.
-     *
-     * @param command The command to execute.
-     */
-    void execute(final @NotNull Runnable command);
-}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/SyncExecutionProvider.java b/core/src/main/java/dev/triumphteam/cmd/core/command/execution/SyncExecutionProvider.java
deleted file mode 100644
index a434e717..00000000
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/SyncExecutionProvider.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/**
- * MIT License
- *
- * Copyright (c) 2019-2021 Matt
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package dev.triumphteam.cmd.core.command.execution;
-
-import org.jetbrains.annotations.NotNull;
-
-public final class SyncExecutionProvider implements ExecutionProvider {
-
-    @Override
-    public void execute(final @NotNull Runnable command) {
-        command.run();
-    }
-}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/TriumphCmdException.java b/core/src/main/java/dev/triumphteam/cmd/core/exceptions/TriumphCmdException.java
deleted file mode 100644
index fde3abfc..00000000
--- a/core/src/main/java/dev/triumphteam/cmd/core/exceptions/TriumphCmdException.java
+++ /dev/null
@@ -1,10 +0,0 @@
-package dev.triumphteam.cmd.core.exceptions;
-
-import org.jetbrains.annotations.NotNull;
-
-public final class TriumphCmdException extends RuntimeException {
-
-    public TriumphCmdException(final @NotNull String message) {
-        super(message);
-    }
-}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java
index 7a2b4aa6..1050aad5 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java
@@ -1,5 +1,6 @@
 package dev.triumphteam.cmd.core.extention;
 
+import dev.triumphteam.cmd.core.command.execution.CommandExecutor;
 import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor;
 import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator;
 import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor;
@@ -17,17 +18,20 @@ public final class CommandExtensions {
 
     private final SenderExtension senderExtension;
     private final ArgumentValidator argumentValidator;
+    private final CommandExecutor commandExecutor;
 
     public CommandExtensions(
             final @NotNull Map, AnnotationProcessor> annotationProcessors,
             final @NotNull List commandMetaProcessors,
             final @NotNull SenderExtension senderExtension,
-            final @NotNull ArgumentValidator argumentValidator
+            final @NotNull ArgumentValidator argumentValidator,
+            final @NotNull CommandExecutor commandExecutor
     ) {
         this.annotationProcessors = annotationProcessors;
         this.commandMetaProcessors = commandMetaProcessors;
         this.senderExtension = senderExtension;
         this.argumentValidator = argumentValidator;
+        this.commandExecutor = commandExecutor;
     }
 
     public @NotNull Map, AnnotationProcessor> getAnnotationProcessors() {
@@ -45,4 +49,8 @@ public CommandExtensions(
     public @NotNull ArgumentValidator getArgumentValidator() {
         return argumentValidator;
     }
+
+    public @NotNull CommandExecutor getCommandExecutor() {
+        return commandExecutor;
+    }
 }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java
index 314ef620..5d06dae6 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java
@@ -1,9 +1,11 @@
 package dev.triumphteam.cmd.core.extention;
 
-import dev.triumphteam.cmd.core.exceptions.TriumphCmdException;
+import dev.triumphteam.cmd.core.command.execution.CommandExecutor;
+import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException;
 import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor;
 import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator;
 import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor;
+import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor;
 import dev.triumphteam.cmd.core.extention.sender.SenderExtension;
 import org.jetbrains.annotations.Contract;
 import org.jetbrains.annotations.NotNull;
@@ -19,8 +21,9 @@ public final class ExtensionBuilder {
     private final Map, AnnotationProcessor> annotationProcessors = new HashMap<>();
     private final List commandMetaProcessors = new ArrayList<>();
 
-    private SenderExtension senderExtension;
-    private ArgumentValidator argumentValidator;
+    private SenderExtension senderExtension = null;
+    private ArgumentValidator argumentValidator = null;
+    private CommandExecutor commandExecutor = null;
 
     @Contract("_, _ -> this")
     public  @NotNull ExtensionBuilder addAnnotationProcessor(
@@ -49,20 +52,31 @@ public final class ExtensionBuilder {
         return this;
     }
 
+    @Contract("_ -> this")
+    public @NotNull ExtensionBuilder setCommandExecutor(final @NotNull CommandExecutor commandExecutor) {
+        this.commandExecutor = commandExecutor;
+        return this;
+    }
+
     public @NotNull CommandExtensions build() {
         if (senderExtension == null) {
-            throw new TriumphCmdException("No sender extension was added to Command Manager.");
+            throw new CommandRegistrationException("No sender extension was added to Command Manager.");
         }
 
         if (argumentValidator == null) {
-            throw new TriumphCmdException("No argument validator was added to Command Manager.");
+            throw new CommandRegistrationException("No argument validator was added to Command Manager.");
+        }
+
+        if (commandExecutor == null) {
+            throw new CommandRegistrationException("No command executor was added to Command Manager.");
         }
 
         return new CommandExtensions<>(
                 annotationProcessors,
                 commandMetaProcessors,
                 senderExtension,
-                argumentValidator
+                argumentValidator,
+                new DefaultCommandExecutor()
         );
     }
 }
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java
new file mode 100644
index 00000000..36d2d7b6
--- /dev/null
+++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java
@@ -0,0 +1,21 @@
+package dev.triumphteam.cmd.core.extention.defaults;
+
+import dev.triumphteam.cmd.core.command.execution.CommandExecutor;
+import dev.triumphteam.cmd.core.extention.meta.CommandMeta;
+import org.jetbrains.annotations.NotNull;
+
+import java.lang.reflect.Method;
+import java.util.List;
+
+public final class DefaultCommandExecutor implements CommandExecutor {
+
+    @Override
+    public void execute(
+            final @NotNull CommandMeta meta,
+            final @NotNull Object instance,
+            final @NotNull Method method,
+            final @NotNull List arguments
+    ) throws Throwable {
+        method.invoke(instance, arguments.toArray());
+    }
+}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
index efe0fcc1..277b35bb 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
@@ -27,7 +27,6 @@
 import dev.triumphteam.cmd.core.annotations.Command;
 import dev.triumphteam.cmd.core.annotations.Description;
 import dev.triumphteam.cmd.core.command.ParentCommand;
-import dev.triumphteam.cmd.core.command.execution.ExecutionProvider;
 import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException;
 import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException;
 import dev.triumphteam.cmd.core.extention.registry.RegistryContainer;
@@ -70,25 +69,18 @@ public abstract class OldAbstractCommandProcessor senderMapper;
     private final SenderValidator senderValidator;
 
-    private final ExecutionProvider syncExecutionProvider;
-    private final ExecutionProvider asyncExecutionProvider;
-
     protected OldAbstractCommandProcessor(
             final @NotNull Class commandClass,
             final @NotNull Supplier instanceSupplier,
             final @NotNull RegistryContainer registryContainer,
             final @NotNull SenderMapper senderMapper,
-            final @NotNull SenderValidator senderValidator,
-            final @NotNull ExecutionProvider syncExecutionProvider,
-            final @NotNull ExecutionProvider asyncExecutionProvider
+            final @NotNull SenderValidator senderValidator
     ) {
         this.commandClass = commandClass;
         this.instanceSupplier = instanceSupplier;
         this.registryContainer = registryContainer;
         this.senderMapper = senderMapper;
         this.senderValidator = senderValidator;
-        this.syncExecutionProvider = syncExecutionProvider;
-        this.asyncExecutionProvider = asyncExecutionProvider;
 
         extractCommandNames();
         extractDescription();
@@ -156,9 +148,6 @@ private void collectMethodSubCommands(
                 );
             }
 
-            final ExecutionProvider executionProvider = processor.isAsync() ? asyncExecutionProvider : syncExecutionProvider;
-
-            final SC subCommand = createSubCommand(processor, executionProvider);
             // command.addSubCommand(subCommandName, subCommand);
 
             // processor.getAlias().forEach(alias -> command.addSubCommandAlias(alias, subCommand));
@@ -167,7 +156,7 @@ private void collectMethodSubCommands(
 
     protected abstract @NotNull P createSubProcessor(final @NotNull AnnotatedElement method);
 
-    protected abstract @NotNull SC createSubCommand(final @NotNull P processor, final @NotNull ExecutionProvider executionProvider);
+    protected abstract @NotNull SC createSubCommand(final @NotNull P processor);
 
     /**
      * Used for the child processors to get the command name.
@@ -206,14 +195,6 @@ private void collectMethodSubCommands(
         return senderValidator;
     }
 
-    public @NotNull ExecutionProvider getSyncExecutionProvider() {
-        return syncExecutionProvider;
-    }
-
-    public @NotNull ExecutionProvider getAsyncExecutionProvider() {
-        return asyncExecutionProvider;
-    }
-
     /**
      * gets the Description of the SubCommand.
      *
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java
index 873629b1..f49772f0 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java
@@ -27,7 +27,6 @@
 import dev.triumphteam.cmd.core.argument.InternalArgument;
 import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument;
 import dev.triumphteam.cmd.core.argument.StringInternalArgument;
-import dev.triumphteam.cmd.core.command.execution.ExecutionProvider;
 import dev.triumphteam.cmd.core.exceptions.CommandExecutionException;
 import dev.triumphteam.cmd.core.extention.registry.MessageRegistry;
 import dev.triumphteam.cmd.core.extention.sender.SenderValidator;
@@ -36,7 +35,6 @@
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -67,7 +65,6 @@ public abstract class OldSubCommand {
     private final Set> requirements;
 
     private final MessageRegistry messageRegistry;
-    private final ExecutionProvider executionProvider;
 
     private final SenderValidator senderValidator;
 
@@ -76,8 +73,7 @@ public abstract class OldSubCommand {
 
     public OldSubCommand(
             @NotNull final OldAbstractSubCommandProcessor processor,
-            @NotNull final String parentName,
-            @NotNull final ExecutionProvider executionProvider
+            @NotNull final String parentName
     ) {
         this.annotatedCommand = processor.getBaseCommand();
         // this.method = processor.getAnnotatedElement();
@@ -93,8 +89,6 @@ public OldSubCommand(
 
         this.parentName = parentName;
 
-        this.executionProvider = executionProvider;
-
         this.hasArguments = !internalArguments.isEmpty();
         this.containsLimitless = internalArguments.stream().anyMatch(LimitlessInternalArgument.class::isInstance);
     }
@@ -167,14 +161,6 @@ public void execute(@NotNull final S sender, @NotNull final List args) {
             return;
         }
 
-        executionProvider.execute(() -> {
-            try {
-                method.invoke(annotatedCommand, invokeArguments.toArray());
-            } catch (IllegalAccessException | InvocationTargetException exception) {
-                throw new CommandExecutionException("An error occurred while executing the command", parentName, name)
-                        .initCause(exception instanceof InvocationTargetException ? exception.getCause() : exception);
-            }
-        });
     }
 
     /**
diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java
index 22342af8..c8545bbe 100644
--- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java
+++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java
@@ -24,9 +24,6 @@
 package dev.triumphteam.cmds.simple;
 
 import dev.triumphteam.cmd.core.CommandManager;
-import dev.triumphteam.cmd.core.command.execution.AsyncExecutionProvider;
-import dev.triumphteam.cmd.core.command.execution.ExecutionProvider;
-import dev.triumphteam.cmd.core.command.execution.SyncExecutionProvider;
 import dev.triumphteam.cmd.core.extention.CommandOptions;
 import dev.triumphteam.cmd.core.extention.registry.RegistryContainer;
 import dev.triumphteam.cmd.core.message.MessageKey;
@@ -47,9 +44,6 @@ public final class SimpleCommandManager extends CommandManager {
 
     private final RegistryContainer registryContainer = new RegistryContainer<>();
 
-    private final ExecutionProvider syncExecutionProvider = new SyncExecutionProvider();
-    private final ExecutionProvider asyncExecutionProvider = new AsyncExecutionProvider();
-
     private SimpleCommandManager(final @NotNull CommandOptions commandOptions) {
         super(commandOptions);
     }
diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java
index 244bfdac..b824922b 100644
--- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java
+++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java
@@ -3,6 +3,7 @@
 import dev.triumphteam.cmd.core.extention.CommandExtensions;
 import dev.triumphteam.cmd.core.extention.CommandOptions;
 import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator;
+import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor;
 import org.jetbrains.annotations.NotNull;
 
 public final class SimpleCommandOptions extends CommandOptions {
@@ -16,6 +17,7 @@ public static final class Builder extends CommandOptions.Builder {
                 builder.setArgumentValidator(new DefaultArgumentValidator<>());
+                builder.setCommandExecutor(new DefaultCommandExecutor());
             });
         }
 
diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java
index 7bb77082..ee4fb110 100644
--- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java
+++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java
@@ -23,7 +23,6 @@
  */
 package dev.triumphteam.cmds.simple;
 
-import dev.triumphteam.cmd.core.command.execution.ExecutionProvider;
 import dev.triumphteam.cmd.core.subcommand.OldSubCommand;
 import org.jetbrains.annotations.NotNull;
 
@@ -31,9 +30,8 @@ public final class SimpleSubCommand extends OldSubCommand {
 
     public SimpleSubCommand(
             final @NotNull SimpleSubCommandProcessor processor,
-            final @NotNull String parentName,
-            final @NotNull ExecutionProvider executionProvider
+            final @NotNull String parentName
     ) {
-        super(processor, parentName, executionProvider);
+        super(processor, parentName);
     }
 }

From a2b109be28540116aa47359db36287df3daeb466 Mon Sep 17 00:00:00 2001
From: Matt 
Date: Sun, 1 Jan 2023 18:46:36 +0000
Subject: [PATCH 048/101] chore: Yeet old code

---
 .../{execution => }/CommandExecutor.java      |   2 +-
 .../cmd/core/command/SubCommand.java          |   1 -
 .../cmd/core/extention/CommandExtensions.java |   2 +-
 .../cmd/core/extention/ExtensionBuilder.java  |   2 +-
 .../defaults/DefaultCommandExecutor.java      |   2 +-
 .../core/extention/sender/SenderMapper.java   |  43 -
 .../extention/sender/SenderValidator.java     |  46 -
 .../OldAbstractCommandProcessor.java          | 239 -----
 .../OldAbstractSubCommandProcessor.java       | 833 ------------------
 .../cmd/core/subcommand/OldSubCommand.java    | 318 -------
 .../cmds/simple/SimpleSubCommand.java         |  37 -
 .../simple/SimpleSubCommandProcessor.java     |  45 -
 12 files changed, 4 insertions(+), 1566 deletions(-)
 rename core/src/main/java/dev/triumphteam/cmd/core/command/{execution => }/CommandExecutor.java (89%)
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderValidator.java
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java
 delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java
 delete mode 100644 simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java
 delete mode 100644 simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java

diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/CommandExecutor.java b/core/src/main/java/dev/triumphteam/cmd/core/command/CommandExecutor.java
similarity index 89%
rename from core/src/main/java/dev/triumphteam/cmd/core/command/execution/CommandExecutor.java
rename to core/src/main/java/dev/triumphteam/cmd/core/command/CommandExecutor.java
index fae721f8..e97a5a71 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/execution/CommandExecutor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/CommandExecutor.java
@@ -1,4 +1,4 @@
-package dev.triumphteam.cmd.core.command.execution;
+package dev.triumphteam.cmd.core.command;
 
 import dev.triumphteam.cmd.core.extention.meta.CommandMeta;
 import org.jetbrains.annotations.NotNull;
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
index 4c624635..cae97e73 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java
@@ -3,7 +3,6 @@
 import dev.triumphteam.cmd.core.argument.InternalArgument;
 import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument;
 import dev.triumphteam.cmd.core.argument.StringInternalArgument;
-import dev.triumphteam.cmd.core.command.execution.CommandExecutor;
 import dev.triumphteam.cmd.core.exceptions.CommandExecutionException;
 import dev.triumphteam.cmd.core.extention.meta.CommandMeta;
 import dev.triumphteam.cmd.core.extention.registry.MessageRegistry;
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java
index 1050aad5..fbaa0a1d 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java
@@ -1,6 +1,6 @@
 package dev.triumphteam.cmd.core.extention;
 
-import dev.triumphteam.cmd.core.command.execution.CommandExecutor;
+import dev.triumphteam.cmd.core.command.CommandExecutor;
 import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor;
 import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator;
 import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor;
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java
index 5d06dae6..9b233105 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java
@@ -1,6 +1,6 @@
 package dev.triumphteam.cmd.core.extention;
 
-import dev.triumphteam.cmd.core.command.execution.CommandExecutor;
+import dev.triumphteam.cmd.core.command.CommandExecutor;
 import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException;
 import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor;
 import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator;
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java
index 36d2d7b6..f5e054d1 100644
--- a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java
+++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java
@@ -1,6 +1,6 @@
 package dev.triumphteam.cmd.core.extention.defaults;
 
-import dev.triumphteam.cmd.core.command.execution.CommandExecutor;
+import dev.triumphteam.cmd.core.command.CommandExecutor;
 import dev.triumphteam.cmd.core.extention.meta.CommandMeta;
 import org.jetbrains.annotations.NotNull;
 
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java
deleted file mode 100644
index e93f2b42..00000000
--- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/**
- * MIT License
- *
- * Copyright (c) 2019-2021 Matt
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package dev.triumphteam.cmd.core.extention.sender;
-
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Interface for mapping a default send into a custom sender.
- *
- * @param  The type of the default sender.
- * @param   The type of the custom sender.
- */
-@FunctionalInterface
-public interface SenderMapper {
-
-    @Nullable S map(final @NotNull D defaultSender);
-
-    static  @NotNull SenderMapper defaultMapper() {
-        return defaultMapper -> defaultMapper;
-    }
-}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderValidator.java
deleted file mode 100644
index 10da1d16..00000000
--- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderValidator.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/**
- * MIT License
- *
- * Copyright (c) 2019-2021 Matt
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package dev.triumphteam.cmd.core.extention.sender;
-
-import dev.triumphteam.cmd.core.subcommand.OldSubCommand;
-import dev.triumphteam.cmd.core.extention.registry.MessageRegistry;
-import org.jetbrains.annotations.NotNull;
-
-import java.util.Set;
-
-/**
- * Interface for mapping a default send into a custom sender.
- *
- * @param  The type of the custom sender.
- */
-public interface SenderValidator {
-
-    @NotNull Set> getAllowedSenders();
-
-    boolean validate(
-            final @NotNull MessageRegistry messageRegistry,
-            final @NotNull OldSubCommand subCommand,
-            final @NotNull S sender
-    );
-}
diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
deleted file mode 100644
index 277b35bb..00000000
--- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractCommandProcessor.java
+++ /dev/null
@@ -1,239 +0,0 @@
-/**
- * MIT License
- *
- * Copyright (c) 2019-2021 Matt
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package dev.triumphteam.cmd.core.processor;
-
-import dev.triumphteam.cmd.core.AnnotatedCommand;
-import dev.triumphteam.cmd.core.annotations.Command;
-import dev.triumphteam.cmd.core.annotations.Description;
-import dev.triumphteam.cmd.core.command.ParentCommand;
-import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException;
-import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException;
-import dev.triumphteam.cmd.core.extention.registry.RegistryContainer;
-import dev.triumphteam.cmd.core.extention.sender.SenderMapper;
-import dev.triumphteam.cmd.core.extention.sender.SenderValidator;
-import dev.triumphteam.cmd.core.subcommand.OldSubCommand;
-import org.jetbrains.annotations.NotNull;
-
-import java.lang.reflect.AnnotatedElement;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.function.Supplier;
-
-/**
- * Abstracts most of the "extracting" from command annotations, allows for extending.
- * 
- * I know this could be done better, but couldn't think of a better way. - * If you do please PR or let me know on my discord! - * - * @param Sender type - */ -public abstract class OldAbstractCommandProcessor, P extends OldAbstractSubCommandProcessor> { - - private String name; - // TODO: 11/28/2021 Add better default description - private String description = "No description provided."; - private final List alias = new ArrayList<>(); - private final Map subCommands = new HashMap<>(); - private final Map subCommandsAlias = new HashMap<>(); - - private final Class commandClass; - private final Supplier instanceSupplier; - private final RegistryContainer registryContainer; - private final SenderMapper senderMapper; - private final SenderValidator senderValidator; - - protected OldAbstractCommandProcessor( - final @NotNull Class commandClass, - final @NotNull Supplier instanceSupplier, - final @NotNull RegistryContainer registryContainer, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator - ) { - this.commandClass = commandClass; - this.instanceSupplier = instanceSupplier; - this.registryContainer = registryContainer; - this.senderMapper = senderMapper; - this.senderValidator = senderValidator; - - extractCommandNames(); - extractDescription(); - } - - // TODO: Comments - public void addSubCommands(final @NotNull ParentCommand command) { - // Method sub commands - - // Classes sub commands - for (final Class klass : commandClass.getDeclaredClasses()) { - final List> constructors = Arrays.asList(klass.getDeclaredConstructors()); - - if (constructors.size() != 1) { - throw new SubCommandRegistrationException("TODO constructs", null, null); - } - - final Constructor constructor = constructors.get(0); - - final boolean isStatic = Modifier.isStatic(klass.getModifiers()); - final int argsSize = isStatic ? constructor.getParameterCount() : constructor.getParameterCount() - 1; - - if (argsSize > 1) { - throw new SubCommandRegistrationException("TODO params", null, null); - } - - final boolean hasArg = argsSize > 0; - - final P processor = createSubProcessor(klass); - final String subCommandName = processor.getName(); - // Not a command - if (subCommandName == null) continue; - // If the name is empty and there is no arguments - if (subCommandName.isEmpty() && !hasArg) { - throw new SubCommandRegistrationException( - "@" + Command.class.getSimpleName() + " name must not be empty on a class unless it has an argument.", - klass, - commandClass - ); - } - - } - } - - private void collectMethodSubCommands( - final @NotNull ParentCommand command, - final @NotNull Class klass - ) { - // Method sub commands - for (final Method method : klass.getDeclaredMethods()) { - // TODO: ALLOW PRIVATE - if (Modifier.isPrivate(method.getModifiers())) continue; - - - final P processor = createSubProcessor(method); - final String subCommandName = processor.getName(); - // Not a command - if (subCommandName == null) continue; - - if (subCommandName.isEmpty()) { - throw new SubCommandRegistrationException( - "@ name must not be empty", - method, - klass - ); - } - - // command.addSubCommand(subCommandName, subCommand); - - // processor.getAlias().forEach(alias -> command.addSubCommandAlias(alias, subCommand)); - } - } - - protected abstract @NotNull P createSubProcessor(final @NotNull AnnotatedElement method); - - protected abstract @NotNull SC createSubCommand(final @NotNull P processor); - - /** - * Used for the child processors to get the command name. - * - * @return The command name. - */ - public @NotNull String getName() { - return name; - } - - /** - * Used for the child processors to get a {@link List} with the command's alias. - * - * @return The command alias. - */ - public @NotNull List<@NotNull String> getAlias() { - return alias; - } - - // TODO: Comments - public @NotNull RegistryContainer getRegistryContainer() { - return registryContainer; - } - - /** - * Gets the {@link SenderMapper}. - * - * @return The {@link SenderMapper}. - */ - public @NotNull SenderMapper getSenderMapper() { - return senderMapper; - } - - // TODO: 2/4/2022 comments - public @NotNull SenderValidator getSenderValidator() { - return senderValidator; - } - - /** - * gets the Description of the SubCommand. - * - * @return either the extracted Description or the default one. - */ - public @NotNull String getDescription() { - return description; - } - - /** - * Helper method for getting the command names from the command annotation. - */ - private void extractCommandNames() { - final Command commandAnnotation = commandClass.getAnnotation(Command.class); - - /*if (commandAnnotation == null) { - final String commandName = baseCommand.getCommand(); - if (commandName == null) { - throw new CommandRegistrationException("Command name or \"@" + Command.class.getSimpleName() + "\" annotation missing", baseCommand.getClass()); - } - - name = commandName; - alias.addAll(baseCommand.getAlias()); - } else { - name = commandAnnotation.value(); - Collections.addAll(alias, commandAnnotation.alias()); - } - - alias.addAll(baseCommand.getAlias());*/ - if (name.isEmpty()) { - throw new CommandRegistrationException("Command name must not be empty", AnnotatedCommand.class); - } - } - - /** - * Extracts the {@link Description} Annotation from the annotatedClass. - */ - private void extractDescription() { - - } - -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java deleted file mode 100644 index 16b51be0..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/OldAbstractSubCommandProcessor.java +++ /dev/null @@ -1,833 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.processor; - -import com.google.common.base.CaseFormat; -import com.google.common.collect.Maps; -import dev.triumphteam.cmd.core.AnnotatedCommand; -import dev.triumphteam.cmd.core.annotations.ArgDescriptions; -import dev.triumphteam.cmd.core.annotations.ArgName; -import dev.triumphteam.cmd.core.annotations.Async; -import dev.triumphteam.cmd.core.annotations.CommandFlags; -import dev.triumphteam.cmd.core.annotations.Description; -import dev.triumphteam.cmd.core.annotations.Flag; -import dev.triumphteam.cmd.core.annotations.Join; -import dev.triumphteam.cmd.core.annotations.NamedArguments; -import dev.triumphteam.cmd.core.annotations.Optional; -import dev.triumphteam.cmd.core.annotations.Requirements; -import dev.triumphteam.cmd.core.annotations.Split; -import dev.triumphteam.cmd.core.annotations.Suggestions; -import dev.triumphteam.cmd.core.argument.ArgumentResolver; -import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; -import dev.triumphteam.cmd.core.argument.EnumInternalArgument; -import dev.triumphteam.cmd.core.argument.FlagInternalArgument; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; -import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; -import dev.triumphteam.cmd.core.argument.NamedInternalArgument; -import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; -import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; -import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; -import dev.triumphteam.cmd.core.argument.keyed.Arguments; -import dev.triumphteam.cmd.core.argument.keyed.Flags; -import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; -import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; -import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; -import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; -import dev.triumphteam.cmd.core.extention.registry.NamedArgumentRegistry; -import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry; -import dev.triumphteam.cmd.core.extention.sender.SenderValidator; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.context.MessageContext; -import dev.triumphteam.cmd.core.requirement.Requirement; -import dev.triumphteam.cmd.core.requirement.RequirementKey; -import dev.triumphteam.cmd.core.requirement.RequirementResolver; -import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; -import dev.triumphteam.cmd.core.suggestion.EnumSuggestion; -import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; -import dev.triumphteam.cmd.core.suggestion.Suggestion; -import dev.triumphteam.cmd.core.suggestion.SuggestionKey; -import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; -import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Parameter; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.Type; -import java.lang.reflect.WildcardType; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.function.BiConsumer; -import java.util.stream.Collectors; - -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; - -/** - * Abstracts most of the "extracting" from sub command annotations, allows for extending. - *
- * I know this could be done better, but couldn't think of a better way. - * If you do please PR or let me know on my discord! - * - * @param The sender type. - */ -@SuppressWarnings("unchecked") -public abstract class OldAbstractSubCommandProcessor { - - private static final Set> COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); - private final AnnotatedCommand annotatedCommand; - private final String parentName; - private final AnnotatedElement annotatedElement; - private final List argDescriptions = new ArrayList<>(); - private final List alias = new ArrayList<>(); - private final boolean isAsync; - private final ArgumentGroup flagGroup = ArgumentGroup.flags(emptyList()); - private final List> suggestionList = new ArrayList<>(); - private final List> internalArguments = new ArrayList<>(); - private final Set> requirements = new HashSet<>(); - private final RegistryContainer registryContainer; - private final SuggestionRegistry suggestionRegistry; - private final ArgumentRegistry argumentRegistry; - private final NamedArgumentRegistry namedArgumentRegistry; - private final RequirementRegistry requirementRegistry; - private final MessageRegistry messageRegistry; - private final SenderValidator senderValidator; - // Name is nullable to detect if the method should or not be considered a sub command. - private String name = null; - // TODO: 11/28/2021 Add better default description - private String description = "No description provided."; - private boolean isDefault = false; - private Class senderType; - - protected OldAbstractSubCommandProcessor( - final @NotNull AnnotatedCommand annotatedCommand, - final @NotNull String parentName, - final @NotNull AnnotatedElement annotatedElement, - final @NotNull RegistryContainer registryContainer, - final @NotNull SenderValidator senderValidator - ) { - this.annotatedCommand = annotatedCommand; - this.parentName = parentName; - - this.annotatedElement = annotatedElement; - - this.registryContainer = registryContainer; - this.suggestionRegistry = registryContainer.getSuggestionRegistry(); - this.argumentRegistry = registryContainer.getArgumentRegistry(); - this.namedArgumentRegistry = registryContainer.getNamedArgumentRegistry(); - this.requirementRegistry = registryContainer.getRequirementRegistry(); - this.messageRegistry = registryContainer.getMessageRegistry(); - this.senderValidator = senderValidator; - - this.isAsync = annotatedElement.isAnnotationPresent(Async.class); - - extractSubCommandNames(); - if (name == null) return; - - extractFlags(); - extractRequirements(); - extractDescription(); - extractArgDescriptions(); - extractSuggestions(); - extractArguments(annotatedElement); - validateArguments(); - } - - /** - * Allows for customizing the internalArgument parsing, for example @Value and @Completion annotations. - * - * @param annotatedElement The method to search from. - */ - protected void extractArguments(final @NotNull AnnotatedElement annotatedElement) { - /*final Parameter[] parameters = method.getParameters(); - for (int i = 0; i < parameters.length; i++) { - final Parameter parameter = parameters[i]; - if (i == 0) { - validateSender(parameter.getType()); - continue; - } - - createArgument(parameter, i - 1); - }*/ - } - - /** - * Used for the child factories to get the sub command name. - * It's nullable because a method might not have a annotation. - * - * @return The sub command name. - */ - public @Nullable String getName() { - return name; - } - - /** - * gets the Description of the SubCommand. - * - * @return either the extracted Description or the default one. - */ - public @NotNull String getDescription() { - return description; - } - - public @NotNull Class getSenderType() { - if (senderType == null) throw createException("Sender type could not be found."); - return senderType; - } - - /** - * Used for the child factories to get a {@link List} with the sub command's alias. - * - * @return The sub command alias. - */ - public @NotNull List<@NotNull String> getAlias() { - return alias; - } - - /** - * Used for the child factories to get whether the sub command is default. - * - * @return Whether the command is default. - */ - public boolean isDefault() { - return isDefault; - } - - /** - * Gets whether the sub command is to be executed asynchronously. - * - * @return If the sub command is async. - */ - public boolean isAsync() { - return isAsync; - } - - /** - * Gets the {@link AnnotatedCommand} instance, so it can be used later to invoke. - * - * @return The base command instance. - */ - public @NotNull AnnotatedCommand getBaseCommand() { - return annotatedCommand; - } - - // TODO comments - public @NotNull AnnotatedElement getAnnotatedElement() { - return annotatedElement; - } - - /** - * Gets a set with the requirements. - * - * @return The requirements. - */ - public @NotNull Set<@NotNull Requirement> getRequirements() { - return requirements; - } - - /** - * Gets the message registry. - * - * @return The message registry. - */ - public @NotNull MessageRegistry getMessageRegistry() { - return messageRegistry; - } - - public @NotNull RegistryContainer getRegistryContainer() { - return registryContainer; - } - - // TODO: 2/4/2022 comments - public @NotNull SenderValidator getSenderValidator() { - return senderValidator; - } - - /** - * Simple utility method for creating a new exception using the method and base command class. - * - * @param message The main message to pass to the exception. - * @return A new {@link SubCommandRegistrationException}. - */ - @Contract("_ -> new") - protected @NotNull SubCommandRegistrationException createException(final @NotNull String message) { - return new SubCommandRegistrationException(message, annotatedElement, annotatedCommand.getClass()); - } - - /** - * Used for validating if the sender is valid or not. - * - * @param type The sender type. - */ - protected void validateSender(final @NotNull Class type) { - final Set> allowedSenders = senderValidator.getAllowedSenders(); - if (allowedSenders.contains(type)) { - senderType = (Class) type; - return; - } - - throw createException( - "\"" + type.getSimpleName() + "\" is not a valid sender. " + - "Sender must be one of the following: " + - allowedSenders - .stream() - .map(it -> "\"" + it.getSimpleName() + "\"") - .collect(Collectors.joining(", ")) - ); - } - - /** - * Gets the necessary arguments for the command. - * - * @return The arguments list. - */ - public @NotNull List<@NotNull InternalArgument> getArguments() { - return internalArguments; - } - - /** - * Creates and adds the internalArgument to the arguments list. - * - * @param parameter The current parameter to get data from. - */ - protected void createArgument(final @NotNull Parameter parameter, final int position) { - final Class type = parameter.getType(); - final String argumentName = getArgName(parameter); - final String argumentDescription = getArgumentDescription(parameter, position); - final boolean optional = parameter.isAnnotationPresent(Optional.class); - - // Handles collection internalArgument. - // TODO: Add more collection types. - if (COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { - final Class collectionType = getGenericType(parameter); - final InternalArgument internalArgument = createSimpleArgument( - collectionType, - argumentName, - argumentDescription, - suggestionList.get(position), - true - ); - - if (parameter.isAnnotationPresent(Split.class)) { - final Split splitAnnotation = parameter.getAnnotation(Split.class); - addArgument( - new SplitStringInternalArgument<>( - argumentName, - argumentDescription, - splitAnnotation.value(), - internalArgument, - type, - suggestionList.get(position), - optional - ) - ); - return; - } - - addArgument( - new CollectionInternalArgument<>( - argumentName, - argumentDescription, - internalArgument, - type, - suggestionList.get(position), - optional - ) - ); - return; - } - - // Handler for using String with `@Join`. - if (type == String.class && parameter.isAnnotationPresent(Join.class)) { - final Join joinAnnotation = parameter.getAnnotation(Join.class); - addArgument( - new JoinedStringInternalArgument<>( - argumentName, - argumentDescription, - joinAnnotation.value(), - suggestionList.get(position), - optional - ) - ); - return; - } - - // Handler for flags. - if (type == Flags.class) { - if (flagGroup.isEmpty()) { - throw createException("Flags internalArgument detected but no flag annotation declared"); - } - - addArgument( - new FlagInternalArgument<>( - argumentName, - argumentDescription, - flagGroup, - optional - ) - ); - return; - } - - // Handler for named arguments - if (type == Arguments.class) { - final NamedArguments namedArguments = annotatedElement.getAnnotation(NamedArguments.class); - if (namedArguments == null) { - throw createException("TODO"); - } - - addArgument( - new NamedInternalArgument<>( - argumentName, - argumentDescription, - collectNamedArgs(namedArguments.value()), - optional - ) - ); - return; - } - - addArgument(createSimpleArgument(type, argumentName, argumentDescription, suggestionList.get(position), optional)); - } - - private @NotNull Map<@NotNull String, @NotNull InternalArgument> collectNamedArgs(final @NotNull String key) { - final List arguments = namedArgumentRegistry.getArguments(ArgumentKey.of(key)); - if (arguments == null || arguments.isEmpty()) { - throw createException("No registered named arguments found for key \"" + key + "\""); - } - - // TODO: Handle list - return arguments.stream().map(argument -> { - final Suggestion suggestion = createSuggestion(argument.getSuggestion(), argument.getType()); - - return Maps.immutableEntry( - argument.getName(), - createSimpleArgument( - argument.getType(), - argument.getName(), - argument.getDescription(), - suggestion, - true - ) - ); - }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - } - - /** - * Gets the internalArgument name, either from the parameter or from the annotation. - * If the parameter is not annotated, turn the name from Camel Case to "lower-hyphen". - * - * @param parameter The parameter to get data from. - * @return The final internalArgument name. - */ - private @NotNull String getArgName(final @NotNull Parameter parameter) { - if (parameter.isAnnotationPresent(ArgName.class)) { - return parameter.getAnnotation(ArgName.class).value(); - } - - return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, parameter.getName()); - } - - /** - * Gets the internalArgument description. - * - * @param parameter The parameter to get data from. - * @param index The index of the internalArgument. - * @return The final internalArgument description. - */ - private @NotNull String getArgumentDescription(final @NotNull Parameter parameter, final int index) { - final Description description = parameter.getAnnotation(Description.class); - if (description != null) { - return description.value(); - } - - if (index < argDescriptions.size()) return argDescriptions.get(index); - // TODO: 11/28/2021 Add better default description - return "No description provided."; - } - - /** - * Create a SimpleArgument. - * - * @param type The Type of this Argument. - * @param parameterName The Name to use for this Argument. - * @param argumentDescription the Description to use for this Argument. - * @param optional whether this Argument is optional. - * @return The created {@link InternalArgument}. - */ - protected @NotNull InternalArgument createSimpleArgument( - final @NotNull Class type, - final @NotNull String parameterName, - final @NotNull String argumentDescription, - final @NotNull Suggestion suggestion, - final boolean optional - ) { - // All other types default to the resolver. - final ArgumentResolver resolver = argumentRegistry.getResolver(type); - if (resolver == null) { - // Handler for using any Enum. - if (Enum.class.isAssignableFrom(type)) { - //noinspection unchecked - return new EnumInternalArgument<>( - parameterName, - argumentDescription, - (Class>) type, - suggestion, - optional - ); - } - - throw createException("No internalArgument of type \"" + type.getName() + "\" registered"); - } - return new ResolverInternalArgument<>( - parameterName, - argumentDescription, - type, - resolver, - suggestion, - optional - ); - } - - /** - * Adds a required internalArgument to the list. - * - * @param requirement The requirement to add. - */ - protected void addRequirement(final @NotNull Requirement requirement) { - requirements.add(requirement); - } - - /** - * Utility to add the internalArgument to the list. - * - * @param internalArgument The created internalArgument. - */ - private void addArgument(final @NotNull InternalArgument internalArgument) { - internalArguments.add(internalArgument); - } - - /** - * Extracts the data from the method to retrieve the sub command name or the default name. - */ - private void extractSubCommandNames() { - - } - - /** - * Extract all the flag data for the subcommand from the method. - */ - private void extractFlags() { - final List flags = getFlagsFromAnnotations(); - if (flags.isEmpty()) return; - - for (final Flag flagAnnotation : flags) { - String flag = flagAnnotation.flag(); - if (flag.isEmpty()) flag = null; - - String longFlag = flagAnnotation.longFlag(); - if (longFlag.contains(" ")) { - throw createException("@" + Flag.class.getSimpleName() + "'s identifiers must not contain spaces"); - } - - if (longFlag.isEmpty()) longFlag = null; - - final Class argumentType = flagAnnotation.argument(); - - final SuggestionKey suggestionKey = flagAnnotation.suggestion().isEmpty() ? null : SuggestionKey.of(flagAnnotation.suggestion()); - final Suggestion suggestion = createSuggestion(suggestionKey, flagAnnotation.argument()); - - StringInternalArgument internalArgument = null; - if (argumentType != void.class) { - if (Enum.class.isAssignableFrom(argumentType)) { - //noinspection unchecked - internalArgument = new EnumInternalArgument<>( - argumentType.getName(), - "", - (Class>) argumentType, - suggestion, - false - ); - } else { - final ArgumentResolver resolver = argumentRegistry.getResolver(argumentType); - if (resolver == null) { - throw createException("@" + Flag.class.getSimpleName() + "'s internalArgument contains unregistered type \"" + argumentType.getName() + "\""); - } - - internalArgument = new ResolverInternalArgument<>( - argumentType.getName(), - "", - argumentType, - resolver, - suggestion, - false - ); - } - } - - // TODO - /*flagGroup.addArgument( - new FlagOptions<>( - flag, - longFlag, - internalArgument - ) - );*/ - } - } - - /** - * Gets the flags from the annotations. - * - * @return The list of flags. - */ - private @NotNull List<@NotNull Flag> getFlagsFromAnnotations() { - final CommandFlags flags = annotatedElement.getAnnotation(CommandFlags.class); - if (flags != null) return Arrays.asList(flags.value()); - - final Flag flag = annotatedElement.getAnnotation(Flag.class); - if (flag == null) return Collections.emptyList(); - return Collections.singletonList(flag); - } - - /** - * Extract all the requirement data for the sub command from the method. - */ - public void extractRequirements() { - for (final dev.triumphteam.cmd.core.annotations.Requirement requirementAnnotation : getRequirementsFromAnnotations()) { - final RequirementKey requirementKey = RequirementKey.of(requirementAnnotation.value()); - final String messageKeyValue = requirementAnnotation.messageKey(); - - final MessageKey messageKey; - if (messageKeyValue.isEmpty()) messageKey = null; - else messageKey = MessageKey.of(messageKeyValue, MessageContext.class); - - final RequirementResolver resolver = requirementRegistry.getRequirement(requirementKey); - if (resolver == null) { - throw createException("Could not find Requirement Key \"" + requirementKey.getKey() + "\""); - } - - // addRequirement(new Requirement<>(resolver, messageKey, DefaultMessageContext::new, requirementAnnotation.invert())); - } - } - - /** - * Gets the requirements from the annotations. - * - * @return The list of requirements. - */ - private @NotNull List getRequirementsFromAnnotations() { - final Requirements requirements = annotatedElement.getAnnotation(Requirements.class); - if (requirements != null) return Arrays.asList(requirements.value()); - - final dev.triumphteam.cmd.core.annotations.Requirement requirement = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.Requirement.class); - if (requirement == null) return Collections.emptyList(); - return Collections.singletonList(requirement); - } - - /** - * Gets a list of all the arg validations for the platform. - * Defaults to just optional and limitless. - * This is likely to change. - * - * @return A list of BiConsumers with checks. - */ - protected @NotNull List<@NotNull BiConsumer<@NotNull Boolean, @NotNull InternalArgument>> getArgValidations() { - return Arrays.asList(validateOptionals(), validateLimitless()); - } - - /** - * Argument validation makes sure some arguments are placed in the correct place. - * For example a limitless arguments and optional arguments are only allowed at the end of the command. - */ - private void validateArguments() { - final List>> validations = getArgValidations(); - final Iterator> iterator = internalArguments.iterator(); - while (iterator.hasNext()) { - final InternalArgument internalArgument = iterator.next(); - validations.forEach(consumer -> consumer.accept(iterator.hasNext(), internalArgument)); - } - } - - /** - * Validation function for optionals. - * - * @return Returns a BiConsumer with an is optional check. - */ - protected @NotNull BiConsumer<@NotNull Boolean, @NotNull InternalArgument> validateOptionals() { - return (hasNext, internalArgument) -> { - if (hasNext && internalArgument.isOptional()) { - throw createException("Optional internalArgument is only allowed as the last internalArgument"); - } - }; - } - - /** - * Validation function for limitless position. - * - * @return Returns a BiConsumer with an instance of check. - */ - protected @NotNull BiConsumer<@NotNull Boolean, @NotNull InternalArgument> validateLimitless() { - return (hasNext, internalArgument) -> { - if (hasNext && internalArgument instanceof LimitlessInternalArgument) { - throw createException("Limitless internalArgument is only allowed as the last internalArgument"); - } - }; - } - - /** - * Extracts the {@link Description} Annotation from the Method. - */ - private void extractDescription() { - final Description description = annotatedElement.getAnnotation(Description.class); - if (description == null) return; - this.description = description.value(); - } - - /** - * Extracts the {@link ArgDescriptions} Annotation from the Method. - */ - private void extractArgDescriptions() { - final ArgDescriptions argDescriptions = annotatedElement.getAnnotation(ArgDescriptions.class); - if (argDescriptions == null) return; - this.argDescriptions.addAll(Arrays.asList(argDescriptions.value())); - } - - /** - * Extract all suggestions from the method and parameters. - */ - public void extractSuggestions() { - for (final dev.triumphteam.cmd.core.annotations.Suggestion suggestion : getSuggestionsFromAnnotations()) { - final String key = suggestion.value(); - if (key.isEmpty()) { - suggestionList.add(new EmptySuggestion<>()); - continue; - } - - final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(SuggestionKey.of(key)); - - if (resolver == null) { - throw createException("Cannot find the suggestion key `" + key + "`"); - } - - suggestionList.add(new SimpleSuggestion<>(resolver)); - } - - extractSuggestionFromParams(); - } - - /** - * Extract all suggestions from the parameters. - * Adds the suggestions to the passed list. - */ - private void extractSuggestionFromParams() { - // TODO SUGGESTIONS - /*final Parameter[] parameters = annotatedElement.getParameters(); - for (int i = 1; i < parameters.length; i++) { - final Parameter parameter = parameters[i]; - - final dev.triumphteam.cmd.core.annotation.Suggestion suggestion = parameter.getAnnotation(dev.triumphteam.cmd.core.annotation.Suggestion.class); - final SuggestionKey suggestionKey = suggestion == null ? null : SuggestionKey.of(suggestion.value()); - - final Class type = getGenericType(parameter); - final int addIndex = i - 1; - setOrAddSuggestion(addIndex, createSuggestion(suggestionKey, type)); - }*/ - } - - private @NotNull Suggestion createSuggestion(final @Nullable SuggestionKey suggestionKey, final @NotNull Class type) { - if (suggestionKey == null) { - if (Enum.class.isAssignableFrom(type)) return new EnumSuggestion<>((Class>) type); - - final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(type); - if (resolver != null) return new SimpleSuggestion<>(resolver); - - return new EmptySuggestion<>(); - } - - final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(suggestionKey); - if (resolver == null) { - throw createException("Cannot find the suggestion key `" + suggestionKey + "`"); - } - return new SimpleSuggestion<>(resolver); - } - - /** - * Adds a suggestion or overrides an existing one. - * - * @param index The index of the suggestion. - * @param suggestion The suggestion. - */ - private void setOrAddSuggestion(final int index, final @Nullable Suggestion suggestion) { - if (index >= suggestionList.size()) { - if (suggestion == null) { - suggestionList.add(new EmptySuggestion<>()); - return; - } - suggestionList.add(suggestion); - return; - } - - if (suggestion == null) return; - suggestionList.set(index, suggestion); - } - - private @NotNull List getSuggestionsFromAnnotations() { - final Suggestions requirements = annotatedElement.getAnnotation(Suggestions.class); - if (requirements != null) return Arrays.asList(requirements.value()); - - final dev.triumphteam.cmd.core.annotations.Suggestion suggestion = annotatedElement.getAnnotation(dev.triumphteam.cmd.core.annotations.Suggestion.class); - if (suggestion == null) return emptyList(); - return singletonList(suggestion); - } - - private @NotNull Class getGenericType(final @NotNull Parameter parameter) { - final Class type = parameter.getType(); - if (COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { - final ParameterizedType parameterizedType = (ParameterizedType) parameter.getParameterizedType(); - final Type[] types = parameterizedType.getActualTypeArguments(); - - if (types.length != 1) { - throw createException("Unsupported collection type \"" + type + "\""); - } - - final Type genericType = types[0]; - return (Class) (genericType instanceof WildcardType ? ((WildcardType) genericType).getUpperBounds()[0] : genericType); - } - - return type; - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java deleted file mode 100644 index f49772f0..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/subcommand/OldSubCommand.java +++ /dev/null @@ -1,318 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.subcommand; - -import dev.triumphteam.cmd.core.AnnotatedCommand; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; -import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; -import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; -import dev.triumphteam.cmd.core.extention.sender.SenderValidator; -import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; -import dev.triumphteam.cmd.core.requirement.Requirement; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.stream.Collectors; - -/** - * SubCommand implementation. - * Might be better to rename this to something different. - * - * @param The sender type. - */ -public abstract class OldSubCommand { - - private final AnnotatedCommand annotatedCommand; - private final Method method = null; - - private final String parentName; - private final String name; - private final List alias; - private final boolean isDefault; - - private final Class senderType; - - private final List> internalArguments; - private final Set> requirements; - - private final MessageRegistry messageRegistry; - - private final SenderValidator senderValidator; - - private final boolean hasArguments; - private final boolean containsLimitless; - - public OldSubCommand( - @NotNull final OldAbstractSubCommandProcessor processor, - @NotNull final String parentName - ) { - this.annotatedCommand = processor.getBaseCommand(); - // this.method = processor.getAnnotatedElement(); - this.name = processor.getName(); - this.alias = processor.getAlias(); - this.internalArguments = processor.getArguments(); - this.requirements = processor.getRequirements(); - this.messageRegistry = processor.getMessageRegistry(); - this.isDefault = processor.isDefault(); - this.senderValidator = processor.getSenderValidator(); - - this.senderType = processor.getSenderType(); - - this.parentName = parentName; - - this.hasArguments = !internalArguments.isEmpty(); - this.containsLimitless = internalArguments.stream().anyMatch(LimitlessInternalArgument.class::isInstance); - } - - /** - * Checks if the sub command is default. - * Can also just check if the name is . - * - * @return Whether the sub command is default. - */ - public boolean isDefault() { - return isDefault; - } - - // TODO: 2/5/2022 comments - @NotNull public Class getSenderType() { - return senderType; - } - - /** - * Gets the name of the parent command. - * - * @return The name of the parent command. - */ - @NotNull public String getParentName() { - return parentName; - } - - /** - * Gets the name of the sub command. - * - * @return The name of the sub command. - */ - @NotNull public String getName() { - return name; - } - - public boolean hasArguments() { - return hasArguments; - } - - /** - * Gets the message registry. - * - * @return The message registry. - */ - @NotNull protected MessageRegistry getMessageRegistry() { - return messageRegistry; - } - - /** - * Executes the sub command. - * - * @param sender The sender. - * @param args The arguments to pass to the executor. - */ - public void execute(@NotNull final S sender, @NotNull final List args) { - if (!senderValidator.validate(messageRegistry, this, sender)) return; - if (!meetRequirements(sender)) return; - - // Creates the invoking arguments list - final List invokeArguments = new ArrayList<>(); - invokeArguments.add(sender); - - if (!validateAndCollectArguments(sender, invokeArguments, args)) { - return; - } - - if ((!containsLimitless) && args.size() >= invokeArguments.size()) { - return; - } - - } - - /** - * Gets the arguments of the sub command. - * - * @return The arguments of the sub command. - */ - @NotNull protected List> getArguments() { - return internalArguments; - } - - @Nullable protected InternalArgument getArgument(@NotNull final String name) { - final List> foundArgs = internalArguments.stream() - .filter(internalArgument -> internalArgument.getName().toLowerCase().startsWith(name)) - .collect(Collectors.toList()); - - if (foundArgs.size() != 1) return null; - return foundArgs.get(0); - } - - @Nullable protected InternalArgument getArgument(final int index) { - final int size = internalArguments.size(); - if (size == 0) return null; - if (index >= size) { - final InternalArgument last = internalArguments.get(size - 1); - if (last instanceof LimitlessInternalArgument) return last; - return null; - } - - return internalArguments.get(index); - } - - // TODO: 2/1/2022 Comments - public List<@Nullable String> mapArguments(@NotNull final Map args) { - final List arguments = getArguments().stream().map(InternalArgument::getName).collect(Collectors.toList()); - return arguments.stream().map(it -> { - final String value = args.get(it); - return value == null ? "" : value; - }).collect(Collectors.toList()); - } - - /** - * Used for checking if the arguments are valid and adding them to the `invokeArguments`. - * - * @param sender The sender of the command. - * @param invokeArguments A list with the arguments that'll be used on the `invoke` of the command method. - * @param commandArgs The command arguments type. - * @return False if any internalArgument fails to pass. - */ - @SuppressWarnings("unchecked") - private boolean validateAndCollectArguments( - @NotNull final S sender, - @NotNull final List invokeArguments, - @NotNull final List commandArgs - ) { - for (int i = 0; i < internalArguments.size(); i++) { - final InternalArgument internalArgument = internalArguments.get(i); - - if (internalArgument instanceof LimitlessInternalArgument) { - final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument; - final List leftOvers = leftOvers(commandArgs, i); - - final java.lang.Object result = limitlessArgument.resolve(sender, leftOvers); - - if (result == null) { - return false; - } - - invokeArguments.add(result); - return true; - } - - if (!(internalArgument instanceof StringInternalArgument)) { - throw new CommandExecutionException("Found unsupported internalArgument", parentName, name); - } - - final StringInternalArgument stringArgument = (StringInternalArgument) internalArgument; - final String arg = valueOrNull(commandArgs, i); - - if (arg == null || arg.isEmpty()) { - if (internalArgument.isOptional()) { - invokeArguments.add(null); - continue; - } - - return false; - } - - final java.lang.Object result = stringArgument.resolve(sender, arg); - if (result == null) { - - return false; - } - - invokeArguments.add(result); - } - - return true; - } - - /** - * Checks if the requirements to run the command are met. - * - * @param sender The sender of the command. - * @return Whether all requirements are met. - */ - private boolean meetRequirements(@NotNull final S sender) { - for (final Requirement requirement : requirements) { - if (!requirement.isMet(sender)) { - return false; - } - } - - return true; - } - - /** - * Gets an internalArgument value or null. - * - * @param list The list to check from. - * @param index The current index of the internalArgument. - * @return The internalArgument name or null. - */ - @Nullable private String valueOrNull(@NotNull final List list, final int index) { - if (index >= list.size()) return null; - return list.get(index); - } - - /** - * Gets the left over of the arguments. - * - * @param list The list with all the arguments. - * @param from The index from which should start removing. - * @return A list with the leftover arguments. - */ - @NotNull private List leftOvers(@NotNull final List list, final int from) { - if (from > list.size()) return Collections.emptyList(); - return list.subList(from, list.size()); - } - - @NotNull @Override - public String toString() { - return "SimpleSubCommand{" + - "baseCommand=" + annotatedCommand + - ", method=" + method + - ", name='" + name + '\'' + - ", alias=" + alias + - ", isDefault=" + isDefault + - ", arguments=" + internalArguments + - ", requirements=" + requirements + - ", messageRegistry=" + messageRegistry + - ", containsLimitlessArgument=" + containsLimitless + - '}'; - } -} diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java deleted file mode 100644 index ee4fb110..00000000 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmds.simple; - -import dev.triumphteam.cmd.core.subcommand.OldSubCommand; -import org.jetbrains.annotations.NotNull; - -public final class SimpleSubCommand extends OldSubCommand { - - public SimpleSubCommand( - final @NotNull SimpleSubCommandProcessor processor, - final @NotNull String parentName - ) { - super(processor, parentName); - } -} diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java deleted file mode 100644 index ae2516c9..00000000 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSubCommandProcessor.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmds.simple; - -import dev.triumphteam.cmd.core.AnnotatedCommand; -import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; -import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import dev.triumphteam.cmd.core.extention.sender.SenderValidator; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Method; - -final class SimpleSubCommandProcessor extends OldAbstractSubCommandProcessor { - - public SimpleSubCommandProcessor( - final @NotNull AnnotatedCommand annotatedCommand, - final @NotNull String parentName, - final @NotNull Method method, - final @NotNull RegistryContainer registries, - final @NotNull SenderValidator senderValidator - ) { - super(annotatedCommand, parentName, method, registries, senderValidator); - } -} From 8b8458c321e44cdce56062dfa9fc3a5429b72710 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 1 Jan 2023 18:51:29 +0000 Subject: [PATCH 049/101] chore: Remove annotations from type parameters --- .../dev/triumphteam/cmd/core/AnnotatedCommand.java | 2 +- .../core/argument/AbstractInternalArgument.java | 4 ++-- .../core/argument/CollectionInternalArgument.java | 2 +- .../cmd/core/argument/FlagInternalArgument.java | 6 +++--- .../cmd/core/argument/InternalArgument.java | 4 ++-- .../argument/JoinedStringInternalArgument.java | 2 +- .../cmd/core/argument/KeyedInternalArgument.java | 14 +++++--------- .../core/argument/LimitlessInternalArgument.java | 6 +++--- .../cmd/core/argument/NamedInternalArgument.java | 6 +++--- .../core/argument/SplitStringInternalArgument.java | 4 ++-- .../cmd/core/argument/UnknownInternalArgument.java | 4 ++-- .../triumphteam/cmd/core/argument/keyed/Flags.java | 2 +- .../argument/keyed/internal/FlagsContainer.java | 2 +- .../core/argument/keyed/internal/FlagsResult.java | 2 +- .../cmd/core/suggestion/EmptySuggestion.java | 2 +- .../cmd/core/suggestion/EnumSuggestion.java | 2 +- .../cmd/core/suggestion/SimpleSuggestion.java | 2 +- .../cmd/core/suggestion/Suggestion.java | 2 +- .../cmd/core/suggestion/SuggestionContext.java | 4 ++-- .../cmd/core/suggestion/SuggestionResolver.java | 2 +- .../dev/triumphteam/cmd/core/util/EnumUtils.java | 2 +- .../triumphteam/cmd/prefixed/PrefixedCommand.java | 2 +- .../cmd/prefixed/PrefixedCommandExecutor.java | 2 +- .../cmd/prefixed/PrefixedCommandManager.java | 4 ++-- .../cmd/prefixed/PrefixedSenderValidator.java | 2 +- .../dev/triumphteam/cmd/slash/SlashCommand.java | 6 +++--- .../triumphteam/cmd/slash/SlashCommandManager.java | 8 ++++---- .../cmd/slash/SlashCommandProcessor.java | 4 ++-- .../cmd/slash/SlashSenderValidator.java | 2 +- .../dev/triumphteam/cmd/slash/SlashSubCommand.java | 2 +- .../cmd/slash/SlashSubCommandProcessor.java | 10 +++++----- .../dev/triumphteam/cmd/slash/choices/Choice.java | 2 +- .../triumphteam/cmd/slash/choices/ChoiceKey.java | 2 +- .../cmd/slash/choices/ChoiceRegistry.java | 4 ++-- .../triumphteam/cmd/slash/choices/EmptyChoice.java | 2 +- .../triumphteam/cmd/slash/choices/EnumChoice.java | 2 +- .../cmd/slash/choices/SimpleChoice.java | 4 ++-- .../cmd/bukkit/BukkitCommandManager.java | 2 +- .../cmd/bukkit/BukkitCommandProcessor.java | 2 +- .../cmd/bukkit/BukkitSenderValidator.java | 2 +- .../triumphteam/cmd/bukkit/BukkitSubCommand.java | 2 +- .../triumphteam/cmd/bukkit/CommandPermission.java | 6 +++--- .../triumphteam/cmd/bukkit/OldBukkitCommand.java | 2 +- .../bukkit/message/NoPermissionMessageContext.java | 2 +- .../cmds/simple/SimpleCommandManager.java | 2 +- 45 files changed, 75 insertions(+), 79 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java index 68a3e35f..98ebc367 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java @@ -81,7 +81,7 @@ public AnnotatedCommand( * * @return The {@link #alias}. */ - public @NotNull List<@NotNull String> getAlias() { + public @NotNull List getAlias() { return alias; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java index fe765a3c..c56d8003 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java @@ -59,9 +59,9 @@ public AbstractInternalArgument( } @Override - public @NotNull List<@NotNull String> suggestions( + public @NotNull List suggestions( final @NotNull S sender, - final @NotNull List<@NotNull String> trimmed, + final @NotNull List trimmed, final @NotNull SuggestionContext context ) { return suggestion.getSuggestions(sender, trimmed.get(0), context); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java index d2ee707b..bf7eef37 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java @@ -63,7 +63,7 @@ public CollectionInternalArgument( * @return A {@link java.util.Collection} type as the resolved value. */ @Override - public @NotNull Object resolve(final @NotNull S sender, final @NotNull List<@NotNull String> value) { + public @NotNull Object resolve(final @NotNull S sender, final @NotNull List value) { final Stream stream = value.stream().map(arg -> internalArgument.resolve(sender, arg)); if (collectionType == Set.class) return stream.collect(Collectors.toSet()); return stream.collect(Collectors.toList()); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java index af424fd4..4f42d859 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java @@ -68,14 +68,14 @@ public FlagInternalArgument( * @return A {@link Flags} which contains the flags and leftovers. */ @Override - public @NotNull Object resolve(final @NotNull S sender, final @NotNull List<@NotNull String> value) { + public @NotNull Object resolve(final @NotNull S sender, final @NotNull List value) { return null;// flagParser.parse(sender, value.size() == 1 ? Arrays.asList(value.get(0).split(" ")) : value); } @Override - public @NotNull List<@NotNull String> suggestions( + public @NotNull List suggestions( final @NotNull S sender, - final @NotNull List<@NotNull String> trimmed, + final @NotNull List trimmed, final @NotNull SuggestionContext context ) { final int size = trimmed.size(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index 0d03da52..8acaac21 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -79,9 +79,9 @@ public interface InternalArgument { @Nullable Object resolve(final @NotNull S sender, final @NotNull T value); // TODO: Comments - @NotNull List<@NotNull String> suggestions( + @NotNull List suggestions( final @NotNull S sender, - final @NotNull List<@NotNull String> trimmed, + final @NotNull List trimmed, final @NotNull SuggestionContext context ); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java index f53edf26..20ecb4f0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java @@ -57,7 +57,7 @@ public JoinedStringInternalArgument( * @return A single {@link String} with the joined {@link List}. */ @Override - public @NotNull Object resolve(final @NotNull S sender, final @NotNull List<@NotNull String> value) { + public @NotNull Object resolve(final @NotNull S sender, final @NotNull List value) { return String.join(delimiter, value); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java index f4a3798a..c34d5e98 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java @@ -62,23 +62,19 @@ public KeyedInternalArgument( * @return A {@link Flags} which contains the flags and leftovers. */ @Override - public @NotNull Object resolve(final @NotNull S sender, final @NotNull List<@NotNull String> value) { + public @NotNull Object resolve(final @NotNull S sender, final @NotNull List value) { + return null;// flagParser.parse(sender, value.size() == 1 ? Arrays.asList(value.get(0).split(" ")) : value); } @Override - public @NotNull List<@NotNull String> suggestions( + public @NotNull List suggestions( final @NotNull S sender, - final @NotNull List<@NotNull String> trimmed, + final @NotNull List trimmed, final @NotNull SuggestionContext context ) { return Collections.emptyList(); } - @Override - public @NotNull String toString() { - return "FlagArgument{" + - "flagGroup=" + flagGroup + - ", super=" + super.toString() + "}"; - } + } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java index 00d57849..ac4a8273 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java @@ -35,7 +35,7 @@ * * @param The sender type. */ -public abstract class LimitlessInternalArgument extends AbstractInternalArgument> { +public abstract class LimitlessInternalArgument extends AbstractInternalArgument> { public LimitlessInternalArgument( final @NotNull String name, @@ -48,9 +48,9 @@ public LimitlessInternalArgument( } @Override - public @NotNull List<@NotNull String> suggestions( + public @NotNull List suggestions( final @NotNull S sender, - final @NotNull List<@NotNull String> trimmed, + final @NotNull List trimmed, final @NotNull SuggestionContext context ) { final String last = trimmed.get(trimmed.size() - 1); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java index 1b1dc241..40643199 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java @@ -52,7 +52,7 @@ public NamedInternalArgument( } @Override - public @NotNull Object resolve(final @NotNull S sender, final @NotNull List<@NotNull String> value) { + public @NotNull Object resolve(final @NotNull S sender, final @NotNull List value) { final Map parsedArgs = Collections.emptyMap();// ArgumentParser.parse(String.join(" ", value)); final Map mapped = new HashMap<>(parsedArgs.size()); @@ -68,9 +68,9 @@ public NamedInternalArgument( } @Override - public @NotNull List<@NotNull String> suggestions( + public @NotNull List suggestions( final @NotNull S sender, - final @NotNull List<@NotNull String> trimmed, + final @NotNull List trimmed, final @NotNull SuggestionContext context ) { final Map parsedArgs = Collections.emptyMap();// ArgumentParser.parse(String.join(" ", trimmed)); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java index 118f264f..8f0afc73 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java @@ -75,9 +75,9 @@ public SplitStringInternalArgument( } @Override - public @NotNull List<@NotNull String> suggestions( + public @NotNull List suggestions( final @NotNull S sender, - final @NotNull List<@NotNull String> trimmed, + final @NotNull List trimmed, final @NotNull SuggestionContext context ) { final List split = Arrays.asList(trimmed.get(trimmed.size() - 1).split(regex)); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index 80b071e6..09a2d8f0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -40,12 +40,12 @@ public boolean isOptional() { } @Override - public @Nullable Object resolve(@NotNull final S sender, final @NotNull String value) { + public @Nullable Object resolve(final @NotNull S sender, final @NotNull String value) { return null; } @Override - public @NotNull List<@NotNull String> suggestions(@NotNull final S sender, final @NotNull List<@NotNull String> trimmed, final @NotNull SuggestionContext context) { + public @NotNull List suggestions(final @NotNull S sender, final @NotNull List trimmed, final @NotNull SuggestionContext context) { return Collections.emptyList(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flags.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flags.java index da235149..569d81d0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flags.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flags.java @@ -83,5 +83,5 @@ public interface Flags { * * @return A {@link List} with the typed arguments. */ - @NotNull List<@NotNull String> getArgs(); + @NotNull List getArgs(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java index e627c118..0d55a07a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java @@ -34,7 +34,7 @@ public boolean hasFlag(final @NotNull String flag) { } @Override - public @NotNull List<@NotNull String> getArgs() { + public @NotNull List getArgs() { return null; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java index 2fbde7a8..546e3fb7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java @@ -125,7 +125,7 @@ public boolean hasFlag(final @NotNull String flag) { * {@inheritDoc} */ @Override - public @NotNull List<@NotNull String> getArgs() { + public @NotNull List getArgs() { return Collections.unmodifiableList(args); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java index 689698f3..b15a100e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java @@ -32,7 +32,7 @@ public final class EmptySuggestion implements Suggestion { @Override - public @NotNull List<@NotNull String> getSuggestions(final @NotNull S sender, final @NotNull String current, final @NotNull SuggestionContext context) { + public @NotNull List getSuggestions(final @NotNull S sender, final @NotNull String current, final @NotNull SuggestionContext context) { return emptyList(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java index 83b0f976..0874b864 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java @@ -42,7 +42,7 @@ public EnumSuggestion(final @NotNull Class> enumType) { } @Override - public @NotNull List<@NotNull String> getSuggestions(final @NotNull S sender, final @NotNull String current, final @NotNull SuggestionContext context) { + public @NotNull List getSuggestions(final @NotNull S sender, final @NotNull String current, final @NotNull SuggestionContext context) { return EnumUtils.getEnumConstants(enumType) .values() .stream() diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java index 44c1b1c9..aa8a806a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java @@ -39,7 +39,7 @@ public SimpleSuggestion(final @NotNull SuggestionResolver resolver) { } @Override - public @NotNull List<@NotNull String> getSuggestions(final @NotNull S sender, final @NotNull String current, final @NotNull SuggestionContext context) { + public @NotNull List getSuggestions(final @NotNull S sender, final @NotNull String current, final @NotNull SuggestionContext context) { return resolver .resolve(sender, context) .stream() diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java index 8d28f209..772eae4e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java @@ -29,7 +29,7 @@ public interface Suggestion { - @NotNull List<@NotNull String> getSuggestions( + @NotNull List getSuggestions( final @NotNull S sender, final @NotNull String current, final @NotNull SuggestionContext context diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java index 0e00e9d2..2df1b13c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java @@ -35,7 +35,7 @@ public final class SuggestionContext { private final String subCommand; public SuggestionContext( - final @NotNull List<@NotNull String> args, + final @NotNull List args, final @NotNull String command, final @NotNull String subCommand ) { @@ -44,7 +44,7 @@ public SuggestionContext( this.subCommand = subCommand; } - public @NotNull List<@NotNull String> getArgs() { + public @NotNull List getArgs() { return Collections.unmodifiableList(args); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java index 39529c9c..3ebe02fd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java @@ -40,6 +40,6 @@ public interface SuggestionResolver { * @param context The command context for the suggestion * @return A list of suggestions. */ - @NotNull List<@NotNull String> resolve(final @NotNull S sender, final @NotNull SuggestionContext context); + @NotNull List resolve(final @NotNull S sender, final @NotNull SuggestionContext context); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java b/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java index 476eb0dd..e32b78f6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/util/EnumUtils.java @@ -44,7 +44,7 @@ public final class EnumUtils { * @param enumClass A non-generic Enum class. * @return A map with enum values that was previously cached. */ - public static @NotNull Map<@NotNull String, @NotNull WeakReference>> getEnumConstants(final @NotNull Class> enumClass) { + public static @NotNull Map>> getEnumConstants(final @NotNull Class> enumClass) { synchronized (ENUM_CONSTANT_CACHE) { Map>> constants = ENUM_CONSTANT_CACHE.get(enumClass); if (constants == null) constants = populateCache(enumClass); diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java index fcb4eccc..2f99cbb4 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java @@ -78,7 +78,7 @@ public PrefixedCommand( * @param sender The sender. * @param args The command arguments. */ - public void execute(final @NotNull S sender, final @NotNull List<@NotNull String> args) { + public void execute(final @NotNull S sender, final @NotNull List args) { /*OldSubCommand subCommand = getDefaultSubCommand(); String subCommandName = ""; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java index d9e9a384..7f7a69fb 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java @@ -84,7 +84,7 @@ public void register(final @NotNull PrefixedCommandProcessor processor) { public void execute( final @NotNull String commandName, final @NotNull S sender, - final @NotNull List<@NotNull String> args + final @NotNull List args ) { final PrefixedCommand command = commands.get(commandName); diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java index 68c46bdb..4615d51c 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java @@ -294,7 +294,7 @@ private void addCommand(final @Nullable Guild guild, final @NotNull BaseCommand * * @return A {@link Set} with all the registered prefixes. */ - @NotNull Set<@NotNull String> getPrefixes() { + @NotNull Set getPrefixes() { return prefixes; } @@ -303,7 +303,7 @@ private void addCommand(final @Nullable Guild guild, final @NotNull BaseCommand * * @return A {@link Set} with all the registered prefixes regexes. */ - @NotNull Set<@NotNull Pattern> getPrefixesRegexes() { + @NotNull Set getPrefixesRegexes() { return prefixesRegexes; } diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java index 34beec60..0aa043e9 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java @@ -41,7 +41,7 @@ class PrefixedSenderValidator implements SenderValidator { * {@inheritDoc} */ @Override - public @NotNull Set<@NotNull Class> getAllowedSenders() { + public @NotNull Set> getAllowedSenders() { return ImmutableSet.of(PrefixedSender.class); } diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java index cd5368c3..b5bede21 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java @@ -69,7 +69,7 @@ final class SlashCommand implements ParentCommand> { public SlashCommand( final @NotNull SlashCommandProcessor processor, - final @NotNull List<@NotNull Permission> allow, + final @NotNull List allow, final @NotNull ExecutionProvider syncExecutionProvider, final @NotNull ExecutionProvider asyncExecutionProvider ) { @@ -85,7 +85,7 @@ public SlashCommand( this.asyncExecutionProvider = asyncExecutionProvider; } - public @NotNull List<@NotNull Permission> getAllowed() { + public @NotNull List getAllowed() { return allow; } @@ -123,7 +123,7 @@ public void addSubCommandAlias(final @NotNull String alias, final @NotNull Slash public void execute( final @NotNull S sender, final @NotNull String subCommandName, - final @NotNull Map<@NotNull String, @NotNull String> args + final @NotNull Map args ) { final SlashSubCommand subCommand = getSubCommand(subCommandName); if (subCommand == null) return; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java index 7f9e4449..3fedeec4 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java @@ -145,7 +145,7 @@ public void registerCommand(final @NotNull Guild guild, final @NotNull BaseComma */ public void registerCommand( final @NotNull BaseCommand baseCommand, - final @NotNull List<@NotNull Permission> enabledPermissions) { + final @NotNull List enabledPermissions) { addCommand(null, baseCommand, enabledPermissions); } @@ -159,7 +159,7 @@ public void registerCommand( public void registerCommand( final @NotNull Guild guild, final @NotNull BaseCommand baseCommand, - final @NotNull List<@NotNull Permission> enabledPermissions) { + final @NotNull List enabledPermissions) { addCommand(guild, baseCommand, enabledPermissions); } @@ -175,7 +175,7 @@ public void registerCommand(final @NotNull Guild guild, final @NotNull BaseComma } } - public void registerChoices(final @NotNull ChoiceKey key, final @NotNull Supplier<@NotNull List<@NotNull String>> choiceSupplier) { + public void registerChoices(final @NotNull ChoiceKey key, final @NotNull Supplier> choiceSupplier) { registryContainer.getChoiceRegistry().register(key, choiceSupplier); } @@ -219,7 +219,7 @@ public void updateAllCommands() { private void addCommand( final @Nullable Guild guild, final @NotNull BaseCommand baseCommand, - final @NotNull List<@NotNull Permission> enabledPermissions + final @NotNull List enabledPermissions ) { final SlashCommandProcessor processor = new SlashCommandProcessor<>( baseCommand, diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java index 94c8d026..ee67ccfa 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java @@ -72,7 +72,7 @@ public SlashCommandProcessor( * * @return The enabled permissions. */ - public @NotNull List<@NotNull Permission> getEnabledPermissions() { + public @NotNull List getEnabledPermissions() { return enabledPermissions; } @@ -91,7 +91,7 @@ public SlashCommandProcessor( * @param klass The class to get from. * @return List with all the roles annotations. */ - private @NotNull List<@NotNull Roles> getRolesFromAnnotations(final @NotNull Class klass) { + private @NotNull List getRolesFromAnnotations(final @NotNull Class klass) { final Privileges privileges = klass.getAnnotation(Privileges.class); if (privileges != null) return Arrays.asList(privileges.value()); diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java index 2644abfb..13ea0fdb 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java @@ -41,7 +41,7 @@ final class SlashSenderValidator implements SenderValidator { * {@inheritDoc} */ @Override - public @NotNull Set<@NotNull Class> getAllowedSenders() { + public @NotNull Set> getAllowedSenders() { return ImmutableSet.of(SlashSender.class); } diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java index b091977a..479ecbe5 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java @@ -64,7 +64,7 @@ public SlashSubCommand( return null; } - public @NotNull List<@NotNull OptionData> getJdaOptions() { + public @NotNull List getJdaOptions() { final List options = new ArrayList<>(); final List> internalArguments = getArguments(); diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java index 96849442..18f3a29c 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java @@ -78,11 +78,11 @@ public SlashSubCommandProcessor( } @Override - protected @NotNull List<@NotNull BiConsumer<@NotNull Boolean, @NotNull InternalArgument>> getArgValidations() { + protected @NotNull List>> getArgValidations() { return Collections.singletonList(validateLimitless()); } - public @NotNull List<@NotNull Choice> getChoices() { + public @NotNull List getChoices() { return choices; } @@ -110,7 +110,7 @@ public SlashSubCommandProcessor( return super.createSimpleArgument(type, parameterName, argumentDescription, suggestion, position, optional); } - public @NotNull List<@NotNull Choice> extractChoices( + public @NotNull List extractChoices( final @NotNull Method method, final @NotNull Class commandClass ) { @@ -138,7 +138,7 @@ public SlashSubCommandProcessor( private void extractSuggestionFromParams( final @NotNull Method method, - final @NotNull List<@NotNull Choice> choiceList, + final @NotNull List choiceList, final @NotNull Class commandClass ) { final Parameter[] parameters = method.getParameters(); @@ -170,7 +170,7 @@ private void extractSuggestionFromParams( } private void setOrAdd( - final @NotNull List<@NotNull Choice> choiceList, + final @NotNull List choiceList, final int index, final @Nullable Choice choice ) { diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java index f964cbcd..97c8c545 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java @@ -29,6 +29,6 @@ public interface Choice { - @NotNull List<@NotNull String> getChoices(); + @NotNull List getChoices(); } diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java index 1a0151e4..6a586d02 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java @@ -60,7 +60,7 @@ private ChoiceKey(final @NotNull String key) { * * @return The keys {@link Set}. */ - public static @NotNull Set<@NotNull ChoiceKey> getRegisteredKeys() { + public static @NotNull Set getRegisteredKeys() { return Collections.unmodifiableSet(REGISTERED_KEYS); } diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java index 5b33c2b2..4f68072a 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java @@ -35,11 +35,11 @@ public final class ChoiceRegistry { private final Map>> suggestions = new HashMap<>(); - public void register(final @NotNull ChoiceKey key, final @NotNull Supplier<@NotNull List<@NotNull String>> resolver) { + public void register(final @NotNull ChoiceKey key, final @NotNull Supplier> resolver) { suggestions.put(key, resolver); } - public @Nullable Supplier<@NotNull List<@NotNull String>> getChoiceResolver(final @NotNull ChoiceKey key) { + public @Nullable Supplier> getChoiceResolver(final @NotNull ChoiceKey key) { return suggestions.get(key); } diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java index d40cffd5..87f7687d 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java @@ -34,7 +34,7 @@ public final class EmptyChoice implements Choice { public static final EmptyChoice INSTANCE = new EmptyChoice(); @Override - public @NotNull List<@NotNull String> getChoices() { + public @NotNull List getChoices() { return emptyList(); } diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java index 7bae5640..cfec8c46 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java @@ -43,7 +43,7 @@ public EnumChoice(final @NotNull Class> enumType) { } @Override - public @NotNull List<@NotNull String> getChoices() { + public @NotNull List getChoices() { return EnumUtils.getEnumConstants(enumType) .values() .stream() diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java index a2e0e227..ffbc03c0 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java @@ -34,12 +34,12 @@ public final class SimpleChoice implements Choice { private final Supplier> resolver; - public SimpleChoice(final @NotNull Supplier<@NotNull List<@NotNull String>> resolver) { + public SimpleChoice(final @NotNull Supplier> resolver) { this.resolver = resolver; } @Override - public @NotNull List<@NotNull String> getChoices() { + public @NotNull List getChoices() { return resolver.get(); } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index 265b11a6..6f68dfa3 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -205,7 +205,7 @@ private static void setUpDefaults(final @NotNull BukkitCommandManager getBukkitCommands(final @NotNull CommandMap commandMap) { + private static @NotNull Map getBukkitCommands(final @NotNull CommandMap commandMap) { try { final Field bukkitCommands = SimpleCommandMap.class.getDeclaredField("knownCommands"); bukkitCommands.setAccessible(true); diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java index 2b5ad452..0f1d132a 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java @@ -64,7 +64,7 @@ public CommandPermission getBasePermission() { static CommandPermission createPermission( final @Nullable CommandPermission parent, - final @NotNull List<@NotNull String> nodes, + final @NotNull List nodes, final @NotNull String description, final @NotNull PermissionDefault permissionDefault ) { diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java index 13f1adb6..fa89e41d 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java @@ -45,7 +45,7 @@ class BukkitSenderValidator implements SenderValidator { * {@inheritDoc} */ @Override - public @NotNull Set<@NotNull Class> getAllowedSenders() { + public @NotNull Set> getAllowedSenders() { return ImmutableSet.of(CommandSender.class, ConsoleCommandSender.class, Player.class); } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java index f312a914..438d6b9d 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java @@ -46,7 +46,7 @@ public BukkitSubCommand(final @NotNull BukkitSubCommandProcessor processor, f if (this.permission != null) this.permission.register(); } - public @NotNull List<@NotNull String> getSuggestions(final @NotNull S sender, final @NotNull List<@NotNull String> args) { + public @NotNull List getSuggestions(final @NotNull S sender, final @NotNull List args) { final int index = args.size() - 1; final InternalArgument internalArgument = getArgument(index); if (internalArgument == null) return emptyList(); diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java index b264caee..6dd4bd70 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java @@ -45,7 +45,7 @@ public final class CommandPermission { private final String description; public CommandPermission( - final @NotNull List<@NotNull String> nodes, + final @NotNull List nodes, final @NotNull String description, final @NotNull PermissionDefault permissionDefault ) { @@ -75,7 +75,7 @@ public static boolean hasPermission( } public @NotNull CommandPermission child( - final @NotNull List<@NotNull String> nodes, + final @NotNull List nodes, final @NotNull String description, final @NotNull PermissionDefault permissionDefault ) { @@ -106,7 +106,7 @@ public void register() { * * @return The permission nodes. */ - public @NotNull List<@NotNull String> getNodes() { + public @NotNull List getNodes() { return nodes; } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java index 4b47ef52..6e460461 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java @@ -112,7 +112,7 @@ public boolean execute( } @Override - public @NotNull List<@NotNull String> tabComplete(final @NotNull CommandSender sender, final @NotNull String alias, final @NotNull String @NotNull [] args) throws IllegalArgumentException { + public @NotNull List tabComplete(final @NotNull CommandSender sender, final @NotNull String alias, final @NotNull String @NotNull [] args) throws IllegalArgumentException { if (args.length == 0) return emptyList(); return emptyList(); /*BukkitSubCommand subCommand = getDefaultSubCommand(); diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java index 29b9334f..d9c669b4 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java @@ -42,7 +42,7 @@ public NoPermissionMessageContext( this.permission = permission; } - public @NotNull List<@NotNull String> getNodes() { + public @NotNull List getNodes() { return permission.getNodes(); } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index c8545bbe..f6816c8c 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -101,7 +101,7 @@ public void unregisterCommand(final @NotNull Object command) { * @param sender The provided sender. * @param args The provided arguments. */ - public void executeCommand(final @NotNull S sender, final @NotNull List<@NotNull String> args) { + public void executeCommand(final @NotNull S sender, final @NotNull List args) { if (args.isEmpty()) return; final String commandName = args.get(0); From 7c1c2d874c6f23340d181248eb2e206e30f27407 Mon Sep 17 00:00:00 2001 From: Matt Date: Tue, 17 Jan 2023 22:13:27 +0000 Subject: [PATCH 050/101] feature: Rework messages again, no with syntax annotation --- .../Syntax.java} | 20 ++- .../argument/CollectionInternalArgument.java | 14 +- .../core/argument/EnumInternalArgument.java | 23 ++- .../core/argument/FlagInternalArgument.java | 12 +- .../cmd/core/argument/InternalArgument.java | 22 ++- .../JoinedStringInternalArgument.java | 12 +- .../core/argument/KeyedInternalArgument.java | 22 ++- .../core/argument/NamedInternalArgument.java | 12 +- .../argument/ResolverInternalArgument.java | 18 ++- .../argument/SplitStringInternalArgument.java | 14 +- .../argument/UnknownInternalArgument.java | 6 +- .../keyed/internal/ArgumentGroup.java | 12 +- .../keyed/internal/ArgumentParser.java | 31 ++-- .../{FlagValue.java => ArgumentValue.java} | 2 +- ...FlagValue.java => EmptyArgumentValue.java} | 4 +- .../core/argument/keyed/internal/Flag.java | 5 + .../argument/keyed/internal/FlagGroup.java | 18 ++- .../argument/keyed/internal/FlagOptions.java | 25 +++- .../argument/keyed/internal/FlagsResult.java | 17 +-- ...rgumentResult.java => KeyedArguments.java} | 4 +- .../argument/keyed/internal/ListArgument.java | 17 ++- .../argument/keyed/internal/NamedGroup.java | 18 +-- .../keyed/internal/SimpleArgument.java | 15 ++ ...lagValue.java => SimpleArgumentValue.java} | 26 ++-- .../triumphteam/cmd/core/command/Command.java | 5 + .../cmd/core/command/ParentSubCommand.java | 105 ++++++++++---- .../cmd/core/command/SubCommand.java | 71 ++++++--- .../cmd/core/extention/Result.java | 47 ++++++ .../cmd/core/extention/meta/MetaKey.java | 3 + .../message/context/BasicMessageContext.java | 37 +---- .../context/InvalidArgumentContext.java | 15 +- .../context/InvalidCommandContext.java | 8 +- .../message/context/InvalidInputContext.java | 10 +- .../core/message/context/MessageContext.java | 10 +- .../processor/AbstractCommandProcessor.java | 136 +++++++++++++++--- .../AbstractRootCommandProcessor.java | 57 +++++--- .../cmd/core/processor/CommandProcessor.java | 4 + .../processor/ParentCommandProcessor.java | 9 +- .../core/processor/SubCommandProcessor.java | 11 +- .../cmd/core/requirement/Requirement.java | 19 ++- gradle/libs.versions.toml | 2 +- .../cmds/simple/SimpleCommand.java | 11 +- .../cmds/simple/SimpleCommandManager.java | 10 +- 43 files changed, 678 insertions(+), 261 deletions(-) rename core/src/main/java/dev/triumphteam/cmd/core/{message/context/MessageContextFactory.java => annotations/Syntax.java} (71%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/{FlagValue.java => ArgumentValue.java} (97%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/{EmptyFlagValue.java => EmptyArgumentValue.java} (90%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/{NamedArgumentResult.java => KeyedArguments.java} (94%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/{ArgFlagValue.java => SimpleArgumentValue.java} (65%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Syntax.java similarity index 71% rename from core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java rename to core/src/main/java/dev/triumphteam/cmd/core/annotations/Syntax.java index 13fb4f09..0d84b8d3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContextFactory.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Syntax.java @@ -21,14 +21,22 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.message.context; +package dev.triumphteam.cmd.core.annotations; -import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; -@FunctionalInterface -public interface MessageContextFactory { +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; - @Contract("_, _ -> new") - @NotNull C create(final @NotNull String command, final @NotNull String subCommand); +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.TYPE, ElementType.METHOD, ElementType.PARAMETER}) +@Inherited +public @interface Syntax { + + @NotNull String value(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java index bf7eef37..2269caff 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java @@ -23,11 +23,16 @@ */ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Set; +import java.util.function.BiFunction; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -63,10 +68,13 @@ public CollectionInternalArgument( * @return A {@link java.util.Collection} type as the resolved value. */ @Override - public @NotNull Object resolve(final @NotNull S sender, final @NotNull List value) { + public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull List value + ) { final Stream stream = value.stream().map(arg -> internalArgument.resolve(sender, arg)); - if (collectionType == Set.class) return stream.collect(Collectors.toSet()); - return stream.collect(Collectors.toList()); + if (collectionType == Set.class) return success(stream.collect(Collectors.toSet())); + return success(stream.collect(Collectors.toList())); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java index 205f657a..8753ece4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java @@ -23,11 +23,14 @@ */ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.lang.ref.WeakReference; +import java.util.function.BiFunction; import static dev.triumphteam.cmd.core.util.EnumUtils.getEnumConstants; import static dev.triumphteam.cmd.core.util.EnumUtils.populateCache; @@ -64,10 +67,22 @@ public EnumInternalArgument( * @return An {@link Enum} value of the correct type. */ @Override - public @Nullable Object resolve(final @NotNull S sender, final @NotNull String value) { + public @NotNull Result> resolve( + final @NotNull S sender, + final @NotNull String value + ) { final WeakReference> reference = getEnumConstants(enumType).get(value.toUpperCase()); - if (reference == null) return null; - return reference.get(); + + if (reference == null) { + return invalid((meta, syntax) -> new InvalidArgumentContext(meta, syntax, value, getName(), getType())); + } + + final Enum enumValue = reference.get(); + if (enumValue == null) { + return invalid((commands, arguments) -> new InvalidArgumentContext(commands, arguments, value, getName(), getType())); + } + + return success(enumValue); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java index 4f42d859..8dfa73b2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java @@ -26,6 +26,9 @@ import dev.triumphteam.cmd.core.argument.keyed.Flags; import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; @@ -36,6 +39,8 @@ import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Set; +import java.util.function.BiFunction; import java.util.stream.Collectors; /** @@ -68,7 +73,10 @@ public FlagInternalArgument( * @return A {@link Flags} which contains the flags and leftovers. */ @Override - public @NotNull Object resolve(final @NotNull S sender, final @NotNull List value) { + public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull List value + ) { return null;// flagParser.parse(sender, value.size() == 1 ? Arrays.asList(value.get(0).split(" ")) : value); } @@ -82,7 +90,7 @@ public FlagInternalArgument( final String current = trimmed.get(size - 1); // TODO: Show flags before long flags. - final List flags = flagGroup.getAllNames(); + final Set flags = flagGroup.getAllNames(); // Parses all the arguments to get the flags that have been used // flagParser.parseFlags(trimmed).entrySet() diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index 8acaac21..8f93be40 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -23,11 +23,15 @@ */ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.function.BiFunction; /** * Command argument. @@ -74,9 +78,12 @@ public interface InternalArgument { * * @param sender The sender to resolve to. * @param value The argument value. - * @return An object with the resolved value. + * @return A resolve {@link Result}. */ - @Nullable Object resolve(final @NotNull S sender, final @NotNull T value); + @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull T value + ); // TODO: Comments @NotNull List suggestions( @@ -85,4 +92,15 @@ public interface InternalArgument { final @NotNull SuggestionContext context ); + default Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> success( + final @NotNull Object value + ) { + return new Result.Success<>(value); + } + + default Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> invalid( + final @NotNull BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext> context + ) { + return new Result.Failure<>(context); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java index 20ecb4f0..d66f8b9a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java @@ -23,10 +23,15 @@ */ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.function.BiFunction; /** * Joined string argument, a {@link LimitlessInternalArgument}. @@ -57,8 +62,11 @@ public JoinedStringInternalArgument( * @return A single {@link String} with the joined {@link List}. */ @Override - public @NotNull Object resolve(final @NotNull S sender, final @NotNull List value) { - return String.join(delimiter, value); + public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull List value + ) { + return success(String.join(delimiter, value)); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java index c34d5e98..61e1e122 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java @@ -28,16 +28,23 @@ import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentParser; import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; - +import java.util.Map; +import java.util.function.BiFunction; public final class KeyedInternalArgument extends LimitlessInternalArgument { + private final Map> flagInternalArguments; + private final Map> argumentInternalArguments; private final ArgumentGroup argumentGroup; private final ArgumentGroup flagGroup; private final ArgumentParser argumentParser; @@ -45,10 +52,14 @@ public final class KeyedInternalArgument extends LimitlessInternalArgument public KeyedInternalArgument( final @NotNull String name, final @NotNull String description, + final @NotNull Map> flagInternalArguments, + final @NotNull Map> argumentInternalArguments, final @NotNull ArgumentGroup flagGroup, final @NotNull ArgumentGroup argumentGroup ) { super(name, description, Flags.class, new EmptySuggestion<>(), true); + this.flagInternalArguments = flagInternalArguments; + this.argumentInternalArguments = argumentInternalArguments; this.flagGroup = flagGroup; this.argumentGroup = argumentGroup; this.argumentParser = new ArgumentParser(flagGroup, argumentGroup); @@ -62,7 +73,12 @@ public KeyedInternalArgument( * @return A {@link Flags} which contains the flags and leftovers. */ @Override - public @NotNull Object resolve(final @NotNull S sender, final @NotNull List value) { + public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull List value + ) { + final ArgumentParser.Result result = argumentParser.parse(value); + return null;// flagParser.parse(sender, value.size() == 1 ? Arrays.asList(value.get(0).split(" ")) : value); } @@ -75,6 +91,4 @@ public KeyedInternalArgument( ) { return Collections.emptyList(); } - - } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java index 40643199..18ece42d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java @@ -23,8 +23,10 @@ */ package dev.triumphteam.cmd.core.argument; -import dev.triumphteam.cmd.core.argument.keyed.internal.NamedArgumentResult; import dev.triumphteam.cmd.core.argument.keyed.Arguments; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; @@ -35,6 +37,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.BiFunction; import java.util.stream.Collectors; public final class NamedInternalArgument extends LimitlessInternalArgument { @@ -52,7 +55,10 @@ public NamedInternalArgument( } @Override - public @NotNull Object resolve(final @NotNull S sender, final @NotNull List value) { + public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull List value + ) { final Map parsedArgs = Collections.emptyMap();// ArgumentParser.parse(String.join(" ", value)); final Map mapped = new HashMap<>(parsedArgs.size()); @@ -64,7 +70,7 @@ public NamedInternalArgument( mapped.put(key, resolved); } - return new NamedArgumentResult(mapped); + return null; } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java index 9a68fabd..5e4394dc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java @@ -23,11 +23,16 @@ */ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.function.BiFunction; + /** * Normal {@link StringInternalArgument}. * Basically the main implementation. @@ -60,8 +65,17 @@ public ResolverInternalArgument( * @return An Object value of the correct type, based on the result from the {@link ArgumentResolver}. */ @Override - public @Nullable Object resolve(final @NotNull S sender, final @NotNull String value) { - return resolver.resolve(sender, value); + public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull String value + ) { + final Object result = resolver.resolve(sender, value); + + if (result == null) { + return invalid((commands, arguments) -> new InvalidArgumentContext(commands, arguments, value, getName(), getType())); + } + + return success(result); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java index 8f0afc73..6c99ba3b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java @@ -23,14 +23,19 @@ */ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; +import java.util.function.BiFunction; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -68,10 +73,13 @@ public SplitStringInternalArgument( * @return A collection of the split strings. */ @Override - public @NotNull Object resolve(final @NotNull S sender, final @NotNull String value) { + public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull String value + ) { final Stream stream = Arrays.stream(value.split(regex)).map(arg -> internalArgument.resolve(sender, arg)); - if (collectionType == Set.class) return stream.collect(Collectors.toSet()); - return stream.collect(Collectors.toList()); + if (collectionType == Set.class) return success(stream.collect(Collectors.toSet())); + return success(stream.collect(Collectors.toList())); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index 09a2d8f0..9ca1b842 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -1,11 +1,15 @@ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Collections; import java.util.List; +import java.util.function.BiFunction; /** * This argument type is always ignored by the creator. @@ -40,7 +44,7 @@ public boolean isOptional() { } @Override - public @Nullable Object resolve(final @NotNull S sender, final @NotNull String value) { + public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve(final @NotNull S sender, final @NotNull String value) { return null; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java index 0ecec743..a3471a48 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java @@ -4,6 +4,7 @@ import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.Set; /** * A group of argument data. @@ -44,14 +45,17 @@ static ArgumentGroup named(final @NotNull List arguments) { /** * Gets a list with all possible argument names. * - * @return A {@link List} of names. + * @return A {@link Set} of names. */ - @NotNull List getAllNames(); + @NotNull Set getAllNames(); /** - * Checks if the group is empty. - * * @return Whether the group is empty. */ boolean isEmpty(); + + /** + * @return Gets a set with all the arguments of type {@link T}. + */ + @NotNull Set getAll(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentParser.java index a14b8e31..cb7d21b6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentParser.java @@ -123,7 +123,7 @@ private void handleNamed( return; } - result.addNamedArgument(namedToken, argToken); + result.addNamedArgument(argument, argToken); result.setWaitingArgument(argToken.isEmpty()); } @@ -203,13 +203,13 @@ private void handleWithEquals( public static class Result { private final Map flags = new HashMap<>(); - private final Map namedArguments = new HashMap<>(); + private final Map namedArguments = new HashMap<>(); private final List nonTokens = new ArrayList<>(); private boolean waitingArgument = false; - public void addNamedArgument(final @NotNull String name, final @NotNull String value) { - namedArguments.put(name, value); + public void addNamedArgument(final @NotNull Argument argument, final @NotNull String value) { + namedArguments.put(argument, value); } public void addFlag(final @NotNull Flag flagOptions) { @@ -224,15 +224,24 @@ public void addNonToken(final @NotNull String token) { nonTokens.add(token); } - public void setWaitingArgument(final boolean value) { - this.waitingArgument = value; + public Map getFlags() { + return flags; + } + + public Map getNamedArguments() { + return namedArguments; + } + + public List getNonTokens() { + return nonTokens; + } + + public boolean isWaitingArgument() { + return waitingArgument; } - public void test() { - System.out.println(flags); - System.out.println(namedArguments); - System.out.println(nonTokens); - System.out.println(waitingArgument); + public void setWaitingArgument(final boolean value) { + this.waitingArgument = value; } } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentValue.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentValue.java index 33d20a80..8fcbb6c5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentValue.java @@ -23,4 +23,4 @@ */ package dev.triumphteam.cmd.core.argument.keyed.internal; -public interface FlagValue {} +interface ArgumentValue {} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyArgumentValue.java similarity index 90% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyFlagValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyArgumentValue.java index 9a61b3a5..e514c135 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyArgumentValue.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.argument.keyed.internal; -public final class EmptyFlagValue implements FlagValue { +final class EmptyArgumentValue implements ArgumentValue { - public static final EmptyFlagValue INSTANCE = new EmptyFlagValue(); + static final EmptyArgumentValue INSTANCE = new EmptyArgumentValue(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Flag.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Flag.java index 544851d1..569088f9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Flag.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Flag.java @@ -60,6 +60,11 @@ public interface Flag { */ boolean hasArgument(); + /** + * @return Gets the argument if there is one. + */ + @Nullable Class getArgument(); + /** * Simple builder for creating new {@link Flag}s. */ diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java index 1c952417..1b46ec7e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java @@ -26,10 +26,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; /** * Basically a holder that contains all the needed flags for the command. @@ -39,7 +40,7 @@ final class FlagGroup implements ArgumentGroup { private final Map flags = new HashMap<>(); private final Map longFlags = new HashMap<>(); - private final List allFlags = new ArrayList<>(); + private final Map allFlags = new HashMap<>(); public FlagGroup(final @NotNull List flags) { flags.forEach(this::addArgument); @@ -50,17 +51,17 @@ public void addArgument(final @NotNull Flag argument) { final String longFlag = argument.getLongFlag(); if (longFlag != null) { - allFlags.add("--" + longFlag); + allFlags.put("--" + longFlag, argument); longFlags.put(longFlag, argument); } - allFlags.add("-" + key); + allFlags.put("-" + key, argument); flags.put(key, argument); } @Override - public @NotNull List getAllNames() { - return allFlags; + public @NotNull Set getAllNames() { + return allFlags.keySet(); } @Override @@ -76,6 +77,11 @@ public boolean isEmpty() { return flag != null ? flag : longFlags.get(stripped); } + @Override + public @NotNull Set getAll() { + return new HashSet<>(flags.values()); + } + /** * Strips the hyphens from the token. * diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagOptions.java index d418567f..266d8af0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagOptions.java @@ -29,6 +29,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Objects; + /** * Contains all the "settings" for the flag. */ @@ -90,13 +92,26 @@ final class FlagOptions implements Flag { return suggestionKey; } - /** - * Checks if the flag has argument or not. - * - * @return Whether it has an argument. - */ @Override public boolean hasArgument() { return argument != null; } + + @Override + public @Nullable Class getArgument() { + return argument; + } + + @Override + public boolean equals(final @Nullable Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + final FlagOptions that = (FlagOptions) o; + return Objects.equals(flag, that.flag) && Objects.equals(longFlag, that.longFlag) && Objects.equals(argument, that.argument); + } + + @Override + public int hashCode() { + return Objects.hash(flag, longFlag, argument); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java index 546e3fb7..0e92924d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java @@ -39,7 +39,7 @@ @SuppressWarnings("unchecked") class FlagsResult implements Flags { - private final Map flags = new HashMap<>(); + private final Map flags = new HashMap<>(); private final List args; private final S sender; @@ -86,11 +86,12 @@ public boolean hasFlag(final @NotNull String flag) { */ @Override public @NotNull Optional getValue(final @NotNull String flag, final @NotNull Class type) { - final FlagValue flagValue = flags.get(flag); + final ArgumentValue flagValue = flags.get(flag); if (flagValue == null) return Optional.empty(); - if (!(flagValue instanceof ArgFlagValue)) return Optional.empty(); - final ArgFlagValue argFlagValue = (ArgFlagValue) flagValue; - return Optional.ofNullable((T) argFlagValue.getValue(sender, type)); + if (!(flagValue instanceof SimpleArgumentValue)) return Optional.empty(); + /* final SimpleArgumentValue argFlagValue = (SimpleArgumentValue) flagValue; + return Optional.ofNullable((T) argFlagValue.getValue(sender, type));*/ + return Optional.empty(); } /** @@ -98,10 +99,10 @@ public boolean hasFlag(final @NotNull String flag) { */ @Override public @NotNull Optional getValue(final @NotNull String flag) { - final FlagValue flagValue = flags.get(flag); + final ArgumentValue flagValue = flags.get(flag); if (flagValue == null) return Optional.empty(); - if (!(flagValue instanceof ArgFlagValue)) return Optional.empty(); - final ArgFlagValue argFlagValue = (ArgFlagValue) flagValue; + if (!(flagValue instanceof SimpleArgumentValue)) return Optional.empty(); + final SimpleArgumentValue argFlagValue = (SimpleArgumentValue) flagValue; return Optional.of(argFlagValue.getAsString()); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedArgumentResult.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/KeyedArguments.java similarity index 94% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedArgumentResult.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/KeyedArguments.java index b8c11ac8..adf460d4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedArgumentResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/KeyedArguments.java @@ -32,11 +32,11 @@ import java.util.Set; @SuppressWarnings("unchecked") -public final class NamedArgumentResult extends FlagsContainer { +public final class KeyedArguments extends FlagsContainer { private final Map values; - public NamedArgumentResult(final @NotNull Map values) { + public KeyedArguments(final @NotNull Map values) { this.values = values; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java index f4fcadcf..bee4d47d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java @@ -27,7 +27,9 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -final class ListArgument implements Argument { +import java.util.Objects; + +public final class ListArgument implements Argument { private final Class collectionType; private final String separator; @@ -73,4 +75,17 @@ public ListArgument(final @NotNull Argument.CollectionBuilder argumentBuilder) { public @NotNull String getSeparator() { return separator; } + + @Override + public boolean equals(final @Nullable Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + final ListArgument that = (ListArgument) o; + return collectionType.equals(that.collectionType) && separator.equals(that.separator) && type.equals(that.type) && name.equals(that.name); + } + + @Override + public int hashCode() { + return Objects.hash(collectionType, separator, type, name); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java index ab6c6842..057119de 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java @@ -26,10 +26,11 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; /** * Basically a holder that contains all the needed arguments for the command. @@ -37,21 +38,18 @@ final class NamedGroup implements ArgumentGroup { private final Map arguments = new HashMap<>(); - private final List allArgumentNames = new ArrayList<>(); NamedGroup(final @NotNull List arguments) { arguments.forEach(this::addArgument); } public void addArgument(final @NotNull Argument argument) { - final String name = argument.getName(); - allArgumentNames.add(name); - arguments.put(name, argument); + arguments.put(argument.getName(), argument); } @Override - public @NotNull List getAllNames() { - return allArgumentNames; + public @NotNull Set getAllNames() { + return arguments.keySet(); } @Override @@ -65,9 +63,7 @@ public boolean isEmpty() { } @Override - public String toString() { - return "NamedGroup{" + - "allArgumentNames=" + allArgumentNames + - '}'; + public @NotNull Set getAll() { + return new HashSet<>(arguments.values()); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java index 8098e9ed..34dd7933 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java @@ -27,6 +27,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Objects; + final class SimpleArgument implements Argument { private final Class type; @@ -60,4 +62,17 @@ public SimpleArgument(final @NotNull Argument.AbstractBuilder argumentBuilder public @Nullable SuggestionKey getSuggestion() { return suggestionKey; } + + @Override + public boolean equals(final @Nullable Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + final SimpleArgument that = (SimpleArgument) o; + return type.equals(that.type) && name.equals(that.name); + } + + @Override + public int hashCode() { + return Objects.hash(type, name); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgFlagValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgumentValue.java similarity index 65% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgFlagValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgumentValue.java index bf2e778c..f6407207 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgFlagValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgumentValue.java @@ -23,34 +23,24 @@ */ package dev.triumphteam.cmd.core.argument.keyed.internal; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -class ArgFlagValue implements FlagValue { +class SimpleArgumentValue implements ArgumentValue { - private final String value; - private final StringInternalArgument argument; + private final String rawValue; + private final Object value; - public ArgFlagValue(final @NotNull String value, final @NotNull StringInternalArgument argument) { + public SimpleArgumentValue(final @NotNull String rawValue, final @NotNull Object value) { + this.rawValue = rawValue; this.value = value; - this.argument = argument; } - public @Nullable Object getValue(final @NotNull S sender, final @NotNull Class type) { - if (!type.equals(argument.getType())) return null; - return argument.resolve(sender, value); - } - - public @NotNull String getAsString() { + public @Nullable Object getValue() { return value; } - @Override - public @NotNull String toString() { - return "ArgFlagValue{" + - "value='" + value + '\'' + - ", argument=" + argument + - '}'; + public @NotNull String getAsString() { + return rawValue; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 4f4e2fe7..4029a396 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -47,4 +47,9 @@ public interface Command extends CommandMetaContainer { * @return Whether the command has arguments. */ boolean hasArguments(); + + /** + * @return The command's syntax. + */ + @NotNull String getSyntax(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index cb80e268..4fda7e57 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -1,12 +1,16 @@ package dev.triumphteam.cmd.core.command; +import dev.triumphteam.cmd.core.annotations.Syntax; import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; +import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.message.context.InvalidCommandContext; +import dev.triumphteam.cmd.core.processor.CommandProcessor; import dev.triumphteam.cmd.core.processor.ParentCommandProcessor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -16,11 +20,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.BiFunction; import java.util.function.Supplier; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; - /** * A parent sub command is basically a holder of other sub commands. * This normally represents an inner class of a main command. @@ -32,8 +34,11 @@ public class ParentSubCommand implements ParentCommand, ExecutableCommand< private final Map> commands = new HashMap<>(); private final Map> commandAliases = new HashMap<>(); + private final String name; + private final String syntax; private final CommandMeta meta; + private final Object invocationInstance; private final Constructor constructor; private final boolean isStatic; @@ -49,7 +54,8 @@ public ParentSubCommand( final @NotNull Constructor constructor, final boolean isStatic, final @Nullable StringInternalArgument argument, - final @NotNull ParentCommandProcessor processor + final @NotNull ParentCommandProcessor processor, + final @NotNull Command parentCommand ) { this.invocationInstance = invocationInstance; this.constructor = constructor; @@ -60,6 +66,8 @@ public ParentSubCommand( this.name = processor.getName(); this.meta = processor.createMeta(); this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); + + this.syntax = createSyntax(parentCommand, processor); } @Override @@ -92,34 +100,45 @@ public void execute( final ExecutableCommand subCommand = getSubCommand(commandName, argumentSize); if (subCommand == null) { - messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(commandPath, emptyList(), commandName)); + messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(meta, commandName)); return; } commandPath.add(subCommand.getName()); - final Object argumentValue; - if (hasArgument) argumentValue = argument.resolve(sender, command); - else argumentValue = null; - - if (hasArgument && argumentValue == null) { - messageRegistry.sendMessage(MessageKey.INVALID_ARGUMENT, sender, new InvalidArgumentContext( - commandPath, - singletonList(commandName), - commandName, - argument.getName(), - argument.getType() - )); - return; - } + final Object instance; + + if (hasArgument) { + final @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> result = + argument.resolve(sender, command); + + if (result instanceof Result.Failure) { + messageRegistry.sendMessage( + MessageKey.INVALID_ARGUMENT, + sender, + ((Result.Failure>) result) + .getFail() + .apply(meta, syntax) + ); + return; + } - final Object instance = createInstance(instanceSupplier, argumentValue); + if (!(result instanceof Result.Success)) { + throw new CommandExecutionException("An error occurred resolving arguments", "", name); + } + + instance = createInstanceWithArgument( + instanceSupplier, ((Result.Success>) result).getValue() + ); + } else { + instance = createInstance(instanceSupplier); + } subCommand.execute( sender, commandName, () -> instance, commandPath, - !subCommand.isDefault() ? arguments.subList(1, arguments.size()) : arguments + !subCommand.isDefault() && !arguments.isEmpty() ? arguments.subList(1, arguments.size()) : arguments ); } @@ -127,33 +146,61 @@ public void execute( * Creates a new instance to be passed down to the child commands. * * @param instanceSupplier The instance supplier from parents. - * @param argumentValue The value of the argument to pass if there is an argument. * @return An instance of this command for execution. */ private @NotNull Object createInstance( + final @Nullable Supplier instanceSupplier + ) throws InvocationTargetException, InstantiationException, IllegalAccessException { + // Non-static classes required parent instance + if (!isStatic) { + return constructor.newInstance(instanceSupplier == null ? invocationInstance : instanceSupplier.get()); + } + + return constructor.newInstance(); + } + + /** + * Creates a new instance to be passed down to the child commands. + * + * @param instanceSupplier The instance supplier from parents. + * @param argumentValue The argument value. + * @return An instance of this command for execution. + */ + private @NotNull Object createInstanceWithArgument( final @Nullable Supplier instanceSupplier, final @Nullable Object argumentValue ) throws InvocationTargetException, InstantiationException, IllegalAccessException { // Non-static classes required parent instance if (!isStatic) { - // If there is no argument don't pass anything - // A bit annoying but if the method has no parameters, "null" is a valid parameter so this check is needed - if (!hasArgument) { - return constructor.newInstance(instanceSupplier == null ? invocationInstance : instanceSupplier.get()); - } - return constructor.newInstance(instanceSupplier == null ? invocationInstance : instanceSupplier.get(), argumentValue); } - if (!hasArgument) constructor.newInstance(); return constructor.newInstance(argumentValue); } + private @NotNull String createSyntax(final @NotNull Command parentCommand, final @NotNull CommandProcessor processor) { + final Syntax syntaxAnnotation = processor.getSyntaxAnnotation(); + if (syntaxAnnotation != null) return syntaxAnnotation.value(); + + final StringBuilder builder = new StringBuilder(); + builder.append(parentCommand.getSyntax()).append(" "); + + if (hasArgument) builder.append("<").append(argument.getName()).append(">"); + else builder.append(name); + + return builder.toString(); + } + @Override public @NotNull String getName() { return name; } + @Override + public @NotNull String getSyntax() { + return syntax; + } + @Override public @NotNull Object getInvocationInstance() { return invocationInstance; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index cae97e73..ad8686c3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -1,15 +1,18 @@ package dev.triumphteam.cmd.core.command; +import dev.triumphteam.cmd.core.annotations.Syntax; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; +import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.BasicMessageContext; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; +import dev.triumphteam.cmd.core.processor.CommandProcessor; import dev.triumphteam.cmd.core.processor.SubCommandProcessor; import dev.triumphteam.cmd.core.requirement.Requirement; import org.jetbrains.annotations.NotNull; @@ -19,6 +22,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.function.BiFunction; import java.util.function.Supplier; public class SubCommand implements ExecutableCommand { @@ -28,6 +32,7 @@ public class SubCommand implements ExecutableCommand { private final List> requirements; private final String name; + private final String syntax; private final CommandMeta meta; private final boolean containsLimitless; @@ -41,7 +46,8 @@ public class SubCommand implements ExecutableCommand { public SubCommand( final @NotNull Object invocationInstance, final @NotNull Method method, - final @NotNull SubCommandProcessor processor + final @NotNull SubCommandProcessor processor, + final @NotNull Command parentCommand ) { this.invocationInstance = invocationInstance; this.method = method; @@ -56,6 +62,10 @@ public SubCommand( this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); this.senderExtension = processor.getCommandExtensions().getSenderExtension(); this.commandExecutor = processor.getCommandExtensions().getCommandExecutor(); + + this.syntax = createSyntax(parentCommand, processor); + + System.out.println(syntax); } @Override @@ -67,7 +77,7 @@ public void execute( final @NotNull List arguments ) throws Throwable { if (!senderExtension.validate(messageRegistry, this, sender)) return; - if (!meetRequirements(sender, commandPath, arguments)) return; + if (!meetRequirements(sender)) return; // Creates the invoking arguments list final List invokeArguments = new ArrayList<>(); @@ -78,7 +88,7 @@ public void execute( } if ((!containsLimitless) && arguments.size() >= invokeArguments.size()) { - messageRegistry.sendMessage(MessageKey.TOO_MANY_ARGUMENTS, sender, new BasicMessageContext(commandPath, arguments)); + messageRegistry.sendMessage(MessageKey.TOO_MANY_ARGUMENTS, sender, new BasicMessageContext(meta)); return; } @@ -100,6 +110,11 @@ public void execute( return name; } + @Override + public @NotNull String getSyntax() { + return syntax; + } + @Override public @NotNull Object getInvocationInstance() { return invocationInstance; @@ -137,13 +152,10 @@ private boolean validateAndCollectArguments( final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument; final List leftOvers = leftOvers(commandArgs, i); - final Object result = limitlessArgument.resolve(sender, leftOvers); - - if (result == null) { - return false; - } - - invokeArguments.add(result); + limitlessArgument.resolve(sender, leftOvers).fold( + invokeArguments::add, + context -> {} + ); return true; } @@ -160,21 +172,27 @@ private boolean validateAndCollectArguments( continue; } - messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new BasicMessageContext(commandPath, commandArgs)); + messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new BasicMessageContext(meta)); return false; } - final Object result = stringArgument.resolve(sender, arg); - if (result == null) { + final @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> result + = stringArgument.resolve(sender, arg); + + if (result instanceof Result.Failure) { messageRegistry.sendMessage( MessageKey.INVALID_ARGUMENT, sender, - new InvalidArgumentContext(commandPath, commandArgs, arg, internalArgument.getName(), internalArgument.getType()) + ((Result.Failure<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>>) result) + .getFail() + .apply(meta, syntax) ); return false; } - invokeArguments.add(result); + if (result instanceof Result.Success) { + invokeArguments.add(((Result.Success<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>>) result).getValue()); + } } return true; @@ -186,14 +204,10 @@ private boolean validateAndCollectArguments( * @param sender The sender of the command. * @return Whether all requirements are met. */ - private boolean meetRequirements( - final @NotNull S sender, - final @NotNull List commandPath, - final @NotNull List argumentPath - ) { + private boolean meetRequirements(final @NotNull S sender) { for (final Requirement requirement : requirements) { if (!requirement.isMet(sender)) { - requirement.sendMessage(messageRegistry, sender, commandPath, argumentPath); + requirement.sendMessage(messageRegistry, sender, meta); return false; } } @@ -224,4 +238,19 @@ private boolean meetRequirements( if (from > list.size()) return Collections.emptyList(); return list.subList(from, list.size()); } + + private @NotNull String createSyntax(final @NotNull Command parentCommand, final @NotNull CommandProcessor processor) { + final Syntax syntaxAnnotation = processor.getSyntaxAnnotation(); + if (syntaxAnnotation != null) return syntaxAnnotation.value(); + + final StringBuilder builder = new StringBuilder(parentCommand.getSyntax()); + + if (!dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME.equals(name)) { + builder.append(" ").append(name); + } + + arguments.forEach(argument -> builder.append(" ").append("<").append(argument.getName()).append(">")); + + return builder.toString(); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java new file mode 100644 index 00000000..c9748b93 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java @@ -0,0 +1,47 @@ +package dev.triumphteam.cmd.core.extention; + +import org.jetbrains.annotations.NotNull; + +import java.util.function.Consumer; + +public interface Result { + + default void fold( + final @NotNull Consumer onSuccess, + final @NotNull Consumer onFailure + ) { + if (this instanceof Success) { + onSuccess.accept(((Success) this).getValue()); + return; + } + + if (this instanceof Failure) { + onFailure.accept(((Failure) this).getFail()); + } + } + + final class Success implements Result { + private final V value; + + public Success(final @NotNull V value) { + this.value = value; + } + + public @NotNull V getValue() { + return value; + } + } + + final class Failure implements Result { + private final F fail; + + public Failure(final @NotNull F fail) { + this.fail = fail; + } + + public @NotNull F getFail() { + return fail; + } + } +} + diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java index 77ee10a6..90ac5a8d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java @@ -11,6 +11,9 @@ */ public final class MetaKey extends StringKey { + public static final MetaKey NAME = new MetaKey<>("command.name", String.class); + public static final MetaKey DESCRIPTION = new MetaKey<>("command.description", String.class); + private final Class valueType; private MetaKey( diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java index 05e19f0d..d0183f47 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java @@ -23,47 +23,22 @@ */ package dev.triumphteam.cmd.core.message.context; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; -import java.util.List; - /** * The default most keys will use, only contains the most basic data. */ public class BasicMessageContext implements MessageContext { - private final List commandPath; - private final List argumentPath; - - public BasicMessageContext( - final @NotNull List commandPath, - final @NotNull List argumentPath - ) { - this.commandPath = commandPath; - this.argumentPath = argumentPath; - } + private final CommandMeta meta; - /** - * {@inheritDoc} - */ - @Override - public @NotNull List getCommandPath() { - return commandPath; - } - - /** - * {@inheritDoc} - */ - @Override - public @NotNull List getArgumentPath() { - return argumentPath; + public BasicMessageContext(final @NotNull CommandMeta meta) { + this.meta = meta; } @Override - public String toString() { - return "BasicMessageContext{" + - "commandPath=" + commandPath + - ", argumentPath=" + argumentPath + - '}'; + public @NotNull CommandMeta getMeta() { + return meta; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java index ebfb2eee..dc378c3c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java @@ -23,30 +23,35 @@ */ package dev.triumphteam.cmd.core.message.context; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; -import java.util.List; - /** * Context for when user types an invalid argument based on its type. */ public final class InvalidArgumentContext extends InvalidInputContext { + private final String syntax; private final String name; private final Class type; public InvalidArgumentContext( - final @NotNull List commandPath, - final @NotNull List argumentPath, + final @NotNull CommandMeta meta, + final @NotNull String syntax, final @NotNull String invalidInput, final @NotNull String name, final @NotNull Class type ) { - super(commandPath, argumentPath, invalidInput); + super(meta, invalidInput); + this.syntax = syntax; this.name = name; this.type = type; } + public @NotNull String getSyntax() { + return syntax; + } + public @NotNull String getArgumentName() { return name; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidCommandContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidCommandContext.java index 02b25ea7..3eef2ecc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidCommandContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidCommandContext.java @@ -23,20 +23,18 @@ */ package dev.triumphteam.cmd.core.message.context; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; -import java.util.List; - /** * Context for when user types an invalid argument based on its type. */ public final class InvalidCommandContext extends InvalidInputContext { public InvalidCommandContext( - final @NotNull List commandPath, - final @NotNull List argumentPath, + final @NotNull CommandMeta meta, final @NotNull String invalidInput ) { - super(commandPath, argumentPath, invalidInput); + super(meta, invalidInput); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java index eb22e0dd..ef67ccff 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java @@ -23,23 +23,21 @@ */ package dev.triumphteam.cmd.core.message.context; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; -import java.util.List; - /** * Context with an invalid input. */ -public abstract class InvalidInputContext extends BasicMessageContext { +abstract class InvalidInputContext extends BasicMessageContext { private final String invalidInput; public InvalidInputContext( - final @NotNull List commandPath, - final @NotNull List argumentPath, + final @NotNull CommandMeta meta, final @NotNull String invalidInput ) { - super(commandPath, argumentPath); + super(meta); this.invalidInput = invalidInput; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java index d21cb8bd..d37ccc24 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/MessageContext.java @@ -23,16 +23,16 @@ */ package dev.triumphteam.cmd.core.message.context; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; -import java.util.List; - /** * Contains specific data for error handling. */ public interface MessageContext { - @NotNull List getCommandPath(); - - @NotNull List getArgumentPath(); + /** + * @return The command's meta. + */ + @NotNull CommandMeta getMeta(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index d32e9274..396abf28 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -30,6 +30,7 @@ import dev.triumphteam.cmd.core.annotations.Join; import dev.triumphteam.cmd.core.annotations.Optional; import dev.triumphteam.cmd.core.annotations.Split; +import dev.triumphteam.cmd.core.annotations.Syntax; import dev.triumphteam.cmd.core.argument.ArgumentResolver; import dev.triumphteam.cmd.core.argument.CollectionInternalArgument; import dev.triumphteam.cmd.core.argument.EnumInternalArgument; @@ -44,6 +45,7 @@ import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; +import dev.triumphteam.cmd.core.argument.keyed.internal.ListArgument; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; @@ -66,6 +68,7 @@ import java.lang.reflect.Type; import java.lang.reflect.WildcardType; import java.util.Arrays; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -84,9 +87,10 @@ abstract class AbstractCommandProcessor implements CommandProcessor { private static final Set> SUPPORTED_COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); - private final String parentName; private final Object invocationInstance; private final String name; + private final String description; + private final Syntax syntax; private final AnnotatedElement annotatedElement; private final RegistryContainer registryContainer; @@ -98,23 +102,24 @@ abstract class AbstractCommandProcessor implements CommandProcessor { private final CommandMeta parentMeta; AbstractCommandProcessor( - final @NotNull String parentName, final @NotNull Object invocationInstance, final @NotNull AnnotatedElement annotatedElement, final @NotNull RegistryContainer registryContainer, final @NotNull CommandExtensions commandExtensions, final @NotNull CommandMeta parentMeta ) { - this.parentName = parentName; this.invocationInstance = invocationInstance; this.annotatedElement = annotatedElement; this.name = nameOf(); + this.description = descriptionOf(); this.parentMeta = parentMeta; this.commandExtensions = commandExtensions; this.registryContainer = registryContainer; this.suggestionRegistry = registryContainer.getSuggestionRegistry(); this.argumentRegistry = registryContainer.getArgumentRegistry(); + + this.syntax = annotatedElement.getAnnotation(Syntax.class); } public @NotNull RegistryContainer getRegistryContainer() { @@ -129,6 +134,11 @@ abstract class AbstractCommandProcessor implements CommandProcessor { return parentMeta; } + @Override + public @Nullable Syntax getSyntaxAnnotation() { + return syntax; + } + @Contract("_ -> new") protected @NotNull SubCommandRegistrationException createException(final @NotNull String message) { return new SubCommandRegistrationException(message, annotatedElement, invocationInstance.getClass()); @@ -146,9 +156,13 @@ abstract class AbstractCommandProcessor implements CommandProcessor { public @Nullable String getName() { return name; } - // TODO COMMENTS - protected @NotNull InternalArgument createArgument( + public String getDescription() { + return description; + } + + // TODO COMMENTS + protected @NotNull InternalArgument argumentFromParameter( final @NotNull Parameter parameter, final @NotNull List argDescriptions, final @NotNull Map> suggestions, @@ -226,7 +240,14 @@ abstract class AbstractCommandProcessor implements CommandProcessor { } } - return new KeyedInternalArgument<>(argumentName, argumentDescription, flagGroup, argumentGroup); + return new KeyedInternalArgument<>( + argumentName, + argumentDescription, + createFlagInternals(flagGroup), + createNamedArgumentInternals(argumentGroup), + flagGroup, + argumentGroup + ); } // No more exceptions found so now just create simple argument @@ -241,8 +262,8 @@ abstract class AbstractCommandProcessor implements CommandProcessor { protected @NotNull InternalArgument createSimpleArgument( final @NotNull Class type, - final @NotNull String parameterName, - final @NotNull String argumentDescription, + final @NotNull String name, + final @NotNull String description, final @NotNull Suggestion suggestion, final boolean optional ) { @@ -253,8 +274,8 @@ abstract class AbstractCommandProcessor implements CommandProcessor { if (Enum.class.isAssignableFrom(type)) { //noinspection unchecked return new EnumInternalArgument<>( - parameterName, - argumentDescription, + name, + description, (Class>) type, suggestion, optional @@ -264,8 +285,8 @@ abstract class AbstractCommandProcessor implements CommandProcessor { return new UnknownInternalArgument<>(type); } return new ResolverInternalArgument<>( - parameterName, - argumentDescription, + name, + description, type, resolver, suggestion, @@ -273,6 +294,80 @@ abstract class AbstractCommandProcessor implements CommandProcessor { ); } + private Map> createFlagInternals(final @NotNull ArgumentGroup group) { + final Map> internalArguments = new HashMap<>(); + + for (final Flag flag : group.getAll()) { + final Class argType = flag.getArgument(); + if (argType == null) continue; + + final Suggestion suggestion = createSuggestion(flag.getSuggestion(), argType); + + internalArguments.put( + flag, + createSimpleArgument( + argType, + "", + flag.getDescription(), + suggestion, + true + ) + ); + } + + return internalArguments; + } + + private Map> createNamedArgumentInternals(final @NotNull ArgumentGroup group) { + final Map> internalArguments = new HashMap<>(); + + for (final Argument argument : group.getAll()) { + final Class argType = argument.getType(); + + final Suggestion suggestion = createSuggestion(argument.getSuggestion(), argType); + + if (argument instanceof ListArgument) { + final ListArgument listArgument = (ListArgument) argument; + + final InternalArgument internalArgument = createSimpleArgument( + listArgument.getType(), + listArgument.getName(), + listArgument.getDescription(), + suggestion, + true + ); + + internalArguments.put( + argument, + new SplitStringInternalArgument<>( + listArgument.getName(), + listArgument.getDescription(), + listArgument.getSeparator(), + internalArgument, + listArgument.getType(), + suggestion, + true + ) + ); + + continue; + } + + internalArguments.put( + argument, + createSimpleArgument( + argType, + argument.getName(), + argument.getDescription(), + suggestion, + true + ) + ); + } + + return internalArguments; + } + /** * Gets the internalArgument name, either from the parameter or from the annotation. * If the parameter is not annotated, turn the name from Camel Case to "lower-hyphen". @@ -310,6 +405,14 @@ abstract class AbstractCommandProcessor implements CommandProcessor { return ""; } + private @NotNull String descriptionOf() { + final Class commandClass = invocationInstance.getClass(); + final Description descriptionAnnotation = commandClass.getAnnotation(Description.class); + + if (descriptionAnnotation != null) return descriptionAnnotation.value(); + return ""; + } + private @NotNull Class getGenericType(final @NotNull Parameter parameter) { final Class type = parameter.getType(); if (SUPPORTED_COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { @@ -327,14 +430,14 @@ abstract class AbstractCommandProcessor implements CommandProcessor { return type; } - protected @Nullable Suggestion createSuggestion(final @Nullable SuggestionKey suggestionKey, final @NotNull Class type) { + protected @NotNull Suggestion createSuggestion(final @Nullable SuggestionKey suggestionKey, final @NotNull Class type) { if (suggestionKey == null) { if (Enum.class.isAssignableFrom(type)) return new EnumSuggestion<>((Class>) type); final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(type); if (resolver != null) return new SimpleSuggestion<>(resolver); - return null; + return new EmptySuggestion<>(); } final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(suggestionKey); @@ -349,10 +452,7 @@ abstract class AbstractCommandProcessor implements CommandProcessor { final SuggestionKey suggestionKey = parameterAnnotation == null ? null : SuggestionKey.of(parameterAnnotation.value()); final Class type = getGenericType(parameter); - final Suggestion suggestion = createSuggestion(suggestionKey, type); - - if (suggestion == null) return new EmptySuggestion<>(); - return suggestion; + return createSuggestion(suggestionKey, type); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java index 5f1bb6b2..831c9511 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java @@ -27,8 +27,10 @@ import dev.triumphteam.cmd.core.AnnotatedCommand; import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.core.annotations.Description; +import dev.triumphteam.cmd.core.annotations.Syntax; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; import dev.triumphteam.cmd.core.command.ExecutableCommand; import dev.triumphteam.cmd.core.command.ParentSubCommand; @@ -37,9 +39,10 @@ import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.meta.MetaKey; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.lang.reflect.Constructor; import java.lang.reflect.Method; @@ -59,6 +62,7 @@ public abstract class AbstractRootCommandProcessor implements CommandProcesso private final Object invocationInstance; private final String name; + private final Syntax syntax; private final List alias; private final String description; @@ -78,6 +82,8 @@ public AbstractRootCommandProcessor( this.registryContainer = registryContainer; this.commandExtensions = commandExtensions; + + this.syntax = invocationInstance.getClass().getAnnotation(Syntax.class); } public String getName() { @@ -92,10 +98,19 @@ public String getDescription() { return description; } - @Contract(" -> new") + @Override + public @Nullable Syntax getSyntaxAnnotation() { + return syntax; + } + @Override public @NotNull CommandMeta createMeta() { final CommandMeta.Builder meta = new CommandMeta.Builder(null); + + // Defaults + meta.add(MetaKey.NAME, getName()); + meta.add(MetaKey.DESCRIPTION, getDescription()); + // Process all the class annotations final Class klass = invocationInstance.getClass(); processAnnotations(commandExtensions, klass, ProcessorTarget.ROOT_COMMAND, meta); @@ -104,18 +119,18 @@ public String getDescription() { return meta.build(); } - public @NotNull List> commands(final @NotNull CommandMeta parentMeta) { + public @NotNull List> commands(final @NotNull dev.triumphteam.cmd.core.command.Command parentCommand) { final Class klass = invocationInstance.getClass(); final List> subCommands = new ArrayList<>(); - subCommands.addAll(methodCommands(parentMeta, klass.getDeclaredMethods())); - subCommands.addAll(classCommands(parentMeta, klass.getDeclaredClasses())); + subCommands.addAll(methodCommands(parentCommand, klass.getDeclaredMethods())); + subCommands.addAll(classCommands(parentCommand, klass.getDeclaredClasses())); return subCommands; } private @NotNull List> methodCommands( - final @NotNull CommandMeta parentMeta, + final @NotNull dev.triumphteam.cmd.core.command.Command parentCommand, final @NotNull Method[] methods ) { final List> commands = new ArrayList<>(); @@ -124,26 +139,25 @@ public String getDescription() { if (!Modifier.isPublic(method.getModifiers())) continue; final SubCommandProcessor processor = new SubCommandProcessor<>( - name, invocationInstance, method, registryContainer, commandExtensions, - parentMeta + parentCommand.getMeta() ); // Not a command, ignore the method if (processor.getName() == null) continue; // Add new command - commands.add(new SubCommand<>(invocationInstance, method, processor)); + commands.add(new SubCommand<>(invocationInstance, method, processor, parentCommand)); } return commands; } private @NotNull List> classCommands( - final @NotNull CommandMeta parentMeta, + final @NotNull dev.triumphteam.cmd.core.command.Command parentCommand, final @NotNull Class[] classes ) { final List> commands = new ArrayList<>(); @@ -152,12 +166,11 @@ public String getDescription() { if (!Modifier.isPublic(klass.getModifiers())) continue; final ParentCommandProcessor processor = new ParentCommandProcessor<>( - name, invocationInstance, klass, registryContainer, commandExtensions, - parentMeta + parentCommand.getMeta() ); // Not a command, ignore the method @@ -189,7 +202,7 @@ public String getDescription() { } final Parameter parameter = isStatic ? parameters[0] : parameters[1]; - argument = processor.createArgument( + argument = processor.argumentFromParameter( parameter, emptyList(), emptyMap(), @@ -199,15 +212,27 @@ public String getDescription() { ); if (!(argument instanceof StringInternalArgument)) { + // Unknown types by default throw + if (argument instanceof UnknownInternalArgument) { + throw new CommandRegistrationException("No internalArgument of type \"" + argument.getType().getName() + "\" registered", klass); + } + throw new CommandRegistrationException("Inner command class with argument must not be limitless, only single string argument is allowed", klass); } } - final ParentSubCommand parent = new ParentSubCommand<>(invocationInstance, constructor, isStatic, (StringInternalArgument) argument, processor); + final ParentSubCommand parent = new ParentSubCommand<>( + invocationInstance, + constructor, + isStatic, + (StringInternalArgument) argument, + processor, + parentCommand + ); // Add children commands to parent - methodCommands(parent.getMeta(), klass.getDeclaredMethods()).forEach(it -> parent.addSubCommand(it, false)); - classCommands(parent.getMeta(), klass.getDeclaredClasses()).forEach(it -> parent.addSubCommand(it, false)); + methodCommands(parent, klass.getDeclaredMethods()).forEach(it -> parent.addSubCommand(it, false)); + classCommands(parent, klass.getDeclaredClasses()).forEach(it -> parent.addSubCommand(it, false)); // Add parent command to main list commands.add(parent); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index d1b39581..d092fcee 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -1,10 +1,12 @@ package dev.triumphteam.cmd.core.processor; +import dev.triumphteam.cmd.core.annotations.Syntax; import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; @@ -19,6 +21,8 @@ public interface CommandProcessor { */ @NotNull CommandMeta createMeta(); + @Nullable Syntax getSyntaxAnnotation(); + /** * Process all annotations for the specific {@link AnnotatedElement}. * diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java index 86d298c7..9a26c5c4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java @@ -26,6 +26,7 @@ import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.meta.MetaKey; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import org.jetbrains.annotations.NotNull; @@ -43,14 +44,13 @@ public final class ParentCommandProcessor extends AbstractCommandProcessor private final Class klass; ParentCommandProcessor( - final @NotNull String parentName, final @NotNull Object invocationInstance, final @NotNull Class klass, final @NotNull RegistryContainer registryContainer, final @NotNull CommandExtensions commandExtensions, final @NotNull CommandMeta parentMeta ) { - super(parentName, invocationInstance, klass, registryContainer, commandExtensions, parentMeta); + super(invocationInstance, klass, registryContainer, commandExtensions, parentMeta); this.klass = klass; } @@ -58,6 +58,11 @@ public final class ParentCommandProcessor extends AbstractCommandProcessor @Override public @NotNull CommandMeta createMeta() { final CommandMeta.Builder meta = new CommandMeta.Builder(getParentMeta()); + + // Defaults + meta.add(MetaKey.NAME, getName()); + meta.add(MetaKey.DESCRIPTION, getDescription()); + // Process all the class annotations processAnnotations(getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); processCommandMeta(getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index 5634ef08..b62f4668 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -38,6 +38,7 @@ import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.meta.MetaKey; import dev.triumphteam.cmd.core.extention.registry.FlagRegistry; import dev.triumphteam.cmd.core.extention.registry.NamedArgumentRegistry; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; @@ -85,14 +86,13 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { private final FlagRegistry flagRegistry; SubCommandProcessor( - final @NotNull String parentName, final @NotNull Object invocationInstance, final @NotNull Method method, final @NotNull RegistryContainer registryContainer, final @NotNull CommandExtensions commandExtensions, final @NotNull CommandMeta parentMeta ) { - super(parentName, invocationInstance, method, registryContainer, commandExtensions, parentMeta); + super(invocationInstance, method, registryContainer, commandExtensions, parentMeta); this.method = method; this.namedArgumentRegistry = registryContainer.getNamedArgumentRegistry(); @@ -103,6 +103,11 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { @Override public @NotNull CommandMeta createMeta() { final CommandMeta.Builder meta = new CommandMeta.Builder(getParentMeta()); + + // Defaults + meta.add(MetaKey.NAME, getName()); + meta.add(MetaKey.DESCRIPTION, getDescription()); + // Process all the class annotations processAnnotations(getCommandExtensions(), method, ProcessorTarget.COMMAND, meta); processCommandMeta(getCommandExtensions(), method, ProcessorTarget.COMMAND, meta); @@ -173,7 +178,7 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { for (int i = 1; i < parameters.length; i++) { final Parameter parameter = parameters[i]; - final InternalArgument argument = createArgument( + final InternalArgument argument = argumentFromParameter( parameter, argDescriptions, suggestions, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java index 39362eae..b64bdeda 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java @@ -23,15 +23,15 @@ */ package dev.triumphteam.cmd.core.requirement; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.ContextualKey; import dev.triumphteam.cmd.core.message.context.MessageContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; import java.util.Objects; -import java.util.function.BiFunction; +import java.util.function.Function; /** * Contains the data for the requirement. @@ -42,13 +42,13 @@ public final class Requirement { private final RequirementResolver resolver; private final ContextualKey messageKey; - private final BiFunction, List, C> contextFactory; + private final Function contextFactory; private final boolean invert; public Requirement( final @NotNull RequirementResolver resolver, final @Nullable ContextualKey messageKey, - final @NotNull BiFunction, List, C> contextFactory, + final @NotNull Function contextFactory, final boolean invert ) { this.resolver = resolver; @@ -67,14 +67,13 @@ public Requirement( } // TODO - public void sendMessage( - final @NotNull MessageRegistry registry, - final @NotNull ST sender, - final @NotNull List commandPath, - final @NotNull List argumentPath + public void sendMessage( + final @NotNull MessageRegistry registry, + final @NotNull S sender, + final @NotNull CommandMeta meta ) { if (messageKey == null) return; - registry.sendMessage(messageKey, sender, contextFactory.apply(commandPath, argumentPath)); + registry.sendMessage(messageKey, sender, contextFactory.apply(meta)); } /** diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a1572510..38c2d19a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] # kotlin -kotlin = "1.7.21" +kotlin = "1.8.0" coroutines = "1.6.4" license = "0.16.1" diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index 6b5961f5..b7913752 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -41,11 +41,10 @@ import java.util.List; import java.util.Map; -import static java.util.Collections.emptyList; - public final class SimpleCommand implements ParentCommand { private final String name; + private final String syntax; private final MessageRegistry messageRegistry; @@ -64,6 +63,7 @@ public SimpleCommand( this.meta = processor.createMeta(); this.messageRegistry = messageRegistry; + this.syntax = "/" + name; } @Override @@ -95,7 +95,7 @@ public void execute( final List commandPath = new ArrayList<>(); if (subCommand == null) { - messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(commandPath, emptyList(), commandName)); + messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(meta, commandName)); return; } @@ -121,6 +121,11 @@ public void execute( return name; } + @Override + public @NotNull String getSyntax() { + return syntax; + } + @Override public @Nullable ExecutableCommand getParentCommandWithArgument() { return parentCommandWithArgument; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index f6816c8c..a4307c83 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -25,6 +25,7 @@ import dev.triumphteam.cmd.core.CommandManager; import dev.triumphteam.cmd.core.extention.CommandOptions; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.InvalidCommandContext; @@ -36,8 +37,6 @@ import java.util.Map; import java.util.function.Consumer; -import static java.util.Collections.emptyList; - public final class SimpleCommandManager extends CommandManager { private final Map> commands = new HashMap<>(); @@ -73,12 +72,12 @@ public void registerCommand(final @NotNull Object command) { // Command does not exist, proceed to add new! final SimpleCommand newSimpleCommand = commands.computeIfAbsent(processor.getName(), it -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); - processor.commands(newSimpleCommand.getMeta()).forEach(it -> newSimpleCommand.addSubCommand(it, false)); + processor.commands(newSimpleCommand).forEach(it -> newSimpleCommand.addSubCommand(it, false)); processor.getAlias().forEach(it -> { final SimpleCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); // Adding sub commands. - processor.commands(newSimpleCommand.getMeta()).forEach(sub -> aliasCommand.addSubCommand(sub, false)); + processor.commands(aliasCommand).forEach(sub -> aliasCommand.addSubCommand(sub, false)); }); } @@ -110,7 +109,8 @@ public void executeCommand(final @NotNull S sender, final @NotNull List registryContainer.getMessageRegistry().sendMessage( MessageKey.UNKNOWN_COMMAND, sender, - new InvalidCommandContext(emptyList(), emptyList(), commandName) + // Empty meta + new InvalidCommandContext(new CommandMeta.Builder(null).build(), commandName) ); return; } From 76e8151dfb76ea78043cd1201138780b61d87401 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 18 Jan 2023 00:41:23 +0000 Subject: [PATCH 051/101] feature: Flag and Named argument internal argument --- .../triumphteam/cmd/core/CommandManager.java | 4 +- .../core/argument/FlagInternalArgument.java | 4 +- .../argument/UnknownInternalArgument.java | 33 +---- .../keyed/{internal => }/Argument.java | 2 +- .../keyed/{internal => }/ArgumentGroup.java | 2 +- .../keyed/{internal => }/ArgumentParser.java | 4 +- .../keyed/{internal => }/ArgumentValue.java | 2 +- .../cmd/core/argument/keyed/Arguments.java | 40 ++++-- .../{internal => }/EmptyArgumentValue.java | 7 +- .../argument/keyed/{internal => }/Flag.java | 2 +- .../keyed/{internal => }/FlagGroup.java | 2 +- .../keyed/{internal => }/FlagOptions.java | 11 +- .../keyed/{internal => }/FlagValidator.java | 2 +- .../cmd/core/argument/keyed/Flags.java | 31 ++-- .../core/argument/keyed/FlagsContainer.java | 57 ++++++++ .../cmd/core/argument/keyed/Keyed.java | 21 +++ .../core/argument/keyed/KeyedArguments.java | 112 +++++++++++++++ .../{ => keyed}/KeyedInternalArgument.java | 76 ++++++++-- .../keyed/{internal => }/ListArgument.java | 14 +- .../keyed/{internal => }/NamedGroup.java | 2 +- .../keyed/{internal => }/SimpleArgument.java | 12 +- .../{internal => }/SimpleArgumentValue.java | 10 +- .../keyed/internal/FlagsContainer.java | 40 ------ .../argument/keyed/internal/FlagsResult.java | 133 ------------------ .../keyed/internal/KeyedArguments.java | 76 ---------- .../cmd/core/command/SubCommand.java | 41 +++--- .../core/extention/registry/FlagRegistry.java | 2 +- .../registry/NamedArgumentRegistry.java | 2 +- .../processor/AbstractCommandProcessor.java | 26 ++-- .../AbstractRootCommandProcessor.java | 2 +- .../core/processor/SubCommandProcessor.java | 6 +- .../dev/triumphteam/cmd/core/util/Pair.java | 28 ++++ 32 files changed, 425 insertions(+), 381 deletions(-) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/Argument.java (99%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/ArgumentGroup.java (96%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/ArgumentParser.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/ArgumentValue.java (95%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/EmptyArgumentValue.java (90%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/Flag.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/FlagGroup.java (98%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/FlagOptions.java (93%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/FlagValidator.java (98%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagsContainer.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Keyed.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedArguments.java rename core/src/main/java/dev/triumphteam/cmd/core/argument/{ => keyed}/KeyedInternalArgument.java (51%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/ListArgument.java (89%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/NamedGroup.java (97%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/SimpleArgument.java (91%) rename core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/{internal => }/SimpleArgumentValue.java (87%) delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/KeyedArguments.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/util/Pair.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index dfa8bf41..f5644826 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -27,9 +27,9 @@ import dev.triumphteam.cmd.core.argument.keyed.Arguments; import dev.triumphteam.cmd.core.argument.keyed.FlagKey; import dev.triumphteam.cmd.core.argument.keyed.Flags; -import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; +import dev.triumphteam.cmd.core.argument.keyed.Argument; import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; -import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; +import dev.triumphteam.cmd.core.argument.keyed.Flag; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.message.ContextualKey; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java index 8dfa73b2..694b88fa 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java @@ -24,8 +24,8 @@ package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.argument.keyed.Flags; -import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; -import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; +import dev.triumphteam.cmd.core.argument.keyed.ArgumentGroup; +import dev.triumphteam.cmd.core.argument.keyed.Flag; import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index 9ca1b842..1c4e813c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -3,6 +3,7 @@ import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; +import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -15,32 +16,10 @@ * This argument type is always ignored by the creator. * This is only used for arguments that are meant to be hidden and not actually part of a command. */ -public final class UnknownInternalArgument implements InternalArgument { - - private final Class type; +public final class UnknownInternalArgument extends StringInternalArgument { public UnknownInternalArgument(final @NotNull Class type) { - this.type = type; - } - - @Override - public @NotNull String getName() { - return "unknown"; - } - - @Override - public @NotNull String getDescription() { - return "Unknown."; - } - - @Override - public @NotNull Class getType() { - return type; - } - - @Override - public boolean isOptional() { - return false; + super("unknown", "unknown.", type, new EmptySuggestion<>(), false); } @Override @@ -54,9 +33,7 @@ public boolean isOptional() { } @Override - public String toString() { - return "UnknownInternalArgument{" + - "type=" + type + - '}'; + public @NotNull String toString() { + return "UnknownInternalArgument{} " + super.toString(); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Argument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Argument.java similarity index 99% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Argument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Argument.java index 30cf1177..8a970626 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Argument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Argument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java similarity index 96% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java index a3471a48..52d651cd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java @@ -1,4 +1,4 @@ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentParser.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java index cb7d21b6..c3e1d5fa 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; import org.jetbrains.annotations.NotNull; @@ -31,7 +31,7 @@ import java.util.List; import java.util.Map; -public final class ArgumentParser { +final class ArgumentParser { private static final String LONG = "--"; private static final String SHORT = "-"; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentValue.java similarity index 95% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentValue.java index 8fcbb6c5..bd393179 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ArgumentValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentValue.java @@ -21,6 +21,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; interface ArgumentValue {} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Arguments.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Arguments.java index 01b2a97a..6e505647 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Arguments.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Arguments.java @@ -34,28 +34,48 @@ public interface Arguments extends Flags { /** * Gets an argument by name. - * The argument will be an empty {@link Optional} if it does not exist or if the value is invalid. + * The argument will be an empty {@link Optional} if it does not exist. * * @param name The name of the argument. * @param type The class of the type of the argument. * @param The generic type of the argument. * @return An {@link Optional} argument. */ - @NotNull Optional get(final @NotNull String name, final @NotNull Class type); + @NotNull Optional getArgument(final @NotNull String name, final @NotNull Class type); - @NotNull Optional> getAsList(final @NotNull String name, final @NotNull Class type); + /** + * Gets a {@link List} argument by name. + * The argument will be an empty {@link Optional} if it does not exist. + * + * @param name The name of the argument. + * @param type The class of the type of the argument. + * @param The generic type of the argument. + * @return An {@link Optional} argument. + */ + @NotNull Optional> getListArgument(final @NotNull String name, final @NotNull Class type); - @NotNull Optional> getAsSet(final @NotNull String name, final @NotNull Class type); + /** + * Gets a {@link Set} argument by name. + * The argument will be an empty {@link Optional} if it does not exist. + * + * @param name The name of the argument. + * @param type The class of the type of the argument. + * @param The generic type of the argument. + * @return An {@link Optional} argument. + */ + @NotNull Optional> getSetArgument(final @NotNull String name, final @NotNull Class type); /** - * Get all arguments passed to this command - * @return a {@link Map} of all arguments + * Get all arguments passed to this command. + * + * @return a {@link Map} of all arguments. */ - @NotNull Map getArguments(); + @NotNull Map getAllArguments(); /** - * Check if no arguments are passed - * @return true if no arguments have been passed in the command + * Check if arguments were typed. + * + * @return true if any argument was typed in the command. */ - boolean isEmpty(); + boolean hasArguments(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyArgumentValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/EmptyArgumentValue.java similarity index 90% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyArgumentValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/EmptyArgumentValue.java index e514c135..c72682e6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/EmptyArgumentValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/EmptyArgumentValue.java @@ -21,9 +21,14 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; final class EmptyArgumentValue implements ArgumentValue { static final EmptyArgumentValue INSTANCE = new EmptyArgumentValue(); + + @Override + public String toString() { + return "Empty{}"; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Flag.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flag.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Flag.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flag.java index 569088f9..cd1ca304 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/Flag.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flag.java @@ -1,4 +1,4 @@ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagGroup.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagGroup.java index 1b46ec7e..312c188c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagGroup.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagOptions.java similarity index 93% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagOptions.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagOptions.java index 266d8af0..d4b54524 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagOptions.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; @@ -94,7 +94,7 @@ final class FlagOptions implements Flag { @Override public boolean hasArgument() { - return argument != null; + return argument != null && argument != Void.TYPE; } @Override @@ -114,4 +114,11 @@ public boolean equals(final @Nullable Object o) { public int hashCode() { return Objects.hash(flag, longFlag, argument); } + + @Override + public String toString() { + return "FlagOptions{" + + "flag='" + getKey() + '\'' + + '}'; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagValidator.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValidator.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagValidator.java index a4955fea..52d5aacb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagValidator.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flags.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flags.java index 569d81d0..549fba1d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flags.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flags.java @@ -25,19 +25,19 @@ import org.jetbrains.annotations.NotNull; -import java.util.List; import java.util.Optional; +import java.util.Set; /** * Contains all the command flags that was typed by the user in an easy-to-access way. */ -public interface Flags { +public interface Flags extends Keyed { /** * Checks if the flag key is present or not. * Useful for simple flags like -l. * Where you just want to check if the flag was added or not. - * For flag with values recommended {@link Flags#getValue(String, Class)}. + * For flag with values recommended {@link Flags#getFlagValue(String, Class)}. * * @param flag The flag to check. * @return Whether the flag is present in the command or not. @@ -53,35 +53,26 @@ public interface Flags { * @param The value type, based on the class from before. * @return The flag's value. */ - @NotNull Optional getValue(final @NotNull String flag, final @NotNull Class type); + @NotNull Optional getFlagValue(final @NotNull String flag, final @NotNull Class type); /** * Instead of converting the value to the desired type, simply get it as string. * If flag is not present then optional will be empty. + * * @param flag The flag to get the value from. * @return The flag's value. */ - @NotNull Optional getValue(final @NotNull String flag); - - /** - * Gets the arguments typed without the flags, joined to string. - * - * @return The arguments joined to string. - */ - @NotNull String getText(); + @NotNull Optional getFlagValue(final @NotNull String flag); /** - * Gets the arguments typed without the flags, joined to string. - * - * @param delimiter The delimiter of the joining. - * @return The arguments joined to string with a delimiter. + * @return A {@link Set} with the present Flags. */ - @NotNull String getText(final @NotNull String delimiter); + @NotNull Set getAllFlags(); /** - * Gets the arguments typed without the flags. + * Check if flags were typed. * - * @return A {@link List} with the typed arguments. + * @return true if any flag was typed in the command. */ - @NotNull List getArgs(); + boolean hasFlags(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagsContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagsContainer.java new file mode 100644 index 00000000..f7a01713 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagsContainer.java @@ -0,0 +1,57 @@ +package dev.triumphteam.cmd.core.argument.keyed; + +import org.jetbrains.annotations.NotNull; + +import java.util.Map; +import java.util.Optional; +import java.util.Set; + +@SuppressWarnings("unchecked") +abstract class FlagsContainer implements Arguments { + + private final Map flags; + + public FlagsContainer(final @NotNull Map flags) { + this.flags = flags; + } + + @Override + public boolean hasFlag(final @NotNull String flag) { + return flags.containsKey(flag); + } + + @Override + public @NotNull Optional getFlagValue(final @NotNull String flag, final @NotNull Class type) { + final ArgumentValue flagValue = flags.get(flag); + if (flagValue == null) return Optional.empty(); + if (!(flagValue instanceof SimpleArgumentValue)) return Optional.empty(); + final SimpleArgumentValue argFlagValue = (SimpleArgumentValue) flagValue; + return Optional.ofNullable((T) argFlagValue.getValue()); + } + + @Override + public @NotNull Optional getFlagValue(final @NotNull String flag) { + final ArgumentValue flagValue = flags.get(flag); + if (flagValue == null) return Optional.empty(); + if (!(flagValue instanceof SimpleArgumentValue)) return Optional.empty(); + final SimpleArgumentValue argFlagValue = (SimpleArgumentValue) flagValue; + return Optional.of(argFlagValue.getAsString()); + } + + @Override + public @NotNull Set getAllFlags() { + return flags.keySet(); + } + + @Override + public boolean hasFlags() { + return !flags.isEmpty(); + } + + @Override + public String toString() { + return "FlagsContainer{" + + "flags=" + flags + + '}'; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Keyed.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Keyed.java new file mode 100644 index 00000000..e2092165 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Keyed.java @@ -0,0 +1,21 @@ +package dev.triumphteam.cmd.core.argument.keyed; + +import org.jetbrains.annotations.NotNull; + +public interface Keyed { + + /** + * Gets the arguments typed without the flags, joined to string. + * + * @return The arguments joined to string. + */ + @NotNull String getText(); + + /** + * Gets the arguments typed without the flags, joined to string. + * + * @param delimiter The delimiter of the joining. + * @return The arguments joined to string with a delimiter. + */ + @NotNull String getText(final @NotNull String delimiter); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedArguments.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedArguments.java new file mode 100644 index 00000000..800400b6 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedArguments.java @@ -0,0 +1,112 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.argument.keyed; + +import dev.triumphteam.cmd.core.util.Pair; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +@SuppressWarnings("unchecked") +public final class KeyedArguments extends FlagsContainer { + + private final Map values; + private final List nonTokens; + + public KeyedArguments( + final @NotNull Map values, + final @NotNull Map flags, + final @NotNull List nonTokens + ) { + super(flags); + this.values = values; + this.nonTokens = nonTokens; + } + + @Override + public @NotNull Optional getArgument(final @NotNull String name, final @NotNull Class type) { + return Optional.ofNullable((T) getValue(name)); + } + + @Override + public @NotNull Optional> getListArgument(final @NotNull String name, final @NotNull Class type) { + final List value = (List) getValue(name); + return Optional.ofNullable(value); + } + + @Override + public @NotNull Optional> getSetArgument(final @NotNull String name, final @NotNull Class type) { + final Set value = (Set) getValue(name); + return Optional.ofNullable(value); + } + + private @Nullable Object getValue(final @NotNull String name) { + final ArgumentValue argumentValue = values.get(name); + if (argumentValue == null) return null; + + if (argumentValue instanceof SimpleArgumentValue) { + return ((SimpleArgumentValue) argumentValue).getValue(); + } + + return null; + } + + @Override + public @NotNull Map getAllArguments() { + return values.entrySet().stream().map(entry -> { + final ArgumentValue value = entry.getValue(); + if (value instanceof SimpleArgumentValue) { + return new Pair<>(entry.getKey(), ((SimpleArgumentValue) value).getValue()); + } + return new Pair<>(entry.getKey(), null); + }).collect(Collectors.toMap(Pair::first, Pair::second)); + } + + @Override + public @NotNull String getText() { + return getText(" "); + } + + @Override + public @NotNull String getText(final @NotNull String delimiter) { + return String.join(delimiter, nonTokens); + } + + @Override + public boolean hasArguments() { + return !values.isEmpty(); + } + + @Override + public @NotNull String toString() { + return "Arguments{" + + "values=" + values + + ", super=" + super.toString() + "}"; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java similarity index 51% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java index 61e1e122..7bde5f56 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/KeyedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java @@ -21,13 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument; +package dev.triumphteam.cmd.core.argument.keyed; -import dev.triumphteam.cmd.core.argument.keyed.Flags; -import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; -import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; -import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentParser; -import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; +import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; @@ -37,23 +34,26 @@ import org.jetbrains.annotations.Nullable; import java.util.Collections; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.BiFunction; public final class KeyedInternalArgument extends LimitlessInternalArgument { - private final Map> flagInternalArguments; - private final Map> argumentInternalArguments; + private final Map> flagInternalArguments; + private final Map> argumentInternalArguments; + private final ArgumentGroup argumentGroup; private final ArgumentGroup flagGroup; + private final ArgumentParser argumentParser; public KeyedInternalArgument( final @NotNull String name, final @NotNull String description, - final @NotNull Map> flagInternalArguments, - final @NotNull Map> argumentInternalArguments, + final @NotNull Map> flagInternalArguments, + final @NotNull Map> argumentInternalArguments, final @NotNull ArgumentGroup flagGroup, final @NotNull ArgumentGroup argumentGroup ) { @@ -78,9 +78,61 @@ public KeyedInternalArgument( final @NotNull List value ) { final ArgumentParser.Result result = argumentParser.parse(value); - - return null;// flagParser.parse(sender, value.size() == 1 ? Arrays.asList(value.get(0).split(" ")) : value); + // Parsing and validating named arguments + final Map arguments = new HashMap<>(); + for (final Map.Entry entry : result.getNamedArguments().entrySet()) { + final Argument argument = entry.getKey(); + final String raw = entry.getValue(); + + final StringInternalArgument internalArgument = argumentInternalArguments.get(argument); + if (internalArgument == null) continue; + + final Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolved = + internalArgument.resolve(sender, entry.getValue()); + + if (resolved instanceof Result.Failure) { + return resolved; + } + + if (resolved instanceof Result.Success) { + final Object resolvedValue = ((Result.Success>) resolved).getValue(); + arguments.put(argument.getName(), new SimpleArgumentValue(raw, resolvedValue)); + } + } + + // Parsing and validating flags + final Map flags = new HashMap<>(); + for (final Map.Entry entry : result.getFlags().entrySet()) { + final Flag flag = entry.getKey(); + final String raw = entry.getValue(); + + if (!flag.hasArgument()) { + flags.put(flag.getFlag(), EmptyArgumentValue.INSTANCE); + flags.put(flag.getLongFlag(), EmptyArgumentValue.INSTANCE); + continue; + } + + final StringInternalArgument internalArgument = flagInternalArguments.get(flag); + if (internalArgument == null) continue; + + final Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolved = + internalArgument.resolve(sender, entry.getValue()); + + if (resolved instanceof Result.Failure) { + return resolved; + } + + if (resolved instanceof Result.Success) { + final Object resolvedValue = ((Result.Success>) resolved).getValue(); + + final ArgumentValue argumentValue = new SimpleArgumentValue(raw, resolvedValue); + flags.put(flag.getFlag(), argumentValue); + flags.put(flag.getLongFlag(), argumentValue); + } + } + + return success(new KeyedArguments(arguments, flags, result.getNonTokens())); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ListArgument.java similarity index 89% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ListArgument.java index bee4d47d..270bbe9e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/ListArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ListArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; @@ -31,10 +31,10 @@ public final class ListArgument implements Argument { + private final String name; private final Class collectionType; private final String separator; private final Class type; - private final String name; private final String description; private final SuggestionKey suggestionKey; @@ -88,4 +88,14 @@ public boolean equals(final @Nullable Object o) { public int hashCode() { return Objects.hash(collectionType, separator, type, name); } + + @Override + public String toString() { + return "ListArgument{" + + "name='" + name + '\'' + + ", collectionType=" + collectionType + + ", separator='" + separator + '\'' + + ", type=" + type + + '}'; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/NamedGroup.java similarity index 97% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/NamedGroup.java index 057119de..85c3156f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/NamedGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/NamedGroup.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/SimpleArgument.java similarity index 91% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/SimpleArgument.java index 34dd7933..679aa598 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/SimpleArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; @@ -31,8 +31,8 @@ final class SimpleArgument implements Argument { - private final Class type; private final String name; + private final Class type; private final String description; private final SuggestionKey suggestionKey; @@ -75,4 +75,12 @@ public boolean equals(final @Nullable Object o) { public int hashCode() { return Objects.hash(type, name); } + + @Override + public String toString() { + return "SimpleArgument{" + + "name='" + name + '\'' + + ", type=" + type + + '}'; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgumentValue.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/SimpleArgumentValue.java similarity index 87% rename from core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgumentValue.java rename to core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/SimpleArgumentValue.java index f6407207..063a80bd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/SimpleArgumentValue.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/SimpleArgumentValue.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.argument.keyed.internal; +package dev.triumphteam.cmd.core.argument.keyed; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -43,4 +43,12 @@ public SimpleArgumentValue(final @NotNull String rawValue, final @NotNull Object public @NotNull String getAsString() { return rawValue; } + + @Override + public String toString() { + return "Simple{" + + "rawValue='" + rawValue + '\'' + + ", value=" + value + + '}'; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java deleted file mode 100644 index 0d55a07a..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsContainer.java +++ /dev/null @@ -1,40 +0,0 @@ -package dev.triumphteam.cmd.core.argument.keyed.internal; - -import dev.triumphteam.cmd.core.argument.keyed.Arguments; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Optional; - -abstract class FlagsContainer implements Arguments { - - @Override - public boolean hasFlag(final @NotNull String flag) { - return false; - } - - @Override - public @NotNull Optional getValue(final @NotNull String flag, final @NotNull Class type) { - return Optional.empty(); - } - - @Override - public @NotNull Optional getValue(final @NotNull String flag) { - return Optional.empty(); - } - - @Override - public @NotNull String getText() { - return null; - } - - @Override - public @NotNull String getText(final @NotNull String delimiter) { - return null; - } - - @Override - public @NotNull List getArgs() { - return null; - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java deleted file mode 100644 index 0e92924d..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/FlagsResult.java +++ /dev/null @@ -1,133 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.argument.keyed.internal; - -import dev.triumphteam.cmd.core.argument.keyed.Flags; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; - -/** - * Implementation of the {@link Flags} which will be passed to the command method. - */ -@SuppressWarnings("unchecked") -class FlagsResult implements Flags { - - private final Map flags = new HashMap<>(); - private final List args; - private final S sender; - - FlagsResult( - final @NotNull S sender, - final @NotNull Map flags, - final @NotNull List args - ) { - this.sender = sender; - flags.forEach(this::addFlag); - this.args = args; - } - - public void addFlag(final @NotNull Flag flag, final @Nullable String value) { - final String shortFlag = flag.getFlag(); - final String longFlag = flag.getLongFlag(); - - // TODO - /* final FlagValue flagValue = value == null ? EmptyFlagValue.INSTANCE : new ArgFlagValue<>(value, flag.getArgument()); - - if (shortFlag != null) { - flags.put(shortFlag, flagValue); - } - - if (longFlag != null) { - flags.put(longFlag, flagValue); - }*/ - } - - void addArg(final @NotNull String arg) { - args.add(arg); - } - - /** - * {@inheritDoc} - */ - @Override - public boolean hasFlag(final @NotNull String flag) { - return flags.containsKey(flag); - } - - /** - * {@inheritDoc} - */ - @Override - public @NotNull Optional getValue(final @NotNull String flag, final @NotNull Class type) { - final ArgumentValue flagValue = flags.get(flag); - if (flagValue == null) return Optional.empty(); - if (!(flagValue instanceof SimpleArgumentValue)) return Optional.empty(); - /* final SimpleArgumentValue argFlagValue = (SimpleArgumentValue) flagValue; - return Optional.ofNullable((T) argFlagValue.getValue(sender, type));*/ - return Optional.empty(); - } - - /** - * {@inheritDoc} - */ - @Override - public @NotNull Optional getValue(final @NotNull String flag) { - final ArgumentValue flagValue = flags.get(flag); - if (flagValue == null) return Optional.empty(); - if (!(flagValue instanceof SimpleArgumentValue)) return Optional.empty(); - final SimpleArgumentValue argFlagValue = (SimpleArgumentValue) flagValue; - return Optional.of(argFlagValue.getAsString()); - } - - /** - * {@inheritDoc} - */ - @Override - public @NotNull String getText() { - return getText(" "); - } - - /** - * {@inheritDoc} - */ - @Override - public @NotNull String getText(final @NotNull String delimiter) { - return String.join(delimiter, args); - } - - /** - * {@inheritDoc} - */ - @Override - public @NotNull List getArgs() { - return Collections.unmodifiableList(args); - } - -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/KeyedArguments.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/KeyedArguments.java deleted file mode 100644 index adf460d4..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/internal/KeyedArguments.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.argument.keyed.internal; - -import com.google.common.collect.ImmutableMap; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; - -@SuppressWarnings("unchecked") -public final class KeyedArguments extends FlagsContainer { - - private final Map values; - - public KeyedArguments(final @NotNull Map values) { - this.values = values; - } - - @Override - public @NotNull Optional get(final @NotNull String name, final @NotNull Class type) { - return (Optional) Optional.ofNullable(values.get(name)); - } - - @Override - public @NotNull Optional> getAsList(final @NotNull String name, final @NotNull Class type) { - final List value = (List) values.get(name); - return Optional.ofNullable(value); - } - - @Override - public @NotNull Optional> getAsSet(final @NotNull String name, final @NotNull Class type) { - final Set value = (Set) values.get(name); - return Optional.ofNullable(value); - } - - @Override - public @NotNull Map getArguments() { - return ImmutableMap.copyOf(values); - } - - @Override - public boolean isEmpty() { - return values.isEmpty(); - } - - @Override - public @NotNull String toString() { - return "Arguments{" + - "values=" + values + - '}'; - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index ad8686c3..cc35c0fc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -64,8 +64,6 @@ public SubCommand( this.commandExecutor = processor.getCommandExtensions().getCommandExecutor(); this.syntax = createSyntax(parentCommand, processor); - - System.out.println(syntax); } @Override @@ -148,37 +146,33 @@ private boolean validateAndCollectArguments( for (int i = 0; i < arguments.size(); i++) { final InternalArgument internalArgument = arguments.get(i); + final @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> result; if (internalArgument instanceof LimitlessInternalArgument) { final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument; final List leftOvers = leftOvers(commandArgs, i); - limitlessArgument.resolve(sender, leftOvers).fold( - invokeArguments::add, - context -> {} - ); - return true; - } + result = limitlessArgument.resolve(sender, leftOvers); + } else if (internalArgument instanceof StringInternalArgument) { + final StringInternalArgument stringArgument = (StringInternalArgument) internalArgument; + final String arg = valueOrNull(commandArgs, i); - if (!(internalArgument instanceof StringInternalArgument)) { - throw new CommandExecutionException("Found unsupported argument", "", name); - } + if (arg == null || arg.isEmpty()) { + if (internalArgument.isOptional()) { + invokeArguments.add(null); + continue; + } - final StringInternalArgument stringArgument = (StringInternalArgument) internalArgument; - final String arg = valueOrNull(commandArgs, i); - - if (arg == null || arg.isEmpty()) { - if (internalArgument.isOptional()) { - invokeArguments.add(null); - continue; + messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new BasicMessageContext(meta)); + return false; } - messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new BasicMessageContext(meta)); - return false; + result = stringArgument.resolve(sender, arg); + } else { + // Should never happen, this should be a sealed type ... but hey, it's Java 8 + throw new CommandExecutionException("Found unsupported argument", "", name); } - final @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> result - = stringArgument.resolve(sender, arg); - + // In case of failure we send the Sender a message if (result instanceof Result.Failure) { messageRegistry.sendMessage( MessageKey.INVALID_ARGUMENT, @@ -190,6 +184,7 @@ private boolean validateAndCollectArguments( return false; } + // In case of success we add the results if (result instanceof Result.Success) { invokeArguments.add(((Result.Success<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>>) result).getValue()); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java index 8180544b..dbdb7456 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/FlagRegistry.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.core.extention.registry; import dev.triumphteam.cmd.core.argument.keyed.FlagKey; -import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; +import dev.triumphteam.cmd.core.argument.keyed.Flag; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java index 10d9fcec..02fce874 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/NamedArgumentRegistry.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.extention.registry; -import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; +import dev.triumphteam.cmd.core.argument.keyed.Argument; import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 396abf28..188074b3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -36,16 +36,18 @@ import dev.triumphteam.cmd.core.argument.EnumInternalArgument; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; -import dev.triumphteam.cmd.core.argument.KeyedInternalArgument; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.argument.keyed.Keyed; +import dev.triumphteam.cmd.core.argument.keyed.KeyedInternalArgument; import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; import dev.triumphteam.cmd.core.argument.keyed.Arguments; import dev.triumphteam.cmd.core.argument.keyed.Flags; -import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; -import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; -import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; -import dev.triumphteam.cmd.core.argument.keyed.internal.ListArgument; +import dev.triumphteam.cmd.core.argument.keyed.Argument; +import dev.triumphteam.cmd.core.argument.keyed.ArgumentGroup; +import dev.triumphteam.cmd.core.argument.keyed.Flag; +import dev.triumphteam.cmd.core.argument.keyed.ListArgument; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; @@ -228,7 +230,7 @@ public String getDescription() { } // Handle flags and named arguments - if (Flags.class.isAssignableFrom(type)) { + if (Keyed.class.isAssignableFrom(type)) { if (type == Arguments.class) { if (argumentGroup.isEmpty()) { @@ -260,7 +262,7 @@ public String getDescription() { ); } - protected @NotNull InternalArgument createSimpleArgument( + protected @NotNull StringInternalArgument createSimpleArgument( final @NotNull Class type, final @NotNull String name, final @NotNull String description, @@ -294,8 +296,8 @@ public String getDescription() { ); } - private Map> createFlagInternals(final @NotNull ArgumentGroup group) { - final Map> internalArguments = new HashMap<>(); + private Map> createFlagInternals(final @NotNull ArgumentGroup group) { + final Map> internalArguments = new HashMap<>(); for (final Flag flag : group.getAll()) { final Class argType = flag.getArgument(); @@ -318,8 +320,8 @@ public String getDescription() { return internalArguments; } - private Map> createNamedArgumentInternals(final @NotNull ArgumentGroup group) { - final Map> internalArguments = new HashMap<>(); + private Map> createNamedArgumentInternals(final @NotNull ArgumentGroup group) { + final Map> internalArguments = new HashMap<>(); for (final Argument argument : group.getAll()) { final Class argType = argument.getType(); @@ -431,7 +433,7 @@ public String getDescription() { } protected @NotNull Suggestion createSuggestion(final @Nullable SuggestionKey suggestionKey, final @NotNull Class type) { - if (suggestionKey == null) { + if (suggestionKey == null || suggestionKey.getKey().isEmpty()) { if (Enum.class.isAssignableFrom(type)) return new EnumSuggestion<>((Class>) type); final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(type); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java index 831c9511..27ec3681 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java @@ -31,7 +31,7 @@ import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; -import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; +import dev.triumphteam.cmd.core.argument.keyed.ArgumentGroup; import dev.triumphteam.cmd.core.command.ExecutableCommand; import dev.triumphteam.cmd.core.command.ParentSubCommand; import dev.triumphteam.cmd.core.command.SubCommand; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index b62f4668..b1bbffc4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -31,9 +31,9 @@ import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; import dev.triumphteam.cmd.core.argument.keyed.FlagKey; -import dev.triumphteam.cmd.core.argument.keyed.internal.Argument; -import dev.triumphteam.cmd.core.argument.keyed.internal.ArgumentGroup; -import dev.triumphteam.cmd.core.argument.keyed.internal.Flag; +import dev.triumphteam.cmd.core.argument.keyed.Argument; +import dev.triumphteam.cmd.core.argument.keyed.ArgumentGroup; +import dev.triumphteam.cmd.core.argument.keyed.Flag; import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/util/Pair.java b/core/src/main/java/dev/triumphteam/cmd/core/util/Pair.java new file mode 100644 index 00000000..374b7444 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/util/Pair.java @@ -0,0 +1,28 @@ +package dev.triumphteam.cmd.core.util; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class Pair { + + private final A first; + private final B second; + + public Pair(final @Nullable A first, final @Nullable B second) { + this.first = first; + this.second = second; + } + + public A first() { + return first; + } + + public B second() { + return second; + } + + @Override + public @NotNull String toString() { + return "(" + first + "," + second + ")"; + } +} From c42ac51fe8869a7b33391dfa2120ac77ecfdf648 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 18 Jan 2023 00:50:38 +0000 Subject: [PATCH 052/101] chore: Yeet unneeded implementation --- ...ocessor.java => RootCommandProcessor.java} | 4 +- .../cmds/simple/SimpleCommand.java | 3 +- .../cmds/simple/SimpleCommandManager.java | 3 +- .../cmds/simple/SimpleCommandProcessor.java | 40 ------------------- 4 files changed, 6 insertions(+), 44 deletions(-) rename core/src/main/java/dev/triumphteam/cmd/core/processor/{AbstractRootCommandProcessor.java => RootCommandProcessor.java} (98%) delete mode 100644 simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java similarity index 98% rename from core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java rename to core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index 27ec3681..2100e6cf 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractRootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -57,7 +57,7 @@ import static java.util.Collections.emptyMap; @SuppressWarnings("unchecked") -public abstract class AbstractRootCommandProcessor implements CommandProcessor { +public class RootCommandProcessor implements CommandProcessor { private final Object invocationInstance; @@ -69,7 +69,7 @@ public abstract class AbstractRootCommandProcessor implements CommandProcesso private final CommandExtensions commandExtensions; private final RegistryContainer registryContainer; - public AbstractRootCommandProcessor( + public RootCommandProcessor( final @NotNull Object invocationInstance, final @NotNull RegistryContainer registryContainer, final @NotNull CommandExtensions commandExtensions diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index b7913752..c2b62bca 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -32,6 +32,7 @@ import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.InvalidCommandContext; +import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -56,7 +57,7 @@ public final class SimpleCommand implements ParentCommand { @SuppressWarnings("unchecked") public SimpleCommand( - final @NotNull SimpleCommandProcessor processor, + final @NotNull RootCommandProcessor processor, final @NotNull MessageRegistry messageRegistry ) { this.name = processor.getName(); diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index a4307c83..3088b2b2 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -29,6 +29,7 @@ import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.InvalidCommandContext; +import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -56,7 +57,7 @@ private SimpleCommandManager(final @NotNull CommandOptions commandOptions) @Override public void registerCommand(final @NotNull Object command) { - final SimpleCommandProcessor processor = new SimpleCommandProcessor<>( + final RootCommandProcessor processor = new RootCommandProcessor<>( command, getRegistryContainer(), getCommandOptions().getCommandExtensions() diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java deleted file mode 100644 index 17232119..00000000 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandProcessor.java +++ /dev/null @@ -1,40 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmds.simple; - -import dev.triumphteam.cmd.core.extention.CommandExtensions; -import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import dev.triumphteam.cmd.core.processor.AbstractRootCommandProcessor; -import org.jetbrains.annotations.NotNull; - -public final class SimpleCommandProcessor extends AbstractRootCommandProcessor { - - public SimpleCommandProcessor( - final @NotNull Object invocationInstance, - final @NotNull RegistryContainer registryContainer, - final @NotNull CommandExtensions commandExtensions - ) { - super(invocationInstance, registryContainer, commandExtensions); - } -} From 7fce5e02603d44703a03fe7f6d4c276b140b1821 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 18 Jan 2023 00:51:39 +0000 Subject: [PATCH 053/101] chore: License headers --- .../argument/UnknownInternalArgument.java | 23 +++++++++++++++++++ .../core/argument/keyed/ArgumentGroup.java | 23 +++++++++++++++++++ .../cmd/core/argument/keyed/Flag.java | 23 +++++++++++++++++++ .../core/argument/keyed/FlagsContainer.java | 23 +++++++++++++++++++ .../cmd/core/argument/keyed/Keyed.java | 23 +++++++++++++++++++ .../cmd/core/command/CommandExecutor.java | 23 +++++++++++++++++++ .../cmd/core/command/ExecutableCommand.java | 23 +++++++++++++++++++ .../cmd/core/command/ParentSubCommand.java | 23 +++++++++++++++++++ .../cmd/core/command/SubCommand.java | 23 +++++++++++++++++++ .../cmd/core/extention/CommandExtensions.java | 23 +++++++++++++++++++ .../cmd/core/extention/CommandOptions.java | 23 +++++++++++++++++++ .../cmd/core/extention/ExtensionBuilder.java | 23 +++++++++++++++++++ .../cmd/core/extention/Result.java | 23 +++++++++++++++++++ .../annotation/AnnotationProcessor.java | 23 +++++++++++++++++++ .../extention/annotation/ProcessorTarget.java | 23 +++++++++++++++++++ .../argument/ArgumentValidationResult.java | 23 +++++++++++++++++++ .../extention/argument/ArgumentValidator.java | 23 +++++++++++++++++++ .../argument/CommandMetaProcessor.java | 23 +++++++++++++++++++ .../defaults/AsyncAnnotationProcessor.java | 23 +++++++++++++++++++ .../defaults/DefaultArgumentValidator.java | 23 +++++++++++++++++++ .../defaults/DefaultCommandExecutor.java | 23 +++++++++++++++++++ .../cmd/core/extention/meta/CommandMeta.java | 23 +++++++++++++++++++ .../extention/meta/CommandMetaContainer.java | 23 +++++++++++++++++++ .../extention/meta/ImmutableCommandMeta.java | 23 +++++++++++++++++++ .../cmd/core/extention/meta/MetaKey.java | 23 +++++++++++++++++++ .../extention/sender/SenderExtension.java | 23 +++++++++++++++++++ .../cmd/core/processor/CommandProcessor.java | 23 +++++++++++++++++++ .../core/processor/RootCommandProcessor.java | 8 +++---- .../dev/triumphteam/cmd/core/util/Pair.java | 23 +++++++++++++++++++ .../cmd/jda/annotation/Privileges.java | 8 +++---- .../triumphteam/cmd/jda/annotation/Roles.java | 8 +++---- .../cmds/CoroutinesCommandExtension.kt | 23 +++++++++++++++++++ .../cmds/simple/SimpleCommand.java | 8 +++---- .../cmds/simple/SimpleCommandManager.java | 8 +++---- .../cmds/simple/SimpleCommandOptions.java | 23 +++++++++++++++++++ 35 files changed, 710 insertions(+), 20 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index 1c4e813c..0af4eb12 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.extention.Result; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java index 52d651cd..2860e31e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.argument.keyed; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flag.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flag.java index cd1ca304..94b13b2a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flag.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Flag.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.argument.keyed; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagsContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagsContainer.java index f7a01713..e3c53a19 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagsContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagsContainer.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.argument.keyed; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Keyed.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Keyed.java index e2092165..397c23e0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Keyed.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/Keyed.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.argument.keyed; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/CommandExecutor.java b/core/src/main/java/dev/triumphteam/cmd/core/command/CommandExecutor.java index e97a5a71..1e617d51 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/CommandExecutor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/CommandExecutor.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.command; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java index 9933ab86..23de633f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.command; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 4fda7e57..59e3232f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.command; import dev.triumphteam.cmd.core.annotations.Syntax; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index cc35c0fc..3074cd6d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.command; import dev.triumphteam.cmd.core.annotations.Syntax; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java index fbaa0a1d..ae0da7b4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention; import dev.triumphteam.cmd.core.command.CommandExecutor; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java index 29031fd9..07473507 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java index 9b233105..b80a44d7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention; import dev.triumphteam.cmd.core.command.CommandExecutor; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java index c9748b93..835619f9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java index c533d99b..f3ed67fa 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.annotation; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/ProcessorTarget.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/ProcessorTarget.java index e809738c..b46d0105 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/ProcessorTarget.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/ProcessorTarget.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.annotation; import dev.triumphteam.cmd.core.AnnotatedCommand; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidationResult.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidationResult.java index 5544ee51..6237d89f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidationResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidationResult.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.argument; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java index 95271efa..09746251 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.argument; import dev.triumphteam.cmd.core.argument.InternalArgument; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMetaProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMetaProcessor.java index c8a0532c..797322ef 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMetaProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMetaProcessor.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.argument; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java index 6b622746..03c90455 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.defaults; import dev.triumphteam.cmd.core.annotations.Async; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java index 79f54473..fef4b200 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.defaults; import dev.triumphteam.cmd.core.argument.InternalArgument; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java index f5e054d1..cc98c4f8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultCommandExecutor.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.defaults; import dev.triumphteam.cmd.core.command.CommandExecutor; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java index e9a9813f..0bd98a15 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.meta; import dev.triumphteam.cmd.core.command.Command; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java index 37676e39..2eefe8a8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMetaContainer.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.meta; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java index 638a6301..72f12562 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/ImmutableCommandMeta.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.meta; import org.jetbrains.annotations.NotNull; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java index 90ac5a8d..982d9813 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/MetaKey.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.meta; import dev.triumphteam.cmd.core.extention.StringKey; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java index b3aca817..88a18817 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.sender; import dev.triumphteam.cmd.core.command.ExecutableCommand; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index d092fcee..f7c01d4f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.processor; import dev.triumphteam.cmd.core.annotations.Syntax; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index 2100e6cf..7ace8e49 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/util/Pair.java b/core/src/main/java/dev/triumphteam/cmd/core/util/Pair.java index 374b7444..a772ba5e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/util/Pair.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/util/Pair.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.util; import org.jetbrains.annotations.NotNull; diff --git a/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java b/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java index 7cfc3132..25daa866 100644 --- a/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java +++ b/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java b/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java index 974a58ff..683feb15 100644 --- a/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java +++ b/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt index cf805bac..06f75fe7 100644 --- a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt +++ b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmds import dev.triumphteam.cmd.core.argument.InternalArgument diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index c2b62bca..26d2b82d 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 3088b2b2..2a1454e3 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - *

+ * * Copyright (c) 2019-2021 Matt - *

+ * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

+ * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

+ * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java index b824922b..5e5aa766 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmds.simple; import dev.triumphteam.cmd.core.extention.CommandExtensions; From e0d9276d6aec3603a54f89e94a063278ca84245e Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 18 Jan 2023 00:52:36 +0000 Subject: [PATCH 054/101] chore: Spotless --- .../src/main/java/dev/triumphteam/cmd/core/extention/Result.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java index 835619f9..b067ecb6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java @@ -67,4 +67,3 @@ public Failure(final @NotNull F fail) { } } } - From f183e05c3eef6a2304293f085cef2f760f4f025f Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 19 Jan 2023 00:02:12 +0000 Subject: [PATCH 055/101] feature: Improved command requirements --- .../triumphteam/cmd/core/CommandManager.java | 4 +- .../cmd/core/command/ParentSubCommand.java | 4 +- .../cmd/core/command/SubCommand.java | 21 +++++----- .../cmd/core/extention/Result.java | 16 ------- .../extention/registry/RegistryContainer.java | 8 ++-- .../registry/RequirementRegistry.java | 9 ++-- .../extention/sender/SenderExtension.java | 7 +--- .../core/extention/sender/SenderMapper.java | 34 +++++++++++++++ .../message/context/BasicMessageContext.java | 17 ++++---- .../message/context/InvalidInputContext.java | 2 +- .../context/SimpleMetaMessageContext.java | 42 +++++++++++++++++++ .../processor/AbstractCommandProcessor.java | 14 +++---- .../processor/ParentCommandProcessor.java | 6 +-- .../core/processor/RootCommandProcessor.java | 16 +++---- .../core/processor/SubCommandProcessor.java | 14 +++---- .../cmd/core/requirement/Requirement.java | 28 ++++++++----- .../core/requirement/RequirementContext.java | 12 ++++++ .../core/requirement/RequirementResolver.java | 6 +-- .../requirement/SimpleRequirementContext.java | 26 ++++++++++++ .../cmds/simple/SimpleCommand.java | 2 +- .../cmds/simple/SimpleCommandManager.java | 6 +-- 21 files changed, 197 insertions(+), 97 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/message/context/SimpleMetaMessageContext.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index f5644826..45a2e5be 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -185,12 +185,12 @@ public final void registerMessage( */ public final void registerRequirement( final @NotNull RequirementKey key, - final @NotNull RequirementResolver resolver + final @NotNull RequirementResolver resolver ) { getRegistryContainer().getRequirementRegistry().register(key, resolver); } - protected abstract @NotNull RegistryContainer getRegistryContainer(); + protected abstract @NotNull RegistryContainer getRegistryContainer(); protected @NotNull CommandOptions getCommandOptions() { return commandOptions; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 59e3232f..71ebfe00 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -53,7 +53,7 @@ * * @param The sender type to be used. */ -public class ParentSubCommand implements ParentCommand, ExecutableCommand { +public class ParentSubCommand implements ParentCommand, ExecutableCommand { private final Map> commands = new HashMap<>(); private final Map> commandAliases = new HashMap<>(); @@ -77,7 +77,7 @@ public ParentSubCommand( final @NotNull Constructor constructor, final boolean isStatic, final @Nullable StringInternalArgument argument, - final @NotNull ParentCommandProcessor processor, + final @NotNull ParentCommandProcessor processor, final @NotNull Command parentCommand ) { this.invocationInstance = invocationInstance; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 3074cd6d..4321b5d2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -48,11 +48,11 @@ import java.util.function.BiFunction; import java.util.function.Supplier; -public class SubCommand implements ExecutableCommand { +public class SubCommand implements ExecutableCommand { private final Class senderType; private final List> arguments; - private final List> requirements; + private final List> requirements; private final String name; private final String syntax; @@ -63,13 +63,13 @@ public class SubCommand implements ExecutableCommand { private final Method method; private final CommandExecutor commandExecutor; - private final SenderExtension senderExtension; + private final SenderExtension senderExtension; private final MessageRegistry messageRegistry; public SubCommand( final @NotNull Object invocationInstance, final @NotNull Method method, - final @NotNull SubCommandProcessor processor, + final @NotNull SubCommandProcessor processor, final @NotNull Command parentCommand ) { this.invocationInstance = invocationInstance; @@ -104,12 +104,12 @@ public void execute( final List invokeArguments = new ArrayList<>(); invokeArguments.add(sender); - if (!validateAndCollectArguments(sender, commandPath, invokeArguments, arguments)) { + if (!validateAndCollectArguments(sender, invokeArguments, arguments)) { return; } if ((!containsLimitless) && arguments.size() >= invokeArguments.size()) { - messageRegistry.sendMessage(MessageKey.TOO_MANY_ARGUMENTS, sender, new BasicMessageContext(meta)); + messageRegistry.sendMessage(MessageKey.TOO_MANY_ARGUMENTS, sender, new BasicMessageContext(meta, syntax)); return; } @@ -162,7 +162,6 @@ public boolean hasArguments() { @SuppressWarnings("unchecked") private boolean validateAndCollectArguments( final @NotNull S sender, - final @NotNull List commandPath, final @NotNull List invokeArguments, final @NotNull List commandArgs ) { @@ -185,7 +184,7 @@ private boolean validateAndCollectArguments( continue; } - messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new BasicMessageContext(meta)); + messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new BasicMessageContext(meta, syntax)); return false; } @@ -223,9 +222,9 @@ private boolean validateAndCollectArguments( * @return Whether all requirements are met. */ private boolean meetRequirements(final @NotNull S sender) { - for (final Requirement requirement : requirements) { - if (!requirement.isMet(sender)) { - requirement.sendMessage(messageRegistry, sender, meta); + for (final Requirement requirement : requirements) { + if (!requirement.isMet(sender, meta, senderExtension)) { + requirement.sendMessage(messageRegistry, sender, meta, syntax); return false; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java index b067ecb6..273994f4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java @@ -25,24 +25,8 @@ import org.jetbrains.annotations.NotNull; -import java.util.function.Consumer; - public interface Result { - default void fold( - final @NotNull Consumer onSuccess, - final @NotNull Consumer onFailure - ) { - if (this instanceof Success) { - onSuccess.accept(((Success) this).getValue()); - return; - } - - if (this instanceof Failure) { - onFailure.accept(((Failure) this).getFail()); - } - } - final class Success implements Result { private final V value; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RegistryContainer.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RegistryContainer.java index 9fecfc55..099ffeb8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RegistryContainer.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RegistryContainer.java @@ -26,12 +26,12 @@ import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; import org.jetbrains.annotations.NotNull; -public class RegistryContainer { +public class RegistryContainer { private final ArgumentRegistry argumentRegistry = new ArgumentRegistry<>(); private final NamedArgumentRegistry namedArgumentRegistry = new NamedArgumentRegistry(); private final FlagRegistry flagRegistry = new FlagRegistry(); - private final RequirementRegistry requirementRegistry = new RequirementRegistry<>(); + private final RequirementRegistry requirementRegistry = new RequirementRegistry<>(); private final MessageRegistry messageRegistry = new MessageRegistry<>(); private final SuggestionRegistry suggestionRegistry = new SuggestionRegistry<>(); @@ -43,11 +43,11 @@ public class RegistryContainer { return namedArgumentRegistry; } - public FlagRegistry getFlagRegistry() { + public @NotNull FlagRegistry getFlagRegistry() { return flagRegistry; } - public @NotNull RequirementRegistry getRequirementRegistry() { + public @NotNull RequirementRegistry getRequirementRegistry() { return requirementRegistry; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RequirementRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RequirementRegistry.java index 73339657..b24fb9a6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RequirementRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/RequirementRegistry.java @@ -36,9 +36,9 @@ * * @param The sender type. */ -public final class RequirementRegistry implements Registry { +public final class RequirementRegistry implements Registry { - private final Map> requirements = new HashMap<>(); + private final Map> requirements = new HashMap<>(); /** * Registers a new {@link RequirementResolver} for the specific Key. @@ -46,7 +46,7 @@ public final class RequirementRegistry implements Registry { * @param key The requirement key. * @param resolver The resolver to check if the requirement is met. */ - public void register(final @NotNull RequirementKey key, final @NotNull RequirementResolver resolver) { + public void register(final @NotNull RequirementKey key, final @NotNull RequirementResolver resolver) { requirements.put(key, resolver); } @@ -56,8 +56,7 @@ public void register(final @NotNull RequirementKey key, final @NotNull Requireme * @param key The specific key. * @return A saved {@link RequirementResolver}. */ - public @Nullable RequirementResolver getRequirement(final @NotNull RequirementKey key) { + public @Nullable RequirementResolver getRequirement(final @NotNull RequirementKey key) { return requirements.get(key); } - } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java index 88a18817..a73e3e5d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java @@ -26,11 +26,10 @@ import dev.triumphteam.cmd.core.command.ExecutableCommand; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import java.util.Set; -public interface SenderExtension { +public interface SenderExtension extends SenderMapper { @NotNull Set> getAllowedSenders(); @@ -39,8 +38,4 @@ boolean validate( final @NotNull ExecutableCommand command, final @NotNull S sender ); - - @Nullable S map(final @NotNull D defaultSender); - - @Nullable D reMap(final @NotNull S defaultSender); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java new file mode 100644 index 00000000..f707a44f --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java @@ -0,0 +1,34 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.extention.sender; + +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public interface SenderMapper { + + @Nullable S map(final @NotNull D defaultSender); + + @Nullable D reMap(final @NotNull S defaultSender); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java index d0183f47..90c268cb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java @@ -29,16 +29,19 @@ /** * The default most keys will use, only contains the most basic data. */ -public class BasicMessageContext implements MessageContext { +public class BasicMessageContext extends SimpleMetaMessageContext { - private final CommandMeta meta; + private final String syntax; - public BasicMessageContext(final @NotNull CommandMeta meta) { - this.meta = meta; + public BasicMessageContext( + final @NotNull CommandMeta meta, + final @NotNull String syntax + ) { + super(meta); + this.syntax = syntax; } - @Override - public @NotNull CommandMeta getMeta() { - return meta; + public @NotNull String getSyntax() { + return syntax; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java index ef67ccff..16264e51 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java @@ -29,7 +29,7 @@ /** * Context with an invalid input. */ -abstract class InvalidInputContext extends BasicMessageContext { +abstract class InvalidInputContext extends SimpleMetaMessageContext { private final String invalidInput; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/SimpleMetaMessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/SimpleMetaMessageContext.java new file mode 100644 index 00000000..7b858387 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/SimpleMetaMessageContext.java @@ -0,0 +1,42 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.message.context; + +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import org.jetbrains.annotations.NotNull; + + +abstract class SimpleMetaMessageContext implements MessageContext { + + private final CommandMeta meta; + + public SimpleMetaMessageContext(final @NotNull CommandMeta meta) { + this.meta = meta; + } + + @Override + public @NotNull CommandMeta getMeta() { + return meta; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 188074b3..eaf95a17 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -85,7 +85,7 @@ * @param The sender type. */ @SuppressWarnings("unchecked") -abstract class AbstractCommandProcessor implements CommandProcessor { +abstract class AbstractCommandProcessor implements CommandProcessor { private static final Set> SUPPORTED_COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); @@ -95,19 +95,19 @@ abstract class AbstractCommandProcessor implements CommandProcessor { private final Syntax syntax; private final AnnotatedElement annotatedElement; - private final RegistryContainer registryContainer; + private final RegistryContainer registryContainer; private final SuggestionRegistry suggestionRegistry; private final ArgumentRegistry argumentRegistry; - private final CommandExtensions commandExtensions; + private final CommandExtensions commandExtensions; private final CommandMeta parentMeta; AbstractCommandProcessor( final @NotNull Object invocationInstance, final @NotNull AnnotatedElement annotatedElement, - final @NotNull RegistryContainer registryContainer, - final @NotNull CommandExtensions commandExtensions, + final @NotNull RegistryContainer registryContainer, + final @NotNull CommandExtensions commandExtensions, final @NotNull CommandMeta parentMeta ) { this.invocationInstance = invocationInstance; @@ -124,11 +124,11 @@ abstract class AbstractCommandProcessor implements CommandProcessor { this.syntax = annotatedElement.getAnnotation(Syntax.class); } - public @NotNull RegistryContainer getRegistryContainer() { + public @NotNull RegistryContainer getRegistryContainer() { return registryContainer; } - public @NotNull CommandExtensions getCommandExtensions() { + public @NotNull CommandExtensions getCommandExtensions() { return commandExtensions; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java index 9a26c5c4..2ea8c251 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java @@ -39,15 +39,15 @@ * @param The sender type. */ @SuppressWarnings("unchecked") -public final class ParentCommandProcessor extends AbstractCommandProcessor { +public final class ParentCommandProcessor extends AbstractCommandProcessor { private final Class klass; ParentCommandProcessor( final @NotNull Object invocationInstance, final @NotNull Class klass, - final @NotNull RegistryContainer registryContainer, - final @NotNull CommandExtensions commandExtensions, + final @NotNull RegistryContainer registryContainer, + final @NotNull CommandExtensions commandExtensions, final @NotNull CommandMeta parentMeta ) { super(invocationInstance, klass, registryContainer, commandExtensions, parentMeta); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index 7ace8e49..8d1c2b07 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -57,7 +57,7 @@ import static java.util.Collections.emptyMap; @SuppressWarnings("unchecked") -public class RootCommandProcessor implements CommandProcessor { +public class RootCommandProcessor implements CommandProcessor { private final Object invocationInstance; @@ -66,13 +66,13 @@ public class RootCommandProcessor implements CommandProcessor { private final List alias; private final String description; - private final CommandExtensions commandExtensions; - private final RegistryContainer registryContainer; + private final CommandExtensions commandExtensions; + private final RegistryContainer registryContainer; public RootCommandProcessor( final @NotNull Object invocationInstance, - final @NotNull RegistryContainer registryContainer, - final @NotNull CommandExtensions commandExtensions + final @NotNull RegistryContainer registryContainer, + final @NotNull CommandExtensions commandExtensions ) { this.invocationInstance = invocationInstance; @@ -138,7 +138,7 @@ public String getDescription() { // Ignore non-public methods if (!Modifier.isPublic(method.getModifiers())) continue; - final SubCommandProcessor processor = new SubCommandProcessor<>( + final SubCommandProcessor processor = new SubCommandProcessor<>( invocationInstance, method, registryContainer, @@ -165,7 +165,7 @@ public String getDescription() { // Ignore non-public methods if (!Modifier.isPublic(klass.getModifiers())) continue; - final ParentCommandProcessor processor = new ParentCommandProcessor<>( + final ParentCommandProcessor processor = new ParentCommandProcessor<>( invocationInstance, klass, registryContainer, @@ -221,7 +221,7 @@ public String getDescription() { } } - final ParentSubCommand parent = new ParentSubCommand<>( + final ParentSubCommand parent = new ParentSubCommand<>( invocationInstance, constructor, isStatic, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index b1bbffc4..7f99c840 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -78,18 +78,18 @@ * @param The sender type. */ @SuppressWarnings("unchecked") -public final class SubCommandProcessor extends AbstractCommandProcessor { +public final class SubCommandProcessor extends AbstractCommandProcessor { private final Method method; private final NamedArgumentRegistry namedArgumentRegistry; - private final RequirementRegistry requirementRegistry; + private final RequirementRegistry requirementRegistry; private final FlagRegistry flagRegistry; SubCommandProcessor( final @NotNull Object invocationInstance, final @NotNull Method method, - final @NotNull RegistryContainer registryContainer, - final @NotNull CommandExtensions commandExtensions, + final @NotNull RegistryContainer registryContainer, + final @NotNull CommandExtensions commandExtensions, final @NotNull CommandMeta parentMeta ) { super(invocationInstance, method, registryContainer, commandExtensions, parentMeta); @@ -214,8 +214,8 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { * * @return A {@link List} of requirements needed to run the command. */ - public @NotNull List> requirements() { - final List> requirements = new ArrayList<>(); + public @NotNull List> requirements() { + final List> requirements = new ArrayList<>(); for (final dev.triumphteam.cmd.core.annotations.Requirement requirementAnnotation : getRequirementsFromAnnotations()) { final RequirementKey requirementKey = RequirementKey.of(requirementAnnotation.value()); final String messageKeyValue = requirementAnnotation.messageKey(); @@ -224,7 +224,7 @@ public final class SubCommandProcessor extends AbstractCommandProcessor { if (messageKeyValue.isEmpty()) messageKey = null; else messageKey = MessageKey.of(messageKeyValue, MessageContext.class); - final RequirementResolver resolver = requirementRegistry.getRequirement(requirementKey); + final RequirementResolver resolver = requirementRegistry.getRequirement(requirementKey); if (resolver == null) { throw createException("Could not find Requirement Key \"" + requirementKey.getKey() + "\""); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java index b64bdeda..13691755 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java @@ -25,30 +25,31 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; import dev.triumphteam.cmd.core.message.ContextualKey; import dev.triumphteam.cmd.core.message.context.MessageContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Objects; -import java.util.function.Function; +import java.util.function.BiFunction; /** * Contains the data for the requirement. * * @param The sender type. */ -public final class Requirement { +public final class Requirement { - private final RequirementResolver resolver; + private final RequirementResolver resolver; private final ContextualKey messageKey; - private final Function contextFactory; + private final BiFunction contextFactory; private final boolean invert; public Requirement( - final @NotNull RequirementResolver resolver, + final @NotNull RequirementResolver resolver, final @Nullable ContextualKey messageKey, - final @NotNull Function contextFactory, + final @NotNull BiFunction contextFactory, final boolean invert ) { this.resolver = resolver; @@ -70,10 +71,11 @@ public Requirement( public void sendMessage( final @NotNull MessageRegistry registry, final @NotNull S sender, - final @NotNull CommandMeta meta + final @NotNull CommandMeta meta, + final @NotNull String syntax ) { if (messageKey == null) return; - registry.sendMessage(messageKey, sender, contextFactory.apply(meta)); + registry.sendMessage(messageKey, sender, contextFactory.apply(meta, syntax)); } /** @@ -82,15 +84,19 @@ public void sendMessage( * @param sender The sender which will be needed to check if the requirement is met or not. * @return Whether the requirement is met. */ - public boolean isMet(final @NotNull S sender) { - return resolver.resolve(sender) != invert; + public boolean isMet( + final @NotNull S sender, + final @NotNull CommandMeta meta, + final @NotNull SenderMapper senderMapper + ) { + return resolver.resolve(sender, new SimpleRequirementContext<>(meta, senderMapper)) != invert; } @Override public boolean equals(final @Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - final Requirement that = (Requirement) o; + final Requirement that = (Requirement) o; return resolver.equals(that.resolver) && Objects.equals(messageKey, that.messageKey); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java new file mode 100644 index 00000000..98d4788e --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java @@ -0,0 +1,12 @@ +package dev.triumphteam.cmd.core.requirement; + +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import org.jetbrains.annotations.NotNull; + +public interface RequirementContext { + + @NotNull CommandMeta getMeta(); + + @NotNull SenderMapper getSenderMapper(); +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java index 280e6bfd..debcb4d0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java @@ -28,10 +28,11 @@ /** * Functional interface to allow simple requirement registering without the use of any hard coded data. * + * @param The default sender type. * @param The command sender type. */ @FunctionalInterface -public interface RequirementResolver { +public interface RequirementResolver { /** * Resolves the requirement. @@ -39,6 +40,5 @@ public interface RequirementResolver { * @param sender The sender to check the requirement. * @return Whether the requirement is met or not. */ - boolean resolve(final @NotNull S sender); - + boolean resolve(final @NotNull S sender, final @NotNull RequirementContext context); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java new file mode 100644 index 00000000..d9de0af3 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java @@ -0,0 +1,26 @@ +package dev.triumphteam.cmd.core.requirement; + +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import org.jetbrains.annotations.NotNull; + +class SimpleRequirementContext implements RequirementContext { + + private final CommandMeta meta; + private final SenderMapper senderMapper; + + public SimpleRequirementContext(final @NotNull CommandMeta meta, final @NotNull SenderMapper senderMapper) { + this.meta = meta; + this.senderMapper = senderMapper; + } + + @Override + public @NotNull CommandMeta getMeta() { + return meta; + } + + @Override + public @NotNull SenderMapper getSenderMapper() { + return senderMapper; + } +} diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index 26d2b82d..fd53b9f6 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -57,7 +57,7 @@ public final class SimpleCommand implements ParentCommand { @SuppressWarnings("unchecked") public SimpleCommand( - final @NotNull RootCommandProcessor processor, + final @NotNull RootCommandProcessor processor, final @NotNull MessageRegistry messageRegistry ) { this.name = processor.getName(); diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 2a1454e3..41400a7b 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -42,7 +42,7 @@ public final class SimpleCommandManager extends CommandManager { private final Map> commands = new HashMap<>(); - private final RegistryContainer registryContainer = new RegistryContainer<>(); + private final RegistryContainer registryContainer = new RegistryContainer<>(); private SimpleCommandManager(final @NotNull CommandOptions commandOptions) { super(commandOptions); @@ -57,7 +57,7 @@ private SimpleCommandManager(final @NotNull CommandOptions commandOptions) @Override public void registerCommand(final @NotNull Object command) { - final RootCommandProcessor processor = new RootCommandProcessor<>( + final RootCommandProcessor processor = new RootCommandProcessor<>( command, getRegistryContainer(), getCommandOptions().getCommandExtensions() @@ -86,7 +86,7 @@ public void registerCommand(final @NotNull Object command) { * {@inheritDoc} */ @Override - protected @NotNull RegistryContainer getRegistryContainer() { + protected @NotNull RegistryContainer getRegistryContainer() { return registryContainer; } From 8d763f49364ef60b1f9882419b0c69dbdcbc1bb5 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 19 Jan 2023 00:17:58 +0000 Subject: [PATCH 056/101] chore: Make mapping not nullable and fix naming --- .../triumphteam/cmd/core/extention/sender/SenderMapper.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java index f707a44f..ffa7098f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java @@ -24,11 +24,10 @@ package dev.triumphteam.cmd.core.extention.sender; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public interface SenderMapper { - @Nullable S map(final @NotNull D defaultSender); + @NotNull S map(final @NotNull D defaultSender); - @Nullable D reMap(final @NotNull S defaultSender); + @NotNull D mapBackwards(final @NotNull S sender); } From c07ab823c81d7a756626de1af6afdb3c8f36898a Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 19 Jan 2023 00:54:29 +0000 Subject: [PATCH 057/101] feature: Proper coroutines support, execution --- .../cmd/core/AnnotatedCommand.java | 3 -- .../cmd/core/extention/ExtensionBuilder.java | 3 +- .../core/extention/sender/SenderMapper.java | 1 + .../core/requirement/RequirementContext.java | 1 + .../cmds/CoroutinesCommandExtension.kt | 32 +++++++++++++++++-- .../cmds/simple/SimpleCommand.java | 1 - 6 files changed, 32 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java index 98ebc367..0c15da23 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java @@ -29,9 +29,6 @@ import java.util.ArrayList; import java.util.List; -/** - * Class in which all commands need to extend. - */ public abstract class AnnotatedCommand { private final String command; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java index b80a44d7..3a46bb0e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java @@ -28,7 +28,6 @@ import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor; -import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -99,7 +98,7 @@ public final class ExtensionBuilder { commandMetaProcessors, senderExtension, argumentValidator, - new DefaultCommandExecutor() + commandExecutor ); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java index ffa7098f..5e70ba4c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java @@ -25,6 +25,7 @@ import org.jetbrains.annotations.NotNull; +// TODO Comments public interface SenderMapper { @NotNull S map(final @NotNull D defaultSender); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java index 98d4788e..0266dbf6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java @@ -4,6 +4,7 @@ import dev.triumphteam.cmd.core.extention.sender.SenderMapper; import org.jetbrains.annotations.NotNull; +// TODO comments public interface RequirementContext { @NotNull CommandMeta getMeta(); diff --git a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt index 06f75fe7..5a191334 100644 --- a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt +++ b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt @@ -26,6 +26,7 @@ package dev.triumphteam.cmds import dev.triumphteam.cmd.core.argument.InternalArgument import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument import dev.triumphteam.cmd.core.argument.UnknownInternalArgument +import dev.triumphteam.cmd.core.command.CommandExecutor import dev.triumphteam.cmd.core.extention.ExtensionBuilder import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult @@ -33,17 +34,30 @@ import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor import dev.triumphteam.cmd.core.extention.meta.CommandMeta import dev.triumphteam.cmd.core.extention.meta.MetaKey +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch import java.lang.reflect.AnnotatedElement import java.lang.reflect.Method import kotlin.coroutines.Continuation +import kotlin.coroutines.CoroutineContext +import kotlin.reflect.full.callSuspend +import kotlin.reflect.jvm.kotlinFunction -public fun > B.useCoroutines() { - val kotlinArgumentExtension = CoroutinesCommandExtension() +public fun > B.useCoroutines( + coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.Default), + coroutineContext: CoroutineContext = Dispatchers.Default, +) { + val kotlinArgumentExtension = CoroutinesCommandExtension(coroutineScope, coroutineContext) addCommandMetaProcessor(kotlinArgumentExtension) setArgumentValidator(kotlinArgumentExtension) + setCommandExecutor(kotlinArgumentExtension) } -public class CoroutinesCommandExtension : CommandMetaProcessor, ArgumentValidator { +public class CoroutinesCommandExtension( + private val coroutineScope: CoroutineScope, + private val coroutineContext: CoroutineContext, +) : CommandMetaProcessor, ArgumentValidator, CommandExecutor { private companion object { /** The key that'll represent a suspending function. */ @@ -105,4 +119,16 @@ public class CoroutinesCommandExtension : CommandMetaProcessor, ArgumentValid // If everything goes well, we now have valid argument return valid() } + + /** Executes the command with normal reflection or call suspending if the method is suspending. */ + override fun execute(meta: CommandMeta, instance: Any, method: Method, arguments: MutableList) { + if (meta.isPresent(SUSPEND_META_KEY)) { + coroutineScope.launch(coroutineContext) { + method.kotlinFunction?.callSuspend(instance, *arguments.toTypedArray()) + } + return + } + + method.invoke(instance, *arguments.toTypedArray()) + } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index fd53b9f6..9a951d7a 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -55,7 +55,6 @@ public final class SimpleCommand implements ParentCommand { private final CommandMeta meta; private ExecutableCommand parentCommandWithArgument; - @SuppressWarnings("unchecked") public SimpleCommand( final @NotNull RootCommandProcessor processor, final @NotNull MessageRegistry messageRegistry From 69ff64785500b27619f6c55b867fe01bf234841c Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 19 Jan 2023 01:11:14 +0000 Subject: [PATCH 058/101] chore: Bukkit time baby --- .../message/NoPermissionMessageContext.java | 17 ++++++++--------- settings.gradle.kts | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java index d9c669b4..5cfdf969 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java @@ -24,25 +24,24 @@ package dev.triumphteam.cmd.bukkit.message; import dev.triumphteam.cmd.bukkit.CommandPermission; -import dev.triumphteam.cmd.core.message.context.AbstractMessageContext; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.BasicMessageContext; import org.jetbrains.annotations.NotNull; -import java.util.List; - -public final class NoPermissionMessageContext extends AbstractMessageContext { +public final class NoPermissionMessageContext extends BasicMessageContext { private final CommandPermission permission; public NoPermissionMessageContext( - final @NotNull String command, - final @NotNull String subCommand, + final @NotNull CommandMeta meta, + final @NotNull String syntax, final @NotNull CommandPermission permission ) { - super(command, subCommand); + super(meta, syntax); this.permission = permission; } - public @NotNull List getNodes() { - return permission.getNodes(); + public @NotNull CommandPermission getPermission() { + return permission; } } diff --git a/settings.gradle.kts b/settings.gradle.kts index e8cf35e2..1294d0c1 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -13,7 +13,7 @@ listOf( ).forEach(::includeProject) listOf( - // "minecraft/bukkit" to "bukkit", + "minecraft/bukkit" to "bukkit", "discord/jda-common" to "jda-common", // "discord/jda-prefixed" to "jda-prefixed", // "discord/jda-slash" to "jda-slash", From 325b30b404e0ba678d5bb295ec3d560cab203964 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 20 Jan 2023 00:41:54 +0000 Subject: [PATCH 059/101] chore: Refactor to manager factories and option builders --- .../cmd/core/extention/CommandExtensions.java | 8 - .../cmd/core/extention/CommandOptions.java | 15 +- .../cmd/core/extention/ExtensionBuilder.java | 12 -- .../extention/sender/SenderExtension.java | 13 ++ minecraft/bukkit/build.gradle.kts | 4 +- .../cmd/bukkit/BukkitCommandManager.java | 176 +++++++++--------- .../cmd/bukkit/BukkitCommandOptions.java | 25 +++ ...idator.java => BukkitSenderExtension.java} | 35 +--- .../cmds/simple/SimpleCommandManager.java | 20 +- ...Options.java => SimpleOptionsBuilder.java} | 26 +-- 10 files changed, 167 insertions(+), 167 deletions(-) create mode 100644 minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java rename minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/{BukkitSenderValidator.java => BukkitSenderExtension.java} (58%) rename simple/src/main/java/dev/triumphteam/cmds/simple/{SimpleCommandOptions.java => SimpleOptionsBuilder.java} (57%) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java index ae0da7b4..64eb5e06 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java @@ -27,7 +27,6 @@ import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor; -import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.NotNull; import java.lang.annotation.Annotation; @@ -39,20 +38,17 @@ public final class CommandExtensions { private final Map, AnnotationProcessor> annotationProcessors; private final List commandMetaProcessors; - private final SenderExtension senderExtension; private final ArgumentValidator argumentValidator; private final CommandExecutor commandExecutor; public CommandExtensions( final @NotNull Map, AnnotationProcessor> annotationProcessors, final @NotNull List commandMetaProcessors, - final @NotNull SenderExtension senderExtension, final @NotNull ArgumentValidator argumentValidator, final @NotNull CommandExecutor commandExecutor ) { this.annotationProcessors = annotationProcessors; this.commandMetaProcessors = commandMetaProcessors; - this.senderExtension = senderExtension; this.argumentValidator = argumentValidator; this.commandExecutor = commandExecutor; } @@ -65,10 +61,6 @@ public CommandExtensions( return commandMetaProcessors; } - public @NotNull SenderExtension getSenderExtension() { - return senderExtension; - } - public @NotNull ArgumentValidator getArgumentValidator() { return argumentValidator; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java index 07473507..32881340 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.extention; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.NotNull; import java.util.function.Consumer; @@ -31,10 +32,13 @@ public class CommandOptions { private final CommandExtensions commandExtensions; + private final SenderExtension senderExtension; public CommandOptions( + final @NotNull SenderExtension senderExtension, final @NotNull CommandExtensions commandExtensions ) { + this.senderExtension = senderExtension; this.commandExtensions = commandExtensions; } @@ -42,21 +46,20 @@ public CommandOptions( return commandExtensions; } + public @NotNull SenderExtension getSenderExtension() { + return senderExtension; + } + public static abstract class Builder, B extends Builder> { private final ExtensionBuilder extensionBuilder = new ExtensionBuilder<>(); - public Builder(final @NotNull Consumer> defaultExtensions) { - // Adding all defaults first so they can be overridden - defaultExtensions.accept(extensionBuilder); - } - public @NotNull B extensions(final @NotNull Consumer> consumer) { consumer.accept(extensionBuilder); return (B) this; } - public abstract @NotNull O build(); + public abstract @NotNull O build(final @NotNull SenderExtension senderExtension); protected @NotNull CommandExtensions getCommandExtensions() { return extensionBuilder.build(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java index 3a46bb0e..0905783d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java @@ -43,7 +43,6 @@ public final class ExtensionBuilder { private final Map, AnnotationProcessor> annotationProcessors = new HashMap<>(); private final List commandMetaProcessors = new ArrayList<>(); - private SenderExtension senderExtension = null; private ArgumentValidator argumentValidator = null; private CommandExecutor commandExecutor = null; @@ -62,12 +61,6 @@ public final class ExtensionBuilder { return this; } - @Contract("_ -> this") - public @NotNull ExtensionBuilder setSenderExtension(final @NotNull SenderExtension senderExtension) { - this.senderExtension = senderExtension; - return this; - } - @Contract("_ -> this") public @NotNull ExtensionBuilder setArgumentValidator(final @NotNull ArgumentValidator argumentValidator) { this.argumentValidator = argumentValidator; @@ -81,10 +74,6 @@ public final class ExtensionBuilder { } public @NotNull CommandExtensions build() { - if (senderExtension == null) { - throw new CommandRegistrationException("No sender extension was added to Command Manager."); - } - if (argumentValidator == null) { throw new CommandRegistrationException("No argument validator was added to Command Manager."); } @@ -96,7 +85,6 @@ public final class ExtensionBuilder { return new CommandExtensions<>( annotationProcessors, commandMetaProcessors, - senderExtension, argumentValidator, commandExecutor ); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java index a73e3e5d..c88abc14 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java @@ -38,4 +38,17 @@ boolean validate( final @NotNull ExecutableCommand command, final @NotNull S sender ); + + interface Default extends SenderExtension { + + @Override + default @NotNull S map(@NotNull final S defaultSender) { + return defaultSender; + } + + @Override + default @NotNull S mapBackwards(@NotNull final S sender) { + return sender; + } + } } diff --git a/minecraft/bukkit/build.gradle.kts b/minecraft/bukkit/build.gradle.kts index b6407f1a..6ecaaa88 100644 --- a/minecraft/bukkit/build.gradle.kts +++ b/minecraft/bukkit/build.gradle.kts @@ -8,6 +8,6 @@ repositories { } dependencies { - api(project(":triumph-cmd-core")) + api(projects.triumphCmdCore) compileOnly(libs.spigot) -} \ No newline at end of file +} diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index 6f68dfa3..2733323c 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -23,16 +23,12 @@ */ package dev.triumphteam.cmd.bukkit; -import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; -import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.CommandManager; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.execution.SyncExecutionProvider; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; +import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Server; @@ -48,19 +44,18 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.*; +import java.util.HashMap; +import java.util.Map; +import java.util.function.Consumer; import java.util.stream.Collectors; public final class BukkitCommandManager extends CommandManager { private final Plugin plugin; - private final RegistryContainer registryContainer = new RegistryContainer<>(); + private final RegistryContainer registryContainer = new RegistryContainer<>(); private final Map> commands = new HashMap<>(); - private final ExecutionProvider syncExecutionProvider = new SyncExecutionProvider(); - private final ExecutionProvider asyncExecutionProvider; - private final CommandMap commandMap; private final Map bukkitCommands; @@ -69,12 +64,10 @@ public final class BukkitCommandManager extends CommandManager senderMapper, - final @NotNull SenderValidator senderValidator + final @NotNull BukkitCommandOptions commandOptions ) { - super(senderMapper, senderValidator); + super(commandOptions); this.plugin = plugin; - this.asyncExecutionProvider = new BukkitAsyncExecutionProvider(plugin); this.commandMap = getCommandMap(); this.bukkitCommands = getBukkitCommands(commandMap); @@ -87,6 +80,30 @@ private BukkitCommandManager( registerSuggestion(Player.class, (sender, context) -> Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList())); } + /** + * Creates a new instance of the {@link BukkitCommandManager}. + * This factory adds all the defaults based on the default sender {@link CommandSender}. + * + * @param plugin The {@link Plugin} instance created. + * @return A new instance of the {@link BukkitCommandManager}. + */ + @Contract("_, _, _ -> new") + public static @NotNull BukkitCommandManager create( + final @NotNull Plugin plugin, + final @NotNull SenderExtension senderExtension, + final @NotNull Consumer> builder + ) { + final BukkitCommandOptions.Builder extensionBuilder = new BukkitCommandOptions.Builder<>(); + + extensionBuilder.extensions(extension -> { + extension.setArgumentValidator(new DefaultArgumentValidator<>()); + extension.setCommandExecutor(new DefaultCommandExecutor()); + }); + + builder.accept(extensionBuilder); + return new BukkitCommandManager<>(plugin, extensionBuilder.build(senderExtension)); + } + /** * Creates a new instance of the {@link BukkitCommandManager}. * This factory adds all the defaults based on the default sender {@link CommandSender}. @@ -96,80 +113,22 @@ private BukkitCommandManager( */ @Contract("_ -> new") public static @NotNull BukkitCommandManager create(final @NotNull Plugin plugin) { - final BukkitCommandManager commandManager = new BukkitCommandManager<>( - plugin, - SenderMapper.defaultMapper(), - new BukkitSenderValidator() - ); - setUpDefaults(commandManager); - return commandManager; + return create(plugin, builder -> {}); } /** * Creates a new instance of the {@link BukkitCommandManager}. - * This factory is used for adding custom senders. + * This factory adds all the defaults based on the default sender {@link CommandSender}. * - * @param plugin The {@link Plugin} instance created. - * @param senderMapper The {@link SenderMapper} used to map the {@link CommandSender} to the {@link S} type. - * @param senderValidator The {@link SenderValidator} used to validate the {@link S} type. + * @param plugin The {@link Plugin} instance created. * @return A new instance of the {@link BukkitCommandManager}. */ - @Contract("_, _, _ -> new") - public static @NotNull BukkitCommandManager create( + @Contract("_, _ -> new") + public static @NotNull BukkitCommandManager create( final @NotNull Plugin plugin, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator + final @NotNull Consumer> builder ) { - return new BukkitCommandManager<>(plugin, senderMapper, senderValidator); - } - - @Override - public void registerCommand(final @NotNull BaseCommand baseCommand) { - final String name = "nameOf(baseCommand)"; - - final BukkitCommand command = commands.get(name); - if (command != null) { - // TODO: Command exists, only care about adding subs - return; - } - - // Command does not exist, proceed to add new! - - final BukkitCommandProcessor processor = new BukkitCommandProcessor<>(name, baseCommand, basePermission); - - final BukkitCommand newCommand = commands.computeIfAbsent(processor.getName(), it -> createAndRegisterCommand(it, processor)); - - // TODO: ADD SUBCOMMANDS - - /*processor.getAlias().forEach(it -> { - final BukkitCommand aliasCommand = commands.computeIfAbsent(it, ignored -> createAndRegisterCommand(it, processor)); - // Adding sub commands. - // TODO: ADD SUBCOMMANDS - });*/ - } - - @Override - public void unregisterCommand(final @NotNull BaseCommand command) { - // TODO add a remove functionality - } - - @Override - protected @NotNull RegistryContainer getRegistryContainer() { - return registryContainer; - } - - private @NotNull BukkitCommand createAndRegisterCommand(final @NotNull String name, final @NotNull BukkitCommandProcessor processor) { - // From ACF (https://github.com/aikar/commands) - // To allow commands to be registered on the plugin.yml - final org.bukkit.command.Command oldCommand = commandMap.getCommand(name); - if (oldCommand instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) oldCommand).getPlugin() == plugin) { - bukkitCommands.remove(name); - oldCommand.unregister(commandMap); - } - - final BukkitCommand newCommand = new BukkitCommand<>(processor, getSenderMapper(), registryContainer.getMessageRegistry()); - commandMap.register(plugin.getName(), newCommand); - return newCommand; + return create(plugin, new BukkitSenderExtension(), builder); } /** @@ -178,14 +137,14 @@ public void unregisterCommand(final @NotNull BaseCommand command) { * @param manager The {@link BukkitCommandManager} instance to set up. */ private static void setUpDefaults(final @NotNull BukkitCommandManager manager) { - manager.registerMessage(MessageKey.UNKNOWN_COMMAND, (sender, context) -> sender.sendMessage("Unknown command: `" + context.getCommand() + "`.")); + /*manager.registerMessage(MessageKey.UNKNOWN_COMMAND, (sender, context) -> sender.sendMessage("Unknown command: `" + context.getCommand() + "`.")); manager.registerMessage(MessageKey.TOO_MANY_ARGUMENTS, (sender, context) -> sender.sendMessage("Invalid usage.")); manager.registerMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, (sender, context) -> sender.sendMessage("Invalid usage.")); manager.registerMessage(MessageKey.INVALID_ARGUMENT, (sender, context) -> sender.sendMessage("Invalid argument `" + context.getTypedArgument() + "` for type `" + context.getArgumentType().getSimpleName() + "`.")); manager.registerMessage(BukkitMessageKey.NO_PERMISSION, (sender, context) -> sender.sendMessage("You do not have permission to perform this command. Permission needed: `" + context.getNodes() + "`.")); manager.registerMessage(BukkitMessageKey.PLAYER_ONLY, (sender, context) -> sender.sendMessage("This command can only be used by players.")); - manager.registerMessage(BukkitMessageKey.CONSOLE_ONLY, (sender, context) -> sender.sendMessage("This command can only be used by the console.")); + manager.registerMessage(BukkitMessageKey.CONSOLE_ONLY, (sender, context) -> sender.sendMessage("This command can only be used by the console."));*/ } /** @@ -216,4 +175,53 @@ private static void setUpDefaults(final @NotNull BukkitCommandManager command = commands.get(name); + if (command != null) { + // TODO: Command exists, only care about adding subs + return; + } + + // Command does not exist, proceed to add new! + + // final BukkitCommandProcessor processor = new BukkitCommandProcessor<>(name, baseCommand, basePermission); + + // final BukkitCommand newCommand = commands.computeIfAbsent(processor.getName(), it -> createAndRegisterCommand(it, processor)); + + // TODO: ADD SUBCOMMANDS + + /*processor.getAlias().forEach(it -> { + final BukkitCommand aliasCommand = commands.computeIfAbsent(it, ignored -> createAndRegisterCommand(it, processor)); + // Adding sub commands. + // TODO: ADD SUBCOMMANDS + });*/ + } + + @Override + public void unregisterCommand(final @NotNull Object command) { + // TODO add a remove functionality + } + + @Override + protected @NotNull RegistryContainer getRegistryContainer() { + return registryContainer; + } + + private @NotNull BukkitCommand createAndRegisterCommand(final @NotNull String name, final @NotNull BukkitCommandProcessor processor) { + // From ACF (https://github.com/aikar/commands) + // To allow commands to be registered on the plugin.yml + final org.bukkit.command.Command oldCommand = commandMap.getCommand(name); + if (oldCommand instanceof PluginIdentifiableCommand && ((PluginIdentifiableCommand) oldCommand).getPlugin() == plugin) { + bukkitCommands.remove(name); + oldCommand.unregister(commandMap); + } + + /*final BukkitCommand newCommand = new BukkitCommand<>(processor, getSenderMapper(), registryContainer.getMessageRegistry()); + commandMap.register(plugin.getName(), newCommand); + return newCommand;*/ + return null; + } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java new file mode 100644 index 00000000..d155e29d --- /dev/null +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java @@ -0,0 +1,25 @@ +package dev.triumphteam.cmd.bukkit; + +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.CommandOptions; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +public final class BukkitCommandOptions extends CommandOptions { + + public BukkitCommandOptions( + final @NotNull SenderExtension senderExtension, + final @NotNull CommandExtensions commandExtensions + ) { + super(senderExtension, commandExtensions); + } + + public static final class Builder extends CommandOptions.Builder, Builder> { + + @Override + public @NotNull BukkitCommandOptions build(final @NotNull SenderExtension senderExtension) { + return new BukkitCommandOptions<>(senderExtension, getCommandExtensions()); + } + } +} diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java similarity index 58% rename from minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java rename to minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java index fa89e41d..fb7c4500 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderValidator.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java @@ -24,11 +24,9 @@ package dev.triumphteam.cmd.bukkit; import com.google.common.collect.ImmutableSet; -import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; -import dev.triumphteam.cmd.core.subcommand.OldSubCommand; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.command.ExecutableCommand; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; @@ -39,11 +37,8 @@ /** * Simple mapper than returns itself. */ -class BukkitSenderValidator implements SenderValidator { +class BukkitSenderExtension implements SenderExtension.Default { - /** - * {@inheritDoc} - */ @Override public @NotNull Set> getAllowedSenders() { return ImmutableSet.of(CommandSender.class, ConsoleCommandSender.class, Player.class); @@ -52,29 +47,9 @@ class BukkitSenderValidator implements SenderValidator { @Override public boolean validate( final @NotNull MessageRegistry messageRegistry, - final @NotNull OldSubCommand subCommand, + final @NotNull ExecutableCommand command, final @NotNull CommandSender sender ) { - final Class senderClass = subCommand.getSenderType(); - - if (Player.class.isAssignableFrom(senderClass) && !(sender instanceof Player)) { - messageRegistry.sendMessage( - BukkitMessageKey.PLAYER_ONLY, - sender, - new DefaultMessageContext(subCommand.getParentName(), subCommand.getName()) - ); - return false; - } - - if (ConsoleCommandSender.class.isAssignableFrom(senderClass) && !(sender instanceof ConsoleCommandSender)) { - messageRegistry.sendMessage( - BukkitMessageKey.CONSOLE_ONLY, - sender, - new DefaultMessageContext(subCommand.getParentName(), subCommand.getName()) - ); - return false; - } - return true; } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 41400a7b..b5b634c7 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -25,8 +25,11 @@ import dev.triumphteam.cmd.core.CommandManager; import dev.triumphteam.cmd.core.extention.CommandOptions; +import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; +import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.InvalidCommandContext; import dev.triumphteam.cmd.core.processor.RootCommandProcessor; @@ -48,11 +51,20 @@ private SimpleCommandManager(final @NotNull CommandOptions commandOptions) super(commandOptions); } - @Contract("_ -> new") - public static @NotNull SimpleCommandManager create(final @NotNull Consumer> builder) { - final SimpleCommandOptions.Builder extensionBuilder = new SimpleCommandOptions.Builder<>(); + @Contract("_, _ -> new") + public static @NotNull SimpleCommandManager create( + final @NotNull SenderExtension senderExtension, + final @NotNull Consumer> builder + ) { + final SimpleOptionsBuilder extensionBuilder = new SimpleOptionsBuilder<>(); + + extensionBuilder.extensions(extension -> { + extension.setArgumentValidator(new DefaultArgumentValidator<>()); + extension.setCommandExecutor(new DefaultCommandExecutor()); + }); + builder.accept(extensionBuilder); - return new SimpleCommandManager<>(extensionBuilder.build()); + return new SimpleCommandManager<>(extensionBuilder.build(senderExtension)); } @Override diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java similarity index 57% rename from simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java rename to simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java index 5e5aa766..14e1228c 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandOptions.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java @@ -23,30 +23,14 @@ */ package dev.triumphteam.cmds.simple; -import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.CommandOptions; -import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; -import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.NotNull; -public final class SimpleCommandOptions extends CommandOptions { +final class SimpleOptionsBuilder extends CommandOptions.Builder, SimpleOptionsBuilder> { - public SimpleCommandOptions(final @NotNull CommandExtensions commandExtensions) { - super(commandExtensions); - } - - public static final class Builder extends CommandOptions.Builder, Builder> { - - public Builder() { - super(builder -> { - builder.setArgumentValidator(new DefaultArgumentValidator<>()); - builder.setCommandExecutor(new DefaultCommandExecutor()); - }); - } - - @Override - public @NotNull SimpleCommandOptions build() { - return new SimpleCommandOptions<>(getCommandExtensions()); - } + @Override + public @NotNull CommandOptions build(final @NotNull SenderExtension senderExtension) { + return new CommandOptions<>(senderExtension, getCommandExtensions()); } } From fa5aec4ecc076ca54398951120027f6dfb868d00 Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 20 Jan 2023 21:45:09 +0000 Subject: [PATCH 060/101] chore: Make builder public --- .../java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java index 14e1228c..fca9092f 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java @@ -27,7 +27,7 @@ import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.NotNull; -final class SimpleOptionsBuilder extends CommandOptions.Builder, SimpleOptionsBuilder> { +public final class SimpleOptionsBuilder extends CommandOptions.Builder, SimpleOptionsBuilder> { @Override public @NotNull CommandOptions build(final @NotNull SenderExtension senderExtension) { From db9c785bd3f13fa2a7eea92ca6eecb221177f13b Mon Sep 17 00:00:00 2001 From: Matt Date: Fri, 20 Jan 2023 21:54:08 +0000 Subject: [PATCH 061/101] chore: Yeeting old code to re-implement Bukkit --- .../bukkit/BukkitAsyncExecutionProvider.java | 49 ----- .../triumphteam/cmd/bukkit/BukkitCommand.java | 80 +++------ .../cmd/bukkit/BukkitCommandManager.java | 5 +- .../cmd/bukkit/BukkitCommandProcessor.java | 75 -------- .../cmd/bukkit/BukkitSenderExtension.java | 1 + .../cmd/bukkit/BukkitSubCommand.java | 78 -------- .../cmd/bukkit/BukkitSubCommandProcessor.java | 69 ------- .../cmd/bukkit/OldBukkitCommand.java | 168 ------------------ 8 files changed, 33 insertions(+), 492 deletions(-) delete mode 100644 minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitAsyncExecutionProvider.java delete mode 100644 minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java delete mode 100644 minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java delete mode 100644 minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java delete mode 100644 minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitAsyncExecutionProvider.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitAsyncExecutionProvider.java deleted file mode 100644 index a8b4faba..00000000 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitAsyncExecutionProvider.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.bukkit; - -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import org.bukkit.Bukkit; -import org.bukkit.plugin.Plugin; -import org.jetbrains.annotations.NotNull; - -/** - * Implementation of asynchronous execution, not necessarily used in all platforms. - */ -public final class BukkitAsyncExecutionProvider implements ExecutionProvider { - - private final Plugin plugin; - - public BukkitAsyncExecutionProvider(final @NotNull Plugin plugin) { - this.plugin = plugin; - } - - /** - * {@inheritDoc} - */ - @Override - public void execute(final @NotNull Runnable command) { - Bukkit.getScheduler().runTaskAsynchronously(plugin, command); - } -} diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index 38d9d217..d31e89df 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -23,81 +23,59 @@ */ package dev.triumphteam.cmd.bukkit; +import dev.triumphteam.cmd.core.command.ExecutableCommand; import dev.triumphteam.cmd.core.command.ParentCommand; -import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.subcommand.OldSubCommand; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.processor.RootCommandProcessor; +import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; -import java.util.Arrays; -import java.util.List; import java.util.Map; -public final class BukkitCommand extends org.bukkit.command.Command implements ParentCommand { +final class BukkitCommand extends Command implements ParentCommand { - private final SenderMapper senderMapper; - private final MessageRegistry messageRegistry; - - public BukkitCommand( - final @NotNull BukkitCommandProcessor processor, - final @NotNull SenderMapper senderMapper, + BukkitCommand( + final @NotNull RootCommandProcessor processor, final @NotNull MessageRegistry messageRegistry ) { super(processor.getName()); - - this.description = processor.getDescription(); - this.senderMapper = senderMapper; - this.messageRegistry = messageRegistry; } - /** - * {@inheritDoc} - * - * @throws CommandExecutionException If the sender mapper returns null. - */ @Override - public boolean execute( - final @NotNull CommandSender sender, - final @NotNull String commandLabel, - final @NotNull String @NotNull [] args - ) { - final List arguments = Arrays.asList(args); - final int argumentSize = arguments.size(); + public void addSubCommand(final @NotNull ExecutableCommand subCommand, final boolean isAlias) { - final OldSubCommand subCommand = getSubCommand(arguments); + } - final S mappedSender = senderMapper.map(sender); - if (mappedSender == null) { - throw new CommandExecutionException("Invalid sender. Sender mapper returned null"); - } + @Override + public boolean execute(@NotNull final CommandSender sender, @NotNull final String commandLabel, @NotNull final String[] args) { + return false; + } - if (subCommand == null || (argumentSize > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { - final String name = argumentSize == 0 ? dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME : arguments.get(0); - messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, mappedSender, new DefaultMessageContext(getName(), name)); - return true; - } + @Override + public @NotNull String getSyntax() { + return null; + } - // TODO: Better command check that is more abstracted - /*final CommandPermission permission = subCommand.getPermission(); - if (!CommandPermission.hasPermission(sender, permission)) { - messageRegistry.sendMessage(BukkitMessageKey.NO_PERMISSION, mappedSender, new NoPermissionMessageContext(getName(), subCommand.getName(), permission)); - return true; - }*/ - subCommand.execute(mappedSender, !subCommand.isDefault() ? arguments.subList(1, argumentSize) : arguments); - return true; + @Override + public @NotNull Map> getCommands() { + return null; + } + + @Override + public @NotNull Map> getCommandAliases() { + return null; } @Override - public @NotNull Map> getCommands() { + public @Nullable ExecutableCommand getParentCommandWithArgument() { return null; } @Override - public @NotNull Map> getCommandAliases() { + public @NotNull CommandMeta getMeta() { return null; } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index 2733323c..0c19c728 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -82,7 +82,6 @@ private BukkitCommandManager( /** * Creates a new instance of the {@link BukkitCommandManager}. - * This factory adds all the defaults based on the default sender {@link CommandSender}. * * @param plugin The {@link Plugin} instance created. * @return A new instance of the {@link BukkitCommandManager}. @@ -210,7 +209,9 @@ public void unregisterCommand(final @NotNull Object command) { return registryContainer; } - private @NotNull BukkitCommand createAndRegisterCommand(final @NotNull String name, final @NotNull BukkitCommandProcessor processor) { + private @NotNull BukkitCommand createAndRegisterCommand( + final @NotNull String name + ) { // From ACF (https://github.com/aikar/commands) // To allow commands to be registered on the plugin.yml final org.bukkit.command.Command oldCommand = commandMap.getCommand(name); diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java deleted file mode 100644 index 0f1d132a..00000000 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandProcessor.java +++ /dev/null @@ -1,75 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.bukkit; - -import dev.triumphteam.cmd.bukkit.annotation.Permission; -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.processor.AbstractRootCommandProcessor; -import org.bukkit.permissions.PermissionDefault; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.*; -import java.util.stream.Collectors; - -final class BukkitCommandProcessor extends AbstractRootCommandProcessor { - - private final CommandPermission basePermission; - - public BukkitCommandProcessor( - final @NotNull String name, - final @NotNull BaseCommand baseCommand, - final @Nullable CommandPermission globalBasePermission - ) { - super(name, baseCommand); - - final Permission annotation = baseCommand.getClass().getAnnotation(Permission.class); - if (annotation == null) { - this.basePermission = null; - return; - } - - this.basePermission = createPermission( - globalBasePermission, - Arrays.stream(annotation.value()).collect(Collectors.toList()), - annotation.description(), - annotation.def() - ); - } - - public CommandPermission getBasePermission() { - return basePermission; - } - - static CommandPermission createPermission( - final @Nullable CommandPermission parent, - final @NotNull List nodes, - final @NotNull String description, - final @NotNull PermissionDefault permissionDefault - ) { - return parent == null - ? new CommandPermission(nodes, description, permissionDefault) - : parent.child(nodes, description, permissionDefault); - } -} diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java index fb7c4500..4b7ba604 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java @@ -50,6 +50,7 @@ public boolean validate( final @NotNull ExecutableCommand command, final @NotNull CommandSender sender ) { + // TODO return true; } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java deleted file mode 100644 index 438d6b9d..00000000 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommand.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.bukkit; - -import dev.triumphteam.cmd.core.subcommand.OldSubCommand; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.suggestion.SuggestionContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -import static java.util.Collections.emptyList; - -public final class BukkitSubCommand extends OldSubCommand { - - private final CommandPermission permission; - - public BukkitSubCommand(final @NotNull BukkitSubCommandProcessor processor, final @NotNull String parentName, final @NotNull ExecutionProvider executionProvider) { - super(processor, parentName, executionProvider); - this.permission = processor.getPermission(); - - if (this.permission != null) this.permission.register(); - } - - public @NotNull List getSuggestions(final @NotNull S sender, final @NotNull List args) { - final int index = args.size() - 1; - final InternalArgument internalArgument = getArgument(index); - if (internalArgument == null) return emptyList(); - - final List trimmed; - if (internalArgument instanceof LimitlessInternalArgument) { - trimmed = args.subList(getArguments().size() - 1, args.size()); - } else { - trimmed = args.subList(index, args.size()); - } - - final SuggestionContext context = new SuggestionContext(args, getParentName(), getName()); - return internalArgument.suggestions(sender, trimmed, context); - } - - /** - * A {@link CommandPermission} used by this sub-command. - * - * @return The command's permission. - */ - public @Nullable CommandPermission getPermission() { - return permission; - } - - @Override - public @Nullable Object resolve(@NotNull final S sender, final @NotNull List value) { - return null; - } -} diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java deleted file mode 100644 index 0049cb25..00000000 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSubCommandProcessor.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.bukkit; - -import dev.triumphteam.cmd.bukkit.annotation.Permission; -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Arrays; -import java.util.stream.Collectors; -import java.lang.reflect.AnnotatedElement; - -final class BukkitSubCommandProcessor extends OldAbstractSubCommandProcessor { - - private final CommandPermission permission; - - public BukkitSubCommandProcessor( - final @NotNull BaseCommand baseCommand, - final @NotNull String parentName, - final @NotNull AnnotatedElement annotatedElement, - final @NotNull RegistryContainer registryContainer, - final @NotNull SenderValidator senderValidator, - final @Nullable CommandPermission basePermission - ) { - super(baseCommand, parentName, annotatedElement, registryContainer, senderValidator); - - final Permission annotation = annotatedElement.getAnnotation(Permission.class); - if (annotation == null) { - this.permission = basePermission; - return; - } - - permission = BukkitCommandProcessor.createPermission( - basePermission, - Arrays.stream(annotation.value()).collect(Collectors.toList()), - annotation.description(), - annotation.def() - ); - } - - public @Nullable CommandPermission getPermission() { - return permission; - } -} diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java deleted file mode 100644 index 6e460461..00000000 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/OldBukkitCommand.java +++ /dev/null @@ -1,168 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.bukkit; - -import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; -import dev.triumphteam.cmd.bukkit.message.NoPermissionMessageContext; -import dev.triumphteam.cmd.core.annotation.AnnotationContainer; -import dev.triumphteam.cmd.core.command.Command; -import dev.triumphteam.cmd.core.command.ParentCommand; -import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import org.bukkit.command.CommandSender; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -import static java.util.Collections.emptyList; - -public final class OldBukkitCommand extends org.bukkit.command.Command implements ParentCommand> { - - private final MessageRegistry messageRegistry; - - private final SenderMapper senderMapper; - - private final Map> subCommands = new HashMap<>(); - private final Map> subCommandAliases = new HashMap<>(); - - public OldBukkitCommand(final @NotNull String name, final @NotNull BukkitCommandProcessor processor) { - super(name); - - this.description = processor.getDescription(); - this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); - this.senderMapper = processor.getSenderMapper(); - } - - @Override - public void addSubCommand(final @NotNull String name, final @NotNull BukkitSubCommand subCommand) { - subCommands.putIfAbsent(name, subCommand); - } - - @Override - public void addSubCommandAlias(final @NotNull String alias, final @NotNull BukkitSubCommand subCommand) { - subCommandAliases.putIfAbsent(alias, subCommand); - } - - /** - * {@inheritDoc} - * @throws CommandExecutionException If the sender mapper returns null. - */ - @Override - public boolean execute( - final @NotNull CommandSender sender, - final @NotNull String commandLabel, - final @NotNull String @NotNull [] args - ) { - /*BukkitSubCommand subCommand = getDefaultSubCommand(); - - String subCommandName = ""; - if (args.length > 0) subCommandName = args[0].toLowerCase(); - if (subCommand == null || subCommandExists(subCommandName)) { - subCommand = getSubCommand(subCommandName); - } - - final S mappedSender = senderMapper.map(sender); - if (mappedSender == null) { - throw new CommandExecutionException("Invalid sender. Sender mapper returned null"); - } - - if (subCommand == null || (args.length > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { - messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, mappedSender, new DefaultMessageContext(getName(), subCommandName)); - return true; - } - - final CommandPermission permission = subCommand.getPermission(); - if (!CommandPermission.hasPermission(sender, permission)) { - messageRegistry.sendMessage(BukkitMessageKey.NO_PERMISSION, mappedSender, new NoPermissionMessageContext(getName(), subCommand.getName(), permission)); - return true; - } - - final List commandArgs = Arrays.asList(!subCommand.isDefault() ? Arrays.copyOfRange(args, 1, args.length) : args); - - subCommand.execute(mappedSender, commandArgs);*/ - return true; - } - - @Override - public @NotNull List tabComplete(final @NotNull CommandSender sender, final @NotNull String alias, final @NotNull String @NotNull [] args) throws IllegalArgumentException { - if (args.length == 0) return emptyList(); - return emptyList(); - /*BukkitSubCommand subCommand = getDefaultSubCommand(); - - final String arg = args[0].toLowerCase(); - - if (args.length == 1 && (subCommand == null || !subCommand.hasArguments())) { - return subCommands.entrySet().stream() - .filter(it -> !it.getValue().isDefault()) - .filter(it -> it.getKey().startsWith(arg)) - .filter(it -> { - final CommandPermission permission = it.getValue().getPermission(); - return CommandPermission.hasPermission(sender, permission); - }) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); - } - - if (subCommandExists(arg)) subCommand = getSubCommand(arg); - if (subCommand == null) return emptyList(); - - final CommandPermission permission = subCommand.getPermission(); - if (!CommandPermission.hasPermission(sender, permission)) return emptyList(); - - final S mappedSender = senderMapper.map(sender); - if (mappedSender == null) { - return emptyList(); - } - - final List commandArgs = Arrays.asList(args); - return subCommand.getSuggestions(mappedSender, !subCommand.isDefault() ? commandArgs.subList(1, commandArgs.size()) : commandArgs);*/ - } - - @Override - public @NotNull AnnotationContainer getAnnotations() { - return null; - } - - @Override - public @NotNull Map> getCommands() { - return null; - } - - @Override - public @NotNull Map> getCommandAliases() { - return null; - } - - @Override - public void addSubCommand(final @NotNull String name, final @NotNull Command subCommand, final boolean isAlias) { - - } -} From 9b945e0e29b8a642fecf2ad5fb34ebdf82f2127b Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 21 Jan 2023 13:57:25 +0000 Subject: [PATCH 062/101] chore: Validation rework --- .../cmd/core/command/SubCommand.java | 31 ++++++++++++++----- ...ationResult.java => ValidationResult.java} | 24 +++++++------- .../extention/argument/ArgumentValidator.java | 15 ++++----- .../defaults/DefaultArgumentValidator.java | 4 +-- .../extention/sender/SenderExtension.java | 30 ++++++++++++------ .../processor/AbstractCommandProcessor.java | 22 ++++++------- .../processor/ParentCommandProcessor.java | 10 +++--- .../core/processor/RootCommandProcessor.java | 16 +++++----- .../core/processor/SubCommandProcessor.java | 28 ++++++++--------- .../cmds/CoroutinesCommandExtension.kt | 4 +-- .../cmd/bukkit/BukkitSenderExtension.java | 24 +++++++++----- .../cmd/bukkit/message/BukkitMessageKey.java | 24 +++----------- .../cmds/simple/SimpleCommandManager.java | 2 +- 13 files changed, 130 insertions(+), 104 deletions(-) rename core/src/main/java/dev/triumphteam/cmd/core/extention/{argument/ArgumentValidationResult.java => ValidationResult.java} (75%) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 4321b5d2..642447a3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -28,13 +28,16 @@ import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; +import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.ValidationResult; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.BasicMessageContext; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; +import dev.triumphteam.cmd.core.message.context.MessageContext; import dev.triumphteam.cmd.core.processor.CommandProcessor; import dev.triumphteam.cmd.core.processor.SubCommandProcessor; import dev.triumphteam.cmd.core.requirement.Requirement; @@ -82,9 +85,11 @@ public SubCommand( this.containsLimitless = arguments.stream().anyMatch(LimitlessInternalArgument.class::isInstance); + final CommandOptions commandOptions = processor.getCommandOptions(); + this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); - this.senderExtension = processor.getCommandExtensions().getSenderExtension(); - this.commandExecutor = processor.getCommandExtensions().getCommandExecutor(); + this.senderExtension = commandOptions.getSenderExtension(); + this.commandExecutor = commandOptions.getCommandExtensions().getCommandExecutor(); this.syntax = createSyntax(parentCommand, processor); } @@ -97,7 +102,19 @@ public void execute( final @NotNull List commandPath, final @NotNull List arguments ) throws Throwable { - if (!senderExtension.validate(messageRegistry, this, sender)) return; + final ValidationResult> validationResult = senderExtension.validate(meta, senderType, sender); + + // If the result is invalid for a reason given by the validator, we stop the execution and use its key to send + // a message to the sender + if (validationResult instanceof ValidationResult.Invalid) { + messageRegistry.sendMessage( + ((ValidationResult.Invalid>) validationResult).getMessage(), + sender, + new BasicMessageContext(meta, syntax) + ); + return; + } + if (!meetRequirements(sender)) return; // Creates the invoking arguments list diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidationResult.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ValidationResult.java similarity index 75% rename from core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidationResult.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/ValidationResult.java index 6237d89f..21fc4c6e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidationResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ValidationResult.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -21,25 +21,25 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.extention.argument; +package dev.triumphteam.cmd.core.extention; import org.jetbrains.annotations.NotNull; -public interface ArgumentValidationResult { +public interface ValidationResult { - class Valid implements ArgumentValidationResult {} + class Valid implements ValidationResult {} - class Ignore implements ArgumentValidationResult {} + class Ignore implements ValidationResult {} - class Invalid implements ArgumentValidationResult { + class Invalid implements ValidationResult { - private final String message; + private final E message; - public Invalid(final @NotNull String message) { + public Invalid(final @NotNull E message) { this.message = message; } - public @NotNull String getMessage() { + public @NotNull E getMessage() { return message; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java index 09746251..7298728e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/ArgumentValidator.java @@ -24,27 +24,28 @@ package dev.triumphteam.cmd.core.extention.argument; import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.extention.ValidationResult; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; public interface ArgumentValidator { - ArgumentValidationResult validate( + ValidationResult validate( final @NotNull CommandMeta meta, final @NotNull InternalArgument argument, final int position, final int last ); - default ArgumentValidationResult invalid(final @NotNull String message) { - return new ArgumentValidationResult.Invalid(message); + default ValidationResult invalid(final @NotNull String message) { + return new ValidationResult.Invalid<>(message); } - default ArgumentValidationResult valid() { - return new ArgumentValidationResult.Valid(); + default ValidationResult valid() { + return new ValidationResult.Valid<>(); } - default ArgumentValidationResult ignore() { - return new ArgumentValidationResult.Ignore(); + default ValidationResult ignore() { + return new ValidationResult.Ignore<>(); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java index fef4b200..d4c4cba7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/DefaultArgumentValidator.java @@ -26,7 +26,7 @@ import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; -import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult; +import dev.triumphteam.cmd.core.extention.ValidationResult; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; @@ -34,7 +34,7 @@ public class DefaultArgumentValidator implements ArgumentValidator { @Override - public ArgumentValidationResult validate( + public ValidationResult validate( final @NotNull CommandMeta data, final @NotNull InternalArgument argument, final int position, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java index c88abc14..2ed82c0a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,8 +23,10 @@ */ package dev.triumphteam.cmd.core.extention.sender; -import dev.triumphteam.cmd.core.command.ExecutableCommand; -import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.ValidationResult; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.context.MessageContext; import org.jetbrains.annotations.NotNull; import java.util.Set; @@ -33,9 +35,9 @@ public interface SenderExtension extends SenderMapper { @NotNull Set> getAllowedSenders(); - boolean validate( - final @NotNull MessageRegistry messageRegistry, - final @NotNull ExecutableCommand command, + @NotNull ValidationResult<@NotNull MessageKey<@NotNull MessageContext>> validate( + final @NotNull CommandMeta meta, + final @NotNull Class allowedSender, final @NotNull S sender ); @@ -51,4 +53,14 @@ interface Default extends SenderExtension { return sender; } } + + static ValidationResult<@NotNull MessageKey<@NotNull MessageContext>> valid() { + return new ValidationResult.Valid<>(); + } + + static ValidationResult<@NotNull MessageKey<@NotNull MessageContext>> invalid( + final @NotNull MessageKey<@NotNull MessageContext> messageKey + ) { + return new ValidationResult.Invalid<>(messageKey); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index eaf95a17..1086e1b0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -36,20 +36,20 @@ import dev.triumphteam.cmd.core.argument.EnumInternalArgument; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.JoinedStringInternalArgument; -import dev.triumphteam.cmd.core.argument.StringInternalArgument; -import dev.triumphteam.cmd.core.argument.keyed.Keyed; -import dev.triumphteam.cmd.core.argument.keyed.KeyedInternalArgument; import dev.triumphteam.cmd.core.argument.ResolverInternalArgument; import dev.triumphteam.cmd.core.argument.SplitStringInternalArgument; +import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; -import dev.triumphteam.cmd.core.argument.keyed.Arguments; -import dev.triumphteam.cmd.core.argument.keyed.Flags; import dev.triumphteam.cmd.core.argument.keyed.Argument; import dev.triumphteam.cmd.core.argument.keyed.ArgumentGroup; +import dev.triumphteam.cmd.core.argument.keyed.Arguments; import dev.triumphteam.cmd.core.argument.keyed.Flag; +import dev.triumphteam.cmd.core.argument.keyed.Flags; +import dev.triumphteam.cmd.core.argument.keyed.Keyed; +import dev.triumphteam.cmd.core.argument.keyed.KeyedInternalArgument; import dev.triumphteam.cmd.core.argument.keyed.ListArgument; import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; @@ -100,14 +100,14 @@ abstract class AbstractCommandProcessor implements CommandProcessor { private final SuggestionRegistry suggestionRegistry; private final ArgumentRegistry argumentRegistry; - private final CommandExtensions commandExtensions; + private final CommandOptions commandOptions; private final CommandMeta parentMeta; AbstractCommandProcessor( final @NotNull Object invocationInstance, final @NotNull AnnotatedElement annotatedElement, final @NotNull RegistryContainer registryContainer, - final @NotNull CommandExtensions commandExtensions, + final @NotNull CommandOptions commandOptions, final @NotNull CommandMeta parentMeta ) { this.invocationInstance = invocationInstance; @@ -116,7 +116,7 @@ abstract class AbstractCommandProcessor implements CommandProcessor { this.description = descriptionOf(); this.parentMeta = parentMeta; - this.commandExtensions = commandExtensions; + this.commandOptions = commandOptions; this.registryContainer = registryContainer; this.suggestionRegistry = registryContainer.getSuggestionRegistry(); this.argumentRegistry = registryContainer.getArgumentRegistry(); @@ -128,8 +128,8 @@ abstract class AbstractCommandProcessor implements CommandProcessor { return registryContainer; } - public @NotNull CommandExtensions getCommandExtensions() { - return commandExtensions; + public @NotNull CommandOptions getCommandOptions() { + return commandOptions; } protected @NotNull CommandMeta getParentMeta() { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java index 2ea8c251..21a3f0df 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.processor; -import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.meta.MetaKey; @@ -47,10 +47,10 @@ public final class ParentCommandProcessor extends AbstractCommandProcessor final @NotNull Object invocationInstance, final @NotNull Class klass, final @NotNull RegistryContainer registryContainer, - final @NotNull CommandExtensions commandExtensions, + final @NotNull CommandOptions commandOptions, final @NotNull CommandMeta parentMeta ) { - super(invocationInstance, klass, registryContainer, commandExtensions, parentMeta); + super(invocationInstance, klass, registryContainer, commandOptions, parentMeta); this.klass = klass; } @@ -64,8 +64,8 @@ public final class ParentCommandProcessor extends AbstractCommandProcessor meta.add(MetaKey.DESCRIPTION, getDescription()); // Process all the class annotations - processAnnotations(getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); - processCommandMeta(getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); + processAnnotations(getCommandOptions().getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); + processCommandMeta(getCommandOptions().getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); // Return modified meta return meta.build(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index 8d1c2b07..e5036254 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -36,7 +36,7 @@ import dev.triumphteam.cmd.core.command.ParentSubCommand; import dev.triumphteam.cmd.core.command.SubCommand; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; -import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.meta.MetaKey; @@ -66,13 +66,13 @@ public class RootCommandProcessor implements CommandProcessor { private final List alias; private final String description; - private final CommandExtensions commandExtensions; + private final CommandOptions commandOptions; private final RegistryContainer registryContainer; public RootCommandProcessor( final @NotNull Object invocationInstance, final @NotNull RegistryContainer registryContainer, - final @NotNull CommandExtensions commandExtensions + final @NotNull CommandOptions commandOptions ) { this.invocationInstance = invocationInstance; @@ -81,7 +81,7 @@ public RootCommandProcessor( this.description = descriptionOf(); this.registryContainer = registryContainer; - this.commandExtensions = commandExtensions; + this.commandOptions = commandOptions; this.syntax = invocationInstance.getClass().getAnnotation(Syntax.class); } @@ -113,8 +113,8 @@ public String getDescription() { // Process all the class annotations final Class klass = invocationInstance.getClass(); - processAnnotations(commandExtensions, klass, ProcessorTarget.ROOT_COMMAND, meta); - processCommandMeta(commandExtensions, klass, ProcessorTarget.PARENT_COMMAND, meta); + processAnnotations(commandOptions.getCommandExtensions(), klass, ProcessorTarget.ROOT_COMMAND, meta); + processCommandMeta(commandOptions.getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); // Return modified meta return meta.build(); } @@ -142,7 +142,7 @@ public String getDescription() { invocationInstance, method, registryContainer, - commandExtensions, + commandOptions, parentCommand.getMeta() ); @@ -169,7 +169,7 @@ public String getDescription() { invocationInstance, klass, registryContainer, - commandExtensions, + commandOptions, parentCommand.getMeta() ); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index 7f99c840..f6bfca95 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -29,14 +29,14 @@ import dev.triumphteam.cmd.core.annotations.Requirements; import dev.triumphteam.cmd.core.annotations.Suggestions; import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; -import dev.triumphteam.cmd.core.argument.keyed.FlagKey; import dev.triumphteam.cmd.core.argument.keyed.Argument; import dev.triumphteam.cmd.core.argument.keyed.ArgumentGroup; +import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; import dev.triumphteam.cmd.core.argument.keyed.Flag; -import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.argument.keyed.FlagKey; +import dev.triumphteam.cmd.core.extention.CommandOptions; +import dev.triumphteam.cmd.core.extention.ValidationResult; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; -import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.meta.MetaKey; import dev.triumphteam.cmd.core.extention.registry.FlagRegistry; @@ -89,10 +89,10 @@ public final class SubCommandProcessor extends AbstractCommandProcessor registryContainer, - final @NotNull CommandExtensions commandExtensions, + final @NotNull CommandOptions commandOptions, final @NotNull CommandMeta parentMeta ) { - super(invocationInstance, method, registryContainer, commandExtensions, parentMeta); + super(invocationInstance, method, registryContainer, commandOptions, parentMeta); this.method = method; this.namedArgumentRegistry = registryContainer.getNamedArgumentRegistry(); @@ -109,8 +109,8 @@ public final class SubCommandProcessor extends AbstractCommandProcessor extends AbstractCommandProcessor type = parameters[0].getType(); - final Set> allowedSenders = getCommandExtensions().getSenderExtension().getAllowedSenders(); + final Set> allowedSenders = getCommandOptions().getSenderExtension().getAllowedSenders(); if (!allowedSenders.contains(type)) { throw createException( @@ -157,7 +157,7 @@ public final class SubCommandProcessor extends AbstractCommandProcessor parameterMetas = new HashMap<>(); for (final Parameter parameter : parameters) { final CommandMeta.Builder meta = new CommandMeta.Builder(parentMeta); - processAnnotations(getCommandExtensions(), parameter, ProcessorTarget.ARGUMENT, meta); + processAnnotations(getCommandOptions().getCommandExtensions(), parameter, ProcessorTarget.ARGUMENT, meta); parameterMetas.put(parameter, meta.build()); } @@ -192,15 +192,15 @@ public final class SubCommandProcessor extends AbstractCommandProcessor result = getCommandOptions().getCommandExtensions().getArgumentValidator().validate(meta, argument, i, last); // If the result is invalid we throw the exception with the passed message - if (result instanceof ArgumentValidationResult.Invalid) { - throw createException(((ArgumentValidationResult.Invalid) result).getMessage()); + if (result instanceof ValidationResult.Invalid) { + throw createException(((ValidationResult.Invalid) result).getMessage()); } // If it's ignorable we ignore it and don't add to the argument list - if (result instanceof ArgumentValidationResult.Ignore) continue; + if (result instanceof ValidationResult.Ignore) continue; // If valid argument then add to list arguments.add(argument); diff --git a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt index 5a191334..706c5c68 100644 --- a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt +++ b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt @@ -28,8 +28,8 @@ import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument import dev.triumphteam.cmd.core.argument.UnknownInternalArgument import dev.triumphteam.cmd.core.command.CommandExecutor import dev.triumphteam.cmd.core.extention.ExtensionBuilder +import dev.triumphteam.cmd.core.extention.ValidationResult import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget -import dev.triumphteam.cmd.core.extention.argument.ArgumentValidationResult import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor import dev.triumphteam.cmd.core.extention.meta.CommandMeta @@ -82,7 +82,7 @@ public class CoroutinesCommandExtension( argument: InternalArgument, position: Int, last: Int, - ): ArgumentValidationResult { + ): ValidationResult { // If we're dealing with a suspending function, the meta will be present val suspend = meta.parentMeta?.isPresent(SUSPEND_META_KEY) ?: false diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java index 4b7ba604..22ee271a 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java @@ -24,9 +24,12 @@ package dev.triumphteam.cmd.bukkit; import com.google.common.collect.ImmutableSet; -import dev.triumphteam.cmd.core.command.ExecutableCommand; -import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; +import dev.triumphteam.cmd.core.extention.ValidationResult; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.context.MessageContext; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.entity.Player; @@ -45,12 +48,19 @@ class BukkitSenderExtension implements SenderExtension.Default { } @Override - public boolean validate( - final @NotNull MessageRegistry messageRegistry, - final @NotNull ExecutableCommand command, + public @NotNull ValidationResult<@NotNull MessageKey<@NotNull MessageContext>> validate( + final @NotNull CommandMeta meta, + final @NotNull Class allowedSender, final @NotNull CommandSender sender ) { - // TODO - return true; + if (Player.class.isAssignableFrom(allowedSender) && !(sender instanceof Player)) { + return SenderExtension.invalid(BukkitMessageKey.PLAYER_ONLY); + } + + if (ConsoleCommandSender.class.isAssignableFrom(allowedSender) && !(sender instanceof ConsoleCommandSender)) { + return SenderExtension.invalid(BukkitMessageKey.CONSOLE_ONLY); + } + + return SenderExtension.valid(); } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java index 03a166b9..9223165d 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java @@ -23,9 +23,8 @@ */ package dev.triumphteam.cmd.bukkit.message; -import dev.triumphteam.cmd.core.message.ContextualKey; +import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.MessageContext; -import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; /** @@ -33,30 +32,17 @@ * * @param A {@link MessageContext} type, this allows for better customization of the messages. */ -public final class BukkitMessageKey extends ContextualKey { +public final class BukkitMessageKey extends MessageKey { // Default keys - public static final BukkitMessageKey NO_PERMISSION = of("no.permission", NoPermissionMessageContext.class); - public static final BukkitMessageKey PLAYER_ONLY = of("player.only", MessageContext.class); - public static final BukkitMessageKey CONSOLE_ONLY = of("console.only", MessageContext.class); + public static final BukkitMessageKey NO_PERMISSION = new BukkitMessageKey<>("no.permission", NoPermissionMessageContext.class); + public static final BukkitMessageKey PLAYER_ONLY = new BukkitMessageKey<>("player.only", MessageContext.class); + public static final BukkitMessageKey CONSOLE_ONLY = new BukkitMessageKey<>("console.only", MessageContext.class); private BukkitMessageKey(final @NotNull String key, final @NotNull Class type) { super(key, type); } - /** - * Factory method for creating a {@link BukkitMessageKey}. - * - * @param key The value of the key, normally separated by .. - * @param type The {@link MessageContext} type. - * @param Generic {@link MessageContext} type. - * @return A new {@link BukkitMessageKey} for a specific {@link MessageContext}. - */ - @Contract("_, _ -> new") - private static @NotNull BukkitMessageKey of(final @NotNull String key, final @NotNull Class type) { - return new BukkitMessageKey<>(key, type); - } - @Override public @NotNull String toString() { return "BukkitMessageKey{super=" + super.toString() + "}"; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index b5b634c7..90759a0e 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -72,7 +72,7 @@ public void registerCommand(final @NotNull Object command) { final RootCommandProcessor processor = new RootCommandProcessor<>( command, getRegistryContainer(), - getCommandOptions().getCommandExtensions() + getCommandOptions() ); final String name = processor.getName(); From 68183685c35572adb183074d0144cbbe75efdea1 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 21 Jan 2023 15:17:29 +0000 Subject: [PATCH 063/101] feature: Bukkit basic execution --- .../cmd/core/command/ExecutableCommand.java | 1 - .../cmd/core/command/ParentSubCommand.java | 7 +- .../cmd/core/command/SubCommand.java | 1 - .../processor/AbstractCommandProcessor.java | 3 +- .../cmd/core/processor/CommandProcessor.java | 5 +- .../core/processor/RootCommandProcessor.java | 15 ++-- .../triumphteam/cmd/bukkit/BukkitCommand.java | 80 +++++++++++++++++-- .../cmd/bukkit/BukkitCommandManager.java | 26 ++++-- .../cmds/simple/SimpleCommand.java | 4 +- 9 files changed, 110 insertions(+), 32 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java index 23de633f..ead8a53b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java @@ -48,7 +48,6 @@ void execute( final @NotNull S sender, final @NotNull String command, final @Nullable Supplier instanceSupplier, - final @NotNull List commandPath, final @NotNull List arguments ) throws Throwable; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 71ebfe00..3cd0c930 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -114,7 +114,6 @@ public void execute( final @NotNull S sender, final @NotNull String command, final @Nullable Supplier instanceSupplier, - final @NotNull List commandPath, final @NotNull List arguments ) throws Throwable { final int argumentSize = arguments.size(); @@ -127,8 +126,6 @@ public void execute( return; } - commandPath.add(subCommand.getName()); - final Object instance; if (hasArgument) { @@ -158,9 +155,9 @@ public void execute( } subCommand.execute( - sender, commandName, + sender, + commandName, () -> instance, - commandPath, !subCommand.isDefault() && !arguments.isEmpty() ? arguments.subList(1, arguments.size()) : arguments ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 642447a3..640978e8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -99,7 +99,6 @@ public void execute( final @NotNull S sender, final @NotNull String command, final @Nullable Supplier instanceSupplier, - final @NotNull List commandPath, final @NotNull List arguments ) throws Throwable { final ValidationResult> validationResult = senderExtension.validate(meta, senderType, sender); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 1086e1b0..785e6c69 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -85,7 +85,7 @@ * @param The sender type. */ @SuppressWarnings("unchecked") -abstract class AbstractCommandProcessor implements CommandProcessor { +abstract class AbstractCommandProcessor implements CommandProcessor { private static final Set> SUPPORTED_COLLECTIONS = new HashSet<>(Arrays.asList(List.class, Set.class)); @@ -128,6 +128,7 @@ abstract class AbstractCommandProcessor implements CommandProcessor { return registryContainer; } + @Override public @NotNull CommandOptions getCommandOptions() { return commandOptions; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index f7c01d4f..ac1c5602 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -25,6 +25,7 @@ import dev.triumphteam.cmd.core.annotations.Syntax; import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; @@ -35,7 +36,7 @@ import java.lang.reflect.AnnotatedElement; import java.util.Map; -public interface CommandProcessor { +public interface CommandProcessor { /** * Create a new meta and handle some processing before it's fully created. @@ -44,6 +45,8 @@ public interface CommandProcessor { */ @NotNull CommandMeta createMeta(); + @NotNull CommandOptions getCommandOptions(); + @Nullable Syntax getSyntaxAnnotation(); /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index e5036254..3100f5e0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -57,7 +57,7 @@ import static java.util.Collections.emptyMap; @SuppressWarnings("unchecked") -public class RootCommandProcessor implements CommandProcessor { +public class RootCommandProcessor implements CommandProcessor { private final Object invocationInstance; @@ -98,6 +98,11 @@ public String getDescription() { return description; } + @Override + public @NotNull CommandOptions getCommandOptions() { + return commandOptions; + } + @Override public @Nullable Syntax getSyntaxAnnotation() { return syntax; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index d31e89df..6952f56a 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -25,57 +25,121 @@ import dev.triumphteam.cmd.core.command.ExecutableCommand; import dev.triumphteam.cmd.core.command.ParentCommand; +import dev.triumphteam.cmd.core.command.ParentSubCommand; +import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.context.InvalidCommandContext; import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.InvocationTargetException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; import java.util.Map; final class BukkitCommand extends Command implements ParentCommand { + private final Map> commands = new HashMap<>(); + + private final MessageRegistry messageRegistry; + private final String syntax; + + private final CommandMeta meta; + private ExecutableCommand parentCommandWithArgument; + private SenderExtension senderExtension; + BukkitCommand( - final @NotNull RootCommandProcessor processor, + final @NotNull RootCommandProcessor processor, final @NotNull MessageRegistry messageRegistry ) { super(processor.getName()); + + this.messageRegistry = messageRegistry; + this.meta = processor.createMeta(); + this.senderExtension = processor.getCommandOptions().getSenderExtension(); + + this.syntax = "/" + getName(); } @Override public void addSubCommand(final @NotNull ExecutableCommand subCommand, final boolean isAlias) { + // If it's a parent command with argument we add it + if (subCommand instanceof ParentSubCommand && subCommand.hasArguments()) { + if (parentCommandWithArgument != null) { + throw new CommandRegistrationException("Only one inner command with argument is allowed per command.", subCommand.getInvocationInstance().getClass()); + } + + parentCommandWithArgument = subCommand; + return; + } + commands.put(subCommand.getName(), subCommand); } @Override - public boolean execute(@NotNull final CommandSender sender, @NotNull final String commandLabel, @NotNull final String[] args) { - return false; + public boolean execute( + @NotNull final CommandSender sender, + @NotNull final String commandLabel, + @NotNull final String[] args + ) { + final List arguments = Arrays.asList(args); + + final String commandName = nameFromArguments(arguments); + final ExecutableCommand subCommand = getSubCommand(commandName, arguments.size()); + + final S mappedSender = senderExtension.map(sender); + + if (subCommand == null) { + messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, mappedSender, new InvalidCommandContext(meta, commandName)); + return true; + } + + // Executing the subcommand. + try { + subCommand.execute( + mappedSender, + commandName, + null, + !subCommand.isDefault() ? arguments.subList(1, arguments.size()) : arguments + ); + } catch (final @NotNull Throwable exception) { + throw new CommandExecutionException("An error occurred while executing the command") + .initCause(exception instanceof InvocationTargetException ? exception.getCause() : exception); + } + + return true; } @Override public @NotNull String getSyntax() { - return null; + return syntax; } @Override public @NotNull Map> getCommands() { - return null; + return commands; } @Override public @NotNull Map> getCommandAliases() { - return null; + return commands; } @Override public @Nullable ExecutableCommand getParentCommandWithArgument() { - return null; + return parentCommandWithArgument; } @Override public @NotNull CommandMeta getMeta() { - return null; + return meta; } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index 0c19c728..643ce3dc 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -29,6 +29,7 @@ import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.Server; @@ -175,18 +176,27 @@ private static void setUpDefaults(final @NotNull BukkitCommandManager processor = new RootCommandProcessor<>( + command, + getRegistryContainer(), + getCommandOptions() + ); - final BukkitCommand command = commands.get(name); - if (command != null) { + final String name = processor.getName(); + + final BukkitCommand bukkitCommand = commands.get(name); + if (bukkitCommand != null) { // TODO: Command exists, only care about adding subs return; } + final BukkitCommand newBukkitCommand = createAndRegisterCommand(processor, name); + processor.commands(newBukkitCommand).forEach(it -> newBukkitCommand.addSubCommand(it, false)); + // Command does not exist, proceed to add new! - // final BukkitCommandProcessor processor = new BukkitCommandProcessor<>(name, baseCommand, basePermission); + // final BukkitCommandProcessor processor = new BukkitCommandProcessor<>(name, command, basePermission); // final BukkitCommand newCommand = commands.computeIfAbsent(processor.getName(), it -> createAndRegisterCommand(it, processor)); @@ -210,6 +220,7 @@ public void unregisterCommand(final @NotNull Object command) { } private @NotNull BukkitCommand createAndRegisterCommand( + final @NotNull RootCommandProcessor processor, final @NotNull String name ) { // From ACF (https://github.com/aikar/commands) @@ -220,9 +231,8 @@ public void unregisterCommand(final @NotNull Object command) { oldCommand.unregister(commandMap); } - /*final BukkitCommand newCommand = new BukkitCommand<>(processor, getSenderMapper(), registryContainer.getMessageRegistry()); + final BukkitCommand newCommand = new BukkitCommand<>(processor, registryContainer.getMessageRegistry()); commandMap.register(plugin.getName(), newCommand); - return newCommand;*/ - return null; + return newCommand; } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index 9a951d7a..9c0ab918 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -105,9 +105,9 @@ public void execute( // Executing the subcommand. try { subCommand.execute( - sender, commandName, + sender, + commandName, null, - commandPath, !subCommand.isDefault() ? arguments.subList(1, arguments.size()) : arguments ); } catch (final @NotNull Throwable exception) { From d3af9a06da6e6fa4e41746bf061e3d9638484742 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 22 Jan 2023 18:52:28 -0600 Subject: [PATCH 064/101] feature: Using Deque for command navigation to simplify executions --- .../argument/CollectionInternalArgument.java | 3 +- .../core/argument/FlagInternalArgument.java | 5 +- .../JoinedStringInternalArgument.java | 3 +- .../argument/LimitlessInternalArgument.java | 3 +- .../core/argument/NamedInternalArgument.java | 3 +- .../core/argument/keyed/ArgumentParser.java | 3 +- .../argument/keyed/KeyedInternalArgument.java | 3 +- .../cmd/core/command/ExecutableCommand.java | 8 +- .../cmd/core/command/ParentCommand.java | 142 +++++++++++------- .../cmd/core/command/ParentSubCommand.java | 104 ++++--------- .../cmd/core/command/RootCommand.java | 91 +++++++++++ .../cmd/core/command/SubCommand.java | 20 +-- .../context/InvalidArgumentContext.java | 3 +- .../context/InvalidCommandContext.java | 3 +- .../message/context/InvalidInputContext.java | 5 +- .../processor/AbstractCommandProcessor.java | 1 + .../cmd/core/processor/CommandProcessor.java | 3 + .../core/processor/RootCommandProcessor.java | 5 + .../triumphteam/cmd/bukkit/BukkitCommand.java | 47 ++---- .../cmd/bukkit/BukkitCommandManager.java | 7 +- .../cmds/simple/SimpleCommand.java | 129 +--------------- .../cmds/simple/SimpleCommandManager.java | 8 +- 22 files changed, 279 insertions(+), 320 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java index 2269caff..11d475f4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java @@ -30,6 +30,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; import java.util.List; import java.util.Set; import java.util.function.BiFunction; @@ -70,7 +71,7 @@ public CollectionInternalArgument( @Override public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( final @NotNull S sender, - final @NotNull List value + final @NotNull Collection value ) { final Stream stream = value.stream().map(arg -> internalArgument.resolve(sender, arg)); if (collectionType == Set.class) return success(stream.collect(Collectors.toSet())); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java index 694b88fa..f6261f4a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java @@ -23,9 +23,9 @@ */ package dev.triumphteam.cmd.core.argument; -import dev.triumphteam.cmd.core.argument.keyed.Flags; import dev.triumphteam.cmd.core.argument.keyed.ArgumentGroup; import dev.triumphteam.cmd.core.argument.keyed.Flag; +import dev.triumphteam.cmd.core.argument.keyed.Flags; import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; @@ -35,6 +35,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; @@ -75,7 +76,7 @@ public FlagInternalArgument( @Override public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( final @NotNull S sender, - final @NotNull List value + final @NotNull Collection value ) { return null;// flagParser.parse(sender, value.size() == 1 ? Arrays.asList(value.get(0).split(" ")) : value); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java index d66f8b9a..150404c9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java @@ -30,6 +30,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; import java.util.List; import java.util.function.BiFunction; @@ -64,7 +65,7 @@ public JoinedStringInternalArgument( @Override public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( final @NotNull S sender, - final @NotNull List value + final @NotNull Collection value ) { return success(String.join(delimiter, value)); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java index ac4a8273..12d0c386 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java @@ -27,6 +27,7 @@ import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; +import java.util.Collection; import java.util.List; /** @@ -35,7 +36,7 @@ * * @param The sender type. */ -public abstract class LimitlessInternalArgument extends AbstractInternalArgument> { +public abstract class LimitlessInternalArgument extends AbstractInternalArgument> { public LimitlessInternalArgument( final @NotNull String name, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java index 18ece42d..6ec618f1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java @@ -33,6 +33,7 @@ import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -57,7 +58,7 @@ public NamedInternalArgument( @Override public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( final @NotNull S sender, - final @NotNull List value + final @NotNull Collection value ) { final Map parsedArgs = Collections.emptyMap();// ArgumentParser.parse(String.join(" ", value)); final Map mapped = new HashMap<>(parsedArgs.size()); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java index c3e1d5fa..f558ba6e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java @@ -26,6 +26,7 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayList; +import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -57,7 +58,7 @@ public ArgumentParser( * @param arguments A {@link List} of raw arguments. * @return A {@link Result} object containing the raw results of the parse. */ - public Result parse(final @NotNull List arguments) { + public Result parse(final @NotNull Collection arguments) { final Iterator tokens = arguments.iterator(); final Result result = new Result(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java index 7bde5f56..6a66312f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java @@ -33,6 +33,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -75,7 +76,7 @@ public KeyedInternalArgument( @Override public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( final @NotNull S sender, - final @NotNull List value + final @NotNull Collection value ) { final ArgumentParser.Result result = argumentParser.parse(value); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java index ead8a53b..e837af43 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java @@ -26,7 +26,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; +import java.util.Deque; +import java.util.Map; import java.util.function.Supplier; /** @@ -40,15 +41,14 @@ public interface ExecutableCommand extends Command { * Executes this command. * * @param sender The sender of the command. - * @param command The command typed. * @param instanceSupplier The instance supplier for execution. * @param arguments The list of arguments passed. */ void execute( final @NotNull S sender, - final @NotNull String command, final @Nullable Supplier instanceSupplier, - final @NotNull List arguments + final @NotNull Deque arguments, + final @NotNull Map extra ) throws Throwable; /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index 1e19532a..ba120337 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,10 +23,17 @@ */ package dev.triumphteam.cmd.core.command; +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.context.InvalidCommandContext; +import dev.triumphteam.cmd.core.processor.CommandProcessor; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.List; +import java.util.Deque; +import java.util.HashMap; import java.util.Map; /** @@ -35,83 +42,106 @@ * * @param The sender type. */ -public interface ParentCommand extends Command { +public abstract class ParentCommand implements Command { - /** - * @return The map with all the commands it holds. - */ - @NotNull Map> getCommands(); + private final Map> commands = new HashMap<>(); + private final Map> commandAliases = new HashMap<>(); - /** - * @return The map with all the command alias it holds. - */ - @NotNull Map> getCommandAliases(); + private final CommandMeta meta; - /** - * @return A parent command with arguments as a sub command. Null if none exists. - */ - @Nullable ExecutableCommand getParentCommandWithArgument(); + // Single parent command with argument + private ExecutableCommand parentCommandWithArgument; + + private final MessageRegistry messageRegistry; + + public ParentCommand(final @NotNull CommandProcessor processor) { + this.meta = processor.createMeta(); + this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); + } /** * Add a new command to the maps. * - * @param subCommand The sub command to be added. - * @param isAlias Whether it is an alias. + * @param command The sub command to be added. + * @param isAlias Whether it is an alias. */ - void addSubCommand(final @NotNull ExecutableCommand subCommand, final boolean isAlias); + public void addSubCommand(final @NotNull ExecutableCommand command, final boolean isAlias) { + // If it's a parent command with argument we add it + if (command instanceof ParentSubCommand && command.hasArguments()) { + if (parentCommandWithArgument != null) { + throw new CommandRegistrationException("Only one inner command with argument is allowed per command", command.getInvocationInstance().getClass()); + } + + parentCommandWithArgument = command; + return; + } - @Override - default boolean isDefault() { - return false; + // Normal commands are added here + commands.put(command.getName(), command); + + // TODO ALIAS } @Override - default boolean hasArguments() { - return !getCommands().isEmpty(); + public boolean isDefault() { + return false; } - /** - * Small abstraction to reduce repetition in the execution. - * - * @param name The name of the command, normally from {@link #nameFromArguments}. - * @param size The size of arguments passed to the execution. - * @return The default command, a sub command, or a parent command with arguments, and lastly null if none exist. - */ - default @Nullable ExecutableCommand getSubCommand(final @NotNull String name, final int size) { - ExecutableCommand subCommand = getDefaultSubCommand(); + protected @Nullable ExecutableCommand findCommand( + final @NotNull S sender, + final @NotNull Deque arguments + ) { + final String name = arguments.peek(); + + // Instant check for default + final ExecutableCommand defaultCommand = getDefaultCommand(); + + // No argument passed + if (name == null) { + // No default command found, send message and return null + // If there is default command then return it + if (defaultCommand == null) { + messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(meta, "")); + } - if (subCommand == null || subCommandExists(name)) { - subCommand = getSubCommand(name); + return defaultCommand; } - if (subCommand == null || (size > 0 && subCommand.isDefault() && !subCommand.hasArguments())) { - return getParentCommandWithArgument(); + final ExecutableCommand command = getCommandByName(name); + if (command != null) { + // Pop command out of arguments list and returns it + arguments.pop(); + return command; } - return subCommand; + if (defaultCommand == null || !defaultCommand.hasArguments()) { + // No command found with the name [name] + if (parentCommandWithArgument == null) { + messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(meta, name)); + } + + // Don't pop because it'll be the argument + return parentCommandWithArgument; + } + + // Default command is never null here + return defaultCommand; } - /** - * Gets the name of the command from the arguments given. - * - * @param arguments The list of arguments. - * @return The name or an empty string if there are no arguments. - */ - default @NotNull String nameFromArguments(final @NotNull List arguments) { - return arguments.size() > 0 ? arguments.get(0) : ""; + protected @Nullable ExecutableCommand getDefaultCommand() { + return commands.get(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); } - default @Nullable ExecutableCommand getDefaultSubCommand() { - return getCommands().get(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); + protected @Nullable ExecutableCommand getCommandByName(final @NotNull String key) { + return commands.getOrDefault(key, commandAliases.get(key)); } - default @Nullable ExecutableCommand getSubCommand(final @NotNull String key) { - final ExecutableCommand subCommand = getCommands().get(key); - if (subCommand != null) return subCommand; - return getCommandAliases().get(key); + @Override + public @NotNull CommandMeta getMeta() { + return meta; } - default boolean subCommandExists(final @NotNull String key) { - return getCommands().containsKey(key) || getCommandAliases().containsKey(key); + protected @NotNull MessageRegistry getMessageRegistry() { + return messageRegistry; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 3cd0c930..ebbf884e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,13 +26,10 @@ import dev.triumphteam.cmd.core.annotations.Syntax; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; -import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; -import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; -import dev.triumphteam.cmd.core.message.context.InvalidCommandContext; import dev.triumphteam.cmd.core.processor.CommandProcessor; import dev.triumphteam.cmd.core.processor.ParentCommandProcessor; import org.jetbrains.annotations.NotNull; @@ -40,8 +37,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.List; +import java.util.Deque; import java.util.Map; import java.util.function.BiFunction; import java.util.function.Supplier; @@ -53,24 +49,16 @@ * * @param The sender type to be used. */ -public class ParentSubCommand implements ParentCommand, ExecutableCommand { - - private final Map> commands = new HashMap<>(); - private final Map> commandAliases = new HashMap<>(); +public class ParentSubCommand extends ParentCommand implements ExecutableCommand { private final String name; private final String syntax; - private final CommandMeta meta; private final Object invocationInstance; private final Constructor constructor; private final boolean isStatic; private final StringInternalArgument argument; private final boolean hasArgument; - private final MessageRegistry messageRegistry; - - // Single parent command with argument - private ExecutableCommand parentCommandWithArgument; public ParentSubCommand( final @NotNull Object invocationInstance, @@ -80,6 +68,8 @@ public ParentSubCommand( final @NotNull ParentCommandProcessor processor, final @NotNull Command parentCommand ) { + super(processor); + this.invocationInstance = invocationInstance; this.constructor = constructor; this.isStatic = isStatic; @@ -87,58 +77,31 @@ public ParentSubCommand( this.hasArgument = argument != null; this.name = processor.getName(); - this.meta = processor.createMeta(); - this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); - this.syntax = createSyntax(parentCommand, processor); } - @Override - public void addSubCommand(final @NotNull ExecutableCommand subCommand, final boolean isAlias) { - // If it's a parent command with argument we add it - if (subCommand instanceof ParentSubCommand && subCommand.hasArguments()) { - if (parentCommandWithArgument != null) { - throw new CommandRegistrationException("Only one inner command with argument is allowed per command", invocationInstance.getClass()); - } - - parentCommandWithArgument = subCommand; - return; - } - - // Normal commands are added here - commands.put(subCommand.getName(), subCommand); - } - @Override public void execute( final @NotNull S sender, - final @NotNull String command, final @Nullable Supplier instanceSupplier, - final @NotNull List arguments + final @NotNull Deque arguments, + final @NotNull Map extra ) throws Throwable { - final int argumentSize = arguments.size(); - - final String commandName = nameFromArguments(arguments); - final ExecutableCommand subCommand = getSubCommand(commandName, argumentSize); - - if (subCommand == null) { - messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(meta, commandName)); - return; - } - + // First we handle the argument if there is any final Object instance; - if (hasArgument) { - final @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> result = - argument.resolve(sender, command); + final String argumentName = arguments.peek() == null ? "" : arguments.pop(); + + final @NotNull Result> result = + argument.resolve(sender, argumentName); if (result instanceof Result.Failure) { - messageRegistry.sendMessage( + getMessageRegistry().sendMessage( MessageKey.INVALID_ARGUMENT, sender, ((Result.Failure>) result) .getFail() - .apply(meta, syntax) + .apply(getMeta(), syntax) ); return; } @@ -154,11 +117,15 @@ public void execute( instance = createInstance(instanceSupplier); } - subCommand.execute( + final ExecutableCommand command = findCommand(sender, arguments); + if (command == null) return; + + // Simply execute the command with the given instance + command.execute( sender, - commandName, () -> instance, - !subCommand.isDefault() && !arguments.isEmpty() ? arguments.subList(1, arguments.size()) : arguments + arguments, + extra ); } @@ -198,7 +165,8 @@ public void execute( return constructor.newInstance(argumentValue); } - private @NotNull String createSyntax(final @NotNull Command parentCommand, final @NotNull CommandProcessor processor) { + private @NotNull String createSyntax(final @NotNull Command parentCommand, + final @NotNull CommandProcessor processor) { final Syntax syntaxAnnotation = processor.getSyntaxAnnotation(); if (syntaxAnnotation != null) return syntaxAnnotation.value(); @@ -226,28 +194,8 @@ public void execute( return invocationInstance; } - @Override - public @Nullable ExecutableCommand getParentCommandWithArgument() { - return parentCommandWithArgument; - } - @Override public boolean hasArguments() { return argument != null; } - - @Override - public @NotNull Map> getCommands() { - return commands; - } - - @Override - public @NotNull Map> getCommandAliases() { - return commandAliases; - } - - @Override - public @NotNull CommandMeta getMeta() { - return meta; - } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java new file mode 100644 index 00000000..ab8d6766 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java @@ -0,0 +1,91 @@ +/** + * MIT License + *

+ * Copyright (c) 2019-2021 Matt + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.command; + +import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; +import dev.triumphteam.cmd.core.processor.RootCommandProcessor; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.InvocationTargetException; +import java.util.Deque; +import java.util.Map; +import java.util.function.Supplier; + +public class RootCommand extends ParentCommand implements ExecutableCommand { + + private final String name; + private final String syntax; + + public RootCommand(final @NotNull RootCommandProcessor processor) { + super(processor); + + this.name = processor.getName(); + this.syntax = "/" + name; + } + + @Override + public void execute( + final @NotNull S sender, + final @Nullable Supplier instanceSupplier, + final @NotNull Deque arguments, + final @NotNull Map extra + ) { + final ExecutableCommand command = findCommand(sender, arguments); + if (command == null) return; + + // Executing the command and catch all exceptions to rethrow with better message + try { + command.execute( + sender, + null, + arguments, + extra + ); + } catch (final @NotNull Throwable exception) { + throw new CommandExecutionException("An error occurred while executing the command") + .initCause(exception instanceof InvocationTargetException ? exception.getCause() : exception); + } + } + + @Override + public @NotNull String getName() { + return name; + } + + @Override + public @NotNull String getSyntax() { + return syntax; + } + + @Override + public @NotNull Object getInvocationInstance() { + return null; + } + + @Override + public boolean hasArguments() { + return false; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 640978e8..6c0000f4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -47,7 +47,9 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; +import java.util.Deque; import java.util.List; +import java.util.Map; import java.util.function.BiFunction; import java.util.function.Supplier; @@ -97,9 +99,9 @@ public SubCommand( @Override public void execute( final @NotNull S sender, - final @NotNull String command, final @Nullable Supplier instanceSupplier, - final @NotNull List arguments + final @NotNull Deque arguments, + final @NotNull Map extra ) throws Throwable { final ValidationResult> validationResult = senderExtension.validate(meta, senderType, sender); @@ -179,20 +181,18 @@ public boolean hasArguments() { private boolean validateAndCollectArguments( final @NotNull S sender, final @NotNull List invokeArguments, - final @NotNull List commandArgs + final @NotNull Deque commandArgs ) { - for (int i = 0; i < arguments.size(); i++) { - final InternalArgument internalArgument = arguments.get(i); - + for (final InternalArgument internalArgument : arguments) { final @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> result; if (internalArgument instanceof LimitlessInternalArgument) { final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument; - final List leftOvers = leftOvers(commandArgs, i); - result = limitlessArgument.resolve(sender, leftOvers); + // From this point on [commandArgs] is treated as a simple Collection instead of Deque + result = limitlessArgument.resolve(sender, commandArgs); } else if (internalArgument instanceof StringInternalArgument) { final StringInternalArgument stringArgument = (StringInternalArgument) internalArgument; - final String arg = valueOrNull(commandArgs, i); + final String arg = commandArgs.peek(); if (arg == null || arg.isEmpty()) { if (internalArgument.isOptional()) { @@ -204,6 +204,8 @@ private boolean validateAndCollectArguments( return false; } + // Pop the command out + commandArgs.pop(); result = stringArgument.resolve(sender, arg); } else { // Should never happen, this should be a sealed type ... but hey, it's Java 8 diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java index dc378c3c..b4a2472d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidArgumentContext.java @@ -25,6 +25,7 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Context for when user types an invalid argument based on its type. @@ -38,7 +39,7 @@ public final class InvalidArgumentContext extends InvalidInputContext { public InvalidArgumentContext( final @NotNull CommandMeta meta, final @NotNull String syntax, - final @NotNull String invalidInput, + final @Nullable String invalidInput, final @NotNull String name, final @NotNull Class type ) { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidCommandContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidCommandContext.java index 3eef2ecc..ee406830 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidCommandContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidCommandContext.java @@ -25,6 +25,7 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Context for when user types an invalid argument based on its type. @@ -33,7 +34,7 @@ public final class InvalidCommandContext extends InvalidInputContext { public InvalidCommandContext( final @NotNull CommandMeta meta, - final @NotNull String invalidInput + final @Nullable String invalidInput ) { super(meta, invalidInput); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java index 16264e51..6b5fab12 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java @@ -25,6 +25,7 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * Context with an invalid input. @@ -35,10 +36,10 @@ abstract class InvalidInputContext extends SimpleMetaMessageContext { public InvalidInputContext( final @NotNull CommandMeta meta, - final @NotNull String invalidInput + final @Nullable String invalidInput ) { super(meta); - this.invalidInput = invalidInput; + this.invalidInput = invalidInput == null ? "" : invalidInput; } public @NotNull String getInvalidInput() { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 785e6c69..08e0978a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -124,6 +124,7 @@ abstract class AbstractCommandProcessor implements CommandProcessor this.syntax = annotatedElement.getAnnotation(Syntax.class); } + @Override public @NotNull RegistryContainer getRegistryContainer() { return registryContainer; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index ac1c5602..e45eb67f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -29,6 +29,7 @@ import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -47,6 +48,8 @@ public interface CommandProcessor { @NotNull CommandOptions getCommandOptions(); + @NotNull RegistryContainer getRegistryContainer(); + @Nullable Syntax getSyntaxAnnotation(); /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index 3100f5e0..d5287a3f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -103,6 +103,11 @@ public String getDescription() { return commandOptions; } + @Override + public @NotNull RegistryContainer getRegistryContainer() { + return registryContainer; + } + @Override public @Nullable Syntax getSyntaxAnnotation() { return syntax; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index 6952f56a..a56f2128 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -23,31 +23,23 @@ */ package dev.triumphteam.cmd.bukkit; -import dev.triumphteam.cmd.core.command.ExecutableCommand; -import dev.triumphteam.cmd.core.command.ParentCommand; -import dev.triumphteam.cmd.core.command.ParentSubCommand; -import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; -import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; -import dev.triumphteam.cmd.core.extention.meta.CommandMeta; -import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; -import dev.triumphteam.cmd.core.extention.sender.SenderExtension; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.context.InvalidCommandContext; -import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.lang.reflect.InvocationTargetException; -import java.util.Arrays; -import java.util.HashMap; import java.util.List; -import java.util.Map; -final class BukkitCommand extends Command implements ParentCommand { +final class BukkitCommand extends Command { + protected BukkitCommand(@NotNull final String name, @NotNull final String description, @NotNull final String usageMessage, @NotNull final List aliases) { + super(name, description, usageMessage, aliases); + } + + @Override + public boolean execute(@NotNull final CommandSender sender, @NotNull final String commandLabel, @NotNull final String[] args) { + return false; + } - private final Map> commands = new HashMap<>(); + /*private final Map> commands = new HashMap<>(); private final MessageRegistry messageRegistry; private final String syntax; @@ -69,21 +61,6 @@ final class BukkitCommand extends Command implements ParentCommand { this.syntax = "/" + getName(); } - @Override - public void addSubCommand(final @NotNull ExecutableCommand subCommand, final boolean isAlias) { - // If it's a parent command with argument we add it - if (subCommand instanceof ParentSubCommand && subCommand.hasArguments()) { - if (parentCommandWithArgument != null) { - throw new CommandRegistrationException("Only one inner command with argument is allowed per command.", subCommand.getInvocationInstance().getClass()); - } - - parentCommandWithArgument = subCommand; - return; - } - - commands.put(subCommand.getName(), subCommand); - } - @Override public boolean execute( @NotNull final CommandSender sender, @@ -92,6 +69,8 @@ public boolean execute( ) { final List arguments = Arrays.asList(args); + // TODO COMPOSITION OVER INHERITANCE TO REDUCE REPETITION + final String commandName = nameFromArguments(arguments); final ExecutableCommand subCommand = getSubCommand(commandName, arguments.size()); @@ -141,5 +120,5 @@ public boolean execute( @Override public @NotNull CommandMeta getMeta() { return meta; - } + }*/ } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index 643ce3dc..d6e95d3a 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -192,7 +192,7 @@ public void registerCommand(final @NotNull Object command) { } final BukkitCommand newBukkitCommand = createAndRegisterCommand(processor, name); - processor.commands(newBukkitCommand).forEach(it -> newBukkitCommand.addSubCommand(it, false)); + // processor.commands(newBukkitCommand).forEach(it -> newBukkitCommand.addSubCommand(it, false)); // Command does not exist, proceed to add new! @@ -231,8 +231,9 @@ public void unregisterCommand(final @NotNull Object command) { oldCommand.unregister(commandMap); } - final BukkitCommand newCommand = new BukkitCommand<>(processor, registryContainer.getMessageRegistry()); + /*final BukkitCommand newCommand = new BukkitCommand<>(processor, registryContainer.getMessageRegistry()); commandMap.register(plugin.getName(), newCommand); - return newCommand; + return newCommand;*/ + return null; } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java index 9c0ab918..4f2fe37e 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,126 +23,13 @@ */ package dev.triumphteam.cmds.simple; -import dev.triumphteam.cmd.core.command.ExecutableCommand; -import dev.triumphteam.cmd.core.command.ParentCommand; -import dev.triumphteam.cmd.core.command.ParentSubCommand; -import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; -import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; -import dev.triumphteam.cmd.core.extention.meta.CommandMeta; -import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.context.InvalidCommandContext; +import dev.triumphteam.cmd.core.command.RootCommand; import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +public final class SimpleCommand extends RootCommand { -public final class SimpleCommand implements ParentCommand { - - private final String name; - private final String syntax; - - private final MessageRegistry messageRegistry; - - private final Map> subCommands = new HashMap<>(); - private final Map> subCommandAliases = new HashMap<>(); - - private final CommandMeta meta; - private ExecutableCommand parentCommandWithArgument; - - public SimpleCommand( - final @NotNull RootCommandProcessor processor, - final @NotNull MessageRegistry messageRegistry - ) { - this.name = processor.getName(); - this.meta = processor.createMeta(); - - this.messageRegistry = messageRegistry; - this.syntax = "/" + name; - } - - @Override - public void addSubCommand(final @NotNull ExecutableCommand subCommand, final boolean isAlias) { - // If it's a parent command with argument we add it - if (subCommand instanceof ParentSubCommand && subCommand.hasArguments()) { - if (parentCommandWithArgument != null) { - throw new CommandRegistrationException("Only one inner command with argument is allowed per command.", subCommand.getInvocationInstance().getClass()); - } - - parentCommandWithArgument = subCommand; - return; - } - - // Normal commands are added here - - subCommands.put(subCommand.getName(), subCommand); - // TODO ALIAS - } - - public void execute( - final @NotNull S sender, - final @NotNull List arguments - ) { - - final String commandName = nameFromArguments(arguments); - final ExecutableCommand subCommand = getSubCommand(commandName, arguments.size()); - - final List commandPath = new ArrayList<>(); - - if (subCommand == null) { - messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(meta, commandName)); - return; - } - - // Add itself as beginning of path - commandPath.add(subCommand.getName()); - - // Executing the subcommand. - try { - subCommand.execute( - sender, - commandName, - null, - !subCommand.isDefault() ? arguments.subList(1, arguments.size()) : arguments - ); - } catch (final @NotNull Throwable exception) { - throw new CommandExecutionException("An error occurred while executing the command") - .initCause(exception instanceof InvocationTargetException ? exception.getCause() : exception); - } - } - - @Override - public @NotNull String getName() { - return name; - } - - @Override - public @NotNull String getSyntax() { - return syntax; - } - - @Override - public @Nullable ExecutableCommand getParentCommandWithArgument() { - return parentCommandWithArgument; - } - - @Override - public @NotNull Map> getCommands() { - return subCommands; - } - - @Override - public @NotNull Map> getCommandAliases() { - return subCommandAliases; - } - - @Override - public @NotNull CommandMeta getMeta() { - return meta; + public SimpleCommand(final @NotNull RootCommandProcessor processor) { + super(processor); } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 90759a0e..3700f7ca 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -36,6 +36,8 @@ import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import java.util.ArrayDeque; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -84,11 +86,11 @@ public void registerCommand(final @NotNull Object command) { } // Command does not exist, proceed to add new! - final SimpleCommand newSimpleCommand = commands.computeIfAbsent(processor.getName(), it -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); + final SimpleCommand newSimpleCommand = commands.computeIfAbsent(processor.getName(), it -> new SimpleCommand<>(processor)); processor.commands(newSimpleCommand).forEach(it -> newSimpleCommand.addSubCommand(it, false)); processor.getAlias().forEach(it -> { - final SimpleCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new SimpleCommand<>(processor, getRegistryContainer().getMessageRegistry())); + final SimpleCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new SimpleCommand<>(processor)); // Adding sub commands. processor.commands(aliasCommand).forEach(sub -> aliasCommand.addSubCommand(sub, false)); }); @@ -128,6 +130,6 @@ public void executeCommand(final @NotNull S sender, final @NotNull List return; } - command.execute(sender, args.subList(1, args.size())); + command.execute(sender, null, new ArrayDeque<>(args.subList(1, args.size())), Collections.emptyMap()); } } From 81dba298229fe0068b92d09ab577b06e80a04350 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 22 Jan 2023 18:54:51 -0600 Subject: [PATCH 065/101] chore: Feature is getting simpler --- .../cmds/simple/SimpleCommand.java | 35 ------------------- .../cmds/simple/SimpleCommandManager.java | 11 +++--- 2 files changed, 6 insertions(+), 40 deletions(-) delete mode 100644 simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java deleted file mode 100644 index 4f2fe37e..00000000 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommand.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * MIT License - *

- * Copyright (c) 2019-2021 Matt - *

- * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

- * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmds.simple; - -import dev.triumphteam.cmd.core.command.RootCommand; -import dev.triumphteam.cmd.core.processor.RootCommandProcessor; -import org.jetbrains.annotations.NotNull; - -public final class SimpleCommand extends RootCommand { - - public SimpleCommand(final @NotNull RootCommandProcessor processor) { - super(processor); - } -} diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 3700f7ca..30e4f114 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -24,6 +24,7 @@ package dev.triumphteam.cmds.simple; import dev.triumphteam.cmd.core.CommandManager; +import dev.triumphteam.cmd.core.command.RootCommand; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; @@ -45,7 +46,7 @@ public final class SimpleCommandManager extends CommandManager { - private final Map> commands = new HashMap<>(); + private final Map> commands = new HashMap<>(); private final RegistryContainer registryContainer = new RegistryContainer<>(); @@ -79,18 +80,18 @@ public void registerCommand(final @NotNull Object command) { final String name = processor.getName(); - final SimpleCommand simpleCommand = commands.get(name); + final RootCommand simpleCommand = commands.get(name); if (simpleCommand != null) { // TODO: Command exists, only care about adding subs return; } // Command does not exist, proceed to add new! - final SimpleCommand newSimpleCommand = commands.computeIfAbsent(processor.getName(), it -> new SimpleCommand<>(processor)); + final RootCommand newSimpleCommand = commands.computeIfAbsent(processor.getName(), it -> new RootCommand<>(processor)); processor.commands(newSimpleCommand).forEach(it -> newSimpleCommand.addSubCommand(it, false)); processor.getAlias().forEach(it -> { - final SimpleCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new SimpleCommand<>(processor)); + final RootCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new RootCommand<>(processor)); // Adding sub commands. processor.commands(aliasCommand).forEach(sub -> aliasCommand.addSubCommand(sub, false)); }); @@ -119,7 +120,7 @@ public void executeCommand(final @NotNull S sender, final @NotNull List if (args.isEmpty()) return; final String commandName = args.get(0); - final SimpleCommand command = commands.get(commandName); + final RootCommand command = commands.get(commandName); if (command == null) { registryContainer.getMessageRegistry().sendMessage( MessageKey.UNKNOWN_COMMAND, From 62b25861b4edd0578be5be0ded02ef26f4285c60 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 22 Jan 2023 19:33:26 -0600 Subject: [PATCH 066/101] chore: Yeet ExecutableCommand, since all commands are executable --- .../triumphteam/cmd/core/command/Command.java | 15 ++- .../cmd/core/command/ExecutableCommand.java | 58 ----------- .../cmd/core/command/ParentCommand.java | 31 +++--- .../cmd/core/command/ParentSubCommand.java | 9 +- .../cmd/core/command/RootCommand.java | 9 +- .../cmd/core/command/SubCommand.java | 9 +- .../core/processor/RootCommandProcessor.java | 39 ++++---- .../triumphteam/cmd/bukkit/BukkitCommand.java | 95 ++++--------------- .../cmd/bukkit/BukkitCommandManager.java | 9 +- .../cmds/simple/SimpleCommandManager.java | 4 +- 10 files changed, 81 insertions(+), 197 deletions(-) delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 4029a396..c6e3ed1d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -25,13 +25,26 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMetaContainer; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Deque; +import java.util.Map; +import java.util.function.Supplier; /** * Representation of a command. * Not all commands are executable directly. * Some implementations will have listeners inside that'll trigger the execution. */ -public interface Command extends CommandMetaContainer { +public interface Command extends CommandMetaContainer { + + // TODO + void execute( + final @NotNull S sender, + final @Nullable Supplier instanceSupplier, + final @NotNull Deque arguments, + final @NotNull Map extra + ) throws Throwable; /** * @return The name of the comamnd. diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java deleted file mode 100644 index e837af43..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ExecutableCommand.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.command; - -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Deque; -import java.util.Map; -import java.util.function.Supplier; - -/** - * An executable command is not just a holder that has its own triggers for commands but one that needs external execution trigger. - * - * @param The type of sender to be used. - */ -public interface ExecutableCommand extends Command { - - /** - * Executes this command. - * - * @param sender The sender of the command. - * @param instanceSupplier The instance supplier for execution. - * @param arguments The list of arguments passed. - */ - void execute( - final @NotNull S sender, - final @Nullable Supplier instanceSupplier, - final @NotNull Deque arguments, - final @NotNull Map extra - ) throws Throwable; - - /** - * @return The instance of the original command instance where the command belongs to. - */ - @NotNull Object getInvocationInstance(); -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index ba120337..d5443f92 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -42,15 +42,15 @@ * * @param The sender type. */ -public abstract class ParentCommand implements Command { +public abstract class ParentCommand implements Command { - private final Map> commands = new HashMap<>(); - private final Map> commandAliases = new HashMap<>(); + private final Map> commands = new HashMap<>(); + private final Map> commandAliases = new HashMap<>(); private final CommandMeta meta; // Single parent command with argument - private ExecutableCommand parentCommandWithArgument; + private Command parentCommandWithArgument; private final MessageRegistry messageRegistry; @@ -62,14 +62,19 @@ public ParentCommand(final @NotNull CommandProcessor processor) { /** * Add a new command to the maps. * - * @param command The sub command to be added. - * @param isAlias Whether it is an alias. + * @param instance The instance of the command the commands came from. + * @param command The sub command to be added. + * @param isAlias Whether it is an alias. */ - public void addSubCommand(final @NotNull ExecutableCommand command, final boolean isAlias) { + public void addCommand( + final @NotNull Object instance, + final @NotNull Command command, + final boolean isAlias + ) { // If it's a parent command with argument we add it if (command instanceof ParentSubCommand && command.hasArguments()) { if (parentCommandWithArgument != null) { - throw new CommandRegistrationException("Only one inner command with argument is allowed per command", command.getInvocationInstance().getClass()); + throw new CommandRegistrationException("Only one inner command with argument is allowed per command", instance.getClass()); } parentCommandWithArgument = command; @@ -87,14 +92,14 @@ public boolean isDefault() { return false; } - protected @Nullable ExecutableCommand findCommand( + protected @Nullable Command findCommand( final @NotNull S sender, final @NotNull Deque arguments ) { final String name = arguments.peek(); // Instant check for default - final ExecutableCommand defaultCommand = getDefaultCommand(); + final Command defaultCommand = getDefaultCommand(); // No argument passed if (name == null) { @@ -107,7 +112,7 @@ public boolean isDefault() { return defaultCommand; } - final ExecutableCommand command = getCommandByName(name); + final Command command = getCommandByName(name); if (command != null) { // Pop command out of arguments list and returns it arguments.pop(); @@ -128,11 +133,11 @@ public boolean isDefault() { return defaultCommand; } - protected @Nullable ExecutableCommand getDefaultCommand() { + protected @Nullable Command getDefaultCommand() { return commands.get(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); } - protected @Nullable ExecutableCommand getCommandByName(final @NotNull String key) { + protected @Nullable Command getCommandByName(final @NotNull String key) { return commands.getOrDefault(key, commandAliases.get(key)); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index ebbf884e..b6d38a00 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -49,7 +49,7 @@ * * @param The sender type to be used. */ -public class ParentSubCommand extends ParentCommand implements ExecutableCommand { +public class ParentSubCommand extends ParentCommand { private final String name; private final String syntax; @@ -117,7 +117,7 @@ public void execute( instance = createInstance(instanceSupplier); } - final ExecutableCommand command = findCommand(sender, arguments); + final Command command = findCommand(sender, arguments); if (command == null) return; // Simply execute the command with the given instance @@ -189,11 +189,6 @@ public void execute( return syntax; } - @Override - public @NotNull Object getInvocationInstance() { - return invocationInstance; - } - @Override public boolean hasArguments() { return argument != null; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java index ab8d6766..72738b0c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java @@ -33,7 +33,7 @@ import java.util.Map; import java.util.function.Supplier; -public class RootCommand extends ParentCommand implements ExecutableCommand { +public class RootCommand extends ParentCommand { private final String name; private final String syntax; @@ -52,7 +52,7 @@ public void execute( final @NotNull Deque arguments, final @NotNull Map extra ) { - final ExecutableCommand command = findCommand(sender, arguments); + final Command command = findCommand(sender, arguments); if (command == null) return; // Executing the command and catch all exceptions to rethrow with better message @@ -79,11 +79,6 @@ public void execute( return syntax; } - @Override - public @NotNull Object getInvocationInstance() { - return null; - } - @Override public boolean hasArguments() { return false; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 6c0000f4..487f7ad7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -53,7 +53,7 @@ import java.util.function.BiFunction; import java.util.function.Supplier; -public class SubCommand implements ExecutableCommand { +public class SubCommand implements Command { private final Class senderType; private final List> arguments; @@ -75,7 +75,7 @@ public SubCommand( final @NotNull Object invocationInstance, final @NotNull Method method, final @NotNull SubCommandProcessor processor, - final @NotNull Command parentCommand + final @NotNull Command parentCommand ) { this.invocationInstance = invocationInstance; this.method = method; @@ -154,11 +154,6 @@ public void execute( return syntax; } - @Override - public @NotNull Object getInvocationInstance() { - return invocationInstance; - } - @Override public boolean isDefault() { return name.equals(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index d5287a3f..118c7c81 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -25,14 +25,12 @@ import com.google.common.base.CaseFormat; import dev.triumphteam.cmd.core.AnnotatedCommand; -import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.core.annotations.Description; import dev.triumphteam.cmd.core.annotations.Syntax; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.StringInternalArgument; -import dev.triumphteam.cmd.core.argument.UnknownInternalArgument; import dev.triumphteam.cmd.core.argument.keyed.ArgumentGroup; -import dev.triumphteam.cmd.core.command.ExecutableCommand; +import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.command.ParentSubCommand; import dev.triumphteam.cmd.core.command.SubCommand; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; @@ -129,21 +127,21 @@ public String getDescription() { return meta.build(); } - public @NotNull List> commands(final @NotNull dev.triumphteam.cmd.core.command.Command parentCommand) { + public @NotNull List> commands(final @NotNull Command parentCommand) { final Class klass = invocationInstance.getClass(); - final List> subCommands = new ArrayList<>(); + final List> subCommands = new ArrayList<>(); subCommands.addAll(methodCommands(parentCommand, klass.getDeclaredMethods())); subCommands.addAll(classCommands(parentCommand, klass.getDeclaredClasses())); return subCommands; } - private @NotNull List> methodCommands( - final @NotNull dev.triumphteam.cmd.core.command.Command parentCommand, + private @NotNull List> methodCommands( + final @NotNull Command parentCommand, final @NotNull Method[] methods ) { - final List> commands = new ArrayList<>(); + final List> commands = new ArrayList<>(); for (final Method method : methods) { // Ignore non-public methods if (!Modifier.isPublic(method.getModifiers())) continue; @@ -166,11 +164,11 @@ public String getDescription() { return commands; } - private @NotNull List> classCommands( - final @NotNull dev.triumphteam.cmd.core.command.Command parentCommand, + private @NotNull List> classCommands( + final @NotNull Command parentCommand, final @NotNull Class[] classes ) { - final List> commands = new ArrayList<>(); + final List> commands = new ArrayList<>(); for (final Class klass : classes) { // Ignore non-public methods if (!Modifier.isPublic(klass.getModifiers())) continue; @@ -207,7 +205,7 @@ public String getDescription() { final InternalArgument argument; if (!hasArgument) argument = null; else { - if (!Command.DEFAULT_CMD_NAME.equals(processor.getName())) { + if (!dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME.equals(processor.getName())) { throw new CommandRegistrationException("Inner command class with argument must not have a name", klass); } @@ -222,11 +220,6 @@ public String getDescription() { ); if (!(argument instanceof StringInternalArgument)) { - // Unknown types by default throw - if (argument instanceof UnknownInternalArgument) { - throw new CommandRegistrationException("No internalArgument of type \"" + argument.getType().getName() + "\" registered", klass); - } - throw new CommandRegistrationException("Inner command class with argument must not be limitless, only single string argument is allowed", klass); } } @@ -241,8 +234,8 @@ public String getDescription() { ); // Add children commands to parent - methodCommands(parent, klass.getDeclaredMethods()).forEach(it -> parent.addSubCommand(it, false)); - classCommands(parent, klass.getDeclaredClasses()).forEach(it -> parent.addSubCommand(it, false)); + methodCommands(parent, klass.getDeclaredMethods()).forEach(it -> parent.addCommand(invocationInstance, it, false)); + classCommands(parent, klass.getDeclaredClasses()).forEach(it -> parent.addCommand(invocationInstance, it, false)); // Add parent command to main list commands.add(parent); @@ -253,7 +246,8 @@ public String getDescription() { private @NotNull String nameOf() { final Class commandClass = invocationInstance.getClass(); - final Command commandAnnotation = commandClass.getAnnotation(Command.class); + final dev.triumphteam.cmd.core.annotations.Command commandAnnotation = + commandClass.getAnnotation(dev.triumphteam.cmd.core.annotations.Command.class); String name = null; if (commandAnnotation != null) { @@ -266,7 +260,7 @@ public String getDescription() { throw new CommandRegistrationException("No \"@" + Command.class.getSimpleName() + "\" annotation found or class doesn't extend \"" + AnnotatedCommand.class.getSimpleName() + "\"", invocationInstance.getClass()); } - if (name.isEmpty() || name.equals(Command.DEFAULT_CMD_NAME)) { + if (name.isEmpty() || name.equals(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME)) { throw new CommandRegistrationException("Command name must not be empty", invocationInstance.getClass()); } @@ -275,7 +269,8 @@ public String getDescription() { private @NotNull List aliasOf() { final Class commandClass = invocationInstance.getClass(); - final Command commandAnnotation = commandClass.getAnnotation(Command.class); + final dev.triumphteam.cmd.core.annotations.Command commandAnnotation = + commandClass.getAnnotation(dev.triumphteam.cmd.core.annotations.Command.class); List aliases = null; if (commandAnnotation != null) { diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index a56f2128..8958de03 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -23,42 +23,27 @@ */ package dev.triumphteam.cmd.bukkit; +import dev.triumphteam.cmd.core.command.RootCommand; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; -import java.util.List; +import java.util.ArrayDeque; +import java.util.Arrays; +import java.util.Collections; final class BukkitCommand extends Command { - protected BukkitCommand(@NotNull final String name, @NotNull final String description, @NotNull final String usageMessage, @NotNull final List aliases) { - super(name, description, usageMessage, aliases); - } - - @Override - public boolean execute(@NotNull final CommandSender sender, @NotNull final String commandLabel, @NotNull final String[] args) { - return false; - } - /*private final Map> commands = new HashMap<>(); + private final RootCommand rootCommand; + private final SenderExtension senderExtension; - private final MessageRegistry messageRegistry; - private final String syntax; - - private final CommandMeta meta; - private ExecutableCommand parentCommandWithArgument; - private SenderExtension senderExtension; - - BukkitCommand( - final @NotNull RootCommandProcessor processor, - final @NotNull MessageRegistry messageRegistry - ) { - super(processor.getName()); + BukkitCommand(final @NotNull RootCommandProcessor processor) { + super(processor.getName(), processor.getDescription(), "", processor.getAlias()); - this.messageRegistry = messageRegistry; - this.meta = processor.createMeta(); + this.rootCommand = new RootCommand<>(processor); this.senderExtension = processor.getCommandOptions().getSenderExtension(); - - this.syntax = "/" + getName(); } @Override @@ -67,58 +52,16 @@ public boolean execute( @NotNull final String commandLabel, @NotNull final String[] args ) { - final List arguments = Arrays.asList(args); - - // TODO COMPOSITION OVER INHERITANCE TO REDUCE REPETITION - - final String commandName = nameFromArguments(arguments); - final ExecutableCommand subCommand = getSubCommand(commandName, arguments.size()); - - final S mappedSender = senderExtension.map(sender); - - if (subCommand == null) { - messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, mappedSender, new InvalidCommandContext(meta, commandName)); - return true; - } - - // Executing the subcommand. - try { - subCommand.execute( - mappedSender, - commandName, - null, - !subCommand.isDefault() ? arguments.subList(1, arguments.size()) : arguments - ); - } catch (final @NotNull Throwable exception) { - throw new CommandExecutionException("An error occurred while executing the command") - .initCause(exception instanceof InvocationTargetException ? exception.getCause() : exception); - } - + rootCommand.execute( + senderExtension.map(sender), + null, + new ArrayDeque<>(Arrays.asList(args)), + Collections.emptyMap() + ); return true; } - @Override - public @NotNull String getSyntax() { - return syntax; + public @NotNull RootCommand getRootCommand() { + return rootCommand; } - - @Override - public @NotNull Map> getCommands() { - return commands; - } - - @Override - public @NotNull Map> getCommandAliases() { - return commands; - } - - @Override - public @Nullable ExecutableCommand getParentCommandWithArgument() { - return parentCommandWithArgument; - } - - @Override - public @NotNull CommandMeta getMeta() { - return meta; - }*/ } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index d6e95d3a..e961810d 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -24,6 +24,7 @@ package dev.triumphteam.cmd.bukkit; import dev.triumphteam.cmd.core.CommandManager; +import dev.triumphteam.cmd.core.command.RootCommand; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; @@ -192,7 +193,8 @@ public void registerCommand(final @NotNull Object command) { } final BukkitCommand newBukkitCommand = createAndRegisterCommand(processor, name); - // processor.commands(newBukkitCommand).forEach(it -> newBukkitCommand.addSubCommand(it, false)); + final RootCommand rootCommand = newBukkitCommand.getRootCommand(); + processor.commands(rootCommand).forEach(it -> rootCommand.addCommand(command, it, false)); // Command does not exist, proceed to add new! @@ -231,9 +233,8 @@ public void unregisterCommand(final @NotNull Object command) { oldCommand.unregister(commandMap); } - /*final BukkitCommand newCommand = new BukkitCommand<>(processor, registryContainer.getMessageRegistry()); + final BukkitCommand newCommand = new BukkitCommand<>(processor); commandMap.register(plugin.getName(), newCommand); - return newCommand;*/ - return null; + return newCommand; } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 30e4f114..f593d88b 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -88,12 +88,12 @@ public void registerCommand(final @NotNull Object command) { // Command does not exist, proceed to add new! final RootCommand newSimpleCommand = commands.computeIfAbsent(processor.getName(), it -> new RootCommand<>(processor)); - processor.commands(newSimpleCommand).forEach(it -> newSimpleCommand.addSubCommand(it, false)); + processor.commands(newSimpleCommand).forEach(it -> newSimpleCommand.addCommand(command, it, false)); processor.getAlias().forEach(it -> { final RootCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new RootCommand<>(processor)); // Adding sub commands. - processor.commands(aliasCommand).forEach(sub -> aliasCommand.addSubCommand(sub, false)); + processor.commands(aliasCommand).forEach(sub -> aliasCommand.addCommand(command, sub, false)); }); } From f9c231553480feb0beb0e87408e99d9b980627e5 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 23 Jan 2023 22:00:57 -0600 Subject: [PATCH 067/101] feature: Full re-implementation of suggestions --- .../argument/AbstractInternalArgument.java | 9 +- .../core/argument/FlagInternalArgument.java | 179 ------------------ .../cmd/core/argument/InternalArgument.java | 16 +- .../argument/LimitlessInternalArgument.java | 20 +- .../core/argument/NamedInternalArgument.java | 145 -------------- .../argument/SplitStringInternalArgument.java | 27 +-- .../core/argument/StringInternalArgument.java | 8 +- .../argument/UnknownInternalArgument.java | 18 +- .../core/argument/keyed/ArgumentGroup.java | 18 +- .../core/argument/keyed/ArgumentParser.java | 124 +++++++++--- .../cmd/core/argument/keyed/FlagGroup.java | 7 +- .../argument/keyed/KeyedInternalArgument.java | 132 ++++++++++++- .../cmd/core/argument/keyed/NamedGroup.java | 16 +- .../triumphteam/cmd/core/command/Command.java | 6 + .../cmd/core/command/ParentCommand.java | 35 +++- .../cmd/core/command/SubCommand.java | 118 +++++++----- .../extention/sender/SenderExtension.java | 4 +- .../processor/AbstractCommandProcessor.java | 1 - .../cmd/core/suggestion/EmptySuggestion.java | 15 +- .../cmd/core/suggestion/EnumSuggestion.java | 8 +- .../cmd/core/suggestion/SimpleSuggestion.java | 8 +- .../cmd/core/suggestion/Suggestion.java | 2 +- .../core/suggestion/SuggestionContext.java | 58 ------ .../core/suggestion/SuggestionResolver.java | 14 +- .../cmd/slash/SlashSubCommand.java | 2 +- .../triumphteam/cmd/bukkit/BukkitCommand.java | 16 +- .../cmd/bukkit/BukkitCommandManager.java | 56 +++--- 27 files changed, 469 insertions(+), 593 deletions(-) delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java delete mode 100644 core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java index c56d8003..ea129281 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java @@ -24,9 +24,10 @@ package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; -import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; +import java.util.ArrayList; +import java.util.Deque; import java.util.List; /** @@ -61,10 +62,10 @@ public AbstractInternalArgument( @Override public @NotNull List suggestions( final @NotNull S sender, - final @NotNull List trimmed, - final @NotNull SuggestionContext context + final @NotNull Deque arguments ) { - return suggestion.getSuggestions(sender, trimmed.get(0), context); + final String current = arguments.peekLast(); + return getSuggestion().getSuggestions(sender, current == null ? "" : current, new ArrayList<>(arguments)); } /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java deleted file mode 100644 index f6261f4a..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/FlagInternalArgument.java +++ /dev/null @@ -1,179 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.argument; - -import dev.triumphteam.cmd.core.argument.keyed.ArgumentGroup; -import dev.triumphteam.cmd.core.argument.keyed.Flag; -import dev.triumphteam.cmd.core.argument.keyed.Flags; -import dev.triumphteam.cmd.core.extention.Result; -import dev.triumphteam.cmd.core.extention.meta.CommandMeta; -import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; -import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; -import dev.triumphteam.cmd.core.suggestion.SuggestionContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.function.BiFunction; -import java.util.stream.Collectors; - -/** - * Flag argument, a {@link LimitlessInternalArgument} but returns {@link Flags} instead. - * Which contains a {@link Flags} object and the left over to be passed to another {@link LimitlessInternalArgument}. - * - * @param The sender type. - */ -public final class FlagInternalArgument extends LimitlessInternalArgument { - - private final ArgumentGroup flagGroup; - // private final FlagParser flagParser; - - public FlagInternalArgument( - final @NotNull String name, - final @NotNull String description, - final @NotNull ArgumentGroup flagGroup, - final boolean isOptional - ) { - super(name, description, Flags.class, new EmptySuggestion<>(), isOptional); - this.flagGroup = flagGroup; - // this.flagParser = new FlagParser<>(flagGroup); - } - - /** - * Resolves the argument type. - * - * @param sender The sender to resolve to. - * @param value The arguments {@link List}. - * @return A {@link Flags} which contains the flags and leftovers. - */ - @Override - public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( - final @NotNull S sender, - final @NotNull Collection value - ) { - return null;// flagParser.parse(sender, value.size() == 1 ? Arrays.asList(value.get(0).split(" ")) : value); - } - - @Override - public @NotNull List suggestions( - final @NotNull S sender, - final @NotNull List trimmed, - final @NotNull SuggestionContext context - ) { - final int size = trimmed.size(); - final String current = trimmed.get(size - 1); - - // TODO: Show flags before long flags. - final Set flags = flagGroup.getAllNames(); - - // Parses all the arguments to get the flags that have been used - // flagParser.parseFlags(trimmed).entrySet() - final List> parsed = new ArrayList<>(); - final List used = new ArrayList<>(); - - // Due to long flags and normal flags being together, loop through them to collect the used ones - // Could have been done with stream but too complex for my brain right now - for (final Map.Entry entry : parsed) { - final Flag options = entry.getKey(); - final String flag = options.getFlag(); - final String longFlag = options.getLongFlag(); - - if (flag != null) used.add("-" + flag); - if (longFlag != null) used.add("--" + longFlag); - } - - // If something was parsed we enter to check for arguments - if (!parsed.isEmpty()) { - // Get the last used flag - final Map.Entry last = parsed.get(parsed.size() - 1); - final Flag flagOptions = last.getKey(); - - // Checking for arguments that doesn't use `=` - if (!current.contains("=")) { - // If there isn't more than 1 arguments typed, then there is no argument present without using `=` - if (size > 1) { - // If the flag has arguments and the previous arg was a flag we get its suggestion - if (flagOptions.hasArgument() && flags.contains(trimmed.get(size - 2))) { - // TODO - return Collections.emptyList();// flagOptions.getArgument().suggestions(sender, Collections.singletonList(current), context); - } - } - } else { - // Split the arg into flag and arg - final String[] split = current.split("="); - // Only `=` present, no flag or arg - if (split.length == 0) return Collections.emptyList(); - - final String flag = split[0]; - final String arg = split.length != 2 ? "" : split[1]; - - // If the flag has arguments we get suggestions and append the flag and `=` to the suggestion - if (flagOptions.hasArgument()) { - // TODO - return Collections.emptyList(); - /*return flagOptions - .getArgument() - .suggestions(sender, Collections.singletonList(arg), context) - .stream() - .map(it -> flag + "=" + it) - .collect(Collectors.toList());*/ - } - } - } - - // Return the flags that haven't been used yet - return flags - .stream() - .filter(it -> !used.contains(it)) - .filter(it -> it.toLowerCase().startsWith(current.toLowerCase())) - .collect(Collectors.toList()); - } - - @Override - public boolean equals(final @Nullable Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - if (!super.equals(o)) return false; - final FlagInternalArgument that = (FlagInternalArgument) o; - return flagGroup.equals(that.flagGroup); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), flagGroup); - } - - @Override - public @NotNull String toString() { - return "FlagArgument{" + - "flagGroup=" + flagGroup + - ", super=" + super.toString() + "}"; - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index 8f93be40..d9e9ea66 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,10 +26,10 @@ import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; -import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Deque; import java.util.List; import java.util.function.BiFunction; @@ -86,11 +86,7 @@ public interface InternalArgument { ); // TODO: Comments - @NotNull List suggestions( - final @NotNull S sender, - final @NotNull List trimmed, - final @NotNull SuggestionContext context - ); + @NotNull List suggestions(final @NotNull S sender, final @NotNull Deque arguments); default Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> success( final @NotNull Object value diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java index 12d0c386..36e5d415 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,11 +24,9 @@ package dev.triumphteam.cmd.core.argument; import dev.triumphteam.cmd.core.suggestion.Suggestion; -import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; import java.util.Collection; -import java.util.List; /** * A limitless internalArgument is an internalArgument type that won't check for internalArgument size. @@ -48,16 +46,6 @@ public LimitlessInternalArgument( super(name, description, type, suggestion, isOptional); } - @Override - public @NotNull List suggestions( - final @NotNull S sender, - final @NotNull List trimmed, - final @NotNull SuggestionContext context - ) { - final String last = trimmed.get(trimmed.size() - 1); - return getSuggestion().getSuggestions(sender, last, context); - } - @Override public @NotNull String toString() { return "LimitlessArgument{super=" + super.toString() + "}"; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java deleted file mode 100644 index 6ec618f1..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/NamedInternalArgument.java +++ /dev/null @@ -1,145 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.argument; - -import dev.triumphteam.cmd.core.argument.keyed.Arguments; -import dev.triumphteam.cmd.core.extention.Result; -import dev.triumphteam.cmd.core.extention.meta.CommandMeta; -import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; -import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; -import dev.triumphteam.cmd.core.suggestion.SuggestionContext; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.function.BiFunction; -import java.util.stream.Collectors; - -public final class NamedInternalArgument extends LimitlessInternalArgument { - - private final Map> arguments; - - public NamedInternalArgument( - final @NotNull String name, - final @NotNull String description, - final @NotNull Map> arguments, - final boolean isOptional - ) { - super(name, description, Arguments.class, new EmptySuggestion<>(), isOptional); - this.arguments = arguments; - } - - @Override - public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( - final @NotNull S sender, - final @NotNull Collection value - ) { - final Map parsedArgs = Collections.emptyMap();// ArgumentParser.parse(String.join(" ", value)); - final Map mapped = new HashMap<>(parsedArgs.size()); - - for (final Map.Entry entry : parsedArgs.entrySet()) { - final String key = entry.getKey(); - final InternalArgument argument = arguments.get(key); - if (argument == null) continue; - final Object resolved = resolveArgument(sender, argument, entry.getValue()); - mapped.put(key, resolved); - } - - return null; - } - - @Override - public @NotNull List suggestions( - final @NotNull S sender, - final @NotNull List trimmed, - final @NotNull SuggestionContext context - ) { - final Map parsedArgs = Collections.emptyMap();// ArgumentParser.parse(String.join(" ", trimmed)); - final String current = trimmed.get(trimmed.size() - 1); - - final List notUsed = arguments.keySet() - .stream() - .filter(it -> parsedArgs.get(it) == null) - .filter(it -> it.startsWith(current)) - .map(it -> it + ":") - .collect(Collectors.toList()); - - if (notUsed.size() > 1) return notUsed; - - // Anything down here is actually terrible, someone with a better brain please fix lmao - final String argName; - if (notUsed.size() == 1) { - argName = notUsed.get(0).replace(":", ""); - } else { - final List parsed = new ArrayList<>(parsedArgs.keySet()); - if (parsed.size() == 0) return Collections.emptyList(); - argName = parsed.get(parsed.size() - 1); - } - - final InternalArgument argument = arguments.get(argName); - - if (argument != null) { - final String raw = argName + ":"; - final List parsed = argument.suggestions( - sender, - Collections.singletonList(!current.contains(raw) ? "" : current.replace(raw, "")), - context - ); - - if (parsed.isEmpty()) return Collections.singletonList(raw); - - return parsed - .stream() - .map(it -> argName + ":" + it) - .collect(Collectors.toList()); - } - - return notUsed; - } - - @SuppressWarnings("unchecked") - private @Nullable Object resolveArgument( - final @NotNull S sender, - final @NotNull InternalArgument argument, - final @NotNull String value - ) { - if (argument instanceof StringInternalArgument) { - return ((StringInternalArgument) argument).resolve(sender, value); - } - - return null; - } - - @Override - public @NotNull String toString() { - return "NamedInternalArgument{" + - "arguments=" + arguments + - ", super=" + super.toString() + "}"; - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java index 6c99ba3b..fb2e10d8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -27,12 +27,13 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.Suggestion; -import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.Deque; import java.util.List; import java.util.Set; import java.util.function.BiFunction; @@ -85,16 +86,20 @@ public SplitStringInternalArgument( @Override public @NotNull List suggestions( final @NotNull S sender, - final @NotNull List trimmed, - final @NotNull SuggestionContext context + final @NotNull Deque arguments ) { - final List split = Arrays.asList(trimmed.get(trimmed.size() - 1).split(regex)); + final String peek = arguments.peekLast(); + final String last = peek == null ? "" : peek; + + final List split = Arrays.asList(last.split(regex)); if (split.size() == 0) return Collections.emptyList(); - final String current = split.get(split.size() - 1); - final String joined = String.join(regex, split.subList(0, split.size() - 1)); + + final String current = last.endsWith(regex) ? "" : split.get(split.size() - 1); + final String joined = String.join(regex, current.isEmpty() ? split : split.subList(0, split.size() - 1)); final String map = joined.isEmpty() ? "" : joined + regex; + return getSuggestion() - .getSuggestions(sender, current, context) + .getSuggestions(sender, current, new ArrayList<>(arguments)) .stream() .map(it -> map + it) .collect(Collectors.toList()); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java index 604083bb..16746385 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index 0af4eb12..af11e125 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -27,12 +27,9 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; -import dev.triumphteam.cmd.core.suggestion.SuggestionContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collections; -import java.util.List; import java.util.function.BiFunction; /** @@ -47,12 +44,7 @@ public UnknownInternalArgument(final @NotNull Class type) { @Override public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve(final @NotNull S sender, final @NotNull String value) { - return null; - } - - @Override - public @NotNull List suggestions(final @NotNull S sender, final @NotNull List trimmed, final @NotNull SuggestionContext context) { - return Collections.emptyList(); + return invalid((meta, syntax) -> new InvalidArgumentContext(meta, syntax, "", "", Void.TYPE)); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java index 2860e31e..8990dc74 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -63,7 +63,15 @@ static ArgumentGroup named(final @NotNull List arguments) { * @param token The current token, an argument name or not. * @return The argument if found or null if not a valid argument name. */ - @Nullable T getMatchingArgument(final @NotNull String token); + @Nullable T matchExact(final @NotNull String token); + + /** + * Get the argument that partially matches a single {@link T} element. + * + * @param token The token to verify. + * @return A partially matched T or null. + */ + @Nullable T matchPartialSingle(final @NotNull String token); /** * Gets a list with all possible argument names. diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java index f558ba6e..5f7eeb40 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,7 +23,9 @@ */ package dev.triumphteam.cmd.core.argument.keyed; +import dev.triumphteam.cmd.core.util.Pair; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; import java.util.Collection; @@ -63,7 +65,19 @@ public Result parse(final @NotNull Collection arguments) { final Result result = new Result(); + boolean pendingResultReset = false; + while (tokens.hasNext()) { + // Reset waiting argument because it's a new token + result.setArgumentWaiting(null); + result.setCurrent(""); + + // Reset the flag argument that is pending + if (pendingResultReset) { + pendingResultReset = false; + result.setFlagWaiting(null); + } + final String token = tokens.next(); // If escaping the flag then just, skip @@ -72,12 +86,28 @@ public Result parse(final @NotNull Collection arguments) { continue; } - // Checks if it's a flag, if not then skip + final Pair waitingFlag = result.getFlagWaiting(); + if (waitingFlag != null) { + // Threat token as an argument + result.addFlag(waitingFlag.first(), token); + result.setCurrent(token); + + // Mark for result reset after + pendingResultReset = true; + continue; + } + + // Checks if it's a flag, if not then it could be named if ((!token.startsWith(LONG) || LONG.equals(token)) && (!token.startsWith(SHORT) || SHORT.equals(token))) { final int separator = token.indexOf(ARGUMENT_SEPARATOR); // Not a flag nor a named argument, so just ignore if (separator == -1) { + final Argument partial = namedGroup.matchPartialSingle(token); + if (partial != null) { + result.setArgumentWaiting(partial); + } + result.addNonToken(token); continue; } @@ -90,12 +120,13 @@ public Result parse(final @NotNull Collection arguments) { final int equals = token.indexOf(FLAG_SEPARATOR); // No equals char was found if (equals == -1) { - handleNoEquals(tokens, result, token); + handleNoEquals(result, token); continue; } // Handling of arguments with equals handleWithEquals(result, token, equals); + pendingResultReset = true; } return result; @@ -117,7 +148,7 @@ private void handleNamed( final String namedToken = token.substring(0, separator); final String argToken = token.substring(separator + 1); - final Argument argument = namedGroup.getMatchingArgument(namedToken); + final Argument argument = namedGroup.matchExact(namedToken); // If there is no valid argument we ignore it if (argument == null) { result.addNonToken(token); @@ -125,24 +156,23 @@ private void handleNamed( } result.addNamedArgument(argument, argToken); - result.setWaitingArgument(argToken.isEmpty()); + result.setCurrent(argToken); + result.setArgumentWaiting(argument); } /** * Parser handler for flags without an equals. * The argument would be the next iteration. * - * @param tokens The tokens {@link Iterator} from the loop. * @param result The results instance to add to. * @param token The current flag token. */ private void handleNoEquals( - final @NotNull Iterator tokens, final @NotNull Result result, final @NotNull String token ) { - final Flag flag = flagGroup.getMatchingArgument(token); + final Flag flag = flagGroup.matchExact(token); // No valid flag with the name, skip if (flag == null) { result.addNonToken(token); @@ -151,16 +181,10 @@ private void handleNoEquals( // Checks if the flag needs argument if (flag.hasArgument()) { - // If an argument is needed and no more tokens present, then just append empty as value - if (!tokens.hasNext()) { - result.addFlag(flag); - result.setWaitingArgument(true); - return; - } - - // Value found so append - result.addFlag(flag, tokens.next()); - result.setWaitingArgument(false); + // Waiting with a type + final Result.FlagType type = token.startsWith("--") ? Result.FlagType.LONG_NO_EQUALS : Result.FlagType.FLAG_NO_EQUALS; + result.setFlagWaiting(new Pair<>(flag, type)); + result.setCurrent(token); return; } @@ -183,7 +207,7 @@ private void handleWithEquals( final String flagToken = token.substring(0, equals); final String argToken = token.substring(equals + 1); - final Flag flag = flagGroup.getMatchingArgument(flagToken); + final Flag flag = flagGroup.matchExact(flagToken); // No valid flag with the name, skip if (flag == null) { result.addNonToken(token); @@ -198,7 +222,10 @@ private void handleWithEquals( // Add flag normally result.addFlag(flag, argToken); - result.setWaitingArgument(argToken.isEmpty()); + result.setCurrent(argToken); + // Waiting with a type + final Result.FlagType type = token.startsWith("--") ? Result.FlagType.LONG : Result.FlagType.FLAG; + result.setFlagWaiting(new Pair<>(flag, type), true); } public static class Result { @@ -207,7 +234,9 @@ public static class Result { private final Map namedArguments = new HashMap<>(); private final List nonTokens = new ArrayList<>(); - private boolean waitingArgument = false; + private String current = ""; + private Argument argumentWaiting = null; + private Pair flagWaiting = null; public void addNamedArgument(final @NotNull Argument argument, final @NotNull String value) { namedArguments.put(argument, value); @@ -237,12 +266,51 @@ public List getNonTokens() { return nonTokens; } - public boolean isWaitingArgument() { - return waitingArgument; + public @Nullable Argument getArgumentWaiting() { + return argumentWaiting; + } + + public void setArgumentWaiting(final @Nullable Argument argumentWaiting) { + this.argumentWaiting = argumentWaiting; + } + + public @Nullable Pair getFlagWaiting() { + return flagWaiting; } - public void setWaitingArgument(final boolean value) { - this.waitingArgument = value; + public void setFlagWaiting(final @Nullable Pair flagWaiting) { + setFlagWaiting(flagWaiting, false); + } + + public void setFlagWaiting(final @Nullable Pair flagWaiting, final boolean ignore) { + if (!ignore && (flagWaiting != null && flags.containsKey(flagWaiting.first()))) { + return; + } + this.flagWaiting = flagWaiting; + } + + public @NotNull String getCurrent() { + return current; + } + + public void setCurrent(final @NotNull String current) { + this.current = current; + } + + public enum FlagType { + FLAG, + FLAG_NO_EQUALS, + + LONG, + LONG_NO_EQUALS; + + public boolean isLong() { + return this == LONG || this == LONG_NO_EQUALS; + } + + public boolean hasEquals() { + return this == FLAG || this == LONG; + } } } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagGroup.java index 312c188c..60fc47b4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/FlagGroup.java @@ -70,13 +70,18 @@ public boolean isEmpty() { } @Override - public @Nullable Flag getMatchingArgument(final @NotNull String token) { + public @Nullable Flag matchExact(final @NotNull String token) { final String stripped = stripLeadingHyphens(token); final Flag flag = flags.get(stripped); return flag != null ? flag : longFlags.get(stripped); } + @Override + public @Nullable Flag matchPartialSingle(final @NotNull String token) { + return null; + } + @Override public @NotNull Set getAll() { return new HashSet<>(flags.values()); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java index 6a66312f..b5b8f196 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,22 +23,27 @@ */ package dev.triumphteam.cmd.core.argument.keyed; +import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.LimitlessInternalArgument; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; -import dev.triumphteam.cmd.core.suggestion.SuggestionContext; +import dev.triumphteam.cmd.core.util.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayDeque; import java.util.Collection; import java.util.Collections; +import java.util.Deque; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.BiFunction; +import java.util.stream.Collectors; public final class KeyedInternalArgument extends LimitlessInternalArgument { @@ -137,11 +142,118 @@ public KeyedInternalArgument( } @Override - public @NotNull List suggestions( - final @NotNull S sender, - final @NotNull List trimmed, - final @NotNull SuggestionContext context + public @NotNull List suggestions(final @NotNull S sender, final @NotNull Deque arguments) { + final String last = arguments.peekLast(); + final String current = last == null ? "" : last; + + final ArgumentParser.Result result = argumentParser.parse(arguments); + final String resultCurrent = result.getCurrent(); + + // Checking if we're waiting for a flag argument + final List waitingFlagArguments = handleFlagArgument(resultCurrent, result, sender); + if (waitingFlagArguments != null) return waitingFlagArguments; + + // Checking if we're waiting for an argument + final List waitingArguments = handleNamedArgument(resultCurrent, result, sender); + if (waitingArguments != null) return waitingArguments; + + // Handle flags only when they are typed + if (current.startsWith("--")) return longFlags(resultCurrent, result.getFlags()); + if (current.startsWith("-")) return flags(resultCurrent, result.getFlags()); + + // If we're not dealing with flags or arguments we return a list of named arguments that haven't been used yet + return namedArguments(resultCurrent, result.getNamedArguments()); + } + + private @NotNull List longFlags( + final @NotNull String current, + final @NotNull Map parsed + ) { + return flagInternalArguments.keySet() + .stream() + .filter(it -> !parsed.containsKey(it)) + .map(Flag::getLongFlag) + .filter(Objects::nonNull) + .map(it -> "--" + it) + .filter(it -> it.startsWith(current)) + .collect(Collectors.toList()); + } + + private @NotNull List flags( + final @NotNull String current, + final @NotNull Map parsed + ) { + return flagInternalArguments.keySet() + .stream() + .filter(it -> !parsed.containsKey(it)) + .map(Flag::getFlag) + .filter(Objects::nonNull) + .map(it -> "-" + it) + .filter(it -> it.startsWith(current)) + .collect(Collectors.toList()); + } + + private @NotNull List namedArguments( + final @NotNull String current, + final @NotNull Map parsed + ) { + return argumentInternalArguments.keySet() + .stream() + .filter(it -> !parsed.containsKey(it)) + .map(Argument::getName) + .filter(it -> it.startsWith(current)) + .map(it -> it + ":") + .collect(Collectors.toList()); + } + + private @Nullable List handleNamedArgument( + final @NotNull String current, + final @NotNull ArgumentParser.Result result, + final @NotNull S sender ) { - return Collections.emptyList(); + // Checking if we're waiting for an argument + final Argument waiting = result.getArgumentWaiting(); + if (waiting == null) return null; + + // If so we get the internal version of the argument, this will likely never be null + final InternalArgument internalArgument = argumentInternalArguments.get(waiting); + if (internalArgument == null) return null; + final String raw = waiting.getName() + ":"; + // Get suggestion from the internal argument and map it to the "raw" argument + final List suggestions = internalArgument.suggestions( + sender, + new ArrayDeque<>(Collections.singleton(current)) + ).stream() + .map(it -> raw + it) + .collect(Collectors.toList()); + + // In case the suggestion returns nothing we just return the raw type as a suggestion + if (suggestions.isEmpty()) return Collections.singletonList(raw); + + // If there are suggestions we return them + return suggestions; + } + + private @Nullable List handleFlagArgument( + final @NotNull String current, + final @NotNull ArgumentParser.Result result, + final @NotNull S sender + ) { + final Pair waitingFlag = result.getFlagWaiting(); + if (waitingFlag == null) return null; + + final Flag flag = waitingFlag.first(); + final ArgumentParser.Result.FlagType type = waitingFlag.second(); + + final InternalArgument internalArgument = flagInternalArguments.get(flag); + if (internalArgument == null) return null; + + return internalArgument.suggestions(sender, new ArrayDeque<>(Collections.singleton(current))) + .stream() + .map(it -> { + if (!type.hasEquals()) return it; // No equals so we just suggest the argument + final String prefix = type.isLong() ? "--" + flag.getLongFlag() : "-" + flag.getFlag(); + return prefix + "=" + it; + }).collect(Collectors.toList()); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/NamedGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/NamedGroup.java index 85c3156f..c38c05c7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/NamedGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/NamedGroup.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; /** * Basically a holder that contains all the needed arguments for the command. @@ -58,10 +59,23 @@ public boolean isEmpty() { } @Override - public @Nullable Argument getMatchingArgument(final @NotNull String token) { + public @Nullable Argument matchExact(final @NotNull String token) { return arguments.get(token); } + @Override + public @Nullable Argument matchPartialSingle(final @NotNull String token) { + final List arguments = this.arguments.entrySet() + .stream() + .filter(it -> it.getKey().startsWith(token)) + .map(Map.Entry::getValue) + .collect(Collectors.toList()); + + if (arguments.size() != 1) return null; + + return arguments.get(0); + } + @Override public @NotNull Set getAll() { return new HashSet<>(arguments.values()); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index c6e3ed1d..036a1e03 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -28,6 +28,7 @@ import org.jetbrains.annotations.Nullable; import java.util.Deque; +import java.util.List; import java.util.Map; import java.util.function.Supplier; @@ -46,6 +47,11 @@ void execute( final @NotNull Map extra ) throws Throwable; + @NotNull List suggestions( + final @NotNull S sender, + final @NotNull Deque arguments + ); + /** * @return The name of the comamnd. */ diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index d5443f92..b6fa383e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -34,7 +34,11 @@ import java.util.Deque; import java.util.HashMap; +import java.util.List; import java.util.Map; +import java.util.stream.Collectors; + +import static java.util.Collections.emptyList; /** * A parent command means it's a simple holder of other commands. @@ -59,6 +63,27 @@ public ParentCommand(final @NotNull CommandProcessor processor) { this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); } + @Override + public @NotNull List suggestions( + final @NotNull S sender, + final @NotNull Deque arguments + ) { + final String argument = arguments.peek(); + if (argument == null) return emptyList(); + + final Command command = findCommand(sender, arguments); + + if (command == null) { + return commands.entrySet().stream() + .filter(it -> !it.getValue().isDefault()) + .filter(it -> it.getKey().startsWith(argument)) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + } + + return command.suggestions(sender, arguments); + } + /** * Add a new command to the maps. * @@ -87,11 +112,6 @@ public void addCommand( // TODO ALIAS } - @Override - public boolean isDefault() { - return false; - } - protected @Nullable Command findCommand( final @NotNull S sender, final @NotNull Deque arguments @@ -133,6 +153,11 @@ public boolean isDefault() { return defaultCommand; } + @Override + public boolean isDefault() { + return false; + } + protected @Nullable Command getDefaultCommand() { return commands.get(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 487f7ad7..3a93b7be 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -41,22 +41,26 @@ import dev.triumphteam.cmd.core.processor.CommandProcessor; import dev.triumphteam.cmd.core.processor.SubCommandProcessor; import dev.triumphteam.cmd.core.requirement.Requirement; +import dev.triumphteam.cmd.core.util.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.reflect.Method; import java.util.ArrayList; -import java.util.Collections; import java.util.Deque; import java.util.List; import java.util.Map; import java.util.function.BiFunction; import java.util.function.Supplier; +import java.util.stream.Collectors; + +import static java.util.Collections.emptyList; public class SubCommand implements Command { private final Class senderType; - private final List> arguments; + private final List> argumentList; + private final Map> argumentMap; private final List> requirements; private final String name; @@ -82,10 +86,15 @@ public SubCommand( this.name = processor.getName(); this.meta = processor.createMeta(); this.senderType = processor.senderType(); - this.arguments = processor.arguments(meta); + + this.argumentList = processor.arguments(meta); + this.argumentMap = this.argumentList.stream() + .map(argument -> new Pair<>(argument.getName(), argument)) + .collect(Collectors.toMap(Pair::first, Pair::second)); + this.requirements = processor.requirements(); - this.containsLimitless = arguments.stream().anyMatch(LimitlessInternalArgument.class::isInstance); + this.containsLimitless = argumentList.stream().anyMatch(LimitlessInternalArgument.class::isInstance); final CommandOptions commandOptions = processor.getCommandOptions(); @@ -140,28 +149,33 @@ public void execute( } @Override - public @NotNull CommandMeta getMeta() { - return meta; - } + public @NotNull List suggestions( + final @NotNull S sender, + final @NotNull Deque arguments + ) { + if (arguments.isEmpty()) return emptyList(); - @Override - public @NotNull String getName() { - return name; - } + final int index = arguments.size() - 1; + final InternalArgument argument = getArgumentFromIndex(index); + if (argument == null) return emptyList(); - @Override - public @NotNull String getSyntax() { - return syntax; + return argument.suggestions(sender, arguments); } - @Override - public boolean isDefault() { - return name.equals(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); + public @Nullable InternalArgument getArgumentFromIndex(final int index) { + if (!hasArguments()) return null; + final int size = argumentList.size(); + if (index >= size) { + final InternalArgument last = argumentList.get(size - 1); + if (last instanceof LimitlessInternalArgument) return last; + return null; + } + + return argumentList.get(index); } - @Override - public boolean hasArguments() { - return !arguments.isEmpty(); + public @Nullable InternalArgument getArgumentFromName(final @NotNull String name) { + return argumentMap.get(name); } /** @@ -178,8 +192,8 @@ private boolean validateAndCollectArguments( final @NotNull List invokeArguments, final @NotNull Deque commandArgs ) { - for (final InternalArgument internalArgument : arguments) { - final @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> result; + for (final InternalArgument internalArgument : argumentList) { + final Result> result; if (internalArgument instanceof LimitlessInternalArgument) { final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument; @@ -212,7 +226,7 @@ private boolean validateAndCollectArguments( messageRegistry.sendMessage( MessageKey.INVALID_ARGUMENT, sender, - ((Result.Failure<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>>) result) + ((Result.Failure>) result) .getFail() .apply(meta, syntax) ); @@ -221,7 +235,7 @@ private boolean validateAndCollectArguments( // In case of success we add the results if (result instanceof Result.Success) { - invokeArguments.add(((Result.Success<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>>) result).getValue()); + invokeArguments.add(((Result.Success>) result).getValue()); } } @@ -245,31 +259,10 @@ private boolean meetRequirements(final @NotNull S sender) { return true; } - /** - * Gets an internalArgument value or null. - * - * @param list The list to check from. - * @param index The current index of the internalArgument. - * @return The internalArgument name or null. - */ - private @Nullable String valueOrNull(final @NotNull List list, final int index) { - if (index >= list.size()) return null; - return list.get(index); - } - - /** - * Gets the left over of the arguments. - * - * @param list The list with all the arguments. - * @param from The index from which should start removing. - * @return A list with the leftover arguments. - */ - private @NotNull List leftOvers(final @NotNull List list, final int from) { - if (from > list.size()) return Collections.emptyList(); - return list.subList(from, list.size()); - } - - private @NotNull String createSyntax(final @NotNull Command parentCommand, final @NotNull CommandProcessor processor) { + private @NotNull String createSyntax( + final @NotNull Command parentCommand, + final @NotNull CommandProcessor processor + ) { final Syntax syntaxAnnotation = processor.getSyntaxAnnotation(); if (syntaxAnnotation != null) return syntaxAnnotation.value(); @@ -279,8 +272,33 @@ private boolean meetRequirements(final @NotNull S sender) { builder.append(" ").append(name); } - arguments.forEach(argument -> builder.append(" ").append("<").append(argument.getName()).append(">")); + argumentList.forEach(argument -> builder.append(" ").append("<").append(argument.getName()).append(">")); return builder.toString(); } + + @Override + public @NotNull CommandMeta getMeta() { + return meta; + } + + @Override + public @NotNull String getName() { + return name; + } + + @Override + public @NotNull String getSyntax() { + return syntax; + } + + @Override + public boolean isDefault() { + return name.equals(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); + } + + @Override + public boolean hasArguments() { + return !argumentList.isEmpty(); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java index 2ed82c0a..f4eaf950 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java @@ -44,12 +44,12 @@ public interface SenderExtension extends SenderMapper { interface Default extends SenderExtension { @Override - default @NotNull S map(@NotNull final S defaultSender) { + default @NotNull S map(final @NotNull S defaultSender) { return defaultSender; } @Override - default @NotNull S mapBackwards(@NotNull final S sender) { + default @NotNull S mapBackwards(final @NotNull S sender) { return sender; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 08e0978a..b4a7a079 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -165,7 +165,6 @@ public String getDescription() { return description; } - // TODO COMMENTS protected @NotNull InternalArgument argumentFromParameter( final @NotNull Parameter parameter, final @NotNull List argDescriptions, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java index b15a100e..106134e3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -32,10 +32,15 @@ public final class EmptySuggestion implements Suggestion { @Override - public @NotNull List getSuggestions(final @NotNull S sender, final @NotNull String current, final @NotNull SuggestionContext context) { + public @NotNull List getSuggestions( + final @NotNull S sender, + final @NotNull String current, + final @NotNull List arguments + ) { return emptyList(); } + @Override public @NotNull String toString() { return "EmptySuggestion{}"; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java index 0874b864..6c90aad4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java @@ -42,7 +42,11 @@ public EnumSuggestion(final @NotNull Class> enumType) { } @Override - public @NotNull List getSuggestions(final @NotNull S sender, final @NotNull String current, final @NotNull SuggestionContext context) { + public @NotNull List getSuggestions( + final @NotNull S sender, + final @NotNull String current, + final @NotNull List arguments + ) { return EnumUtils.getEnumConstants(enumType) .values() .stream() @@ -60,7 +64,7 @@ public EnumSuggestion(final @NotNull Class> enumType) { public boolean equals(final @Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - final EnumSuggestion that = (EnumSuggestion) o; + final EnumSuggestion that = (EnumSuggestion) o; return enumType.equals(that.enumType); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java index aa8a806a..2edf71b4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java @@ -39,9 +39,13 @@ public SimpleSuggestion(final @NotNull SuggestionResolver resolver) { } @Override - public @NotNull List getSuggestions(final @NotNull S sender, final @NotNull String current, final @NotNull SuggestionContext context) { + public @NotNull List getSuggestions( + final @NotNull S sender, + final @NotNull String current, + final @NotNull List arguments + ) { return resolver - .resolve(sender, context) + .resolve(sender, arguments) .stream() .filter(it -> it.toLowerCase().startsWith(current.toLowerCase())) .collect(Collectors.toList()); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java index 772eae4e..96cee9d8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/Suggestion.java @@ -32,6 +32,6 @@ public interface Suggestion { @NotNull List getSuggestions( final @NotNull S sender, final @NotNull String current, - final @NotNull SuggestionContext context + final @NotNull List arguments ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java deleted file mode 100644 index 2df1b13c..00000000 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionContext.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.core.suggestion; - -import org.jetbrains.annotations.NotNull; - -import java.util.Collections; -import java.util.List; - -public final class SuggestionContext { - - private final List args; - private final String command; - private final String subCommand; - - public SuggestionContext( - final @NotNull List args, - final @NotNull String command, - final @NotNull String subCommand - ) { - this.args = args; - this.command = command; - this.subCommand = subCommand; - } - - public @NotNull List getArgs() { - return Collections.unmodifiableList(args); - } - - public @NotNull String getCommand() { - return command; - } - - public @NotNull String getSubCommand() { - return subCommand; - } -} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java index 3ebe02fd..03b7d76a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -36,10 +36,10 @@ public interface SuggestionResolver { /** * Resolves the suggestions for the command argument. * - * @param sender The command sender - * @param context The command context for the suggestion + * @param sender The command sender. + * @param arguments A list with all the typed arguments. * @return A list of suggestions. */ - @NotNull List resolve(final @NotNull S sender, final @NotNull SuggestionContext context); + @NotNull List resolve(final @NotNull S sender, final @NotNull List arguments); } diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java index 479ecbe5..5d7b0003 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java +++ b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java @@ -60,7 +60,7 @@ public SlashSubCommand( // TODO @Override - public @Nullable Object resolve(@NotNull final S sender, final @NotNull List value) { + public @Nullable Object resolve(final @NotNull S sender, final @NotNull List value) { return null; } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index 8958de03..38aba883 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -33,6 +33,7 @@ import java.util.ArrayDeque; import java.util.Arrays; import java.util.Collections; +import java.util.List; final class BukkitCommand extends Command { @@ -48,9 +49,9 @@ final class BukkitCommand extends Command { @Override public boolean execute( - @NotNull final CommandSender sender, - @NotNull final String commandLabel, - @NotNull final String[] args + final @NotNull CommandSender sender, + final @NotNull String commandLabel, + final @NotNull String[] args ) { rootCommand.execute( senderExtension.map(sender), @@ -61,6 +62,15 @@ public boolean execute( return true; } + @Override + public @NotNull List tabComplete( + final @NotNull CommandSender sender, + final @NotNull String alias, + final @NotNull String[] args + ) { + return rootCommand.suggestions(senderExtension.map(sender), new ArrayDeque<>(Arrays.asList(args))); + } + public @NotNull RootCommand getRootCommand() { return rootCommand; } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index e961810d..a0d6b225 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -79,7 +79,7 @@ private BukkitCommandManager( registerArgument(Player.class, (sender, arg) -> Bukkit.getPlayer(arg)); registerArgument(World.class, (sender, arg) -> Bukkit.getWorld(arg)); - registerSuggestion(Player.class, (sender, context) -> Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList())); + registerSuggestion(Player.class, (sender, arguments) -> Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList())); } /** @@ -148,34 +148,6 @@ private static void setUpDefaults(final @NotNull BukkitCommandManager sender.sendMessage("This command can only be used by the console."));*/ } - /** - * Gets the Command Map to register the commands - * - * @return The Command Map - */ - private static @NotNull CommandMap getCommandMap() { - try { - final Server server = Bukkit.getServer(); - final Method getCommandMap = server.getClass().getDeclaredMethod("getCommandMap"); - getCommandMap.setAccessible(true); - - return (CommandMap) getCommandMap.invoke(server); - } catch (final Exception ignored) { - throw new CommandRegistrationException("Unable get Command Map. Commands will not be registered!"); - } - } - - private static @NotNull Map getBukkitCommands(final @NotNull CommandMap commandMap) { - try { - final Field bukkitCommands = SimpleCommandMap.class.getDeclaredField("knownCommands"); - bukkitCommands.setAccessible(true); - //noinspection unchecked - return (Map) bukkitCommands.get(commandMap); - } catch (NoSuchFieldException | IllegalAccessException e) { - throw new CommandRegistrationException("Unable get Bukkit commands. Commands might not be registered correctly!"); - } - } - @Override public void registerCommand(final @NotNull Object command) { final RootCommandProcessor processor = new RootCommandProcessor<>( @@ -237,4 +209,30 @@ public void unregisterCommand(final @NotNull Object command) { commandMap.register(plugin.getName(), newCommand); return newCommand; } + + /** + * @return Bukkit's {@link CommandMap} to register commands to. + */ + private static @NotNull CommandMap getCommandMap() { + try { + final Server server = Bukkit.getServer(); + final Method getCommandMap = server.getClass().getDeclaredMethod("getCommandMap"); + getCommandMap.setAccessible(true); + + return (CommandMap) getCommandMap.invoke(server); + } catch (final Exception ignored) { + throw new CommandRegistrationException("Unable get Command Map. Commands will not be registered!"); + } + } + + private static @NotNull Map getBukkitCommands(final @NotNull CommandMap commandMap) { + try { + final Field bukkitCommands = SimpleCommandMap.class.getDeclaredField("knownCommands"); + bukkitCommands.setAccessible(true); + //noinspection unchecked + return (Map) bukkitCommands.get(commandMap); + } catch (NoSuchFieldException | IllegalAccessException e) { + throw new CommandRegistrationException("Unable get Bukkit commands. Commands might not be registered correctly!"); + } + } } From 3b1bdd57a31203c0709b465dfffb238a8a5ac731 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 23 Jan 2023 22:15:16 -0600 Subject: [PATCH 068/101] feature: Suggestion for argument-as-command --- .../cmd/core/command/ParentSubCommand.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index b6d38a00..5138b1c3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -38,6 +38,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Deque; +import java.util.List; import java.util.Map; import java.util.function.BiFunction; import java.util.function.Supplier; @@ -66,7 +67,7 @@ public ParentSubCommand( final boolean isStatic, final @Nullable StringInternalArgument argument, final @NotNull ParentCommandProcessor processor, - final @NotNull Command parentCommand + final @NotNull Command parentCommand ) { super(processor); @@ -129,6 +130,18 @@ public void execute( ); } + @Override + public @NotNull List suggestions(@NotNull final S sender, final @NotNull Deque arguments) { + // If we're dealing with only 1 argument it means it's the argument suggestion + if (arguments.size() == 1 && hasArgument) { + return argument.suggestions(sender, arguments); + } + + // If we do have arguments we need to pop them out before continuing + if (hasArgument) arguments.pop(); + return super.suggestions(sender, arguments); + } + /** * Creates a new instance to be passed down to the child commands. * From 49b107c3ca047fdba0d86185f92be6fa2a62f287 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 28 Jan 2023 12:49:17 -0600 Subject: [PATCH 069/101] feature: Improved requirements --- .../cmd/core/annotations/Requirement.java | 17 +-- .../triumphteam/cmd/core/command/Command.java | 7 +- .../cmd/core/command/ParentCommand.java | 63 +++++++--- .../cmd/core/command/ParentSubCommand.java | 8 +- .../cmd/core/command/RootCommand.java | 5 +- .../cmd/core/command/SubCommand.java | 64 +++++----- .../cmd/core/extention/CommandExtensions.java | 20 ++-- .../cmd/core/extention/ExtensionBuilder.java | 19 ++- .../cmd/core/extention/Result.java | 2 + .../extention/command/CommandSettings.java | 66 +++++++++++ .../command/ImmutableCommandSettings.java | 54 +++++++++ .../Processor.java} | 17 +-- .../cmd/core/extention/meta/CommandMeta.java | 9 +- .../extention/registry/MessageRegistry.java | 7 +- .../message/context/BasicMessageContext.java | 20 ++-- .../message/context/InvalidInputContext.java | 2 +- ...Context.java => SyntaxMessageContext.java} | 21 ++-- .../cmd/core/processor/CommandProcessor.java | 61 ++++++++-- .../processor/ParentCommandProcessor.java | 27 ++++- .../core/processor/RootCommandProcessor.java | 34 ++++-- .../core/processor/SubCommandProcessor.java | 63 +++------- .../core/requirement/InternalRequirement.java | 79 +++++++++++++ .../cmd/core/requirement/Requirement.java | 110 ++---------------- .../core/requirement/RequirementContext.java | 14 ++- .../core/requirement/RequirementResolver.java | 15 ++- .../requirement/SimpleRequirementContext.java | 5 +- .../cmds/CoroutinesCommandExtension.kt | 20 ++-- .../cmd/bukkit/BukkitCommandManager.java | 1 + .../cmd/bukkit/CommandPermission.java | 11 +- .../cmd/bukkit/PermissionProcessor.java | 58 +++++++++ .../cmd/bukkit/PermissionRequirement.java | 44 +++++++ .../cmd/bukkit/annotation/Permission.java | 4 + .../message/NoPermissionMessageContext.java | 3 +- 33 files changed, 637 insertions(+), 313 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/command/CommandSettings.java create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableCommandSettings.java rename core/src/main/java/dev/triumphteam/cmd/core/extention/{argument/CommandMetaProcessor.java => command/Processor.java} (81%) rename core/src/main/java/dev/triumphteam/cmd/core/message/context/{SimpleMetaMessageContext.java => SyntaxMessageContext.java} (75%) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/requirement/InternalRequirement.java create mode 100644 minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java create mode 100644 minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java index d4f7276c..afe1e855 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -38,7 +38,7 @@ */ @Documented @Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.METHOD) +@Target({ElementType.METHOD, ElementType.TYPE}) @Repeatable(Requirements.class) public @interface Requirement { @@ -53,9 +53,12 @@ /** * The message key will be used to send a custom message if the specified requirement is denied. * - * @return The message key or empty if not needed. + * @return The message key. */ - @NotNull String messageKey() default ""; + @NotNull String messageKey(); + /** + * @return If the requirement should be inverted. + */ boolean invert() default false; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 036a1e03..14cf850b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.command; +import dev.triumphteam.cmd.core.extention.command.CommandSettings; import dev.triumphteam.cmd.core.extention.meta.CommandMetaContainer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -37,7 +38,7 @@ * Not all commands are executable directly. * Some implementations will have listeners inside that'll trigger the execution. */ -public interface Command extends CommandMetaContainer { +public interface Command extends CommandMetaContainer { // TODO void execute( @@ -52,8 +53,10 @@ void execute( final @NotNull Deque arguments ); + @NotNull CommandSettings getCommandSettings(); + /** - * @return The name of the comamnd. + * @return The name of the command. */ @NotNull String getName(); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index b6fa383e..c89d5f29 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -24,8 +24,10 @@ package dev.triumphteam.cmd.core.command; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; +import dev.triumphteam.cmd.core.extention.command.CommandSettings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.context.InvalidCommandContext; import dev.triumphteam.cmd.core.processor.CommandProcessor; @@ -46,21 +48,30 @@ * * @param The sender type. */ -public abstract class ParentCommand implements Command { +public abstract class ParentCommand implements Command { - private final Map> commands = new HashMap<>(); - private final Map> commandAliases = new HashMap<>(); + private Command defaultCommand = null; + private final Map> commands = new HashMap<>(); + private final Map> commandAliases = new HashMap<>(); private final CommandMeta meta; + private final CommandSettings settings; // Single parent command with argument - private Command parentCommandWithArgument; + private Command parentCommandWithArgument; private final MessageRegistry messageRegistry; + private final SenderExtension senderExtension; public ParentCommand(final @NotNull CommandProcessor processor) { - this.meta = processor.createMeta(); + final CommandSettings.Builder settingsBuilder = new CommandSettings.Builder<>(); + processor.captureRequirements(settingsBuilder); + this.meta = processor.createMeta(settingsBuilder); + this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); + this.senderExtension = processor.getCommandOptions().getSenderExtension(); + + this.settings = settingsBuilder.build(); } @Override @@ -71,12 +82,15 @@ public ParentCommand(final @NotNull CommandProcessor processor) { final String argument = arguments.peek(); if (argument == null) return emptyList(); - final Command command = findCommand(sender, arguments); + final Command command = findCommand(sender, arguments); if (command == null) { return commands.entrySet().stream() - .filter(it -> !it.getValue().isDefault()) + // Filter commands the sender can't see + .filter(it -> it.getValue().getCommandSettings().testRequirements(sender, meta, senderExtension)) + // Commands that match what the sender is typing .filter(it -> it.getKey().startsWith(argument)) + // Only use the names .map(Map.Entry::getKey) .collect(Collectors.toList()); } @@ -93,7 +107,7 @@ public ParentCommand(final @NotNull CommandProcessor processor) { */ public void addCommand( final @NotNull Object instance, - final @NotNull Command command, + final @NotNull Command command, final boolean isAlias ) { // If it's a parent command with argument we add it @@ -106,20 +120,24 @@ public void addCommand( return; } - // Normal commands are added here - commands.put(command.getName(), command); + if (command.isDefault()) { + this.defaultCommand = command; + } else { + // Normal commands are added here + commands.put(command.getName(), command); + } // TODO ALIAS } - protected @Nullable Command findCommand( + protected @Nullable Command findCommand( final @NotNull S sender, final @NotNull Deque arguments ) { final String name = arguments.peek(); // Instant check for default - final Command defaultCommand = getDefaultCommand(); + final Command defaultCommand = this.defaultCommand; // No argument passed if (name == null) { @@ -132,7 +150,7 @@ public void addCommand( return defaultCommand; } - final Command command = getCommandByName(name); + final Command command = getCommandByName(name); if (command != null) { // Pop command out of arguments list and returns it arguments.pop(); @@ -154,15 +172,16 @@ public void addCommand( } @Override - public boolean isDefault() { - return false; + public @NotNull CommandSettings getCommandSettings() { + return settings; } - protected @Nullable Command getDefaultCommand() { - return commands.get(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); + @Override + public boolean isDefault() { + return false; } - protected @Nullable Command getCommandByName(final @NotNull String key) { + protected @Nullable Command getCommandByName(final @NotNull String key) { return commands.getOrDefault(key, commandAliases.get(key)); } @@ -174,4 +193,12 @@ public boolean isDefault() { protected @NotNull MessageRegistry getMessageRegistry() { return messageRegistry; } + + protected @NotNull CommandSettings getSettings() { + return settings; + } + + protected @NotNull SenderExtension getSenderExtension() { + return senderExtension; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 5138b1c3..2eb9445d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -67,7 +67,7 @@ public ParentSubCommand( final boolean isStatic, final @Nullable StringInternalArgument argument, final @NotNull ParentCommandProcessor processor, - final @NotNull Command parentCommand + final @NotNull Command parentCommand ) { super(processor); @@ -88,6 +88,10 @@ public void execute( final @NotNull Deque arguments, final @NotNull Map extra ) throws Throwable { + + // Test all requirements before continuing + if (!getSettings().testRequirements(getMessageRegistry(), sender, getMeta(), getSenderExtension())) return; + // First we handle the argument if there is any final Object instance; if (hasArgument) { @@ -118,7 +122,7 @@ public void execute( instance = createInstance(instanceSupplier); } - final Command command = findCommand(sender, arguments); + final Command command = findCommand(sender, arguments); if (command == null) return; // Simply execute the command with the given instance diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java index 72738b0c..b12990b4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java @@ -52,7 +52,10 @@ public void execute( final @NotNull Deque arguments, final @NotNull Map extra ) { - final Command command = findCommand(sender, arguments); + // Test all requirements before continuing + if (!getSettings().testRequirements(getMessageRegistry(), sender, getMeta(), getSenderExtension())) return; + + final Command command = findCommand(sender, arguments); if (command == null) return; // Executing the command and catch all exceptions to rethrow with better message diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 3a93b7be..0a97b47d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -31,16 +31,16 @@ import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.ValidationResult; +import dev.triumphteam.cmd.core.extention.command.CommandSettings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.context.BasicMessageContext; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.message.context.MessageContext; +import dev.triumphteam.cmd.core.message.context.SyntaxMessageContext; import dev.triumphteam.cmd.core.processor.CommandProcessor; import dev.triumphteam.cmd.core.processor.SubCommandProcessor; -import dev.triumphteam.cmd.core.requirement.Requirement; import dev.triumphteam.cmd.core.util.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -56,18 +56,20 @@ import static java.util.Collections.emptyList; -public class SubCommand implements Command { +public class SubCommand implements Command { private final Class senderType; + private final List> argumentList; private final Map> argumentMap; - private final List> requirements; private final String name; private final String syntax; - private final CommandMeta meta; private final boolean containsLimitless; + private final CommandMeta meta; + private final CommandSettings settings; + private final Object invocationInstance; private final Method method; private final CommandExecutor commandExecutor; @@ -79,21 +81,22 @@ public SubCommand( final @NotNull Object invocationInstance, final @NotNull Method method, final @NotNull SubCommandProcessor processor, - final @NotNull Command parentCommand + final @NotNull Command parentCommand ) { this.invocationInstance = invocationInstance; this.method = method; this.name = processor.getName(); - this.meta = processor.createMeta(); - this.senderType = processor.senderType(); + final CommandSettings.Builder settingsBuilder = new CommandSettings.Builder<>(); + processor.captureRequirements(settingsBuilder); + this.meta = processor.createMeta(settingsBuilder); + + this.senderType = processor.senderType(); this.argumentList = processor.arguments(meta); this.argumentMap = this.argumentList.stream() .map(argument -> new Pair<>(argument.getName(), argument)) .collect(Collectors.toMap(Pair::first, Pair::second)); - this.requirements = processor.requirements(); - this.containsLimitless = argumentList.stream().anyMatch(LimitlessInternalArgument.class::isInstance); final CommandOptions commandOptions = processor.getCommandOptions(); @@ -103,6 +106,8 @@ public SubCommand( this.commandExecutor = commandOptions.getCommandExtensions().getCommandExecutor(); this.syntax = createSyntax(parentCommand, processor); + + this.settings = settingsBuilder.build(); } @Override @@ -120,23 +125,22 @@ public void execute( messageRegistry.sendMessage( ((ValidationResult.Invalid>) validationResult).getMessage(), sender, - new BasicMessageContext(meta, syntax) + new SyntaxMessageContext(meta, syntax) ); return; } - if (!meetRequirements(sender)) return; + // Testing if all requirements pass before we continue + if (!settings.testRequirements(messageRegistry, sender, meta, senderExtension)) return; // Creates the invoking arguments list - final List invokeArguments = new ArrayList<>(); + final List invokeArguments = new ArrayList<>(); invokeArguments.add(sender); - if (!validateAndCollectArguments(sender, invokeArguments, arguments)) { - return; - } + if (!validateAndCollectArguments(sender, invokeArguments, arguments)) return; if ((!containsLimitless) && arguments.size() >= invokeArguments.size()) { - messageRegistry.sendMessage(MessageKey.TOO_MANY_ARGUMENTS, sender, new BasicMessageContext(meta, syntax)); + messageRegistry.sendMessage(MessageKey.TOO_MANY_ARGUMENTS, sender, new SyntaxMessageContext(meta, syntax)); return; } @@ -209,7 +213,7 @@ private boolean validateAndCollectArguments( continue; } - messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new BasicMessageContext(meta, syntax)); + messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new SyntaxMessageContext(meta, syntax)); return false; } @@ -242,25 +246,8 @@ private boolean validateAndCollectArguments( return true; } - /** - * Checks if the requirements to run the command are met. - * - * @param sender The sender of the command. - * @return Whether all requirements are met. - */ - private boolean meetRequirements(final @NotNull S sender) { - for (final Requirement requirement : requirements) { - if (!requirement.isMet(sender, meta, senderExtension)) { - requirement.sendMessage(messageRegistry, sender, meta, syntax); - return false; - } - } - - return true; - } - private @NotNull String createSyntax( - final @NotNull Command parentCommand, + final @NotNull Command parentCommand, final @NotNull CommandProcessor processor ) { final Syntax syntaxAnnotation = processor.getSyntaxAnnotation(); @@ -282,6 +269,11 @@ private boolean meetRequirements(final @NotNull S sender) { return meta; } + @Override + public @NotNull CommandSettings getCommandSettings() { + return settings; + } + @Override public @NotNull String getName() { return name; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java index 64eb5e06..d183f2be 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,7 +26,7 @@ import dev.triumphteam.cmd.core.command.CommandExecutor; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; -import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor; +import dev.triumphteam.cmd.core.extention.command.Processor; import org.jetbrains.annotations.NotNull; import java.lang.annotation.Annotation; @@ -36,19 +36,19 @@ public final class CommandExtensions { private final Map, AnnotationProcessor> annotationProcessors; - private final List commandMetaProcessors; + private final List> processors; private final ArgumentValidator argumentValidator; private final CommandExecutor commandExecutor; public CommandExtensions( final @NotNull Map, AnnotationProcessor> annotationProcessors, - final @NotNull List commandMetaProcessors, + final @NotNull List> processors, final @NotNull ArgumentValidator argumentValidator, final @NotNull CommandExecutor commandExecutor ) { this.annotationProcessors = annotationProcessors; - this.commandMetaProcessors = commandMetaProcessors; + this.processors = processors; this.argumentValidator = argumentValidator; this.commandExecutor = commandExecutor; } @@ -57,8 +57,8 @@ public CommandExtensions( return annotationProcessors; } - public @NotNull List getCommandMetaProcessors() { - return commandMetaProcessors; + public @NotNull List> getProcessors() { + return processors; } public @NotNull ArgumentValidator getArgumentValidator() { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java index 0905783d..2de06857 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -27,8 +27,7 @@ import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; -import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor; -import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.core.extention.command.Processor; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -41,7 +40,7 @@ public final class ExtensionBuilder { private final Map, AnnotationProcessor> annotationProcessors = new HashMap<>(); - private final List commandMetaProcessors = new ArrayList<>(); + private final List> processors = new ArrayList<>(); private ArgumentValidator argumentValidator = null; private CommandExecutor commandExecutor = null; @@ -56,8 +55,8 @@ public final class ExtensionBuilder { } @Contract("_ -> this") - public @NotNull ExtensionBuilder addCommandMetaProcessor(final @NotNull CommandMetaProcessor commandMetaProcessor) { - commandMetaProcessors.add(commandMetaProcessor); + public @NotNull ExtensionBuilder addProcessor(final @NotNull Processor processor) { + processors.add(processor); return this; } @@ -84,7 +83,7 @@ public final class ExtensionBuilder { return new CommandExtensions<>( annotationProcessors, - commandMetaProcessors, + processors, argumentValidator, commandExecutor ); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java index 273994f4..cedb2a3b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/Result.java @@ -28,6 +28,7 @@ public interface Result { final class Success implements Result { + private final V value; public Success(final @NotNull V value) { @@ -40,6 +41,7 @@ public Success(final @NotNull V value) { } final class Failure implements Result { + private final F fail; public Failure(final @NotNull F fail) { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/CommandSettings.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/CommandSettings.java new file mode 100644 index 00000000..045fc50b --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/CommandSettings.java @@ -0,0 +1,66 @@ +package dev.triumphteam.cmd.core.extention.command; + +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import dev.triumphteam.cmd.core.requirement.Requirement; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +public interface CommandSettings { + + /** + * Tests all the requirements present in the setting. + * If any fails, handle the return and returns false. + * Only truly succeeds if all requirements pass. + * + * @param sender The sender to test the requirements to. + * @param meta The {@link CommandMeta} which is used by some requirements. + * @param senderMapper The {@link SenderMapper} which is used by some requirements. + * @return True only if all requirements pass. + */ + boolean testRequirements( + final @NotNull S sender, + final @NotNull CommandMeta meta, + final @NotNull SenderMapper senderMapper + ); + + /** + * Tests all the requirements present in the setting. + * If any fails, handle the return and returns false. + * Only truly succeeds if all requirements pass. + * + * @param messageRegistry The {@link MessageRegistry} to send message to the sender. + * @param sender The sender to test the requirements to. + * @param meta The {@link CommandMeta} which is used by some requirements. + * @param senderMapper The {@link SenderMapper} which is used by some requirements. + * @return True only if all requirements pass. + */ + boolean testRequirements( + final @NotNull MessageRegistry messageRegistry, + final @NotNull S sender, + final @NotNull CommandMeta meta, + final @NotNull SenderMapper senderMapper + ); + + class Builder { + + private final List> requirements = new ArrayList<>(); + + @Contract("_ -> this") + public @NotNull Builder addRequirement(final @NotNull Requirement requirement) { + requirements.add(requirement); + return this; + } + + // TODO add more things to the settings + + public CommandSettings build() { + return new ImmutableCommandSettings<>(Collections.unmodifiableList(requirements)); + } + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableCommandSettings.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableCommandSettings.java new file mode 100644 index 00000000..9fd834c3 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableCommandSettings.java @@ -0,0 +1,54 @@ +package dev.triumphteam.cmd.core.extention.command; + +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import dev.triumphteam.cmd.core.requirement.Requirement; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public final class ImmutableCommandSettings implements CommandSettings { + + private final List> requirements; + + public ImmutableCommandSettings(final @NotNull List> requirements) { + this.requirements = requirements; + } + + @Override + public boolean testRequirements( + final @NotNull MessageRegistry messageRegistry, + final @NotNull S sender, + final @NotNull CommandMeta meta, + final @NotNull SenderMapper senderMapper + ) { + final Requirement requirement = getFailedRequirement(sender, meta, senderMapper); + if (requirement == null) return true; + + requirement.onDeny(sender, messageRegistry, meta); + return false; + } + + @Override + public boolean testRequirements( + final @NotNull S sender, + final @NotNull CommandMeta meta, + final @NotNull SenderMapper senderMapper + ) { + return getFailedRequirement(sender, meta, senderMapper) == null; + } + + private @Nullable Requirement getFailedRequirement( + final @NotNull S sender, + final @NotNull CommandMeta meta, + final @NotNull SenderMapper senderMapper + ) { + for (final Requirement requirement : requirements) { + if (!requirement.test(sender, meta, senderMapper)) return requirement; + } + + return null; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMetaProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Processor.java similarity index 81% rename from core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMetaProcessor.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/command/Processor.java index 797322ef..d5c20507 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/argument/CommandMetaProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Processor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.core.extention.argument; +package dev.triumphteam.cmd.core.extention.command; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; @@ -29,11 +29,12 @@ import java.lang.reflect.AnnotatedElement; -public interface CommandMetaProcessor { +public interface Processor { void process( - final @NotNull AnnotatedElement method, + final @NotNull AnnotatedElement element, final @NotNull ProcessorTarget target, - final @NotNull CommandMeta.Builder meta + final @NotNull CommandMeta.@NotNull Builder meta, + final @NotNull CommandSettings.@NotNull Builder settingsBuilder ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java index 0bd98a15..b5a1a4ad 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/meta/CommandMeta.java @@ -104,8 +104,10 @@ public Builder(final @Nullable CommandMeta parentMeta) { * @param value The nullable value {@link V} to be stored. * @param The type of value that'll be stored. */ - public void add(final @NotNull MetaKey metaKey, final @Nullable V value) { + @Contract("_, _ -> this") + public @NotNull Builder add(final @NotNull MetaKey metaKey, final @Nullable V value) { metaMap.put(metaKey, value); + return this; } /** @@ -115,8 +117,9 @@ public void add(final @NotNull MetaKey metaKey, final @Nullable V value) * @param metaKey The {@link MetaKey} to be the key of the internal map. * @param The type of value that'll be stored. */ - public void add(final @NotNull MetaKey metaKey) { - add(metaKey, null); + @Contract("_, -> this") + public @NotNull Builder add(final @NotNull MetaKey metaKey) { + return add(metaKey, null); } /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/MessageRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/MessageRegistry.java index 1b11fbec..09e1db61 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/MessageRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/MessageRegistry.java @@ -24,6 +24,7 @@ package dev.triumphteam.cmd.core.extention.registry; import dev.triumphteam.cmd.core.message.ContextualKey; +import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.message.MessageResolver; import dev.triumphteam.cmd.core.message.context.MessageContext; import org.jetbrains.annotations.NotNull; @@ -55,15 +56,15 @@ public void register( } /** - * Sends a message to the sender based on the {@link ContextualKey}. + * Sends a message to the sender based on the {@link MessageKey}. * - * @param key The {@link ContextualKey} to get the correct {@link MessageResolver}. + * @param key The {@link MessageKey} to get the correct {@link MessageResolver}. * @param sender A {@link S} sender, which will receive the message. * @param context The {@link MessageContext} generated by the command executor. * @param The type of {@link MessageContext} to be used. */ public void sendMessage( - final @NotNull ContextualKey key, + final @NotNull MessageKey key, final @NotNull S sender, final @NotNull C context ) { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java index 90c268cb..7acebf22 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/BasicMessageContext.java @@ -26,22 +26,16 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; -/** - * The default most keys will use, only contains the most basic data. - */ -public class BasicMessageContext extends SimpleMetaMessageContext { +public class BasicMessageContext implements MessageContext { - private final String syntax; + private final CommandMeta meta; - public BasicMessageContext( - final @NotNull CommandMeta meta, - final @NotNull String syntax - ) { - super(meta); - this.syntax = syntax; + public BasicMessageContext(final @NotNull CommandMeta meta) { + this.meta = meta; } - public @NotNull String getSyntax() { - return syntax; + @Override + public @NotNull CommandMeta getMeta() { + return meta; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java index 6b5fab12..87b223c1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/InvalidInputContext.java @@ -30,7 +30,7 @@ /** * Context with an invalid input. */ -abstract class InvalidInputContext extends SimpleMetaMessageContext { +abstract class InvalidInputContext extends BasicMessageContext { private final String invalidInput; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/message/context/SimpleMetaMessageContext.java b/core/src/main/java/dev/triumphteam/cmd/core/message/context/SyntaxMessageContext.java similarity index 75% rename from core/src/main/java/dev/triumphteam/cmd/core/message/context/SimpleMetaMessageContext.java rename to core/src/main/java/dev/triumphteam/cmd/core/message/context/SyntaxMessageContext.java index 7b858387..8ab7e9e8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/message/context/SimpleMetaMessageContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/message/context/SyntaxMessageContext.java @@ -26,17 +26,22 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; +/** + * The default most keys will use, only contains the most basic data. + */ +public class SyntaxMessageContext extends BasicMessageContext { -abstract class SimpleMetaMessageContext implements MessageContext { - - private final CommandMeta meta; + private final String syntax; - public SimpleMetaMessageContext(final @NotNull CommandMeta meta) { - this.meta = meta; + public SyntaxMessageContext( + final @NotNull CommandMeta meta, + final @NotNull String syntax + ) { + super(meta); + this.syntax = syntax; } - @Override - public @NotNull CommandMeta getMeta() { - return meta; + public @NotNull String getSyntax() { + return syntax; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index e45eb67f..c1815a11 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,18 +23,30 @@ */ package dev.triumphteam.cmd.core.processor; +import dev.triumphteam.cmd.core.annotations.Requirements; import dev.triumphteam.cmd.core.annotations.Syntax; +import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; +import dev.triumphteam.cmd.core.extention.command.CommandSettings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.context.MessageContext; +import dev.triumphteam.cmd.core.requirement.InternalRequirement; +import dev.triumphteam.cmd.core.requirement.RequirementKey; +import dev.triumphteam.cmd.core.requirement.RequirementResolver; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import java.util.Map; public interface CommandProcessor { @@ -44,12 +56,14 @@ public interface CommandProcessor { * * @return The immutable {@link CommandMeta} instance. */ - @NotNull CommandMeta createMeta(); + @NotNull CommandMeta createMeta(final @NotNull CommandSettings.Builder settingsBuilder); @NotNull CommandOptions getCommandOptions(); @NotNull RegistryContainer getRegistryContainer(); + @NotNull AnnotatedElement getAnnotatedElement(); + @Nullable Syntax getSyntaxAnnotation(); /** @@ -81,12 +95,43 @@ default void processAnnotations( } } + default void captureRequirements(final @NotNull CommandSettings.Builder settingsBuilder) { + final RequirementRegistry requirementRegistry = getRegistryContainer().getRequirementRegistry(); + + for (final dev.triumphteam.cmd.core.annotations.Requirement requirementAnnotation : getRequirementsFromAnnotations()) { + final RequirementKey requirementKey = RequirementKey.of(requirementAnnotation.value()); + final String messageKeyValue = requirementAnnotation.messageKey(); + + final MessageKey messageKey = MessageKey.of(messageKeyValue, MessageContext.class); + + final RequirementResolver resolver = requirementRegistry.getRequirement(requirementKey); + if (resolver == null) { + // TODO EXCEPTION CHECK + throw new CommandRegistrationException("Could not find Requirement Key \"" + requirementKey.getKey() + "\""); + } + + settingsBuilder.addRequirement(new InternalRequirement<>(resolver, messageKey, requirementAnnotation.invert())); + } + } + default void processCommandMeta( - final @NotNull CommandExtensions extensions, + final @NotNull CommandExtensions extensions, final @NotNull AnnotatedElement element, final @NotNull ProcessorTarget target, - final @NotNull CommandMeta.Builder meta + final @NotNull CommandMeta.Builder meta, + final @NotNull CommandSettings.Builder settingsBuilder ) { - extensions.getCommandMetaProcessors().forEach(it -> it.process(element, target, meta)); + extensions.getProcessors().forEach(it -> it.process(element, target, meta, settingsBuilder)); + } + + default @NotNull List getRequirementsFromAnnotations() { + final AnnotatedElement element = getAnnotatedElement(); + + final Requirements requirements = element.getAnnotation(Requirements.class); + if (requirements != null) return Arrays.asList(requirements.value()); + + final dev.triumphteam.cmd.core.annotations.Requirement requirement = element.getAnnotation(dev.triumphteam.cmd.core.annotations.Requirement.class); + if (requirement == null) return Collections.emptyList(); + return Collections.singletonList(requirement); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java index 21a3f0df..47725dd4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -25,11 +25,14 @@ import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; +import dev.triumphteam.cmd.core.extention.command.CommandSettings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.meta.MetaKey; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.AnnotatedElement; + /** * Abstracts most of the "extracting" from sub command annotations, allows for extending. *
@@ -56,7 +59,12 @@ public final class ParentCommandProcessor extends AbstractCommandProcessor } @Override - public @NotNull CommandMeta createMeta() { + public @NotNull AnnotatedElement getAnnotatedElement() { + return klass; + } + + @Override + public @NotNull CommandMeta createMeta(final @NotNull CommandSettings.@NotNull Builder settingsBuilder) { final CommandMeta.Builder meta = new CommandMeta.Builder(getParentMeta()); // Defaults @@ -65,7 +73,14 @@ public final class ParentCommandProcessor extends AbstractCommandProcessor // Process all the class annotations processAnnotations(getCommandOptions().getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); - processCommandMeta(getCommandOptions().getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); + processCommandMeta( + getCommandOptions().getCommandExtensions(), + klass, + ProcessorTarget.PARENT_COMMAND, + meta, + settingsBuilder + ); + // Return modified meta return meta.build(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index 118c7c81..d75b056d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -36,12 +36,14 @@ import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; +import dev.triumphteam.cmd.core.extention.command.CommandSettings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.meta.MetaKey; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -112,7 +114,12 @@ public String getDescription() { } @Override - public @NotNull CommandMeta createMeta() { + public @NotNull AnnotatedElement getAnnotatedElement() { + return invocationInstance.getClass(); + } + + @Override + public @NotNull CommandMeta createMeta(final @NotNull CommandSettings.@NotNull Builder settingsBuilder) { final CommandMeta.Builder meta = new CommandMeta.Builder(null); // Defaults @@ -122,26 +129,33 @@ public String getDescription() { // Process all the class annotations final Class klass = invocationInstance.getClass(); processAnnotations(commandOptions.getCommandExtensions(), klass, ProcessorTarget.ROOT_COMMAND, meta); - processCommandMeta(commandOptions.getCommandExtensions(), klass, ProcessorTarget.PARENT_COMMAND, meta); + processCommandMeta( + commandOptions.getCommandExtensions(), + klass, + ProcessorTarget.PARENT_COMMAND, + meta, + settingsBuilder + ); + // Return modified meta return meta.build(); } - public @NotNull List> commands(final @NotNull Command parentCommand) { + public @NotNull List> commands(final @NotNull Command parentCommand) { final Class klass = invocationInstance.getClass(); - final List> subCommands = new ArrayList<>(); + final List> subCommands = new ArrayList<>(); subCommands.addAll(methodCommands(parentCommand, klass.getDeclaredMethods())); subCommands.addAll(classCommands(parentCommand, klass.getDeclaredClasses())); return subCommands; } - private @NotNull List> methodCommands( - final @NotNull Command parentCommand, + private @NotNull List> methodCommands( + final @NotNull Command parentCommand, final @NotNull Method[] methods ) { - final List> commands = new ArrayList<>(); + final List> commands = new ArrayList<>(); for (final Method method : methods) { // Ignore non-public methods if (!Modifier.isPublic(method.getModifiers())) continue; @@ -164,11 +178,11 @@ public String getDescription() { return commands; } - private @NotNull List> classCommands( - final @NotNull Command parentCommand, + private @NotNull List> classCommands( + final @NotNull Command parentCommand, final @NotNull Class[] classes ) { - final List> commands = new ArrayList<>(); + final List> commands = new ArrayList<>(); for (final Class klass : classes) { // Ignore non-public methods if (!Modifier.isPublic(klass.getModifiers())) continue; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index f6bfca95..fb1c21ca 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -26,7 +26,6 @@ import dev.triumphteam.cmd.core.annotations.ArgDescriptions; import dev.triumphteam.cmd.core.annotations.CommandFlags; import dev.triumphteam.cmd.core.annotations.NamedArguments; -import dev.triumphteam.cmd.core.annotations.Requirements; import dev.triumphteam.cmd.core.annotations.Suggestions; import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.keyed.Argument; @@ -37,6 +36,7 @@ import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.ValidationResult; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; +import dev.triumphteam.cmd.core.extention.command.CommandSettings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.meta.MetaKey; import dev.triumphteam.cmd.core.extention.registry.FlagRegistry; @@ -44,17 +44,12 @@ import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.message.context.BasicMessageContext; -import dev.triumphteam.cmd.core.message.context.MessageContext; -import dev.triumphteam.cmd.core.requirement.Requirement; -import dev.triumphteam.cmd.core.requirement.RequirementKey; -import dev.triumphteam.cmd.core.requirement.RequirementResolver; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Method; import java.lang.reflect.Parameter; import java.util.ArrayList; @@ -101,7 +96,12 @@ public final class SubCommandProcessor extends AbstractCommandProcessor settingsBuilder) { final CommandMeta.Builder meta = new CommandMeta.Builder(getParentMeta()); // Defaults @@ -110,7 +110,14 @@ public final class SubCommandProcessor extends AbstractCommandProcessor extends AbstractCommandProcessor> requirements() { - final List> requirements = new ArrayList<>(); - for (final dev.triumphteam.cmd.core.annotations.Requirement requirementAnnotation : getRequirementsFromAnnotations()) { - final RequirementKey requirementKey = RequirementKey.of(requirementAnnotation.value()); - final String messageKeyValue = requirementAnnotation.messageKey(); - - final MessageKey messageKey; - if (messageKeyValue.isEmpty()) messageKey = null; - else messageKey = MessageKey.of(messageKeyValue, MessageContext.class); - - final RequirementResolver resolver = requirementRegistry.getRequirement(requirementKey); - if (resolver == null) { - throw createException("Could not find Requirement Key \"" + requirementKey.getKey() + "\""); - } - - requirements.add(new Requirement<>(resolver, messageKey, BasicMessageContext::new, requirementAnnotation.invert())); - } - - return Collections.unmodifiableList(requirements); - } - - /** - * @return The list of requirements annotations. - */ - private @NotNull List getRequirementsFromAnnotations() { - final Requirements requirements = method.getAnnotation(Requirements.class); - if (requirements != null) return Arrays.asList(requirements.value()); - - final dev.triumphteam.cmd.core.annotations.Requirement requirement = method.getAnnotation(dev.triumphteam.cmd.core.annotations.Requirement.class); - if (requirement == null) return Collections.emptyList(); - return Collections.singletonList(requirement); - } - /** * Create a named argument group from the values passed by the annotation. * diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/InternalRequirement.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/InternalRequirement.java new file mode 100644 index 00000000..34a8e4f0 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/InternalRequirement.java @@ -0,0 +1,79 @@ +/** + * MIT License + *

+ * Copyright (c) 2019-2021 Matt + *

+ * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

+ * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.core.requirement; + +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.context.BasicMessageContext; +import dev.triumphteam.cmd.core.message.context.MessageContext; +import org.jetbrains.annotations.NotNull; + +/** + * Contains the data for the requirement. + * + * @param The sender type. + */ +public final class InternalRequirement implements Requirement { + + private final RequirementResolver resolver; + private final MessageKey messageKey; + private final boolean invert; + + public InternalRequirement( + final @NotNull RequirementResolver resolver, + final @NotNull MessageKey messageKey, + final boolean invert + ) { + this.resolver = resolver; + this.messageKey = messageKey; + this.invert = invert; + } + + @Override + public boolean test( + final @NotNull S sender, + final @NotNull CommandMeta meta, + final @NotNull SenderMapper senderMapper + ) { + return resolver.resolve(sender, new SimpleRequirementContext<>(meta, senderMapper)) != invert; + } + + @Override + public void onDeny( + final @NotNull S sender, + final @NotNull MessageRegistry messageRegistry, + final @NotNull CommandMeta meta + ) { + messageRegistry.sendMessage(messageKey, sender, new BasicMessageContext(meta)); + } + + @Override + public @NotNull String toString() { + return "InternalRequirement{" + + "resolver=" + resolver + + '}'; + } +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java index 13691755..91b570de 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java @@ -1,115 +1,21 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ package dev.triumphteam.cmd.core.requirement; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.extention.sender.SenderMapper; -import dev.triumphteam.cmd.core.message.ContextualKey; -import dev.triumphteam.cmd.core.message.context.MessageContext; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.util.Objects; -import java.util.function.BiFunction; +public interface Requirement { -/** - * Contains the data for the requirement. - * - * @param The sender type. - */ -public final class Requirement { - - private final RequirementResolver resolver; - private final ContextualKey messageKey; - private final BiFunction contextFactory; - private final boolean invert; - - public Requirement( - final @NotNull RequirementResolver resolver, - final @Nullable ContextualKey messageKey, - final @NotNull BiFunction contextFactory, - final boolean invert - ) { - this.resolver = resolver; - this.messageKey = messageKey; - this.contextFactory = contextFactory; - this.invert = invert; - } - - /** - * The message key which will be used to send the defined message to the sender. - * - * @return The message key or null if no message should be sent. - */ - public @Nullable ContextualKey getMessageKey() { - return messageKey; - } - - // TODO - public void sendMessage( - final @NotNull MessageRegistry registry, - final @NotNull S sender, - final @NotNull CommandMeta meta, - final @NotNull String syntax - ) { - if (messageKey == null) return; - registry.sendMessage(messageKey, sender, contextFactory.apply(meta, syntax)); - } - - /** - * Checks if the requirement is met or not. - * - * @param sender The sender which will be needed to check if the requirement is met or not. - * @return Whether the requirement is met. - */ - public boolean isMet( + boolean test( final @NotNull S sender, final @NotNull CommandMeta meta, final @NotNull SenderMapper senderMapper - ) { - return resolver.resolve(sender, new SimpleRequirementContext<>(meta, senderMapper)) != invert; - } - - @Override - public boolean equals(final @Nullable Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - final Requirement that = (Requirement) o; - return resolver.equals(that.resolver) && Objects.equals(messageKey, that.messageKey); - } + ); - @Override - public int hashCode() { - return Objects.hash(resolver, messageKey); - } - - @Override - public @NotNull String toString() { - return "Requirement{" + - "resolver=" + resolver + - ", messageKey=" + messageKey + - '}'; - } + void onDeny( + final @NotNull S sender, + final @NotNull MessageRegistry messageRegistry, + final @NotNull CommandMeta meta + ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java index 0266dbf6..52c263b9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java @@ -1,13 +1,25 @@ package dev.triumphteam.cmd.core.requirement; +import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.sender.SenderMapper; import org.jetbrains.annotations.NotNull; -// TODO comments +/** + * Holder for some context data to pass over to the {@link RequirementResolver}. + * + * @param The default sender. + * @param The final sender. + */ public interface RequirementContext { + /** + * @return The {@link CommandMeta} of the current {@link Command}. + */ @NotNull CommandMeta getMeta(); + /** + * @return The {@link SenderMapper} for reverse mapping if needed. + */ @NotNull SenderMapper getSenderMapper(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java index debcb4d0..0d0d9ac6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

* Copyright (c) 2019-2021 Matt - * + *

* Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -38,7 +38,10 @@ public interface RequirementResolver { * Resolves the requirement. * * @param sender The sender to check the requirement. - * @return Whether the requirement is met or not. + * @return Whether the requirement passes or fails. */ - boolean resolve(final @NotNull S sender, final @NotNull RequirementContext context); + boolean resolve( + final @NotNull S sender, + final @NotNull RequirementContext context + ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java index d9de0af3..96b576c4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java @@ -9,7 +9,10 @@ class SimpleRequirementContext implements RequirementContext { private final CommandMeta meta; private final SenderMapper senderMapper; - public SimpleRequirementContext(final @NotNull CommandMeta meta, final @NotNull SenderMapper senderMapper) { + public SimpleRequirementContext( + final @NotNull CommandMeta meta, + final @NotNull SenderMapper senderMapper + ) { this.meta = meta; this.senderMapper = senderMapper; } diff --git a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt index 706c5c68..20cb7abe 100644 --- a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt +++ b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt @@ -31,7 +31,8 @@ import dev.triumphteam.cmd.core.extention.ExtensionBuilder import dev.triumphteam.cmd.core.extention.ValidationResult import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator -import dev.triumphteam.cmd.core.extention.argument.CommandMetaProcessor +import dev.triumphteam.cmd.core.extention.command.Processor +import dev.triumphteam.cmd.core.extention.command.CommandSettings import dev.triumphteam.cmd.core.extention.meta.CommandMeta import dev.triumphteam.cmd.core.extention.meta.MetaKey import kotlinx.coroutines.CoroutineScope @@ -44,20 +45,20 @@ import kotlin.coroutines.CoroutineContext import kotlin.reflect.full.callSuspend import kotlin.reflect.jvm.kotlinFunction -public fun > B.useCoroutines( +public fun > B.useCoroutines( coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.Default), coroutineContext: CoroutineContext = Dispatchers.Default, ) { - val kotlinArgumentExtension = CoroutinesCommandExtension(coroutineScope, coroutineContext) - addCommandMetaProcessor(kotlinArgumentExtension) + val kotlinArgumentExtension = CoroutinesCommandExtension(coroutineScope, coroutineContext) + addProcessor(kotlinArgumentExtension) setArgumentValidator(kotlinArgumentExtension) setCommandExecutor(kotlinArgumentExtension) } -public class CoroutinesCommandExtension( +public class CoroutinesCommandExtension( private val coroutineScope: CoroutineScope, private val coroutineContext: CoroutineContext, -) : CommandMetaProcessor, ArgumentValidator, CommandExecutor { +) : Processor, ArgumentValidator, CommandExecutor { private companion object { /** The key that'll represent a suspending function. */ @@ -65,7 +66,12 @@ public class CoroutinesCommandExtension( } /** Simply processing if the [element] contains a [Continuation], if so, we're dealing with a suspend function. */ - override fun process(element: AnnotatedElement, target: ProcessorTarget, meta: CommandMeta.Builder) { + override fun process( + element: AnnotatedElement, + target: ProcessorTarget, + meta: CommandMeta.Builder, + settingsBuilder: CommandSettings.Builder + ) { if (element !is Method) return // Not really necessary but doesn't hurt to check if (target != ProcessorTarget.COMMAND) return diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index a0d6b225..be280f2b 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -97,6 +97,7 @@ private BukkitCommandManager( final BukkitCommandOptions.Builder extensionBuilder = new BukkitCommandOptions.Builder<>(); extensionBuilder.extensions(extension -> { + extension.addProcessor(new PermissionProcessor<>()); extension.setArgumentValidator(new DefaultArgumentValidator<>()); extension.setCommandExecutor(new DefaultCommandExecutor()); }); diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java index 6dd4bd70..48fe48d6 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java @@ -52,6 +52,8 @@ public CommandPermission( this.nodes = nodes; this.description = description; this.permissionDefault = permissionDefault; + + register(); } /** @@ -63,7 +65,7 @@ public CommandPermission( *

  • The sender has the permission
  • * * - * @param sender The main command sender. + * @param sender The main command sender. * @param permission The permission. * @return Whether the sender has permission to run the command. */ @@ -119,4 +121,11 @@ public void register() { public boolean hasPermission(final @NotNull CommandSender sender) { return nodes.stream().anyMatch(sender::hasPermission); } + + @Override + public String toString() { + return "CommandPermission{" + + "nodes=" + nodes + + '}'; + } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java new file mode 100644 index 00000000..77dd9ec7 --- /dev/null +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java @@ -0,0 +1,58 @@ +package dev.triumphteam.cmd.bukkit; + +import dev.triumphteam.cmd.bukkit.annotation.Permission; +import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; +import dev.triumphteam.cmd.core.extention.command.CommandSettings; +import dev.triumphteam.cmd.core.extention.command.Processor; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.lang.reflect.AnnotatedElement; +import java.util.Arrays; + +final class PermissionProcessor implements Processor { + + @Override + public void process( + final @NotNull AnnotatedElement element, + final @NotNull ProcessorTarget target, + final @NotNull CommandMeta.@NotNull Builder meta, + final @NotNull CommandSettings.@NotNull Builder settingsBuilder + ) { + final Permission permissionAnnotation = element.getAnnotation(Permission.class); + if (permissionAnnotation == null) return; + + final CommandPermission parentPermission = permissionRecursively(meta); + + final CommandPermission permission; + if (parentPermission != null) { + permission = parentPermission.child( + Arrays.asList(permissionAnnotation.value()), + permissionAnnotation.description(), + permissionAnnotation.def() + ); + } else { + permission = new CommandPermission( + Arrays.asList(permissionAnnotation.value()), + permissionAnnotation.description(), + permissionAnnotation.def() + ); + } + + meta.add(Permission.META_KEY, permission); + settingsBuilder.addRequirement(new PermissionRequirement<>(permission)); + } + + private @Nullable CommandPermission permissionRecursively( + final @Nullable CommandMeta meta + ) { + if (meta == null) return null; + + final CommandPermission permission = meta.getNullable(Permission.META_KEY); + if (permission != null) return permission; + + return permissionRecursively(meta.getParentMeta()); + } +} diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java new file mode 100644 index 00000000..af5205ba --- /dev/null +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java @@ -0,0 +1,44 @@ +package dev.triumphteam.cmd.bukkit; + +import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; +import dev.triumphteam.cmd.bukkit.message.NoPermissionMessageContext; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import dev.triumphteam.cmd.core.requirement.Requirement; +import org.bukkit.command.CommandSender; +import org.jetbrains.annotations.NotNull; + +public final class PermissionRequirement implements Requirement { + + private final CommandPermission permission; + + public PermissionRequirement(final @NotNull CommandPermission permission) { + this.permission = permission; + } + + @Override + public boolean test( + final @NotNull S sender, + final @NotNull CommandMeta meta, + final @NotNull SenderMapper senderMapper + ) { + return permission.hasPermission(senderMapper.mapBackwards(sender)); + } + + @Override + public void onDeny( + final @NotNull S sender, + final @NotNull MessageRegistry messageRegistry, + final @NotNull CommandMeta meta + ) { + messageRegistry.sendMessage(BukkitMessageKey.NO_PERMISSION, sender, new NoPermissionMessageContext(meta, permission)); + } + + @Override + public String toString() { + return "PermissionRequirement{" + + "permission=" + permission + + '}'; + } +} diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java index 810042cd..12dba866 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java @@ -23,6 +23,8 @@ */ package dev.triumphteam.cmd.bukkit.annotation; +import dev.triumphteam.cmd.bukkit.CommandPermission; +import dev.triumphteam.cmd.core.extention.meta.MetaKey; import org.bukkit.permissions.PermissionDefault; import java.lang.annotation.ElementType; @@ -61,4 +63,6 @@ * @see org.bukkit.permissions.Permission#getDescription() */ String description() default ""; + + MetaKey META_KEY = MetaKey.of("command.permission", CommandPermission.class); } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java index 5cfdf969..47918045 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java @@ -34,10 +34,9 @@ public final class NoPermissionMessageContext extends BasicMessageContext { public NoPermissionMessageContext( final @NotNull CommandMeta meta, - final @NotNull String syntax, final @NotNull CommandPermission permission ) { - super(meta, syntax); + super(meta); this.permission = permission; } From 22d3a66a1a9863879b2e739b8482623c34a19884 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 28 Jan 2023 18:59:06 -0600 Subject: [PATCH 070/101] feature: Better command manager builder --- .../cmd/core/argument/InternalArgument.java | 8 +- .../triumphteam/cmd/core/command/Command.java | 39 +++-- .../cmd/core/command/ParentCommand.java | 45 +++--- .../cmd/core/command/SubCommand.java | 8 +- .../cmd/core/extention/CommandOptions.java | 133 +++++++++++++++++- ...ndSettings.java => ImmutableSettings.java} | 4 +- .../cmd/core/extention/command/Processor.java | 2 +- .../{CommandSettings.java => Settings.java} | 6 +- .../core/extention/sender/SenderMapper.java | 29 +++- .../cmd/core/processor/CommandProcessor.java | 8 +- .../processor/ParentCommandProcessor.java | 4 +- .../core/processor/RootCommandProcessor.java | 4 +- .../core/processor/SubCommandProcessor.java | 4 +- .../cmds/CoroutinesCommandExtension.kt | 4 +- .../cmd/bukkit/BukkitCommandManager.java | 57 ++++---- .../cmd/bukkit/BukkitCommandOptions.java | 56 +++++++- .../cmd/bukkit/PermissionProcessor.java | 16 ++- .../cmds/simple/SimpleCommandManager.java | 29 ++-- .../cmds/simple/SimpleOptionsBuilder.java | 22 ++- .../triumphteam/cmds/simple/SimpleSetup.java | 35 +++++ 20 files changed, 398 insertions(+), 115 deletions(-) rename core/src/main/java/dev/triumphteam/cmd/core/extention/command/{ImmutableCommandSettings.java => ImmutableSettings.java} (90%) rename core/src/main/java/dev/triumphteam/cmd/core/extention/command/{CommandSettings.java => Settings.java} (92%) create mode 100644 simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSetup.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index d9e9ea66..227e55e3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -85,7 +85,13 @@ public interface InternalArgument { final @NotNull T value ); - // TODO: Comments + /** + * Create a list of suggestion strings to return to the platform requesting it. + * + * @param sender Rhe sender to get suggestions for. + * @param arguments The arguments used in the suggestion. + * @return A list of valid suggestions for the argument. + */ @NotNull List suggestions(final @NotNull S sender, final @NotNull Deque arguments); default Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> success( diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 14cf850b..3bba5b5d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.core.command; -import dev.triumphteam.cmd.core.extention.command.CommandSettings; +import dev.triumphteam.cmd.core.extention.command.Settings; import dev.triumphteam.cmd.core.extention.meta.CommandMetaContainer; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -35,12 +35,21 @@ /** * Representation of a command. - * Not all commands are executable directly. - * Some implementations will have listeners inside that'll trigger the execution. + * Commands can either be command holders and commands themselves. + * Some holders are {@link ParentCommand}s. + * And actual commands can be for example {@link SubCommand}. */ public interface Command extends CommandMetaContainer { - // TODO + /** + * Execute the command with the needed arguments, instance, and some extra. + * + * @param sender The sender of the command. + * @param instanceSupplier A supplier for which instance will be needed when invoking the command. + * @param arguments A {@link Deque} with the arguments passed, these are consumed on each step. + * @param extra A map of extra details to pass down to the command. + * @throws Throwable Anything that goes wrong with the execution. + */ void execute( final @NotNull S sender, final @Nullable Supplier instanceSupplier, @@ -48,18 +57,30 @@ void execute( final @NotNull Map extra ) throws Throwable; + /** + * Create a list of suggestion strings to return to the platform requesting it. + * + * @param sender Rhe sender to get suggestions for. + * @param arguments The arguments used in the suggestion. + * @return A list of valid suggestions for the command. + */ @NotNull List suggestions( final @NotNull S sender, final @NotNull Deque arguments ); - @NotNull CommandSettings getCommandSettings(); + @NotNull Settings getCommandSettings(); /** * @return The name of the command. */ @NotNull String getName(); + /** + * @return A list with all of its aliases. + */ + @NotNull List getAliases(); + /** * @return Whether this is a "default" command, meaning it represents the class itself and is not separate. */ diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index c89d5f29..a2f98876 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -24,7 +24,7 @@ package dev.triumphteam.cmd.core.command; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; -import dev.triumphteam.cmd.core.extention.command.CommandSettings; +import dev.triumphteam.cmd.core.extention.command.Settings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; @@ -55,7 +55,7 @@ public abstract class ParentCommand implements Command { private final Map> commandAliases = new HashMap<>(); private final CommandMeta meta; - private final CommandSettings settings; + private final Settings settings; // Single parent command with argument private Command parentCommandWithArgument; @@ -64,7 +64,7 @@ public abstract class ParentCommand implements Command { private final SenderExtension senderExtension; public ParentCommand(final @NotNull CommandProcessor processor) { - final CommandSettings.Builder settingsBuilder = new CommandSettings.Builder<>(); + final Settings.Builder settingsBuilder = new Settings.Builder<>(); processor.captureRequirements(settingsBuilder); this.meta = processor.createMeta(settingsBuilder); @@ -102,31 +102,32 @@ public ParentCommand(final @NotNull CommandProcessor processor) { * Add a new command to the maps. * * @param instance The instance of the command the commands came from. - * @param command The sub command to be added. - * @param isAlias Whether it is an alias. + * @param commands A list of command to be added. */ public void addCommand( final @NotNull Object instance, - final @NotNull Command command, - final boolean isAlias + final @NotNull List> commands ) { - // If it's a parent command with argument we add it - if (command instanceof ParentSubCommand && command.hasArguments()) { - if (parentCommandWithArgument != null) { - throw new CommandRegistrationException("Only one inner command with argument is allowed per command", instance.getClass()); + for (final Command command : commands) { + // If it's a parent command with argument we add it + if (command instanceof ParentSubCommand && command.hasArguments()) { + if (parentCommandWithArgument != null) { + throw new CommandRegistrationException("Only one inner command with argument is allowed per command", instance.getClass()); + } + + parentCommandWithArgument = command; + return; } - parentCommandWithArgument = command; - return; - } + if (command.isDefault()) { + this.defaultCommand = command; + } else { + // Normal commands are added here + this.commands.put(command.getName(), command); + } - if (command.isDefault()) { - this.defaultCommand = command; - } else { - // Normal commands are added here - commands.put(command.getName(), command); + command } - // TODO ALIAS } @@ -172,7 +173,7 @@ public void addCommand( } @Override - public @NotNull CommandSettings getCommandSettings() { + public @NotNull Settings getCommandSettings() { return settings; } @@ -194,7 +195,7 @@ public boolean isDefault() { return messageRegistry; } - protected @NotNull CommandSettings getSettings() { + protected @NotNull Settings getSettings() { return settings; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 0a97b47d..aa5ff507 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -31,7 +31,7 @@ import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.ValidationResult; -import dev.triumphteam.cmd.core.extention.command.CommandSettings; +import dev.triumphteam.cmd.core.extention.command.Settings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; @@ -68,7 +68,7 @@ public class SubCommand implements Command { private final boolean containsLimitless; private final CommandMeta meta; - private final CommandSettings settings; + private final Settings settings; private final Object invocationInstance; private final Method method; @@ -87,7 +87,7 @@ public SubCommand( this.method = method; this.name = processor.getName(); - final CommandSettings.Builder settingsBuilder = new CommandSettings.Builder<>(); + final Settings.Builder settingsBuilder = new Settings.Builder<>(); processor.captureRequirements(settingsBuilder); this.meta = processor.createMeta(settingsBuilder); @@ -270,7 +270,7 @@ private boolean validateAndCollectArguments( } @Override - public @NotNull CommandSettings getCommandSettings() { + public @NotNull Settings getCommandSettings() { return settings; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java index 32881340..21971d2a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,9 +23,28 @@ */ package dev.triumphteam.cmd.core.extention; +import dev.triumphteam.cmd.core.argument.ArgumentResolver; +import dev.triumphteam.cmd.core.argument.keyed.Argument; +import dev.triumphteam.cmd.core.argument.keyed.ArgumentKey; +import dev.triumphteam.cmd.core.argument.keyed.Flag; +import dev.triumphteam.cmd.core.argument.keyed.FlagKey; +import dev.triumphteam.cmd.core.extention.registry.ArgumentRegistry; +import dev.triumphteam.cmd.core.extention.registry.FlagRegistry; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.registry.NamedArgumentRegistry; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.MessageResolver; +import dev.triumphteam.cmd.core.message.context.MessageContext; +import dev.triumphteam.cmd.core.suggestion.SuggestionKey; +import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; +import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; +import java.util.List; import java.util.function.Consumer; @SuppressWarnings("unchecked") @@ -50,9 +69,19 @@ public CommandOptions( return senderExtension; } - public static abstract class Builder, B extends Builder> { + public static abstract class Builder, I extends Setup, B extends Builder> { private final ExtensionBuilder extensionBuilder = new ExtensionBuilder<>(); + private final I setup; + + public Builder(final @NotNull I setup) { + this.setup = setup; + } + + public @NotNull B setup(final @NotNull Consumer consumer) { + consumer.accept(setup); + return (B) this; + } public @NotNull B extensions(final @NotNull Consumer> consumer) { consumer.accept(extensionBuilder); @@ -65,4 +94,98 @@ public static abstract class Builder, B ext return extensionBuilder.build(); } } + + public static abstract class Setup> { + private final RegistryContainer registryContainer; + + private final MessageRegistry messageRegistry; + private final SuggestionRegistry suggestionRegistry; + private final ArgumentRegistry argumentRegistry; + private final NamedArgumentRegistry namedArgumentRegistry; + private final FlagRegistry flagRegistry; + + public Setup(final @NotNull RegistryContainer registryContainer) { + this.registryContainer = registryContainer; + + this.messageRegistry = registryContainer.getMessageRegistry(); + this.suggestionRegistry = registryContainer.getSuggestionRegistry(); + this.argumentRegistry = registryContainer.getArgumentRegistry(); + this.namedArgumentRegistry = registryContainer.getNamedArgumentRegistry(); + this.flagRegistry = registryContainer.getFlagRegistry(); + } + + @Contract("_, _ -> new") + public I message( + final @NotNull MessageKey messageKey, + final @NotNull MessageResolver resolver + ) { + messageRegistry.register(messageKey, resolver); + return (I) this; + } + + @Contract("_, _ -> new") + public I argument( + final @NotNull Class type, + final @NotNull ArgumentResolver resolver + ) { + argumentRegistry.register(type, resolver); + return (I) this; + } + + @Contract("_, _ -> new") + public I suggestion( + final @NotNull Class type, + final @NotNull SuggestionResolver resolver + ) { + suggestionRegistry.register(type, resolver); + return (I) this; + } + + @Contract("_, _ -> new") + public I suggestion( + final @NotNull SuggestionKey key, + final @NotNull SuggestionResolver resolver + ) { + suggestionRegistry.register(key, resolver); + return (I) this; + } + + @Contract("_, _ -> new") + public I namedArguments( + final @NotNull ArgumentKey key, + final @NotNull List arguments + ) { + namedArgumentRegistry.register(key, arguments); + return (I) this; + } + + @Contract("_, _ -> new") + public I namedArguments( + final @NotNull ArgumentKey key, + final @NotNull Argument @NotNull ... arguments + ) { + return namedArguments(key, Arrays.asList(arguments)); + } + + @Contract("_, _ -> new") + public I flags( + final @NotNull FlagKey key, + final @NotNull List flags + ) { + flagRegistry.register(key, flags); + return (I) this; + } + + @Contract("_, _ -> new") + public I flags( + final @NotNull FlagKey key, + final @NotNull Flag @NotNull ... flags + ) { + return flags(key, Arrays.asList(flags)); + } + + protected @NotNull RegistryContainer getRegistryContainer() { + return registryContainer; + } + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableCommandSettings.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableSettings.java similarity index 90% rename from core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableCommandSettings.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableSettings.java index 9fd834c3..6f117ae6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableCommandSettings.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableSettings.java @@ -9,11 +9,11 @@ import java.util.List; -public final class ImmutableCommandSettings implements CommandSettings { +public final class ImmutableSettings implements Settings { private final List> requirements; - public ImmutableCommandSettings(final @NotNull List> requirements) { + public ImmutableSettings(final @NotNull List> requirements) { this.requirements = requirements; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Processor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Processor.java index d5c20507..f570011c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Processor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Processor.java @@ -35,6 +35,6 @@ void process( final @NotNull AnnotatedElement element, final @NotNull ProcessorTarget target, final @NotNull CommandMeta.@NotNull Builder meta, - final @NotNull CommandSettings.@NotNull Builder settingsBuilder + final @NotNull Settings.@NotNull Builder settingsBuilder ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/CommandSettings.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Settings.java similarity index 92% rename from core/src/main/java/dev/triumphteam/cmd/core/extention/command/CommandSettings.java rename to core/src/main/java/dev/triumphteam/cmd/core/extention/command/Settings.java index 045fc50b..dd4430bd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/CommandSettings.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Settings.java @@ -11,7 +11,7 @@ import java.util.Collections; import java.util.List; -public interface CommandSettings { +public interface Settings { /** * Tests all the requirements present in the setting. @@ -59,8 +59,8 @@ class Builder { // TODO add more things to the settings - public CommandSettings build() { - return new ImmutableCommandSettings<>(Collections.unmodifiableList(requirements)); + public Settings build() { + return new ImmutableSettings<>(Collections.unmodifiableList(requirements)); } } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java index 5e70ba4c..dbee54d7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -25,10 +25,29 @@ import org.jetbrains.annotations.NotNull; -// TODO Comments +/** + * Map a sender into a new type of sender that can be used on the commands. + * This is useful if you want to have a custom type for your project. + * For example a "User" sender with more data than the platform's sender provides. + * + * @param The default sender, aka the platforms default. + * @param The mapped/final sender. + */ public interface SenderMapper { + /** + * Map from a default sender into your custom sender. + * + * @param defaultSender The platform provided sender. + * @return A final usable version of the sender. + */ @NotNull S map(final @NotNull D defaultSender); + /** + * Return back to the original sender. + * + * @param sender The mapped/final sender. + * @return The platform provided sender, that was used to map into the current sender. + */ @NotNull D mapBackwards(final @NotNull S sender); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index c1815a11..287239ed 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -30,7 +30,7 @@ import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; -import dev.triumphteam.cmd.core.extention.command.CommandSettings; +import dev.triumphteam.cmd.core.extention.command.Settings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry; @@ -56,7 +56,7 @@ public interface CommandProcessor { * * @return The immutable {@link CommandMeta} instance. */ - @NotNull CommandMeta createMeta(final @NotNull CommandSettings.Builder settingsBuilder); + @NotNull CommandMeta createMeta(final @NotNull Settings.Builder settingsBuilder); @NotNull CommandOptions getCommandOptions(); @@ -95,7 +95,7 @@ default void processAnnotations( } } - default void captureRequirements(final @NotNull CommandSettings.Builder settingsBuilder) { + default void captureRequirements(final @NotNull Settings.Builder settingsBuilder) { final RequirementRegistry requirementRegistry = getRegistryContainer().getRequirementRegistry(); for (final dev.triumphteam.cmd.core.annotations.Requirement requirementAnnotation : getRequirementsFromAnnotations()) { @@ -119,7 +119,7 @@ default void processCommandMeta( final @NotNull AnnotatedElement element, final @NotNull ProcessorTarget target, final @NotNull CommandMeta.Builder meta, - final @NotNull CommandSettings.Builder settingsBuilder + final @NotNull Settings.Builder settingsBuilder ) { extensions.getProcessors().forEach(it -> it.process(element, target, meta, settingsBuilder)); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java index 47725dd4..4ad61bd4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java @@ -25,7 +25,7 @@ import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; -import dev.triumphteam.cmd.core.extention.command.CommandSettings; +import dev.triumphteam.cmd.core.extention.command.Settings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.meta.MetaKey; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; @@ -64,7 +64,7 @@ public final class ParentCommandProcessor extends AbstractCommandProcessor } @Override - public @NotNull CommandMeta createMeta(final @NotNull CommandSettings.@NotNull Builder settingsBuilder) { + public @NotNull CommandMeta createMeta(final @NotNull Settings.@NotNull Builder settingsBuilder) { final CommandMeta.Builder meta = new CommandMeta.Builder(getParentMeta()); // Defaults diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index d75b056d..66dc044e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -36,7 +36,7 @@ import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; -import dev.triumphteam.cmd.core.extention.command.CommandSettings; +import dev.triumphteam.cmd.core.extention.command.Settings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.meta.MetaKey; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; @@ -119,7 +119,7 @@ public String getDescription() { } @Override - public @NotNull CommandMeta createMeta(final @NotNull CommandSettings.@NotNull Builder settingsBuilder) { + public @NotNull CommandMeta createMeta(final @NotNull Settings.@NotNull Builder settingsBuilder) { final CommandMeta.Builder meta = new CommandMeta.Builder(null); // Defaults diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index fb1c21ca..a6efc731 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -36,7 +36,7 @@ import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.ValidationResult; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; -import dev.triumphteam.cmd.core.extention.command.CommandSettings; +import dev.triumphteam.cmd.core.extention.command.Settings; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.meta.MetaKey; import dev.triumphteam.cmd.core.extention.registry.FlagRegistry; @@ -101,7 +101,7 @@ public final class SubCommandProcessor extends AbstractCommandProcessor settingsBuilder) { + public @NotNull CommandMeta createMeta(final @NotNull Settings.Builder settingsBuilder) { final CommandMeta.Builder meta = new CommandMeta.Builder(getParentMeta()); // Defaults diff --git a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt index 20cb7abe..f3be6858 100644 --- a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt +++ b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt @@ -32,7 +32,7 @@ import dev.triumphteam.cmd.core.extention.ValidationResult import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator import dev.triumphteam.cmd.core.extention.command.Processor -import dev.triumphteam.cmd.core.extention.command.CommandSettings +import dev.triumphteam.cmd.core.extention.command.Settings import dev.triumphteam.cmd.core.extention.meta.CommandMeta import dev.triumphteam.cmd.core.extention.meta.MetaKey import kotlinx.coroutines.CoroutineScope @@ -70,7 +70,7 @@ public class CoroutinesCommandExtension( element: AnnotatedElement, target: ProcessorTarget, meta: CommandMeta.Builder, - settingsBuilder: CommandSettings.Builder + settingsBuilder: Settings.Builder ) { if (element !is Method) return // Not really necessary but doesn't hurt to check diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index be280f2b..47f6d956 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -23,13 +23,14 @@ */ package dev.triumphteam.cmd.bukkit; +import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; import dev.triumphteam.cmd.core.CommandManager; import dev.triumphteam.cmd.core.command.RootCommand; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; -import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; -import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import org.bukkit.Bukkit; import org.bukkit.Material; @@ -54,22 +55,21 @@ public final class BukkitCommandManager extends CommandManager { private final Plugin plugin; - private final RegistryContainer registryContainer = new RegistryContainer<>(); + private final RegistryContainer registryContainer; private final Map> commands = new HashMap<>(); private final CommandMap commandMap; private final Map bukkitCommands; - // TODO: Default base from constructor - private final CommandPermission basePermission = null; - private BukkitCommandManager( final @NotNull Plugin plugin, - final @NotNull BukkitCommandOptions commandOptions + final @NotNull BukkitCommandOptions commandOptions, + final @NotNull RegistryContainer registryContainer ) { super(commandOptions); this.plugin = plugin; + this.registryContainer = registryContainer; this.commandMap = getCommandMap(); this.bukkitCommands = getBukkitCommands(commandMap); @@ -94,16 +94,10 @@ private BukkitCommandManager( final @NotNull SenderExtension senderExtension, final @NotNull Consumer> builder ) { - final BukkitCommandOptions.Builder extensionBuilder = new BukkitCommandOptions.Builder<>(); - - extensionBuilder.extensions(extension -> { - extension.addProcessor(new PermissionProcessor<>()); - extension.setArgumentValidator(new DefaultArgumentValidator<>()); - extension.setCommandExecutor(new DefaultCommandExecutor()); - }); - + final RegistryContainer registryContainer = new RegistryContainer<>(); + final BukkitCommandOptions.Builder extensionBuilder = new BukkitCommandOptions.Builder<>(registryContainer); builder.accept(extensionBuilder); - return new BukkitCommandManager<>(plugin, extensionBuilder.build(senderExtension)); + return new BukkitCommandManager<>(plugin, extensionBuilder.build(senderExtension), registryContainer); } /** @@ -130,23 +124,32 @@ private BukkitCommandManager( final @NotNull Plugin plugin, final @NotNull Consumer> builder ) { - return create(plugin, new BukkitSenderExtension(), builder); + final RegistryContainer registryContainer = new RegistryContainer<>(); + final BukkitCommandOptions.Builder extensionBuilder = new BukkitCommandOptions.Builder<>(registryContainer); + + // Setup defaults for Bukkit + final MessageRegistry messageRegistry = registryContainer.getMessageRegistry(); + setUpDefaults(messageRegistry); + + // Then accept configured values + builder.accept(extensionBuilder); + return new BukkitCommandManager<>(plugin, extensionBuilder.build(new BukkitSenderExtension()), registryContainer); } /** * Sets up all the default values for the Bukkit implementation. * - * @param manager The {@link BukkitCommandManager} instance to set up. + * @param messageRegistry The {@link BukkitCommandManager} instance to set up. */ - private static void setUpDefaults(final @NotNull BukkitCommandManager manager) { - /*manager.registerMessage(MessageKey.UNKNOWN_COMMAND, (sender, context) -> sender.sendMessage("Unknown command: `" + context.getCommand() + "`.")); - manager.registerMessage(MessageKey.TOO_MANY_ARGUMENTS, (sender, context) -> sender.sendMessage("Invalid usage.")); - manager.registerMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, (sender, context) -> sender.sendMessage("Invalid usage.")); - manager.registerMessage(MessageKey.INVALID_ARGUMENT, (sender, context) -> sender.sendMessage("Invalid argument `" + context.getTypedArgument() + "` for type `" + context.getArgumentType().getSimpleName() + "`.")); - - manager.registerMessage(BukkitMessageKey.NO_PERMISSION, (sender, context) -> sender.sendMessage("You do not have permission to perform this command. Permission needed: `" + context.getNodes() + "`.")); - manager.registerMessage(BukkitMessageKey.PLAYER_ONLY, (sender, context) -> sender.sendMessage("This command can only be used by players.")); - manager.registerMessage(BukkitMessageKey.CONSOLE_ONLY, (sender, context) -> sender.sendMessage("This command can only be used by the console."));*/ + private static void setUpDefaults(final @NotNull MessageRegistry messageRegistry) { + messageRegistry.register(MessageKey.UNKNOWN_COMMAND, (sender, context) -> sender.sendMessage("Unknown command: `" + context.getInvalidInput() + "`.")); + messageRegistry.register(MessageKey.TOO_MANY_ARGUMENTS, (sender, context) -> sender.sendMessage("Invalid usage.")); + messageRegistry.register(MessageKey.NOT_ENOUGH_ARGUMENTS, (sender, context) -> sender.sendMessage("Invalid usage.")); + messageRegistry.register(MessageKey.INVALID_ARGUMENT, (sender, context) -> sender.sendMessage("Invalid argument `" + context.getInvalidInput() + "` for type `" + context.getArgumentType().getSimpleName() + "`.")); + + messageRegistry.register(BukkitMessageKey.NO_PERMISSION, (sender, context) -> sender.sendMessage("You do not have permission to perform this command.")); + messageRegistry.register(BukkitMessageKey.PLAYER_ONLY, (sender, context) -> sender.sendMessage("This command can only be used by players.")); + messageRegistry.register(BukkitMessageKey.CONSOLE_ONLY, (sender, context) -> sender.sendMessage("This command can only be used by the console.")); } @Override diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java index d155e29d..c8ef8a28 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java @@ -2,10 +2,16 @@ import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.CommandOptions; +import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; +import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.bukkit.command.CommandSender; +import org.bukkit.permissions.PermissionDefault; import org.jetbrains.annotations.NotNull; +import java.util.List; + public final class BukkitCommandOptions extends CommandOptions { public BukkitCommandOptions( @@ -15,10 +21,58 @@ public BukkitCommandOptions( super(senderExtension, commandExtensions); } - public static final class Builder extends CommandOptions.Builder, Builder> { + public static final class Setup extends CommandOptions.Setup> { + public Setup(final @NotNull RegistryContainer registryContainer) { + super(registryContainer); + } + } + + public static final class Builder extends CommandOptions.Builder, Setup, Builder> { + + private CommandPermission globalPermission = null; + + public Builder(final @NotNull RegistryContainer registryContainer) { + super(new Setup<>(registryContainer)); + + // Setters have to be done first thing, so they can be overriden. + extensions(extension -> { + extension.setArgumentValidator(new DefaultArgumentValidator<>()); + extension.setCommandExecutor(new DefaultCommandExecutor()); + }); + } + + /** + * Set a {@link CommandPermission} that'll apply to all commands registered by this manager. + * + * @param commandPermission The permission to be globally used. + * @return This {@link Builder}. + */ + public Builder setGlobalPermission(final @NotNull CommandPermission commandPermission) { + this.globalPermission = commandPermission; + return this; + } + + /** + * Set a {@link CommandPermission} that'll apply to all commands registered by this manager. + * + * @param nodes Permission nodes to be used. + * @param description A description for the command. + * @param permissionDefault The {@link PermissionDefault} to be used when registering the permission. + * @return This {@link Builder}. + */ + public Builder setGlobalPermission( + final @NotNull List nodes, + final @NotNull String description, + final @NotNull PermissionDefault permissionDefault + ) { + return setGlobalPermission(new CommandPermission(nodes, description, permissionDefault)); + } @Override public @NotNull BukkitCommandOptions build(final @NotNull SenderExtension senderExtension) { + // Add permissions + extensions(extension -> extension.addProcessor(new PermissionProcessor<>(globalPermission))); + return new BukkitCommandOptions<>(senderExtension, getCommandExtensions()); } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java index 77dd9ec7..4aca8f45 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java @@ -2,7 +2,7 @@ import dev.triumphteam.cmd.bukkit.annotation.Permission; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; -import dev.triumphteam.cmd.core.extention.command.CommandSettings; +import dev.triumphteam.cmd.core.extention.command.Settings; import dev.triumphteam.cmd.core.extention.command.Processor; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.bukkit.command.CommandSender; @@ -14,12 +14,18 @@ final class PermissionProcessor implements Processor { + private final CommandPermission globalPermission; + + public PermissionProcessor(final @Nullable CommandPermission globalPermission) { + this.globalPermission = globalPermission; + } + @Override public void process( final @NotNull AnnotatedElement element, final @NotNull ProcessorTarget target, final @NotNull CommandMeta.@NotNull Builder meta, - final @NotNull CommandSettings.@NotNull Builder settingsBuilder + final @NotNull Settings.@NotNull Builder settingsBuilder ) { final Permission permissionAnnotation = element.getAnnotation(Permission.class); if (permissionAnnotation == null) return; @@ -33,6 +39,12 @@ public void process( permissionAnnotation.description(), permissionAnnotation.def() ); + } else if (globalPermission != null) { + permission = globalPermission.child( + Arrays.asList(permissionAnnotation.value()), + permissionAnnotation.description(), + permissionAnnotation.def() + ); } else { permission = new CommandPermission( Arrays.asList(permissionAnnotation.value()), diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index f593d88b..63edb495 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,8 +26,6 @@ import dev.triumphteam.cmd.core.CommandManager; import dev.triumphteam.cmd.core.command.RootCommand; import dev.triumphteam.cmd.core.extention.CommandOptions; -import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; -import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; @@ -48,10 +46,14 @@ public final class SimpleCommandManager extends CommandManager { private final Map> commands = new HashMap<>(); - private final RegistryContainer registryContainer = new RegistryContainer<>(); + private final RegistryContainer registryContainer; - private SimpleCommandManager(final @NotNull CommandOptions commandOptions) { + private SimpleCommandManager( + final @NotNull CommandOptions commandOptions, + final @NotNull RegistryContainer registryContainer + ) { super(commandOptions); + this.registryContainer = registryContainer; } @Contract("_, _ -> new") @@ -59,15 +61,10 @@ private SimpleCommandManager(final @NotNull CommandOptions commandOptions) final @NotNull SenderExtension senderExtension, final @NotNull Consumer> builder ) { - final SimpleOptionsBuilder extensionBuilder = new SimpleOptionsBuilder<>(); - - extensionBuilder.extensions(extension -> { - extension.setArgumentValidator(new DefaultArgumentValidator<>()); - extension.setCommandExecutor(new DefaultCommandExecutor()); - }); - + final RegistryContainer registryContainer = new RegistryContainer<>(); + final SimpleOptionsBuilder extensionBuilder = new SimpleOptionsBuilder<>(registryContainer); builder.accept(extensionBuilder); - return new SimpleCommandManager<>(extensionBuilder.build(senderExtension)); + return new SimpleCommandManager<>(extensionBuilder.build(senderExtension), registryContainer); } @Override diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java index fca9092f..26ab54a3 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,10 +24,22 @@ package dev.triumphteam.cmds.simple; import dev.triumphteam.cmd.core.extention.CommandOptions; +import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; +import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.NotNull; -public final class SimpleOptionsBuilder extends CommandOptions.Builder, SimpleOptionsBuilder> { +public final class SimpleOptionsBuilder extends CommandOptions.Builder, SimpleSetup, SimpleOptionsBuilder> { + + public SimpleOptionsBuilder(final @NotNull RegistryContainer registryContainer) { + super(new SimpleSetup<>(registryContainer)); + + extensions(extension -> { + extension.setArgumentValidator(new DefaultArgumentValidator<>()); + extension.setCommandExecutor(new DefaultCommandExecutor()); + }); + } @Override public @NotNull CommandOptions build(final @NotNull SenderExtension senderExtension) { diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSetup.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSetup.java new file mode 100644 index 00000000..2a300f9f --- /dev/null +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleSetup.java @@ -0,0 +1,35 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmds.simple; + +import dev.triumphteam.cmd.core.extention.CommandOptions; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import org.jetbrains.annotations.NotNull; + +public final class SimpleSetup extends CommandOptions.Setup> { + + public SimpleSetup(final @NotNull RegistryContainer registryContainer) { + super(registryContainer); + } +} From 4fdb6a6e1e551d79c9e6c91c92ed248a0732a9d2 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 28 Jan 2023 19:17:41 -0600 Subject: [PATCH 071/101] chore: Finalizing Core, Bukkit, and Simple (for now) --- .../cmd/core/command/ParentCommand.java | 7 ++--- .../cmd/core/command/ParentSubCommand.java | 7 +++++ .../cmd/core/command/RootCommand.java | 8 ++++++ .../cmd/core/command/SubCommand.java | 7 +++++ .../processor/AbstractCommandProcessor.java | 26 +++++++++++++++--- .../core/processor/RootCommandProcessor.java | 18 ++++++------- .../core/processor/SubCommandProcessor.java | 3 --- .../triumphteam/cmd/bukkit/BukkitCommand.java | 2 +- .../cmd/bukkit/BukkitCommandManager.java | 27 ++++--------------- .../cmds/simple/SimpleCommandManager.java | 18 +++---------- 10 files changed, 66 insertions(+), 57 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index a2f98876..48dc2dc5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -104,7 +104,7 @@ public ParentCommand(final @NotNull CommandProcessor processor) { * @param instance The instance of the command the commands came from. * @param commands A list of command to be added. */ - public void addCommand( + public void addCommands( final @NotNull Object instance, final @NotNull List> commands ) { @@ -126,9 +126,10 @@ public void addCommand( this.commands.put(command.getName(), command); } - command + for (final String alias : command.getAliases()) { + this.commandAliases.put(alias, command); + } } - // TODO ALIAS } protected @Nullable Command findCommand( diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 2eb9445d..37a472c3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -53,6 +53,7 @@ public class ParentSubCommand extends ParentCommand { private final String name; + private final List aliases; private final String syntax; private final Object invocationInstance; @@ -78,6 +79,7 @@ public ParentSubCommand( this.hasArgument = argument != null; this.name = processor.getName(); + this.aliases = processor.getAliases(); this.syntax = createSyntax(parentCommand, processor); } @@ -201,6 +203,11 @@ public void execute( return name; } + @Override + public @NotNull List getAliases() { + return aliases; + } + @Override public @NotNull String getSyntax() { return syntax; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java index b12990b4..51006a6d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java @@ -30,18 +30,21 @@ import java.lang.reflect.InvocationTargetException; import java.util.Deque; +import java.util.List; import java.util.Map; import java.util.function.Supplier; public class RootCommand extends ParentCommand { private final String name; + private final List aliases; private final String syntax; public RootCommand(final @NotNull RootCommandProcessor processor) { super(processor); this.name = processor.getName(); + this.aliases = processor.getAliases(); this.syntax = "/" + name; } @@ -77,6 +80,11 @@ public void execute( return name; } + @Override + public @NotNull List getAliases() { + return aliases; + } + @Override public @NotNull String getSyntax() { return syntax; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index aa5ff507..613c2724 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -64,6 +64,7 @@ public class SubCommand implements Command { private final Map> argumentMap; private final String name; + private final List aliases; private final String syntax; private final boolean containsLimitless; @@ -86,6 +87,7 @@ public SubCommand( this.invocationInstance = invocationInstance; this.method = method; this.name = processor.getName(); + this.aliases = processor.getAliases(); final Settings.Builder settingsBuilder = new Settings.Builder<>(); processor.captureRequirements(settingsBuilder); @@ -279,6 +281,11 @@ private boolean validateAndCollectArguments( return name; } + @Override + public @NotNull List getAliases() { + return aliases; + } + @Override public @NotNull String getSyntax() { return syntax; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index b4a7a079..0aee3822 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -75,6 +75,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.stream.Collectors; /** * Abstracts most of the "extracting" from sub command annotations, allows for extending. @@ -91,6 +92,7 @@ abstract class AbstractCommandProcessor implements CommandProcessor private final Object invocationInstance; private final String name; + private final List aliases; private final String description; private final Syntax syntax; private final AnnotatedElement annotatedElement; @@ -113,6 +115,7 @@ abstract class AbstractCommandProcessor implements CommandProcessor this.invocationInstance = invocationInstance; this.annotatedElement = annotatedElement; this.name = nameOf(); + this.aliases = aliasesOf(); this.description = descriptionOf(); this.parentMeta = parentMeta; @@ -157,10 +160,25 @@ abstract class AbstractCommandProcessor implements CommandProcessor return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, commandAnnotation.value()); } + private @Nullable List aliasesOf() { + final Command commandAnnotation = annotatedElement.getAnnotation(Command.class); + + // Not a command element + if (commandAnnotation == null) return null; + + return Arrays.stream(commandAnnotation.alias()) + .map(it -> CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, it)) + .collect(Collectors.toList()); + } + public @Nullable String getName() { return name; } + public @NotNull List getAliases() { + return aliases; + } + public String getDescription() { return description; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index 66dc044e..10900801 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -63,7 +63,7 @@ public class RootCommandProcessor implements CommandProcessor { private final String name; private final Syntax syntax; - private final List alias; + private final List aliases; private final String description; private final CommandOptions commandOptions; @@ -77,7 +77,7 @@ public RootCommandProcessor( this.invocationInstance = invocationInstance; this.name = nameOf(); - this.alias = aliasOf(); + this.aliases = aliasesOf(); this.description = descriptionOf(); this.registryContainer = registryContainer; @@ -86,15 +86,15 @@ public RootCommandProcessor( this.syntax = invocationInstance.getClass().getAnnotation(Syntax.class); } - public String getName() { + public @NotNull String getName() { return name; } - public List getAlias() { - return alias; + public @NotNull List getAliases() { + return aliases; } - public String getDescription() { + public @NotNull String getDescription() { return description; } @@ -248,8 +248,8 @@ public String getDescription() { ); // Add children commands to parent - methodCommands(parent, klass.getDeclaredMethods()).forEach(it -> parent.addCommand(invocationInstance, it, false)); - classCommands(parent, klass.getDeclaredClasses()).forEach(it -> parent.addCommand(invocationInstance, it, false)); + parent.addCommands(invocationInstance, methodCommands(parent, klass.getDeclaredMethods())); + parent.addCommands(invocationInstance, classCommands(parentCommand, klass.getDeclaredClasses())); // Add parent command to main list commands.add(parent); @@ -281,7 +281,7 @@ public String getDescription() { return CaseFormat.LOWER_CAMEL.to(CaseFormat.LOWER_HYPHEN, name); } - private @NotNull List aliasOf() { + private @NotNull List aliasesOf() { final Class commandClass = invocationInstance.getClass(); final dev.triumphteam.cmd.core.annotations.Command commandAnnotation = commandClass.getAnnotation(dev.triumphteam.cmd.core.annotations.Command.class); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index a6efc731..d0dd421b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -42,7 +42,6 @@ import dev.triumphteam.cmd.core.extention.registry.FlagRegistry; import dev.triumphteam.cmd.core.extention.registry.NamedArgumentRegistry; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import dev.triumphteam.cmd.core.extention.registry.RequirementRegistry; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.Suggestion; @@ -77,7 +76,6 @@ public final class SubCommandProcessor extends AbstractCommandProcessor requirementRegistry; private final FlagRegistry flagRegistry; SubCommandProcessor( @@ -91,7 +89,6 @@ public final class SubCommandProcessor extends AbstractCommandProcessor extends Command { private final SenderExtension senderExtension; BukkitCommand(final @NotNull RootCommandProcessor processor) { - super(processor.getName(), processor.getDescription(), "", processor.getAlias()); + super(processor.getName(), processor.getDescription(), "", processor.getAliases()); this.rootCommand = new RootCommand<>(processor); this.senderExtension = processor.getCommandOptions().getSenderExtension(); diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index 47f6d956..9930d9f4 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -162,29 +162,12 @@ public void registerCommand(final @NotNull Object command) { final String name = processor.getName(); - final BukkitCommand bukkitCommand = commands.get(name); - if (bukkitCommand != null) { - // TODO: Command exists, only care about adding subs - return; - } - - final BukkitCommand newBukkitCommand = createAndRegisterCommand(processor, name); - final RootCommand rootCommand = newBukkitCommand.getRootCommand(); - processor.commands(rootCommand).forEach(it -> rootCommand.addCommand(command, it, false)); - - // Command does not exist, proceed to add new! - - // final BukkitCommandProcessor processor = new BukkitCommandProcessor<>(name, command, basePermission); - - // final BukkitCommand newCommand = commands.computeIfAbsent(processor.getName(), it -> createAndRegisterCommand(it, processor)); - - // TODO: ADD SUBCOMMANDS + // Get or add command, then add its sub commands + final BukkitCommand bukkitCommand = commands.computeIfAbsent(name, it -> createAndRegisterCommand(processor, name)); + final RootCommand rootCommand = bukkitCommand.getRootCommand(); + rootCommand.addCommands(command, processor.commands(rootCommand)); - /*processor.getAlias().forEach(it -> { - final BukkitCommand aliasCommand = commands.computeIfAbsent(it, ignored -> createAndRegisterCommand(it, processor)); - // Adding sub commands. - // TODO: ADD SUBCOMMANDS - });*/ + // TODO: ALIASES } @Override diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 63edb495..2ffc405c 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -77,21 +77,9 @@ public void registerCommand(final @NotNull Object command) { final String name = processor.getName(); - final RootCommand simpleCommand = commands.get(name); - if (simpleCommand != null) { - // TODO: Command exists, only care about adding subs - return; - } - - // Command does not exist, proceed to add new! - final RootCommand newSimpleCommand = commands.computeIfAbsent(processor.getName(), it -> new RootCommand<>(processor)); - processor.commands(newSimpleCommand).forEach(it -> newSimpleCommand.addCommand(command, it, false)); - - processor.getAlias().forEach(it -> { - final RootCommand aliasCommand = commands.computeIfAbsent(it, ignored -> new RootCommand<>(processor)); - // Adding sub commands. - processor.commands(aliasCommand).forEach(sub -> aliasCommand.addCommand(command, sub, false)); - }); + final RootCommand rootCommand = commands.computeIfAbsent(name, it -> new RootCommand<>(processor)); + rootCommand.addCommands(command, processor.commands(rootCommand)); + processor.getAliases().forEach(it -> commands.putIfAbsent(it, rootCommand)); } /** From c61436ecc33b334d9a601b1e8c76f4d643cd2fa9 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 28 Jan 2023 19:18:42 -0600 Subject: [PATCH 072/101] chore: License --- .../cmd/core/annotations/Requirement.java | 8 +++---- .../cmd/core/argument/InternalArgument.java | 8 +++---- .../argument/LimitlessInternalArgument.java | 8 +++---- .../argument/SplitStringInternalArgument.java | 8 +++---- .../core/argument/StringInternalArgument.java | 8 +++---- .../argument/UnknownInternalArgument.java | 8 +++---- .../core/argument/keyed/ArgumentGroup.java | 8 +++---- .../core/argument/keyed/ArgumentParser.java | 8 +++---- .../argument/keyed/KeyedInternalArgument.java | 8 +++---- .../triumphteam/cmd/core/command/Command.java | 8 +++---- .../cmd/core/command/ParentCommand.java | 8 +++---- .../cmd/core/command/ParentSubCommand.java | 8 +++---- .../cmd/core/command/RootCommand.java | 8 +++---- .../cmd/core/command/SubCommand.java | 8 +++---- .../cmd/core/extention/CommandExtensions.java | 8 +++---- .../cmd/core/extention/CommandOptions.java | 8 +++---- .../cmd/core/extention/ExtensionBuilder.java | 8 +++---- .../cmd/core/extention/ValidationResult.java | 8 +++---- .../extention/command/ImmutableSettings.java | 23 +++++++++++++++++++ .../cmd/core/extention/command/Processor.java | 8 +++---- .../cmd/core/extention/command/Settings.java | 23 +++++++++++++++++++ .../extention/sender/SenderExtension.java | 8 +++---- .../core/extention/sender/SenderMapper.java | 8 +++---- .../processor/AbstractCommandProcessor.java | 8 +++---- .../cmd/core/processor/CommandProcessor.java | 8 +++---- .../processor/ParentCommandProcessor.java | 8 +++---- .../core/processor/RootCommandProcessor.java | 8 +++---- .../core/requirement/InternalRequirement.java | 8 +++---- .../cmd/core/requirement/Requirement.java | 23 +++++++++++++++++++ .../core/requirement/RequirementContext.java | 23 +++++++++++++++++++ .../core/requirement/RequirementResolver.java | 8 +++---- .../requirement/SimpleRequirementContext.java | 23 +++++++++++++++++++ .../cmd/core/suggestion/EmptySuggestion.java | 8 +++---- .../core/suggestion/SuggestionResolver.java | 8 +++---- .../triumphteam/cmd/bukkit/BukkitCommand.java | 8 +++---- .../cmd/bukkit/BukkitCommandManager.java | 8 +++---- .../cmd/bukkit/BukkitCommandOptions.java | 23 +++++++++++++++++++ .../cmd/bukkit/BukkitSenderExtension.java | 8 +++---- .../cmd/bukkit/CommandPermission.java | 8 +++---- .../cmd/bukkit/PermissionProcessor.java | 23 +++++++++++++++++++ .../cmd/bukkit/PermissionRequirement.java | 23 +++++++++++++++++++ .../cmd/bukkit/annotation/Permission.java | 8 +++---- .../cmd/bukkit/message/BukkitMessageKey.java | 8 +++---- .../message/NoPermissionMessageContext.java | 8 +++---- .../cmds/simple/SimpleCommandManager.java | 8 +++---- .../cmds/simple/SimpleOptionsBuilder.java | 8 +++---- 46 files changed, 336 insertions(+), 152 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java index afe1e855..6706760c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/annotations/Requirement.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index 227e55e3..6cbd1fa7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java index 36e5d415..23c2dd09 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java index fb2e10d8..cf5bda91 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java index 16746385..604083bb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index af11e125..2ca215e5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java index 8990dc74..e5b1387a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentGroup.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java index 5f7eeb40..43f55f70 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/ArgumentParser.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java index b5b8f196..7c6ee380 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 3bba5b5d..52e8672f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index 48dc2dc5..5649f8b0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 37a472c3..7df7bed6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java index 51006a6d..392969f1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 613c2724..99033a5d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java index d183f2be..d45f1375 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java index 21971d2a..99c5d453 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java index 2de06857..8d0a3e29 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ValidationResult.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ValidationResult.java index 21fc4c6e..8b0dc363 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/ValidationResult.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ValidationResult.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableSettings.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableSettings.java index 6f117ae6..6b569159 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableSettings.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/ImmutableSettings.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.command; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Processor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Processor.java index f570011c..1d28edac 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Processor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Processor.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Settings.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Settings.java index dd4430bd..5f18ed88 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Settings.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/command/Settings.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.extention.command; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java index f4eaf950..60551d3e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java index dbee54d7..fea1a475 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderMapper.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 0aee3822..94bb2c2f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index 287239ed..7c01f4b3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java index 4ad61bd4..a88bb6b0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/ParentCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index 10900801..c5e94e65 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/InternalRequirement.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/InternalRequirement.java index 34a8e4f0..341cd60b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/InternalRequirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/InternalRequirement.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java index 91b570de..d3c5f334 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/Requirement.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.requirement; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java index 52c263b9..4b7b1d89 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementContext.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.requirement; import dev.triumphteam.cmd.core.command.Command; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java index 0d0d9ac6..9afe97c4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/RequirementResolver.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java b/core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java index 96b576c4..450b7e52 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/requirement/SimpleRequirementContext.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.core.requirement; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java index 106134e3..418daf34 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EmptySuggestion.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java index 03b7d76a..ee39d4d4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionResolver.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index e261ecbb..f2594db6 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index 9930d9f4..c2cb6ed0 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java index c8ef8a28..f3d1e0ab 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.bukkit; import dev.triumphteam.cmd.core.extention.CommandExtensions; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java index 22ee271a..a23d28a2 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java index 48fe48d6..fc3aec83 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/CommandPermission.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java index 4aca8f45..4801437b 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionProcessor.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.bukkit; import dev.triumphteam.cmd.bukkit.annotation.Permission; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java index af5205ba..16e14ecf 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.bukkit; import dev.triumphteam.cmd.bukkit.message.BukkitMessageKey; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java index 12dba866..9d95b95c 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/annotation/Permission.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java index 9223165d..bcb080c9 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/BukkitMessageKey.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java index 47918045..67ccd8e6 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/message/NoPermissionMessageContext.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 2ffc405c..644791d7 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java index 26ab54a3..f1fdb211 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE From db2a7ecd3b475185ab358181f6deabfa9b5c8281 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 28 Jan 2023 19:23:16 -0600 Subject: [PATCH 073/101] version: Highly experimental `2.0.0-ALPHA-1` --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 717cc1f1..9ad49154 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ kotlin.stdlib.default.dependency=false -version=2.0.0-SNAPSHOT +version=2.0.0-ALPHA-1 group=dev.triumphteam From 2e5246547a0303da9274f71655945879143624aa Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 28 Jan 2023 19:49:15 -0600 Subject: [PATCH 074/101] chore: Small fixes --- .../java/dev/triumphteam/cmd/core/AnnotatedCommand.java | 1 - .../cmd/core/argument/keyed/KeyedInternalArgument.java | 5 ----- .../dev/triumphteam/cmd/core/command/ParentCommand.java | 9 +++++---- .../triumphteam/cmd/core/command/ParentSubCommand.java | 2 +- .../dev/triumphteam/cmd/core/command/RootCommand.java | 2 +- .../triumphteam/cmd/core/suggestion/SuggestionKey.java | 2 +- .../triumphteam/cmd/bukkit/PermissionRequirement.java | 2 +- 7 files changed, 9 insertions(+), 14 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java index 0c15da23..9a9b7c52 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/AnnotatedCommand.java @@ -35,7 +35,6 @@ public abstract class AnnotatedCommand { private final List alias = new ArrayList<>(); private final String description; - public AnnotatedCommand() { this(null, null, null); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java index 7c6ee380..51c19f8a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java @@ -50,9 +50,6 @@ public final class KeyedInternalArgument extends LimitlessInternalArgument private final Map> flagInternalArguments; private final Map> argumentInternalArguments; - private final ArgumentGroup argumentGroup; - private final ArgumentGroup flagGroup; - private final ArgumentParser argumentParser; public KeyedInternalArgument( @@ -66,8 +63,6 @@ public KeyedInternalArgument( super(name, description, Flags.class, new EmptySuggestion<>(), true); this.flagInternalArguments = flagInternalArguments; this.argumentInternalArguments = argumentInternalArguments; - this.flagGroup = flagGroup; - this.argumentGroup = argumentGroup; this.argumentParser = new ArgumentParser(flagGroup, argumentGroup); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index 5649f8b0..db9a77b6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -82,7 +82,7 @@ public ParentCommand(final @NotNull CommandProcessor processor) { final String argument = arguments.peek(); if (argument == null) return emptyList(); - final Command command = findCommand(sender, arguments); + final Command command = findCommand(sender, arguments, false); if (command == null) { return commands.entrySet().stream() @@ -134,7 +134,8 @@ public void addCommands( protected @Nullable Command findCommand( final @NotNull S sender, - final @NotNull Deque arguments + final @NotNull Deque arguments, + final boolean message ) { final String name = arguments.peek(); @@ -145,7 +146,7 @@ public void addCommands( if (name == null) { // No default command found, send message and return null // If there is default command then return it - if (defaultCommand == null) { + if (defaultCommand == null && message) { messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(meta, "")); } @@ -161,7 +162,7 @@ public void addCommands( if (defaultCommand == null || !defaultCommand.hasArguments()) { // No command found with the name [name] - if (parentCommandWithArgument == null) { + if (parentCommandWithArgument == null && message) { messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new InvalidCommandContext(meta, name)); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 7df7bed6..dec31c0d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -124,7 +124,7 @@ public void execute( instance = createInstance(instanceSupplier); } - final Command command = findCommand(sender, arguments); + final Command command = findCommand(sender, arguments, true); if (command == null) return; // Simply execute the command with the given instance diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java index 392969f1..c440cdd3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java @@ -58,7 +58,7 @@ public void execute( // Test all requirements before continuing if (!getSettings().testRequirements(getMessageRegistry(), sender, getMeta(), getSenderExtension())) return; - final Command command = findCommand(sender, arguments); + final Command command = findCommand(sender, arguments, true); if (command == null) return; // Executing the command and catch all exceptions to rethrow with better message diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java index 54306133..40a5c63c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionKey.java @@ -28,7 +28,7 @@ import org.jetbrains.annotations.NotNull; /** - * Key used to identify the {@link } in the {@link }. + * Key used to identify the {@link SuggestionResolver} in the {@link SuggestionRegistry}. */ public final class SuggestionKey extends StringKey { diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java index 16e14ecf..d8a92422 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/PermissionRequirement.java @@ -32,7 +32,7 @@ import org.bukkit.command.CommandSender; import org.jetbrains.annotations.NotNull; -public final class PermissionRequirement implements Requirement { +final class PermissionRequirement implements Requirement { private final CommandPermission permission; From 5899484da3266abd7daf0df13fb5468fddc2c0ac Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 28 Jan 2023 19:58:12 -0600 Subject: [PATCH 075/101] chore: Hello JDA --- discord/jda-common/build.gradle.kts | 8 ++------ .../triumphteam/cmd/prefixed/PrefixedCommandManager.java | 3 --- gradle/libs.versions.toml | 2 +- .../dev/triumphteam/cmd/bukkit/annotation/Permission.java | 2 ++ settings.gradle.kts | 4 ++-- 5 files changed, 7 insertions(+), 12 deletions(-) diff --git a/discord/jda-common/build.gradle.kts b/discord/jda-common/build.gradle.kts index f57c6337..65eec94e 100644 --- a/discord/jda-common/build.gradle.kts +++ b/discord/jda-common/build.gradle.kts @@ -3,12 +3,8 @@ plugins { id("cmds.library-conventions") } -repositories { - maven("https://m2.dv8tion.net/releases") -} - dependencies { - api(project(":triumph-cmd-core")) + api(projects.triumphCmdCore) api(libs.guava) api(libs.jda) -} \ No newline at end of file +} diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java index 4615d51c..33f1bb0b 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java @@ -76,9 +76,6 @@ public final class PrefixedCommandManager extends CommandManager Date: Sat, 28 Jan 2023 20:03:46 -0600 Subject: [PATCH 076/101] feature: Re-implement senders for prefixed JDA --- .../extention/sender/SenderExtension.java | 4 +-- .../cmd/prefixed/PrefixedCommandManager.java | 2 +- .../cmd/prefixed/PrefixedCommandSender.java | 2 +- ...ator.java => PrefixedSenderExtension.java} | 34 ++++++++++--------- .../cmd/prefixed/sender/PrefixedSender.java | 2 +- .../cmd/bukkit/BukkitSenderExtension.java | 6 ++-- 6 files changed, 26 insertions(+), 24 deletions(-) rename discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/{PrefixedSenderValidator.java => PrefixedSenderExtension.java} (64%) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java index 60551d3e..bcff20d3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java @@ -54,11 +54,11 @@ interface Default extends SenderExtension { } } - static ValidationResult<@NotNull MessageKey<@NotNull MessageContext>> valid() { + default ValidationResult<@NotNull MessageKey<@NotNull MessageContext>> valid() { return new ValidationResult.Valid<>(); } - static ValidationResult<@NotNull MessageKey<@NotNull MessageContext>> invalid( + default ValidationResult<@NotNull MessageKey<@NotNull MessageContext>> invalid( final @NotNull MessageKey<@NotNull MessageContext> messageKey ) { return new ValidationResult.Invalid<>(messageKey); diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java index 33f1bb0b..88f7204d 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java @@ -141,7 +141,7 @@ private PrefixedCommandManager( jda, globalPrefix, SenderMapper.defaultMapper(), - new PrefixedSenderValidator() + new PrefixedSenderExtension() ); setUpDefaults(manager); return manager; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java index 6d28446d..86f991bd 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java @@ -28,8 +28,8 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderExtension.java similarity index 64% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java rename to discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderExtension.java index 0aa043e9..d74fae66 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderValidator.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderExtension.java @@ -24,9 +24,11 @@ package dev.triumphteam.cmd.prefixed; import com.google.common.collect.ImmutableSet; -import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; -import dev.triumphteam.cmd.core.extention.sender.SenderValidator; -import dev.triumphteam.cmd.core.subcommand.OldSubCommand; +import dev.triumphteam.cmd.core.extention.ValidationResult; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.core.message.MessageKey; +import dev.triumphteam.cmd.core.message.context.MessageContext; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; @@ -35,25 +37,25 @@ /** * Simple mapper than returns itself. */ -class PrefixedSenderValidator implements SenderValidator { +class PrefixedSenderExtension implements SenderExtension { - /** - * {@inheritDoc} - */ @Override public @NotNull Set> getAllowedSenders() { return ImmutableSet.of(PrefixedSender.class); } - /** - * {@inheritDoc} - */ @Override - public boolean validate( - final @NotNull MessageRegistry messageRegistry, - final @NotNull OldSubCommand subCommand, - final @NotNull PrefixedSender sender - ) { - return true; + public @NotNull ValidationResult<@NotNull MessageKey<@NotNull MessageContext>> validate(final @NotNull CommandMeta meta, final @NotNull Class allowedSender, final @NotNull PrefixedSender sender) { + return valid(); + } + + @Override + public @NotNull PrefixedSender map(final @NotNull PrefixedSender defaultSender) { + return defaultSender; + } + + @Override + public @NotNull PrefixedSender mapBackwards(final @NotNull PrefixedSender sender) { + return sender; } } diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java index 91f1fe04..f87d4f33 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java @@ -27,8 +27,8 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.TextChannel; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java index a23d28a2..80b0f242 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitSenderExtension.java @@ -54,13 +54,13 @@ class BukkitSenderExtension implements SenderExtension.Default { final @NotNull CommandSender sender ) { if (Player.class.isAssignableFrom(allowedSender) && !(sender instanceof Player)) { - return SenderExtension.invalid(BukkitMessageKey.PLAYER_ONLY); + return invalid(BukkitMessageKey.PLAYER_ONLY); } if (ConsoleCommandSender.class.isAssignableFrom(allowedSender) && !(sender instanceof ConsoleCommandSender)) { - return SenderExtension.invalid(BukkitMessageKey.CONSOLE_ONLY); + return invalid(BukkitMessageKey.CONSOLE_ONLY); } - return SenderExtension.valid(); + return valid(); } } From a2d543e6a108b2fb073692366b735d311295332c Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 28 Jan 2023 22:31:24 -0600 Subject: [PATCH 077/101] chore: Slight work on prefixed but will swap to slash as it's needed --- ...ecutor.java => PrefixedCommandHolder.java} | 32 +-- .../cmd/prefixed/PrefixedCommandListener.java | 2 +- .../cmd/prefixed/PrefixedCommandManager.java | 268 +++--------------- .../cmd/prefixed/PrefixedCommandOptions.java | 82 ++++++ .../prefixed/PrefixedCommandProcessor.java | 95 ------- .../prefixed/PrefixedSubCommandProcessor.java | 51 ---- settings.gradle.kts | 4 +- 7 files changed, 135 insertions(+), 399 deletions(-) rename discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/{PrefixedCommandExecutor.java => PrefixedCommandHolder.java} (74%) create mode 100644 discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandOptions.java delete mode 100644 discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java delete mode 100644 discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandHolder.java similarity index 74% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java rename to discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandHolder.java index 7f7a69fb..45c7f671 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandExecutor.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandHolder.java @@ -23,45 +23,21 @@ */ package dev.triumphteam.cmd.prefixed; +import dev.triumphteam.cmd.core.command.Command; import dev.triumphteam.cmd.core.execution.ExecutionProvider; import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.message.context.DefaultMessageContext; +import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.List; import java.util.Map; -/** - * Main executor for the commands. - * - * @param The sender type. - */ -final class PrefixedCommandExecutor { - - private final Map> commands = new HashMap<>(); +final class PrefixedCommandHolder { - private final MessageRegistry messageRegistry; - - private final ExecutionProvider syncExecutionProvider; - private final ExecutionProvider asyncExecutionProvider; - - public PrefixedCommandExecutor( - final @NotNull MessageRegistry messageRegistry, - final @NotNull ExecutionProvider syncExecutionProvider, - final @NotNull ExecutionProvider asyncExecutionProvider - ) { - this.messageRegistry = messageRegistry; - this.syncExecutionProvider = syncExecutionProvider; - this.asyncExecutionProvider = asyncExecutionProvider; - } - - /** - * Registers a command to the current executor. - * - * @param processor The processor with all the command data. - */ + private final Map> commands = new HashMap<>(); public void register(final @NotNull PrefixedCommandProcessor processor) { final String name = processor.getName(); diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java index b28fc95f..ad6ef39e 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java @@ -94,7 +94,7 @@ public void onMessageReceived(final @NotNull MessageReceivedEvent event) { final String commandName = firstArg.replace(prefix, ""); - PrefixedCommandExecutor commandExecutor = commandManager.getCommand(prefix); + PrefixedCommandHolder commandExecutor = commandManager.getCommand(prefix); if (commandExecutor == null) commandExecutor = commandManager.getCommand(guild, prefix); if (commandExecutor == null) { messageRegistry.sendMessage(MessageKey.UNKNOWN_COMMAND, sender, new DefaultMessageContext(commandName, "")); diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java index 88f7204d..f59c7849 100644 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java @@ -23,24 +23,18 @@ */ package dev.triumphteam.cmd.prefixed; -import com.google.common.primitives.Longs; import dev.triumphteam.cmd.core.BaseCommand; import dev.triumphteam.cmd.core.CommandManager; +import dev.triumphteam.cmd.core.command.RootCommand; import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; -import dev.triumphteam.cmd.core.execution.AsyncExecutionProvider; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.execution.SyncExecutionProvider; -import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import dev.triumphteam.cmd.core.extention.sender.SenderMapper; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.extention.sender.SenderValidator; +import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.VoiceChannel; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -50,7 +44,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.regex.Matcher; +import java.util.function.Consumer; import java.util.regex.Pattern; /** @@ -67,155 +61,78 @@ public final class PrefixedCommandManager extends CommandManager\\d+)>"); private static final Pattern USER_TAG_PATTERN = Pattern.compile(".{3,32}#\\d{4}"); - private final RegistryContainer registryContainer = new RegistryContainer<>(); + private final RegistryContainer registryContainer; private final Set prefixes = new HashSet<>(); private final Set prefixesRegexes = new HashSet<>(); - private final Map> globalCommands = new HashMap<>(); - private final Map>> guildCommands = new HashMap<>(); + + private final Map> globalCommands = new HashMap<>(); + private final Map>> guildCommands = new HashMap<>(); private final String globalPrefix; private PrefixedCommandManager( final @NotNull JDA jda, - final @NotNull String globalPrefix, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator + final @NotNull PrefixedCommandOptions commandOptions, + final @NotNull RegistryContainer registryContainer ) { - super(senderMapper, senderValidator); - this.globalPrefix = globalPrefix; + super(commandOptions); - jda.addEventListener(new PrefixedCommandListener<>(this, registryContainer, senderMapper)); + this.registryContainer = registryContainer; + this.globalPrefix = commandOptions.getGlobalPrefix(); } - /** - * Creates a new instance of the PrefixedCommandManager. - * This factory is for adding a custom sender, for default sender use {@link #create(JDA, String)}. - * - * @param jda The JDA instance. - * @param globalPrefix The global prefix. - * @param senderMapper The sender mapper. - * @param senderValidator The sender validator. - * @param The sender type. - * @return The new instance. - */ - @Contract("_, _, _, _ -> new") + @Contract("_, _, _, -> new") public static @NotNull PrefixedCommandManager create( final @NotNull JDA jda, - final @NotNull String globalPrefix, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator + final @NotNull SenderExtension senderExtension, + final @NotNull Consumer> builder ) { - return new PrefixedCommandManager<>(jda, globalPrefix, senderMapper, senderValidator); - } - - /** - * Creates a new instance of the {@link PrefixedCommandManager}. - * This factory is for adding a custom sender, for default sender use {@link #create(JDA)}. - * - * @param jda The JDA instance. - * @param senderMapper The sender mapper. - * @param senderValidator The sender validator. - * @param The sender type. - * @return The new instance. - */ - @Contract("_, _, _ -> new") - public static @NotNull PrefixedCommandManager create( - final @NotNull JDA jda, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator - ) { - return create(jda, "", senderMapper, senderValidator); - } - - /** - * Creates a new instance of the PrefixedCommandManager with its default sender. - * - * @param jda The JDA instance. - * @param globalPrefix The global prefix. - * @return The new instance. - */ - @Contract("_, _ -> new") - public static @NotNull PrefixedCommandManager create(final @NotNull JDA jda, final @NotNull String globalPrefix) { - final PrefixedCommandManager manager = create( - jda, - globalPrefix, - SenderMapper.defaultMapper(), - new PrefixedSenderExtension() - ); - setUpDefaults(manager); - return manager; + final RegistryContainer registryContainer = new RegistryContainer<>(); + final PrefixedCommandOptions.Builder extensionBuilder = new PrefixedCommandOptions.Builder<>(registryContainer); + builder.accept(extensionBuilder); + return new PrefixedCommandManager<>(jda, extensionBuilder.build(senderExtension), registryContainer); } - /** - * Creates a new instance of the PrefixedCommandManager with its default sender. - * - * @param jda The JDA instance. - * @return The new instance. - */ - @Contract("_, -> new") + @Contract("_ -> new") public static @NotNull PrefixedCommandManager create(final @NotNull JDA jda) { - return create(jda, ""); + return create(jda, new PrefixedSenderExtension(), builder -> {}); } - /** - * Registers a global command. - * - * @param baseCommand The {@link BaseCommand} to be registered. - */ + @Override - public void registerCommand(final @NotNull BaseCommand baseCommand) { - addCommand(null, baseCommand); + public void registerCommand(final @NotNull Object command) { + // TODO } - /** - * Registers a {@link Guild} command. - * - * @param guild the {@link Guild} to register the command to. - * @param baseCommand The {@link BaseCommand} to be registered. - */ - public void registerCommand(final @NotNull Guild guild, final @NotNull BaseCommand baseCommand) { - addCommand(guild, baseCommand); - } - - /** - * Registers a list of guild {@link BaseCommand}s. - * - * @param guild The {@link Guild} to register the commands for. - * @param baseCommands A list of baseCommands to be registered. - */ - public void registerCommand(final @NotNull Guild guild, final @NotNull BaseCommand @NotNull ... baseCommands) { - for (final BaseCommand command : baseCommands) { - registerCommand(guild, command); - } + public void registerCommand(final @NotNull Guild guild, final @NotNull Object command) { + // TODO } @Override - public void unregisterCommand(final @NotNull BaseCommand command) { - // TODO: 11/23/2021 Add unregistering commands and also guild commands + public void unregisterCommand(final @NotNull Object command) { + } @Override - protected @NotNull RegistryContainer getRegistryContainer() { + protected @NotNull RegistryContainer getRegistryContainer() { return registryContainer; } - /** - * Adds a command to the manager. - * - * @param guild The guild to add the command to or null if it's a global command. - * @param baseCommand The {@link BaseCommand} to be added. - */ - private void addCommand(final @Nullable Guild guild, final @NotNull BaseCommand baseCommand) { - final PrefixedCommandProcessor processor = new PrefixedCommandProcessor<>( - baseCommand, - registryContainer, - getSenderMapper(), - getSenderValidator(), - syncExecutionProvider, - asyncExecutionProvider + private void addCommand(final @Nullable Guild guild, final @NotNull Object command) { + final RootCommandProcessor processor = new RootCommandProcessor<>( + command, + getRegistryContainer(), + getCommandOptions() ); + final String name = processor.getName(); + + // Get or add command, then add its sub commands + final PrefixedCommandHolder holder = globalCommands.computeIfAbsent(name, it -> new RootCommand<>(processor)); + final RootCommand rootCommand = bukkitCommand.getRootCommand(); + rootCommand.addCommands(command, processor.commands(rootCommand)); + String prefix = processor.getPrefix(); if (prefix.isEmpty()) { if (globalPrefix.isEmpty()) { @@ -231,9 +148,9 @@ private void addCommand(final @Nullable Guild guild, final @NotNull BaseCommand // Global command if (guild == null) { - final PrefixedCommandExecutor commandExecutor = globalCommands.computeIfAbsent( + final PrefixedCommandHolder commandExecutor = globalCommands.computeIfAbsent( prefix, - ignored -> new PrefixedCommandExecutor<>(registryContainer.getMessageRegistry(), syncExecutionProvider, asyncExecutionProvider) + ignored -> new PrefixedCommandHolder<>(registryContainer.getMessageRegistry(), syncExecutionProvider, asyncExecutionProvider) ); for (final String alias : processor.getAlias()) { @@ -245,11 +162,11 @@ private void addCommand(final @Nullable Guild guild, final @NotNull BaseCommand } // Guild command - final PrefixedCommandExecutor commandExecutor = guildCommands + final PrefixedCommandHolder commandExecutor = guildCommands .computeIfAbsent(guild.getIdLong(), ignored -> new HashMap<>()) .computeIfAbsent( prefix, - ignored -> new PrefixedCommandExecutor<>( + ignored -> new PrefixedCommandHolder<>( registryContainer.getMessageRegistry(), syncExecutionProvider, asyncExecutionProvider @@ -263,97 +180,4 @@ private void addCommand(final @Nullable Guild guild, final @NotNull BaseCommand commandExecutor.register(processor); } - - /** - * Gets a guild command. - * - * @param guild The {@link Guild} to get the command from. - * @param prefix The prefix of the command. - * @return The {@link BaseCommand} or null if it doesn't exist. - */ - @Nullable PrefixedCommandExecutor getCommand(final @NotNull Guild guild, final @NotNull String prefix) { - final Map> commands = guildCommands.get(guild.getIdLong()); - return commands != null ? commands.get(prefix) : null; - } - - /** - * Gets a global command. - * - * @param prefix The prefix of the command. - * @return The {@link BaseCommand} or null if it doesn't exist. - */ - @Nullable PrefixedCommandExecutor getCommand(final @NotNull String prefix) { - return globalCommands.get(prefix); - } - - /** - * Gets a {@link Set} with all the registered prefixes. - * - * @return A {@link Set} with all the registered prefixes. - */ - @NotNull Set getPrefixes() { - return prefixes; - } - - /** - * Gets a {@link Set} with all registered prefixes regexes. - * - * @return A {@link Set} with all the registered prefixes regexes. - */ - @NotNull Set getPrefixesRegexes() { - return prefixesRegexes; - } - - private static void setUpDefaults(final @NotNull PrefixedCommandManager manager) { - manager.registerMessage(MessageKey.UNKNOWN_COMMAND, (sender, context) -> sender.getMessage().reply("Unknown command: `" + context.getCommand() + "`.").queue()); - manager.registerMessage(MessageKey.TOO_MANY_ARGUMENTS, (sender, context) -> sender.getMessage().reply("Invalid usage.").queue()); - manager.registerMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, (sender, context) -> sender.getMessage().reply("Invalid usage.").queue()); - manager.registerMessage(MessageKey.INVALID_ARGUMENT, (sender, context) -> sender.getMessage().reply("Invalid argument `" + context.getTypedArgument() + "` for type `" + context.getArgumentType().getSimpleName() + "`.").queue()); - - manager.registerArgument(User.class, (sender, arg) -> { - final JDA jda = sender.getJDA(); - final Long id = Longs.tryParse(arg); - if (id != null) return jda.getUserById(id); - - if (USER_TAG_PATTERN.matcher(arg).matches()) return jda.getUserByTag(arg); - - final Matcher userMentionMatcher = USER_MENTION_PATTERN.matcher(arg); - return userMentionMatcher.matches() ? jda.getUserById(userMentionMatcher.group("id")) : null; - }); - manager.registerArgument(Member.class, (sender, arg) -> { - final Guild guild = sender.getGuild(); - final Long id = Longs.tryParse(arg); - if (id != null) return guild.getMemberById(id); - - if (USER_TAG_PATTERN.matcher(arg).matches()) return guild.getMemberByTag(arg); - - final Matcher userMentionMatcher = USER_MENTION_PATTERN.matcher(arg); - return userMentionMatcher.matches() ? guild.getMemberById(userMentionMatcher.group("id")) : null; - }); - manager.registerArgument(TextChannel.class, (sender, arg) -> { - final Guild guild = sender.getGuild(); - final Long id = Longs.tryParse(arg); - if (id != null) return guild.getTextChannelById(id); - - final Matcher channelMentionMatcher = CHANNEL_MENTION_PATTERN.matcher(arg); - return channelMentionMatcher.matches() ? guild.getTextChannelById(channelMentionMatcher.group("id")) : null; - }); - manager.registerArgument(VoiceChannel.class, (sender, arg) -> { - final Guild guild = sender.getGuild(); - final Long id = Longs.tryParse(arg); - if (id != null) return guild.getVoiceChannelById(id); - - final Matcher channelMentionMatcher = CHANNEL_MENTION_PATTERN.matcher(arg); - return channelMentionMatcher.matches() ? guild.getVoiceChannelById(channelMentionMatcher.group("id")) : null; - }); - manager.registerArgument(Role.class, (sender, arg) -> { - final Guild guild = sender.getGuild(); - final Long id = Longs.tryParse(arg); - if (id != null) return guild.getRoleById(id); - - final Matcher roleMentionMatcher = ROLE_MENTION_PATTERN.matcher(arg); - return roleMentionMatcher.matches() ? guild.getRoleById(roleMentionMatcher.group("id")) : null; - }); - } - } diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandOptions.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandOptions.java new file mode 100644 index 00000000..f2f554f3 --- /dev/null +++ b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandOptions.java @@ -0,0 +1,82 @@ +/** + * MIT License + *

    + * Copyright (c) 2019-2021 Matt + *

    + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

    + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

    + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.prefixed; + +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.CommandOptions; +import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; +import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public final class PrefixedCommandOptions extends CommandOptions { + + private final String globalPrefix; + + public PrefixedCommandOptions( + final @NotNull SenderExtension senderExtension, + final @NotNull CommandExtensions commandExtensions, + final @Nullable String globalPrefix + ) { + super(senderExtension, commandExtensions); + this.globalPrefix = globalPrefix; + } + + public @Nullable String getGlobalPrefix() { + return globalPrefix; + } + + public static final class Setup extends CommandOptions.Setup> { + public Setup(final @NotNull RegistryContainer registryContainer) { + super(registryContainer); + } + } + + public static final class Builder extends CommandOptions.Builder, Setup, Builder> { + + private String globalPrefix = null; + + public Builder(final @NotNull RegistryContainer registryContainer) { + super(new Setup<>(registryContainer)); + + // Setters have to be done first thing, so they can be overriden. + extensions(extension -> { + extension.setArgumentValidator(new DefaultArgumentValidator<>()); + extension.setCommandExecutor(new DefaultCommandExecutor()); + }); + } + + public void setGlobalPrefix(final @NotNull String globalPrefix) { + this.globalPrefix = globalPrefix; + } + + @Override + public @NotNull PrefixedCommandOptions build(final @NotNull SenderExtension senderExtension) { + return new PrefixedCommandOptions<>(senderExtension, getCommandExtensions(), globalPrefix); + } + } +} diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java deleted file mode 100644 index e3db2b5b..00000000 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandProcessor.java +++ /dev/null @@ -1,95 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.prefixed; - -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.processor.OldAbstractCommandProcessor; -import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import dev.triumphteam.cmd.core.extention.sender.SenderMapper; -import dev.triumphteam.cmd.core.extention.sender.SenderValidator; -import dev.triumphteam.cmd.prefixed.sender.PrefixedSender; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.AnnotatedElement; - -/** - * Processor for Prefixed JDA platform specific code. - * - * @param The sender type. - */ -final class PrefixedCommandProcessor extends OldAbstractCommandProcessor, PrefixedSubCommandProcessor> { - - private final String prefix; - - public PrefixedCommandProcessor( - final @NotNull BaseCommand baseCommand, - final @NotNull RegistryContainer registryContainer, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator, - final @NotNull ExecutionProvider syncExecutionProvider, - final @NotNull ExecutionProvider asyncExecutionProvider - ) { - super(null, null, null, null, null, null, null); - prefix = extractPrefix(); - } - - /** - * Gets the prefix used by the command. - * The prefix can be any string, as long as it's not empty. - * - * @return The command's prefix. - */ - public @NotNull String getPrefix() { - return prefix; - } - - /** - * Extracts the prefix from the command class. - * - * @return The prefix from the annotation or an empty string. - */ - private @NotNull String extractPrefix() { - /*final Prefix prefixAnnotation = getBaseCommand().getClass().getAnnotation(Prefix.class); - return prefixAnnotation == null ? "" : prefixAnnotation.value();*/ - return ""; - } - - @Override - protected @NotNull PrefixedSubCommandProcessor createSubProcessor(final @NotNull AnnotatedElement method) { - return null; - /*return new PrefixedSubCommandProcessor<>( - getBaseCommand(), - getName(), - method, - getRegistryContainer(), - getSenderValidator() - );*/ - } - - @Override - protected @NotNull PrefixedSubCommand createSubCommand(final @NotNull PrefixedSubCommandProcessor processor, final @NotNull ExecutionProvider executionProvider) { - return new PrefixedSubCommand<>(processor, getName(), executionProvider); - } -} diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java b/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java deleted file mode 100644 index 40c3c1a4..00000000 --- a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommandProcessor.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.prefixed; - -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; -import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import dev.triumphteam.cmd.core.extention.sender.SenderValidator; -import org.jetbrains.annotations.NotNull; - -import java.lang.reflect.Method; - -/** - * Processor for Prefixed JDA platform specific code. - * - * @param The sender type. - */ -final class PrefixedSubCommandProcessor extends OldAbstractSubCommandProcessor { - - public PrefixedSubCommandProcessor( - final @NotNull BaseCommand baseCommand, - final @NotNull String parentName, - final @NotNull Method method, - final @NotNull RegistryContainer registryContainer, - final @NotNull SenderValidator senderValidator - ) { - super(baseCommand, parentName, method, registryContainer, senderValidator); - } - -} diff --git a/settings.gradle.kts b/settings.gradle.kts index d6c36b29..5edfc087 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,8 +15,8 @@ listOf( listOf( "minecraft/bukkit" to "bukkit", "discord/jda-common" to "jda-common", - "discord/jda-prefixed" to "jda-prefixed", - // "discord/jda-slash" to "jda-slash", + // "discord/jda-prefixed" to "jda-prefixed", + "discord/jda-slash" to "jda-slash", "kotlin/coroutines" to "kotlin-coroutines", "kotlin/extensions" to "kotlin-extensions" ).forEach { From c7cf0ac83c6e37b4a9bf0df5091b715de65bb5cc Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 29 Jan 2023 13:41:29 -0600 Subject: [PATCH 078/101] feature: JDA registration reimplemented WIP --- .../kotlin/cmds.base-conventions.gradle.kts | 1 + .../kotlin/cmds.logger-conventions.gradle.kts | 19 ++ .../triumphteam/cmd/core/command/Command.java | 13 +- .../cmd/core/command/ParentCommand.java | 8 + .../cmd/core/command/ParentSubCommand.java | 15 +- .../cmd/core/command/RootCommand.java | 7 + .../cmd/core/command/SubCommand.java | 15 + .../extention/sender/SenderExtension.java | 9 + .../cmd/slash/AttachmentArgument.java | 52 --- .../cmd/slash/AttachmentRegistry.java | 44 --- .../triumphteam/cmd/slash/SlashCommand.java | 176 ---------- .../cmd/slash/SlashCommandListener.java | 137 -------- .../cmd/slash/SlashCommandManager.java | 308 ------------------ .../cmd/slash/SlashCommandProcessor.java | 122 ------- .../cmd/slash/SlashSubCommand.java | 97 ------ .../cmd/slash/SlashSubCommandProcessor.java | 198 ----------- .../cmd/slash/util/JdaOptionUtil.java | 71 ---- .../common}/build.gradle.kts | 0 .../cmd/jda/annotation/Privileges.java | 0 .../triumphteam/cmd/jda/annotation/Roles.java | 0 .../prefixed}/build.gradle.kts | 0 .../cmd/prefixed/PrefixedCommand.java | 0 .../cmd/prefixed/PrefixedCommandHolder.java | 0 .../cmd/prefixed/PrefixedCommandListener.java | 0 .../cmd/prefixed/PrefixedCommandManager.java | 0 .../cmd/prefixed/PrefixedCommandOptions.java | 0 .../cmd/prefixed/PrefixedCommandSender.java | 0 .../cmd/prefixed/PrefixedSenderExtension.java | 0 .../cmd/prefixed/PrefixedSubCommand.java | 0 .../cmd/prefixed/annotation/Prefix.java | 0 .../cmd/prefixed/sender/PrefixedSender.java | 0 .../{jda-slash => jda/slash}/build.gradle.kts | 4 +- .../cmd/slash/SlashCommandManager.java | 177 ++++++++++ .../cmd/slash/SlashCommandOptions.java | 67 ++++ .../cmd/slash/SlashCommandSender.java | 4 +- .../cmd/slash/SlashRegistryContainer.java | 11 +- .../cmd/slash/SlashSenderExtension.java} | 20 +- .../cmd/slash/annotation/Choice.java | 0 .../cmd/slash/annotation/Choices.java | 0 .../triumphteam/cmd/slash/choices/Choice.java | 0 .../cmd/slash/choices/ChoiceKey.java | 4 +- .../cmd/slash/choices/ChoiceRegistry.java | 0 .../cmd/slash/choices/EmptyChoice.java | 0 .../cmd/slash/choices/EnumChoice.java | 0 .../cmd/slash/choices/SimpleChoice.java | 0 .../cmd/slash/sender/SlashSender.java | 4 +- .../cmd/slash/util/JdaMappingUtil.java | 151 +++++++++ examples/discord/jda/slash/build.gradle.kts | 8 + .../triumphteam/slash/example/Example.java | 19 ++ .../slash/example/ExampleCommand.java | 14 + .../slash/example/ExampleCommandGroup.java | 23 ++ .../slash/example/ExampleSubCommand.java | 19 ++ .../jda/slash/src/main/resources/log4j2.xml | 17 + examples/minecraft/bukkit/build.gradle.kts | 12 + gradle/libs.versions.toml | 8 + settings.gradle.kts | 18 +- 56 files changed, 623 insertions(+), 1249 deletions(-) create mode 100644 build-logic/src/main/kotlin/cmds.logger-conventions.gradle.kts delete mode 100644 discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java delete mode 100644 discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentRegistry.java delete mode 100644 discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java delete mode 100644 discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java delete mode 100644 discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java delete mode 100644 discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java delete mode 100644 discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java delete mode 100644 discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java delete mode 100644 discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaOptionUtil.java rename discord/{jda-common => jda/common}/build.gradle.kts (100%) rename discord/{jda-common => jda/common}/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java (100%) rename discord/{jda-common => jda/common}/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java (100%) rename discord/{jda-prefixed => jda/prefixed}/build.gradle.kts (100%) rename discord/{jda-prefixed => jda/prefixed}/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java (100%) rename discord/{jda-prefixed => jda/prefixed}/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandHolder.java (100%) rename discord/{jda-prefixed => jda/prefixed}/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java (100%) rename discord/{jda-prefixed => jda/prefixed}/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java (100%) rename discord/{jda-prefixed => jda/prefixed}/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandOptions.java (100%) rename discord/{jda-prefixed => jda/prefixed}/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java (100%) rename discord/{jda-prefixed => jda/prefixed}/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderExtension.java (100%) rename discord/{jda-prefixed => jda/prefixed}/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java (100%) rename discord/{jda-prefixed => jda/prefixed}/src/main/java/dev/triumphteam/cmd/prefixed/annotation/Prefix.java (100%) rename discord/{jda-prefixed => jda/prefixed}/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java (100%) rename discord/{jda-slash => jda/slash}/build.gradle.kts (67%) create mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java create mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java rename discord/{jda-slash => jda/slash}/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java (96%) rename discord/{jda-slash => jda/slash}/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java (85%) rename discord/{jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java => jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java} (70%) rename discord/{jda-slash => jda/slash}/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java (100%) rename discord/{jda-slash => jda/slash}/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java (100%) rename discord/{jda-slash => jda/slash}/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java (100%) rename discord/{jda-slash => jda/slash}/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java (95%) rename discord/{jda-slash => jda/slash}/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java (100%) rename discord/{jda-slash => jda/slash}/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java (100%) rename discord/{jda-slash => jda/slash}/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java (100%) rename discord/{jda-slash => jda/slash}/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java (100%) rename discord/{jda-slash => jda/slash}/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java (97%) create mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaMappingUtil.java create mode 100644 examples/discord/jda/slash/build.gradle.kts create mode 100644 examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java create mode 100644 examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommand.java create mode 100644 examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommandGroup.java create mode 100644 examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleSubCommand.java create mode 100644 examples/discord/jda/slash/src/main/resources/log4j2.xml create mode 100644 examples/minecraft/bukkit/build.gradle.kts diff --git a/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts b/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts index 79c99499..401856e9 100644 --- a/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts +++ b/build-logic/src/main/kotlin/cmds.base-conventions.gradle.kts @@ -81,6 +81,7 @@ spotless { tasks { withType { options.encoding = "UTF-8" + options.compilerArgs.add("-parameters") } withType { diff --git a/build-logic/src/main/kotlin/cmds.logger-conventions.gradle.kts b/build-logic/src/main/kotlin/cmds.logger-conventions.gradle.kts new file mode 100644 index 00000000..f329e6c5 --- /dev/null +++ b/build-logic/src/main/kotlin/cmds.logger-conventions.gradle.kts @@ -0,0 +1,19 @@ + +import org.gradle.accessors.dm.LibrariesForLibs + +// Hack which exposes `libs` to this convention plugin +val libs = the() + +plugins { + `java-library` +} + +repositories { + mavenCentral() +} + +dependencies { + implementation(libs.logger.api) + implementation(libs.logger.core) + implementation(libs.logger.impl) +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 52e8672f..1c185144 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -76,6 +76,11 @@ void execute( */ @NotNull String getName(); + /** + * @return The command's description. + */ + @NotNull String getDescription(); + /** * @return A list with all of its aliases. */ diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index db9a77b6..cf2a9d4b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -184,6 +184,14 @@ public boolean isDefault() { return false; } + public Command getDefaultCommand() { + return defaultCommand; + } + + public @NotNull Map> getCommands() { + return commands; + } + protected @Nullable Command getCommandByName(final @NotNull String key) { return commands.getOrDefault(key, commandAliases.get(key)); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index dec31c0d..f38e50c9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -54,6 +54,7 @@ public class ParentSubCommand extends ParentCommand { private final String name; private final List aliases; + private final String description; private final String syntax; private final Object invocationInstance; @@ -79,6 +80,7 @@ public ParentSubCommand( this.hasArgument = argument != null; this.name = processor.getName(); + this.description = processor.getDescription(); this.aliases = processor.getAliases(); this.syntax = createSyntax(parentCommand, processor); } @@ -203,6 +205,11 @@ public void execute( return name; } + @Override + public @NotNull String getDescription() { + return description; + } + @Override public @NotNull List getAliases() { return aliases; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java index c440cdd3..cbd50d58 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java @@ -38,12 +38,14 @@ public class RootCommand extends ParentCommand { private final String name; private final List aliases; + private final String description; private final String syntax; public RootCommand(final @NotNull RootCommandProcessor processor) { super(processor); this.name = processor.getName(); + this.description = processor.getDescription(); this.aliases = processor.getAliases(); this.syntax = "/" + name; } @@ -80,6 +82,11 @@ public void execute( return name; } + @Override + public @NotNull String getDescription() { + return description; + } + @Override public @NotNull List getAliases() { return aliases; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 99033a5d..2af8006d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -65,6 +65,7 @@ public class SubCommand implements Command { private final String name; private final List aliases; + private final String description; private final String syntax; private final boolean containsLimitless; @@ -87,6 +88,7 @@ public SubCommand( this.invocationInstance = invocationInstance; this.method = method; this.name = processor.getName(); + this.description = processor.getDescription(); this.aliases = processor.getAliases(); final Settings.Builder settingsBuilder = new Settings.Builder<>(); @@ -281,6 +283,11 @@ private boolean validateAndCollectArguments( return name; } + @Override + public @NotNull String getDescription() { + return description; + } + @Override public @NotNull List getAliases() { return aliases; @@ -291,6 +298,14 @@ private boolean validateAndCollectArguments( return syntax; } + public @NotNull List> getArgumentList() { + return argumentList; + } + + public @NotNull Map> getArgumentMap() { + return argumentMap; + } + @Override public boolean isDefault() { return name.equals(dev.triumphteam.cmd.core.annotations.Command.DEFAULT_CMD_NAME); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java index bcff20d3..1c8b175d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/sender/SenderExtension.java @@ -43,6 +43,15 @@ public interface SenderExtension extends SenderMapper { interface Default extends SenderExtension { + @Override + default @NotNull ValidationResult<@NotNull MessageKey<@NotNull MessageContext>> validate( + final @NotNull CommandMeta meta, + final @NotNull Class allowedSender, + final @NotNull S sender + ) { + return valid(); + } + @Override default @NotNull S map(final @NotNull S defaultSender) { return defaultSender; diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java deleted file mode 100644 index 67f72b54..00000000 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentArgument.java +++ /dev/null @@ -1,52 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.slash; - -import dev.triumphteam.cmd.core.argument.StringInternalArgument; -import dev.triumphteam.cmd.core.suggestion.Suggestion; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public class AttachmentArgument extends StringInternalArgument { - - private final AttachmentRegistry attachmentRegistry; - - public AttachmentArgument( - final @NotNull AttachmentRegistry attachmentRegistry, - final @NotNull String name, - final @NotNull String description, - final @NotNull Class type, - final @NotNull Suggestion suggestion, - final int position, - final boolean optional - ) { - super(name, description, type, suggestion, position, optional); - this.attachmentRegistry = attachmentRegistry; - } - - @Override - public @Nullable Object resolve(final @NotNull S sender, final @NotNull String value) { - return attachmentRegistry.getAttachment(value); - } -} diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentRegistry.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentRegistry.java deleted file mode 100644 index df6e96c8..00000000 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/AttachmentRegistry.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.slash; - -import com.google.common.collect.MapMaker; -import net.dv8tion.jda.api.entities.Message; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.Map; - -class AttachmentRegistry { - - private final Map attachments = new MapMaker().weakValues().makeMap(); - - public Message.@Nullable Attachment getAttachment(final @NotNull String id) { - return attachments.get(id); - } - - public void addAttachment(final @NotNull String id, final Message.@NotNull Attachment attachment) { - attachments.put(id, attachment); - } -} diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java deleted file mode 100644 index b5bede21..00000000 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommand.java +++ /dev/null @@ -1,176 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.slash; - -import dev.triumphteam.cmd.core.command.ParentCommand; -import dev.triumphteam.cmd.core.annotations.Default; -import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.registry.RegistryContainer; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.slash.choices.ChoiceRegistry; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions; -import net.dv8tion.jda.api.interactions.commands.build.Commands; -import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData; -import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; - -/** - * Main implementation of the command for prefixed JDA. - * - * @param The sender type. - */ -final class SlashCommand implements ParentCommand> { - - private final Map> subCommands = new HashMap<>(); - - private final String name; - private final String description; - - private final List allow; - - private final RegistryContainer registryContainer; - private final ChoiceRegistry choiceRegistry; - - private final SenderValidator senderValidator; - - private final ExecutionProvider syncExecutionProvider; - private final ExecutionProvider asyncExecutionProvider; - - private boolean isDefault = false; - - public SlashCommand( - final @NotNull SlashCommandProcessor processor, - final @NotNull List allow, - final @NotNull ExecutionProvider syncExecutionProvider, - final @NotNull ExecutionProvider asyncExecutionProvider - ) { - this.name = processor.getName(); - this.description = processor.getDescription(); - this.registryContainer = processor.getRegistryContainer(); - this.choiceRegistry = processor.getChoiceRegistry(); - this.senderValidator = processor.getSenderValidator(); - - this.allow = allow; - - this.syncExecutionProvider = syncExecutionProvider; - this.asyncExecutionProvider = asyncExecutionProvider; - } - - public @NotNull List getAllowed() { - return allow; - } - - - @Override - public void addSubCommand(final @NotNull String name, final @NotNull SlashSubCommand subCommand) { - if (name.equals(Default.DEFAULT_CMD_NAME)) { - if (!this.subCommands.isEmpty()) { - throw new CommandRegistrationException(String.format("Can not register default command for '%s' because it has subcommands", this.name)); - } - - this.subCommands.put(name, subCommand); - isDefault = true; - return; - } - - if (isDefault) { - throw new CommandRegistrationException(String.format("Can not register subcommand '%s' for command '%s' because it has a default command", name, this.name)); - } - - this.subCommands.putIfAbsent(name, subCommand); - } - - @Override - public void addSubCommandAlias(final @NotNull String alias, final @NotNull SlashSubCommand subCommand) { - // Doesn't support alias .. yet - } - - /** - * Executes the current command for the given sender. - * - * @param sender The sender. - * @param args The command arguments. - */ - public void execute( - final @NotNull S sender, - final @NotNull String subCommandName, - final @NotNull Map args - ) { - final SlashSubCommand subCommand = getSubCommand(subCommandName); - if (subCommand == null) return; - subCommand.execute(sender, subCommand.mapArguments(args)); - } - - public @NotNull SlashCommandData asCommandData() { - final SlashCommandData commandData = Commands.slash(name, description); - final DefaultMemberPermissions memberPermission = allow.isEmpty() ? DefaultMemberPermissions.ENABLED : DefaultMemberPermissions.enabledFor(allow); - - commandData.setDefaultPermissions(memberPermission); - - if (isDefault) { - final SlashSubCommand subCommand = getDefaultSubCommand(); - // Should never be null. - if (subCommand == null) throw new CommandRegistrationException("Could not find default subcommand"); - commandData.addOptions(subCommand.getJdaOptions()); - return commandData; - } - - final List subData = subCommands - .entrySet() - .stream() - .map(entry -> new SubcommandData(entry.getKey().toLowerCase(), entry.getValue().getDescription()).addOptions(entry.getValue().getJdaOptions())) - .collect(Collectors.toList()); - - commandData.addSubcommands(subData); - - return commandData; - } - - /** - * Gets the default sub command or null if there is none. - * - * @return The default sub command. - */ - private @Nullable SlashSubCommand getDefaultSubCommand() { - return subCommands.get(Default.DEFAULT_CMD_NAME); - } - - /** - * Gets the valid sub command for the given name or null if there is none. - * - * @param key The sub command name. - * @return A sub command or null. - */ - private @Nullable SlashSubCommand getSubCommand(final @NotNull String key) { - return subCommands.get(key); - } -} diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java deleted file mode 100644 index ac86f910..00000000 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandListener.java +++ /dev/null @@ -1,137 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.slash; - -import com.google.common.collect.Maps; -import dev.triumphteam.cmd.core.annotations.Command; -import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.slash.sender.SlashSender; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.events.ReadyEvent; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.hooks.ListenerAdapter; -import net.dv8tion.jda.api.interactions.commands.OptionType; -import org.jetbrains.annotations.NotNull; - -import java.util.Map; -import java.util.stream.Collectors; - -/** - * Listener for handling slash command registration and execution. - * - * @param The sender type. - */ -final class SlashCommandListener extends ListenerAdapter { - - private final SlashCommandManager commandManager; - private final SenderMapper senderMapper; - private final AttachmentRegistry attachmentRegistry; - - public SlashCommandListener( - final @NotNull SlashCommandManager commandManager, - final @NotNull SenderMapper senderMapper - ) { - this.commandManager = commandManager; - this.senderMapper = senderMapper; - this.attachmentRegistry = commandManager.getRegistryContainer().getAttachmentRegistry(); - } - - /** - * Handler for the slash commands. - * Needs to map the given result to the correct arguments to be used. - * - * @param event The slash command event. - * @throws CommandExecutionException If the sender mapper returns null. - */ - @Override - public void onSlashCommandInteraction(final @NotNull SlashCommandInteractionEvent event) { - final String name = event.getName(); - SlashCommand command = commandManager.getCommand(name); - if (command == null) { - final Guild guild = event.getGuild(); - if (guild == null) return; - command = commandManager.getCommand(guild, name); - } - if (command == null) return; - - final S sender = senderMapper.map(new SlashCommandSender(event)); - if (sender == null) { - throw new CommandExecutionException("Invalid sender. Sender mapper returned null"); - } - - final String subCommandName = event.getSubcommandName(); - - final Map args = event.getOptions() - .stream() - .map(it -> { - final OptionType type = it.getType(); - // Special case for attachments. - if (type == OptionType.ATTACHMENT) { - final Message.Attachment attachment = it.getAsAttachment(); - final String id = it.getAsString(); - - attachmentRegistry.addAttachment(id, attachment); - return Maps.immutableEntry(it.getName(), id); - } - - return Maps.immutableEntry(it.getName(), it.getAsString()); - }).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); - - command.execute(sender, subCommandName != null ? subCommandName : Command.DEFAULT_CMD_NAME, args); - } - - // private static final List ass = Arrays.asList("Hello", "There", "Ass", "Fuck", "Hoy"); - - /*@Override - public void onCommandAutoCompleteInteraction(final @NotNull CommandAutoCompleteInteractionEvent event) { - final String name = event.getName(); - SlashCommand command = commandManager.getCommand(name); - if (command == null) { - final Guild guild = event.getGuild(); - if (guild == null) return; - command = commandManager.getCommand(guild, name); - } - - if (command == null) return; - - // final S sender = senderMapper.map(new SlashCommandSender(event)); - event.replyChoiceStrings( - ass.stream() - .filter(it -> it.toLowerCase(Locale.ROOT).startsWith(event.getFocusedOption().getValue().toLowerCase(Locale.ROOT))) - .collect(Collectors.toList()) - ).queue(); - }*/ - - /** - * Updates all the commands on ready. - * - * @param event The ready event. - */ - @Override - public void onReady(final @NotNull ReadyEvent event) { - commandManager.updateAllCommands(); - } -} diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java deleted file mode 100644 index 3fedeec4..00000000 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java +++ /dev/null @@ -1,308 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.slash; - -import com.google.common.collect.Maps; -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.CommandManager; -import dev.triumphteam.cmd.core.execution.AsyncExecutionProvider; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.execution.SyncExecutionProvider; -import dev.triumphteam.cmd.core.message.MessageKey; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.slash.choices.ChoiceKey; -import dev.triumphteam.cmd.slash.sender.SlashSender; -import net.dv8tion.jda.api.JDA; -import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.Guild; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.entities.VoiceChannel; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.function.Supplier; -import java.util.stream.Collectors; - -/** - * Command Manager for Slash Commands. - * Allows for registering of global and guild specific commands. - * As well the implementation of custom command senders. - * - * @param The sender type. - */ -public final class SlashCommandManager extends CommandManager { - - private final JDA jda; - - private final SlashRegistryContainer registryContainer = new SlashRegistryContainer<>(); - - private final Map> globalCommands = new HashMap<>(); - private final Map>> guildCommands = new HashMap<>(); - - private final ExecutionProvider syncExecutionProvider = new SyncExecutionProvider(); - private final ExecutionProvider asyncExecutionProvider = new AsyncExecutionProvider(); - - public SlashCommandManager( - final @NotNull JDA jda, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator - ) { - super(senderMapper, senderValidator); - this.jda = jda; - - jda.addEventListener(new SlashCommandListener<>(this, senderMapper)); - } - - /** - * Creates a new instance of the {@link SlashCommandManager}. - * This factory is for adding a custom sender, for default sender use {@link #create(JDA)}. - * - * @param jda The JDA instance created. - * @param senderMapper The Mapper to get the custom sender from. - * @param senderValidator The validator to validate the sender. - * @param The type of the custom sender. - * @return A new instance of the {@link SlashCommandManager}. - */ - @Contract("_, _, _ -> new") - public static @NotNull SlashCommandManager create( - final @NotNull JDA jda, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator - ) { - return new SlashCommandManager<>(jda, senderMapper, senderValidator); - } - - /** - * Creates a new instance of the {@link SlashCommandManager}. - * This factory adds all the defaults based on the default sender {@link SlashSender}. - * - * @param jda The JDA instance created. - * @return A new instance of the {@link SlashCommandManager}. - */ - public static @NotNull SlashCommandManager create(final @NotNull JDA jda) { - final SlashCommandManager commandManager = create(jda, SenderMapper.defaultMapper(), new SlashSenderValidator()); - setUpDefaults(commandManager); - return commandManager; - } - - /** - * Registers a global command. - * - * @param baseCommand The {@link BaseCommand} to be registered. - */ - @Override - public void registerCommand(final @NotNull BaseCommand baseCommand) { - addCommand(null, baseCommand, Collections.emptyList()); - } - - /** - * Registers a {@link Guild} command. - * - * @param guild The {@link Guild} to register the command for. - * @param baseCommand The {@link BaseCommand} to be registered. - */ - public void registerCommand(final @NotNull Guild guild, final @NotNull BaseCommand baseCommand) { - addCommand(guild, baseCommand, Collections.emptyList()); - } - - /** - * Registers a global command for only specific permissions. - * - * @param baseCommand The {@link BaseCommand} to be registered. - * @param enabledPermissions The {@link Role}s that are allowed to use the command. - */ - public void registerCommand( - final @NotNull BaseCommand baseCommand, - final @NotNull List enabledPermissions) { - addCommand(null, baseCommand, enabledPermissions); - } - - /** - * Registers a {@link Guild} command for only specific permissions. - * - * @param guild The {@link Guild} to register the command for. - * @param baseCommand The {@link BaseCommand} to be registered. - * @param enabledPermissions The {@link Permission}s that are allowed to use the command. - */ - public void registerCommand( - final @NotNull Guild guild, - final @NotNull BaseCommand baseCommand, - final @NotNull List enabledPermissions) { - addCommand(guild, baseCommand, enabledPermissions); - } - - /** - * Registers a {@link Guild} command varargs. - * - * @param guild The {@link Guild} to register the command for. - * @param baseCommands The {@link BaseCommand}s to be registered. - */ - public void registerCommand(final @NotNull Guild guild, final @NotNull BaseCommand @NotNull ... baseCommands) { - for (final BaseCommand baseCommand : baseCommands) { - registerCommand(guild, baseCommand); - } - } - - public void registerChoices(final @NotNull ChoiceKey key, final @NotNull Supplier> choiceSupplier) { - registryContainer.getChoiceRegistry().register(key, choiceSupplier); - } - - @Override - public void unregisterCommand(final @NotNull BaseCommand command) { - // TODO: 12/7/2021 Implement some sort of unregistering - } - - /** - * Updates all the commands in one go. - * This should be used if the default trigger for the updating of the commands isn't working. - * Or if commands are added after the initial setup. - */ - public void updateAllCommands() { - jda.updateCommands().addCommands(globalCommands.values().stream().map(SlashCommand::asCommandData).collect(Collectors.toList())).queue(); - - guildCommands - .entrySet() - .stream() - .map(entry -> { - final Guild guild = jda.getGuildById(entry.getKey()); - return guild != null ? Maps.immutableEntry(guild, entry.getValue()) : null; - }) - .filter(Objects::nonNull) - .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)) - .forEach((guild, commands) -> guild.updateCommands() - .addCommands(commands.values().stream().map(SlashCommand::asCommandData).collect(Collectors.toList())).queue()); - } - - @Override - protected @NotNull SlashRegistryContainer getRegistryContainer() { - return registryContainer; - } - - /** - * Adds a command to the manager. - * - * @param guild The guild to add the command to or null if it's a global command. - * @param baseCommand The {@link BaseCommand} to be added. - */ - private void addCommand( - final @Nullable Guild guild, - final @NotNull BaseCommand baseCommand, - final @NotNull List enabledPermissions - ) { - final SlashCommandProcessor processor = new SlashCommandProcessor<>( - baseCommand, - registryContainer, - getSenderMapper(), - getSenderValidator(), - syncExecutionProvider, - asyncExecutionProvider - ); - - final String name = processor.getName(); - - final List finalEnabledPermissions = new ArrayList<>(enabledPermissions); - - finalEnabledPermissions.addAll(processor.getEnabledPermissions()); - - final SlashCommand command; - if (guild == null) { - // Global command - command = globalCommands.computeIfAbsent(name, ignored -> new SlashCommand<>(processor, enabledPermissions, syncExecutionProvider, asyncExecutionProvider)); - } else { - command = guildCommands - .computeIfAbsent(guild.getIdLong(), map -> new HashMap<>()) - .computeIfAbsent(name, ignored -> new SlashCommand<>(processor, finalEnabledPermissions, syncExecutionProvider, asyncExecutionProvider)); - } - - processor.addSubCommands(command); - } - - /** - * Gets the {@link SlashCommand} for the given name. - * - * @param name The name of the command. - * @return The {@link SlashCommand} or null if it doesn't exist. - */ - @Nullable SlashCommand getCommand(final @NotNull String name) { - return globalCommands.get(name); - } - - /** - * Gets the {@link SlashCommand} for the given name and guild. - * - * @param guild The guild to get the command from. - * @param name The name of the command. - * @return The {@link SlashCommand} or null if it doesn't exist. - */ - @Nullable SlashCommand getCommand(@NotNull Guild guild, final @NotNull String name) { - final Map> commands = guildCommands.get(guild.getIdLong()); - return commands != null ? commands.get(name) : null; - } - - /** - * Sets up all the default values for the default sender on the platform. - * - * @param manager The {@link CommandManager} to use. - */ - private static void setUpDefaults(final @NotNull SlashCommandManager manager) { - manager.registerMessage(MessageKey.UNKNOWN_COMMAND, (sender, context) -> sender.reply("Unknown command: `" + context.getCommand() + "`.").setEphemeral(true).queue()); - manager.registerMessage(MessageKey.TOO_MANY_ARGUMENTS, (sender, context) -> sender.reply("Invalid usage.").setEphemeral(true).queue()); - manager.registerMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, (sender, context) -> sender.reply("Invalid usage.").setEphemeral(true).queue()); - manager.registerMessage(MessageKey.INVALID_ARGUMENT, (sender, context) -> sender.reply("Invalid argument `" + context.getTypedArgument() + "` for type `" + context.getArgumentType().getSimpleName() + "`.").setEphemeral(true).queue()); - - manager.registerArgument(Member.class, (sender, arg) -> { - final Guild guild = sender.getGuild(); - if (guild == null) return null; - return guild.getMemberById(arg); - }); - manager.registerArgument(User.class, (sender, arg) -> sender.getEvent().getJDA().retrieveUserById(arg)); - manager.registerArgument(TextChannel.class, (sender, arg) -> { - final Guild guild = sender.getGuild(); - if (guild == null) return null; - return guild.getTextChannelById(arg); - }); - manager.registerArgument(VoiceChannel.class, (sender, arg) -> { - final Guild guild = sender.getGuild(); - if (guild == null) return null; - return guild.getVoiceChannelById(arg); - }); - manager.registerArgument(Role.class, (sender, arg) -> { - final Guild guild = sender.getGuild(); - if (guild == null) return null; - return guild.getRoleById(arg); - }); - } - -} diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java deleted file mode 100644 index ee67ccfa..00000000 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandProcessor.java +++ /dev/null @@ -1,122 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.slash; - -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.core.processor.OldAbstractCommandProcessor; -import dev.triumphteam.cmd.core.sender.SenderMapper; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.jda.annotation.Privileges; -import dev.triumphteam.cmd.jda.annotation.Roles; -import dev.triumphteam.cmd.slash.choices.ChoiceRegistry; -import dev.triumphteam.cmd.slash.sender.SlashSender; -import net.dv8tion.jda.api.Permission; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.AnnotatedElement; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -/** - * Processor for Slash JDA platform specific code. - * - * @param The sender type. - */ -final class SlashCommandProcessor - extends OldAbstractCommandProcessor, SlashSubCommandProcessor> { - - private final ChoiceRegistry choiceRegistry; - - private final List enabledPermissions = new ArrayList<>(); - - public SlashCommandProcessor( - final @NotNull BaseCommand baseCommand, - final @NotNull SlashRegistryContainer registryContainer, - final @NotNull SenderMapper senderMapper, - final @NotNull SenderValidator senderValidator, - final @NotNull ExecutionProvider syncExecutionProvider, - final @NotNull ExecutionProvider asyncExecutionProvider - ) { - super(baseCommand, registryContainer, senderMapper, senderValidator, syncExecutionProvider, asyncExecutionProvider); - this.choiceRegistry = registryContainer.getChoiceRegistry(); - - } - - /** - * Gets the permissions to which the command should be enabled to by default. - * - * @return The enabled permissions. - */ - public @NotNull List getEnabledPermissions() { - return enabledPermissions; - } - - /** - * Gets the choice registry. - * - * @return The choice registry. - */ - public @NotNull ChoiceRegistry getChoiceRegistry() { - return choiceRegistry; - } - - /** - * Gets the roles annotations from the class. - * - * @param klass The class to get from. - * @return List with all the roles annotations. - */ - private @NotNull List getRolesFromAnnotations(final @NotNull Class klass) { - final Privileges privileges = klass.getAnnotation(Privileges.class); - if (privileges != null) return Arrays.asList(privileges.value()); - - final Roles roles = klass.getAnnotation(Roles.class); - if (roles != null) return Collections.singletonList(roles); - return Collections.emptyList(); - } - - @Override - protected @NotNull SlashSubCommandProcessor createSubProcessor(final @NotNull AnnotatedElement method) { - return null; - /*return new SlashSubCommandProcessor<>( - getBaseCommand(), - getName(), - method, - (SlashRegistryContainer) getRegistryContainer(), - getSenderValidator() - );*/ - } - - @Override - protected @Nullable SlashSubCommand createSubCommand( - final @NotNull SlashSubCommandProcessor processor, - final @NotNull ExecutionProvider executionProvider - ) { - return new SlashSubCommand<>(processor, getName(), executionProvider); - } -} diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java deleted file mode 100644 index 5d7b0003..00000000 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommand.java +++ /dev/null @@ -1,97 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.slash; - -import dev.triumphteam.cmd.core.subcommand.OldSubCommand; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.execution.ExecutionProvider; -import dev.triumphteam.cmd.slash.choices.Choice; -import dev.triumphteam.cmd.slash.choices.EmptyChoice; -import dev.triumphteam.cmd.slash.util.JdaOptionUtil; -import net.dv8tion.jda.api.interactions.commands.Command; -import net.dv8tion.jda.api.interactions.commands.OptionType; -import net.dv8tion.jda.api.interactions.commands.build.OptionData; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -final class SlashSubCommand extends OldSubCommand { - - private final String description; - private final List choices; - - public SlashSubCommand( - final @NotNull SlashSubCommandProcessor processor, - final @NotNull String parentName, - final @NotNull ExecutionProvider executionProvider - ) { - super(processor, parentName, executionProvider); - this.description = processor.getDescription(); - this.choices = processor.getChoices(); - } - - public @NotNull String getDescription() { - return description; - } - - // TODO - @Override - public @Nullable Object resolve(final @NotNull S sender, final @NotNull List value) { - return null; - } - - public @NotNull List getJdaOptions() { - final List options = new ArrayList<>(); - final List> internalArguments = getArguments(); - - for (int i = 0; i < internalArguments.size(); i++) { - final InternalArgument internalArgument = internalArguments.get(i); - - final OptionType type = JdaOptionUtil.fromType(internalArgument.getType()); - final OptionData option = new OptionData( - type, - internalArgument.getName(), - internalArgument.getDescription(), - !internalArgument.isOptional() - ); - // option.setAutoComplete(type.canSupportChoices()); - options.add(option); - - final Choice suggestion = getChoice(i); - if (suggestion instanceof EmptyChoice) continue; - - option.addChoices(suggestion.getChoices().stream().map(it -> new Command.Choice(it, it)).limit(25).collect(Collectors.toList())); - } - - return options; - } - - private @NotNull Choice getChoice(final int index) { - if (index >= choices.size()) return EmptyChoice.INSTANCE; - return choices.get(index); - } -} diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java deleted file mode 100644 index 18f3a29c..00000000 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSubCommandProcessor.java +++ /dev/null @@ -1,198 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.slash; - -import dev.triumphteam.cmd.core.BaseCommand; -import dev.triumphteam.cmd.core.argument.InternalArgument; -import dev.triumphteam.cmd.core.exceptions.SubCommandRegistrationException; -import dev.triumphteam.cmd.core.processor.OldAbstractSubCommandProcessor; -import dev.triumphteam.cmd.core.sender.SenderValidator; -import dev.triumphteam.cmd.core.suggestion.Suggestion; -import dev.triumphteam.cmd.slash.annotation.Choices; -import dev.triumphteam.cmd.slash.choices.Choice; -import dev.triumphteam.cmd.slash.choices.ChoiceKey; -import dev.triumphteam.cmd.slash.choices.ChoiceRegistry; -import dev.triumphteam.cmd.slash.choices.EmptyChoice; -import dev.triumphteam.cmd.slash.choices.EnumChoice; -import dev.triumphteam.cmd.slash.choices.SimpleChoice; -import net.dv8tion.jda.api.entities.Message; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.lang.reflect.Method; -import java.lang.reflect.Parameter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.function.BiConsumer; -import java.util.function.Supplier; - -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; - -/** - * Processor for Slash JDA platform specific code. - * - * @param The sender type. - */ -final class SlashSubCommandProcessor extends OldAbstractSubCommandProcessor { - - private final ChoiceRegistry choiceRegistry; - private final AttachmentRegistry attachmentRegistry; - - private final List choices; - - public SlashSubCommandProcessor( - final @NotNull BaseCommand baseCommand, - final @NotNull String parentName, - final @NotNull Method method, - final @NotNull SlashRegistryContainer registryContainer, - final @NotNull SenderValidator senderValidator - ) { - super(baseCommand, parentName, method, registryContainer, senderValidator); - this.choiceRegistry = registryContainer.getChoiceRegistry(); - this.attachmentRegistry = registryContainer.getAttachmentRegistry(); - this.choices = extractChoices(method, baseCommand.getClass()); - } - - @Override - protected @NotNull List>> getArgValidations() { - return Collections.singletonList(validateLimitless()); - } - - public @NotNull List getChoices() { - return choices; - } - - @Override - protected @NotNull InternalArgument createSimpleArgument( - final @NotNull Class type, - final @NotNull String parameterName, - final @NotNull String argumentDescription, - final @NotNull Suggestion suggestion, - final int position, - final boolean optional - ) { - if (type == Message.Attachment.class) { - return new AttachmentArgument<>( - ((SlashRegistryContainer) getRegistryContainer()).getAttachmentRegistry(), - parameterName, - argumentDescription, - type, - suggestion, - position, - optional - ); - } - - return super.createSimpleArgument(type, parameterName, argumentDescription, suggestion, position, optional); - } - - public @NotNull List extractChoices( - final @NotNull Method method, - final @NotNull Class commandClass - ) { - final List choiceList = new ArrayList<>(); - - for (final dev.triumphteam.cmd.slash.annotation.Choice choice : getChoicesFromAnnotation(method)) { - final String key = choice.value(); - if (key.isEmpty()) { - choiceList.add(new EmptyChoice()); - continue; - } - - final Supplier> resolver = choiceRegistry.getChoiceResolver(ChoiceKey.of(key)); - - if (resolver == null) { - throw new SubCommandRegistrationException("Cannot find the suggestion key `" + key + "`", method, commandClass); - } - - choiceList.add(new SimpleChoice(resolver)); - } - - extractSuggestionFromParams(method, choiceList, commandClass); - return choiceList; - } - - private void extractSuggestionFromParams( - final @NotNull Method method, - final @NotNull List choiceList, - final @NotNull Class commandClass - ) { - final Parameter[] parameters = method.getParameters(); - for (int i = 1; i < parameters.length; i++) { - final Parameter parameter = parameters[i]; - final Class type = parameter.getType(); - - final dev.triumphteam.cmd.slash.annotation.Choice choice = parameter.getAnnotation(dev.triumphteam.cmd.slash.annotation.Choice.class); - final String choiceKey = choice == null ? "" : choice.value(); - - final int addIndex = i - 1; - if (choiceKey.isEmpty() || choiceKey.equals("enum")) { - if (Enum.class.isAssignableFrom(type)) { - //noinspection unchecked - setOrAdd(choiceList, addIndex, new EnumChoice((Class>) type)); - continue; - } - - setOrAdd(choiceList, addIndex, null); - continue; - } - - final Supplier> resolver = choiceRegistry.getChoiceResolver(ChoiceKey.of(choiceKey)); - if (resolver == null) { - throw new SubCommandRegistrationException("Cannot find the choice key `" + choiceKey + "`", method, commandClass); - } - setOrAdd(choiceList, addIndex, new SimpleChoice(resolver)); - } - } - - private void setOrAdd( - final @NotNull List choiceList, - final int index, - final @Nullable Choice choice - ) { - if (index >= choiceList.size()) { - if (choice == null) { - choiceList.add(new EmptyChoice()); - return; - } - choiceList.add(choice); - return; - } - - if (choice == null) return; - choiceList.set(index, choice); - } - - private List getChoicesFromAnnotation(final @NotNull Method method) { - final Choices requirements = method.getAnnotation(Choices.class); - if (requirements != null) return Arrays.asList(requirements.value()); - - final dev.triumphteam.cmd.slash.annotation.Choice suggestion = method.getAnnotation(dev.triumphteam.cmd.slash.annotation.Choice.class); - if (suggestion == null) return emptyList(); - return singletonList(suggestion); - } -} diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaOptionUtil.java b/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaOptionUtil.java deleted file mode 100644 index 653a1636..00000000 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaOptionUtil.java +++ /dev/null @@ -1,71 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.slash.util; - -import com.google.common.collect.ImmutableMap; -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageChannel; -import net.dv8tion.jda.api.entities.Role; -import net.dv8tion.jda.api.entities.TextChannel; -import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.interactions.commands.OptionType; -import org.jetbrains.annotations.NotNull; - -import java.util.HashMap; -import java.util.Map; - -public final class JdaOptionUtil { - - private static final Map, OptionType> OPTION_TYPE_MAP; - - static { - final Map, OptionType> map = new HashMap<>(); - map.put(Short.class, OptionType.INTEGER); - map.put(short.class, OptionType.INTEGER); - map.put(Integer.class, OptionType.INTEGER); - map.put(int.class, OptionType.INTEGER); - map.put(Long.class, OptionType.INTEGER); - map.put(long.class, OptionType.INTEGER); - map.put(Double.class, OptionType.NUMBER); - map.put(double.class, OptionType.NUMBER); - map.put(Boolean.class, OptionType.BOOLEAN); - map.put(boolean.class, OptionType.BOOLEAN); - map.put(Role.class, OptionType.ROLE); - map.put(User.class, OptionType.USER); - map.put(Member.class, OptionType.USER); - map.put(TextChannel.class, OptionType.CHANNEL); - map.put(MessageChannel.class, OptionType.CHANNEL); - map.put(Message.Attachment.class, OptionType.ATTACHMENT); - - OPTION_TYPE_MAP = ImmutableMap.copyOf(map); - } - - private JdaOptionUtil() {} - - public static @NotNull OptionType fromType(final @NotNull Class type) { - return OPTION_TYPE_MAP.getOrDefault(type, OptionType.STRING); - } - -} diff --git a/discord/jda-common/build.gradle.kts b/discord/jda/common/build.gradle.kts similarity index 100% rename from discord/jda-common/build.gradle.kts rename to discord/jda/common/build.gradle.kts diff --git a/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java b/discord/jda/common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java similarity index 100% rename from discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java rename to discord/jda/common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java diff --git a/discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java b/discord/jda/common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java similarity index 100% rename from discord/jda-common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java rename to discord/jda/common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java diff --git a/discord/jda-prefixed/build.gradle.kts b/discord/jda/prefixed/build.gradle.kts similarity index 100% rename from discord/jda-prefixed/build.gradle.kts rename to discord/jda/prefixed/build.gradle.kts diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java b/discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java similarity index 100% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java rename to discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommand.java diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandHolder.java b/discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandHolder.java similarity index 100% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandHolder.java rename to discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandHolder.java diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java b/discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java similarity index 100% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java rename to discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandListener.java diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java b/discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java similarity index 100% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java rename to discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandManager.java diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandOptions.java b/discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandOptions.java similarity index 100% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandOptions.java rename to discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandOptions.java diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java b/discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java similarity index 100% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java rename to discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedCommandSender.java diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderExtension.java b/discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderExtension.java similarity index 100% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderExtension.java rename to discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSenderExtension.java diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java b/discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java similarity index 100% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java rename to discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/PrefixedSubCommand.java diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/annotation/Prefix.java b/discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/annotation/Prefix.java similarity index 100% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/annotation/Prefix.java rename to discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/annotation/Prefix.java diff --git a/discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java b/discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java similarity index 100% rename from discord/jda-prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java rename to discord/jda/prefixed/src/main/java/dev/triumphteam/cmd/prefixed/sender/PrefixedSender.java diff --git a/discord/jda-slash/build.gradle.kts b/discord/jda/slash/build.gradle.kts similarity index 67% rename from discord/jda-slash/build.gradle.kts rename to discord/jda/slash/build.gradle.kts index 3432ce02..2c16e3d2 100644 --- a/discord/jda-slash/build.gradle.kts +++ b/discord/jda/slash/build.gradle.kts @@ -4,5 +4,5 @@ plugins { } dependencies { - api(project(":triumph-cmd-jda-common")) -} \ No newline at end of file + api(projects.triumphCmdJdaCommon) +} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java new file mode 100644 index 00000000..507df379 --- /dev/null +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java @@ -0,0 +1,177 @@ +/** + * MIT License + *

    + * Copyright (c) 2019-2021 Matt + *

    + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

    + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

    + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.slash; + +import dev.triumphteam.cmd.core.CommandManager; +import dev.triumphteam.cmd.core.command.RootCommand; +import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.core.processor.RootCommandProcessor; +import dev.triumphteam.cmd.slash.choices.ChoiceKey; +import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.slash.util.JdaMappingUtil; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import org.jetbrains.annotations.Contract; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Consumer; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +/** + * Command Manager for Slash Commands. + * Allows for registering of global and guild specific commands. + * As well the implementation of custom command senders. + * + * @param The sender type. + */ +public final class SlashCommandManager extends CommandManager { + + private final JDA jda; + + private final SlashRegistryContainer registryContainer; + + private final Map> globalCommands = new HashMap<>(); + private final Map>> guildCommands = new HashMap<>(); + + public SlashCommandManager( + final @NotNull JDA jda, + final @NotNull SlashCommandOptions commandOptions, + final @NotNull SlashRegistryContainer registryContainer + ) { + super(commandOptions); + this.jda = jda; + this.registryContainer = registryContainer; + + registerArgument(User.class, (sender, arg) -> ""); + // jda.addEventListener(new SlashCommandListener<>(this, senderMapper)); + } + + @Contract("_, _, _ -> new") + public static @NotNull SlashCommandManager create( + final @NotNull JDA jda, + final @NotNull SenderExtension senderExtension, + final @NotNull Consumer> builder + ) { + final SlashRegistryContainer registryContainer = new SlashRegistryContainer<>(); + final SlashCommandOptions.Builder extensionBuilder = new SlashCommandOptions.Builder<>(registryContainer); + builder.accept(extensionBuilder); + return new SlashCommandManager<>(jda, extensionBuilder.build(senderExtension), registryContainer); + } + + @Contract("_, _ -> new") + public static @NotNull SlashCommandManager create( + final @NotNull JDA jda, + final @NotNull Consumer> builder + ) { + final SlashRegistryContainer registryContainer = new SlashRegistryContainer<>(); + final SlashCommandOptions.Builder extensionBuilder = new SlashCommandOptions.Builder<>(registryContainer); + + // Setup defaults for Bukkit + final MessageRegistry messageRegistry = registryContainer.getMessageRegistry(); + // setUpDefaults(messageRegistry); + + // Then accept configured values + builder.accept(extensionBuilder); + return new SlashCommandManager<>(jda, extensionBuilder.build(new SlashSenderExtension()), registryContainer); + } + + @Contract("_ -> new") + public static @NotNull SlashCommandManager create(final @NotNull JDA jda) { + return create(jda, builder -> {}); + } + + public void registerChoices(final @NotNull ChoiceKey key, final @NotNull Supplier> choiceSupplier) { + registryContainer.getChoiceRegistry().register(key, choiceSupplier); + } + + public void execute(final @NotNull SlashCommandInteractionEvent event) { + final Guild guild = event.getGuild(); + if (guild == null) return; + + final String name = event.getName(); + final RootCommand command = guildCommands + .getOrDefault(guild.getIdLong(), Collections.emptyMap()) + .get(name); + + final SenderExtension senderExtension = getCommandOptions().getSenderExtension(); + final S sender = senderExtension.map(new SlashCommandSender(event)); + + + // TODO continue + } + + @Override + public void registerCommand(final @NotNull Object command) { + + } + + public void registerCommand(final Guild guild, final @NotNull Object command) { + registerCommand(guild.getIdLong(), command); + } + + public void registerCommand(final Long guildId, final @NotNull Object command) { + final RootCommandProcessor processor = new RootCommandProcessor<>( + command, + getRegistryContainer(), + getCommandOptions() + ); + + final String name = processor.getName(); + + // Get or add command, then add its sub commands + final RootCommand rootCommand = guildCommands + .computeIfAbsent(guildId, it -> new HashMap<>()) + .computeIfAbsent(name, it -> new RootCommand<>(processor)); + + rootCommand.addCommands(command, processor.commands(rootCommand)); + } + + public void pushCommands() { + guildCommands.forEach((key, value) -> { + final Guild guild = jda.getGuildById(key); + if (guild == null) return; + guild.updateCommands() + .addCommands(value.values().stream().map(JdaMappingUtil::mapCommand).collect(Collectors.toList())) + .queue(); + }); + } + + @Override + public void unregisterCommand(final @NotNull Object command) { + + } + + @Override + protected @NotNull SlashRegistryContainer getRegistryContainer() { + return registryContainer; + } +} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java new file mode 100644 index 00000000..2fab36d1 --- /dev/null +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java @@ -0,0 +1,67 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.slash; + +import dev.triumphteam.cmd.core.extention.CommandExtensions; +import dev.triumphteam.cmd.core.extention.CommandOptions; +import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; +import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.slash.sender.SlashSender; +import org.jetbrains.annotations.NotNull; + +public final class SlashCommandOptions extends CommandOptions { + + public SlashCommandOptions( + final @NotNull SenderExtension senderExtension, + final @NotNull CommandExtensions commandExtensions + ) { + super(senderExtension, commandExtensions); + } + + public static final class Setup extends CommandOptions.Setup> { + public Setup(final @NotNull RegistryContainer registryContainer) { + super(registryContainer); + } + } + + public static final class Builder extends CommandOptions.Builder, Setup, Builder> { + + public Builder(final @NotNull RegistryContainer registryContainer) { + super(new Setup<>(registryContainer)); + + // Setters have to be done first thing, so they can be overriden. + extensions(extension -> { + extension.setArgumentValidator(new DefaultArgumentValidator<>()); + extension.setCommandExecutor(new DefaultCommandExecutor()); + }); + } + + @Override + public @NotNull SlashCommandOptions build(final @NotNull SenderExtension senderExtension) { + return new SlashCommandOptions<>(senderExtension, getCommandExtensions()); + } + } +} diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java similarity index 96% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java index a503c3e5..17a0160c 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java @@ -26,9 +26,9 @@ import dev.triumphteam.cmd.slash.sender.SlashSender; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; @@ -66,7 +66,7 @@ public SlashCommandSender(final @NotNull SlashCommandInteractionEvent event) { * {@inheritDoc} */ @Override - public @NotNull MessageChannel getChannel() { + public @NotNull MessageChannelUnion getChannel() { return event.getChannel(); } diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java similarity index 85% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java index 24dbfd43..a5f47419 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java @@ -23,21 +23,16 @@ */ package dev.triumphteam.cmd.slash; -import dev.triumphteam.cmd.core.registry.RegistryContainer; +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.slash.choices.ChoiceRegistry; +import dev.triumphteam.cmd.slash.sender.SlashSender; import org.jetbrains.annotations.NotNull; // TODO: Comments -final class SlashRegistryContainer extends RegistryContainer { +final class SlashRegistryContainer extends RegistryContainer { private final ChoiceRegistry choiceRegistry = new ChoiceRegistry(); - private final AttachmentRegistry attachmentRegistry = new AttachmentRegistry(); - public @NotNull ChoiceRegistry getChoiceRegistry() { return choiceRegistry; } - - public @NotNull AttachmentRegistry getAttachmentRegistry() { - return attachmentRegistry; - } } diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java similarity index 70% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java index 13ea0fdb..1fda2107 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderValidator.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java @@ -24,9 +24,7 @@ package dev.triumphteam.cmd.slash; import com.google.common.collect.ImmutableSet; -import dev.triumphteam.cmd.core.subcommand.OldSubCommand; -import dev.triumphteam.cmd.core.message.MessageRegistry; -import dev.triumphteam.cmd.core.sender.SenderValidator; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.slash.sender.SlashSender; import org.jetbrains.annotations.NotNull; @@ -35,22 +33,10 @@ /** * Simple validator that always returns true. */ -final class SlashSenderValidator implements SenderValidator { +final class SlashSenderExtension implements SenderExtension.Default { - /** - * {@inheritDoc} - */ @Override - public @NotNull Set> getAllowedSenders() { + public @NotNull Set> getAllowedSenders() { return ImmutableSet.of(SlashSender.class); } - - @Override - public boolean validate( - final @NotNull MessageRegistry messageRegistry, - final @NotNull OldSubCommand subCommand, - final @NotNull SlashSender sender - ) { - return true; - } } diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java similarity index 100% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java similarity index 100% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java similarity index 100% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java similarity index 95% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java index 6a586d02..fafddc5a 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.slash.choices; -import dev.triumphteam.cmd.core.registry.RegistryKey; +import dev.triumphteam.cmd.core.extention.StringKey; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -34,7 +34,7 @@ /** * Key used to identify the {@link } in the {@link }. */ -public final class ChoiceKey extends RegistryKey { +public final class ChoiceKey extends StringKey { // Holds all registered keys, default and custom ones private static final Set REGISTERED_KEYS = new HashSet<>(); diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java similarity index 100% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java similarity index 100% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java similarity index 100% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java similarity index 100% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java diff --git a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java similarity index 97% rename from discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java index d07c3fb8..7d62509d 100644 --- a/discord/jda-slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java @@ -25,9 +25,9 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.MessageChannel; import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; @@ -62,7 +62,7 @@ public interface SlashSender { * * @return The channel. */ - @NotNull MessageChannel getChannel(); + @NotNull MessageChannelUnion getChannel(); /** * Gets the user that sent the command. diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaMappingUtil.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaMappingUtil.java new file mode 100644 index 00000000..8f51c44e --- /dev/null +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaMappingUtil.java @@ -0,0 +1,151 @@ +/** + * MIT License + *

    + * Copyright (c) 2019-2021 Matt + *

    + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

    + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

    + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.slash.util; + +import com.google.common.collect.ImmutableMap; +import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.command.Command; +import dev.triumphteam.cmd.core.command.ParentSubCommand; +import dev.triumphteam.cmd.core.command.RootCommand; +import dev.triumphteam.cmd.core.command.SubCommand; +import dev.triumphteam.cmd.slash.sender.SlashSender; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.Role; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.build.Commands; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.api.interactions.commands.build.SlashCommandData; +import net.dv8tion.jda.api.interactions.commands.build.SubcommandData; +import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +public final class JdaMappingUtil { + + private static final Map, OptionType> OPTION_TYPE_MAP; + + static { + final Map, OptionType> map = new HashMap<>(); + map.put(Short.class, OptionType.INTEGER); + map.put(short.class, OptionType.INTEGER); + map.put(Integer.class, OptionType.INTEGER); + map.put(int.class, OptionType.INTEGER); + map.put(Long.class, OptionType.INTEGER); + map.put(long.class, OptionType.INTEGER); + map.put(Double.class, OptionType.NUMBER); + map.put(double.class, OptionType.NUMBER); + map.put(Boolean.class, OptionType.BOOLEAN); + map.put(boolean.class, OptionType.BOOLEAN); + map.put(Role.class, OptionType.ROLE); + map.put(User.class, OptionType.USER); + map.put(Member.class, OptionType.USER); + map.put(TextChannel.class, OptionType.CHANNEL); + map.put(MessageChannel.class, OptionType.CHANNEL); + map.put(Message.Attachment.class, OptionType.ATTACHMENT); + + OPTION_TYPE_MAP = ImmutableMap.copyOf(map); + } + + private JdaMappingUtil() {} + + public static @NotNull OptionType fromType(final @NotNull Class type) { + return OPTION_TYPE_MAP.getOrDefault(type, OptionType.STRING); + } + + public static @NotNull SlashCommandData mapCommand(final @NotNull RootCommand rootCommand) { + final String name = rootCommand.getName(); + final String description = rootCommand.getDescription(); + + final SlashCommandData commandData = Commands.slash(name, description.isEmpty() ? name : description); + + final Command defaultCommand = rootCommand.getDefaultCommand(); + if (defaultCommand != null) { + // Safe to cast because only subcommands can be default + final SubCommand subCommand = (SubCommand) defaultCommand; + return commandData.addOptions( + subCommand.getArgumentList().stream().map(JdaMappingUtil::mapOption).collect(Collectors.toList()) + ); + } + + final Collection> commands = rootCommand.getCommands().values(); + + commandData.addSubcommands( + commands.stream().map(it -> { + if (!(it instanceof SubCommand)) return null; + return mapSubCommand((SubCommand) it); + }).filter(Objects::nonNull).collect(Collectors.toList()) + ); + + commandData.addSubcommandGroups( + commands.stream().map(it -> { + if (!(it instanceof ParentSubCommand)) return null; + return mapSubCommandGroup((ParentSubCommand) it); + }).filter(Objects::nonNull).collect(Collectors.toList()) + ); + + return commandData; + } + + public static @NotNull SubcommandData mapSubCommand(final @NotNull SubCommand subCommand) { + final String name = subCommand.getName(); + final String description = subCommand.getDescription(); + + return new SubcommandData(name, description.isEmpty() ? name : description) + .addOptions(subCommand.getArgumentList().stream().map(JdaMappingUtil::mapOption).collect(Collectors.toList())); + } + + public static @NotNull SubcommandGroupData mapSubCommandGroup(final @NotNull ParentSubCommand parentCommand) { + final String name = parentCommand.getName(); + final String description = parentCommand.getDescription(); + + return new SubcommandGroupData(name, description.isEmpty() ? name : description) + .addSubcommands( + parentCommand.getCommands().values().stream().map(it -> { + if (!(it instanceof SubCommand)) return null; + return mapSubCommand((SubCommand) it); + }).filter(Objects::nonNull).collect(Collectors.toList()) + ); + } + + public static @NotNull OptionData mapOption(final @NotNull InternalArgument argument) { + final String name = argument.getName(); + final String description = argument.getDescription(); + + return new OptionData( + fromType(argument.getType()), + name, + description.isEmpty() ? name : description, + !argument.isOptional() + ); + } +} diff --git a/examples/discord/jda/slash/build.gradle.kts b/examples/discord/jda/slash/build.gradle.kts new file mode 100644 index 00000000..99e3be37 --- /dev/null +++ b/examples/discord/jda/slash/build.gradle.kts @@ -0,0 +1,8 @@ +plugins { + id("cmds.base-conventions") + id("cmds.logger-conventions") +} + +dependencies { + api(projects.triumphCmdJdaSlash) +} diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java new file mode 100644 index 00000000..a99e2388 --- /dev/null +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java @@ -0,0 +1,19 @@ +package dev.triumphteam.slash.example; + +import dev.triumphteam.cmd.slash.SlashCommandManager; +import dev.triumphteam.cmd.slash.sender.SlashSender; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.JDABuilder; + +public class Example { + + public static void main(String[] args) throws InterruptedException { + final JDA jda = JDABuilder.createDefault(args[0]).build().awaitReady(); + + final SlashCommandManager commandManager = SlashCommandManager.create(jda); + commandManager.registerCommand(820696172477677628L, new ExampleCommand()); + commandManager.registerCommand(820696172477677628L, new ExampleCommandGroup()); + commandManager.registerCommand(820696172477677628L, new ExampleSubCommand()); + commandManager.pushCommands(); + } +} diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommand.java new file mode 100644 index 00000000..7b4b374d --- /dev/null +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommand.java @@ -0,0 +1,14 @@ +package dev.triumphteam.slash.example; + +import dev.triumphteam.cmd.core.annotations.Command; +import dev.triumphteam.cmd.slash.sender.SlashSender; +import net.dv8tion.jda.api.entities.User; + +@Command("example") +public class ExampleCommand { + + @Command + public void execute(final SlashSender sender, final String name, final User user) { + + } +} diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommandGroup.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommandGroup.java new file mode 100644 index 00000000..a43902cf --- /dev/null +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommandGroup.java @@ -0,0 +1,23 @@ +package dev.triumphteam.slash.example; + +import dev.triumphteam.cmd.core.annotations.Command; +import dev.triumphteam.cmd.slash.sender.SlashSender; +import net.dv8tion.jda.api.entities.User; + +@Command("group") +public class ExampleCommandGroup { + + @Command("test") + public class Group { + + @Command("first") + public void first(final SlashSender sender) { + + } + + @Command("second") + public void second(final SlashSender sender, final User user) { + + } + } +} diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleSubCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleSubCommand.java new file mode 100644 index 00000000..bd3d5f1b --- /dev/null +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleSubCommand.java @@ -0,0 +1,19 @@ +package dev.triumphteam.slash.example; + +import dev.triumphteam.cmd.core.annotations.Command; +import dev.triumphteam.cmd.slash.sender.SlashSender; +import net.dv8tion.jda.api.entities.User; + +@Command("sub") +public class ExampleSubCommand { + + @Command("first") + public void first(final SlashSender sender) { + + } + + @Command("second") + public void second(final SlashSender sender, final User user) { + + } +} diff --git a/examples/discord/jda/slash/src/main/resources/log4j2.xml b/examples/discord/jda/slash/src/main/resources/log4j2.xml new file mode 100644 index 00000000..f6ff3dfb --- /dev/null +++ b/examples/discord/jda/slash/src/main/resources/log4j2.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/examples/minecraft/bukkit/build.gradle.kts b/examples/minecraft/bukkit/build.gradle.kts new file mode 100644 index 00000000..6ca4b2f5 --- /dev/null +++ b/examples/minecraft/bukkit/build.gradle.kts @@ -0,0 +1,12 @@ +plugins { + id("cmds.base-conventions") +} + +repositories { + maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") +} + +dependencies { + api(projects.triumphCmdBukkit) + compileOnly(libs.spigot) +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 5ee0cfe5..d2fa5a74 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -24,6 +24,9 @@ spotless = "6.12.0" # For now only using for checkstyle indra = "3.0.1" +# Logging +log4j = "2.19.0" + [libraries] # Core guava = { module = "com.google.guava:guava", version.ref = "guava" } @@ -43,6 +46,11 @@ jda = { module = "net.dv8tion:JDA", version.ref = "jda" } # Kotlin coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" } +# Logger +logger-api = { module = "org.apache.logging.log4j:log4j-api", version.ref = "log4j" } +logger-core = { module = "org.apache.logging.log4j:log4j-core", version.ref = "log4j" } +logger-impl = { module = "org.apache.logging.log4j:log4j-slf4j-impl", version.ref = "log4j" } + # build build-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } build-license = { module = "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin", version.ref = "license" } diff --git a/settings.gradle.kts b/settings.gradle.kts index 5edfc087..cbf8f2a2 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -14,11 +14,23 @@ listOf( listOf( "minecraft/bukkit" to "bukkit", - "discord/jda-common" to "jda-common", + + "discord/jda/common" to "jda-common", // "discord/jda-prefixed" to "jda-prefixed", - "discord/jda-slash" to "jda-slash", + "discord/jda/slash" to "jda-slash", + "kotlin/coroutines" to "kotlin-coroutines", - "kotlin/extensions" to "kotlin-extensions" + "kotlin/extensions" to "kotlin-extensions", +).forEach { + includeProjectFolders(it.first, it.second) +} + +// Examples +listOf( + "examples/minecraft/bukkit" to "bukkit-examples", + + // "discord/jda-prefixed" to "jda-prefixed", + "examples/discord/jda/slash" to "jda-slash-examples", ).forEach { includeProjectFolders(it.first, it.second) } From 513391132f284d0d0fc388ff971490d23cd4ad0d Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 29 Jan 2023 18:35:23 -0600 Subject: [PATCH 079/101] feature: We got JDA execution baby --- .../triumphteam/cmd/core/CommandManager.java | 5 + .../argument/AbstractInternalArgument.java | 6 + .../argument/CollectionInternalArgument.java | 3 +- .../core/argument/EnumInternalArgument.java | 4 +- .../cmd/core/argument/InternalArgument.java | 43 ++++- .../JoinedStringInternalArgument.java | 3 +- .../argument/ResolverInternalArgument.java | 5 +- .../argument/SplitStringInternalArgument.java | 3 +- .../argument/UnknownInternalArgument.java | 6 +- .../argument/keyed/KeyedInternalArgument.java | 3 +- .../triumphteam/cmd/core/command/Command.java | 13 +- .../cmd/core/command/ParentCommand.java | 4 + .../cmd/core/command/ParentSubCommand.java | 33 +++- .../cmd/core/command/RootCommand.java | 43 ++++- .../cmd/core/command/SubCommand.java | 165 +++++++++++++----- .../extention/registry/ArgumentRegistry.java | 23 +-- .../processor/AbstractCommandProcessor.java | 5 + .../cmd/slash/{util => }/JdaMappingUtil.java | 94 +++++++--- .../cmd/slash/ProvidedInternalArgument.java | 36 ++++ .../cmd/slash/SlashCommandManager.java | 40 ++++- .../triumphteam/slash/example/Example.java | 10 ++ .../triumphteam/slash/example/Listener.java | 21 +++ .../{ => commands}/ExampleCommand.java | 4 +- .../{ => commands}/ExampleCommandGroup.java | 6 +- .../{ => commands}/ExampleSubCommand.java | 6 +- .../jda/slash/src/main/resources/log4j2.xml | 4 - gradle.properties | 2 +- 27 files changed, 462 insertions(+), 128 deletions(-) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/{util => }/JdaMappingUtil.java (76%) create mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java create mode 100644 examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java rename examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/{ => commands}/ExampleCommand.java (68%) rename examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/{ => commands}/ExampleCommandGroup.java (71%) rename examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/{ => commands}/ExampleSubCommand.java (69%) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index 45a2e5be..a1afbabc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -24,6 +24,7 @@ package dev.triumphteam.cmd.core; import dev.triumphteam.cmd.core.argument.ArgumentResolver; +import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.argument.keyed.Arguments; import dev.triumphteam.cmd.core.argument.keyed.FlagKey; import dev.triumphteam.cmd.core.argument.keyed.Flags; @@ -104,6 +105,10 @@ public final void registerArgument(final @NotNull Class clazz, final @NotNull getRegistryContainer().getArgumentRegistry().register(clazz, resolver); } + public final void registerArgument(final @NotNull Class clazz, final @NotNull InternalArgument.Factory factory) { + getRegistryContainer().getArgumentRegistry().register(clazz, factory); + } + /** * Registers a suggestion to be used for specific arguments. * diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java index ea129281..19b08391 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; @@ -106,6 +107,11 @@ public boolean isOptional() { return optional; } + @Override + public boolean canSuggest() { + return !(suggestion instanceof EmptySuggestion); + } + protected @NotNull Suggestion getSuggestion() { return suggestion; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java index 11d475f4..265eb2fc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java @@ -71,7 +71,8 @@ public CollectionInternalArgument( @Override public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( final @NotNull S sender, - final @NotNull Collection value + final @NotNull Collection value, + final @Nullable Object provided ) { final Stream stream = value.stream().map(arg -> internalArgument.resolve(sender, arg)); if (collectionType == Set.class) return success(stream.collect(Collectors.toSet())); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java index 8753ece4..4e5fa693 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java @@ -28,6 +28,7 @@ import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.lang.ref.WeakReference; import java.util.function.BiFunction; @@ -69,7 +70,8 @@ public EnumInternalArgument( @Override public @NotNull Result> resolve( final @NotNull S sender, - final @NotNull String value + final @NotNull String value, + final @Nullable Object provided ) { final WeakReference> reference = getEnumConstants(enumType).get(value.toUpperCase()); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index 6cbd1fa7..1c09bc86 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -26,6 +26,7 @@ import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; +import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -73,6 +74,22 @@ public interface InternalArgument { */ boolean isOptional(); + boolean canSuggest(); + + /** + * Resolves the argument type. + * + * @param sender The sender to resolve to. + * @param value The argument value. + * @param provided A provided value by a platform in case parsing isn't needed. + * @return A resolve {@link Result}. + */ + @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull T value, + final @Nullable Object provided + ); + /** * Resolves the argument type. * @@ -80,10 +97,12 @@ public interface InternalArgument { * @param value The argument value. * @return A resolve {@link Result}. */ - @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + default @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( final @NotNull S sender, final @NotNull T value - ); + ) { + return resolve(sender, value, null); + } /** * Create a list of suggestion strings to return to the platform requesting it. @@ -105,4 +124,16 @@ public interface InternalArgument { ) { return new Result.Failure<>(context); } + + @FunctionalInterface + interface Factory { + + @NotNull StringInternalArgument create( + final @NotNull String name, + final @NotNull String description, + final @NotNull Class type, + final @NotNull Suggestion suggestion, + final boolean optional + ); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java index 150404c9..c9238589 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java @@ -65,7 +65,8 @@ public JoinedStringInternalArgument( @Override public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( final @NotNull S sender, - final @NotNull Collection value + final @NotNull Collection value, + final @Nullable Object provided ) { return success(String.join(delimiter, value)); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java index 5e4394dc..6ee6502e 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java @@ -67,8 +67,11 @@ public ResolverInternalArgument( @Override public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( final @NotNull S sender, - final @NotNull String value + final @NotNull String value, + final @Nullable Object provided ) { + if (provided != null) return success(provided); + final Object result = resolver.resolve(sender, value); if (result == null) { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java index cf5bda91..1fc4f5ac 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java @@ -76,7 +76,8 @@ public SplitStringInternalArgument( @Override public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( final @NotNull S sender, - final @NotNull String value + final @NotNull String value, + final @Nullable Object provided ) { final Stream stream = Arrays.stream(value.split(regex)).map(arg -> internalArgument.resolve(sender, arg)); if (collectionType == Set.class) return success(stream.collect(Collectors.toSet())); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index 2ca215e5..03384afa 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -43,7 +43,11 @@ public UnknownInternalArgument(final @NotNull Class type) { } @Override - public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve(final @NotNull S sender, final @NotNull String value) { + public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull String value, + final @Nullable Object provided + ) { return invalid((meta, syntax) -> new InvalidArgumentContext(meta, syntax, "", "", Void.TYPE)); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java index 51c19f8a..b863c416 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java @@ -76,7 +76,8 @@ public KeyedInternalArgument( @Override public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( final @NotNull S sender, - final @NotNull Collection value + final @NotNull Collection value, + final @Nullable Object provided ) { final ArgumentParser.Result result = argumentParser.parse(value); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 1c185144..86092436 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -25,12 +25,14 @@ import dev.triumphteam.cmd.core.extention.command.Settings; import dev.triumphteam.cmd.core.extention.meta.CommandMetaContainer; +import dev.triumphteam.cmd.core.util.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.Deque; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.function.Supplier; /** @@ -47,14 +49,19 @@ public interface Command extends CommandMetaContainer { * @param sender The sender of the command. * @param instanceSupplier A supplier for which instance will be needed when invoking the command. * @param arguments A {@link Deque} with the arguments passed, these are consumed on each step. - * @param extra A map of extra details to pass down to the command. * @throws Throwable Anything that goes wrong with the execution. */ void execute( final @NotNull S sender, final @Nullable Supplier instanceSupplier, - final @NotNull Deque arguments, - final @NotNull Map extra + final @NotNull Deque arguments + ) throws Throwable; + + void executeNonLinear( + final @NotNull S sender, + final @Nullable Supplier instanceSupplier, + final @NotNull Deque commands, + final @NotNull Map, Pair>> arguments ) throws Throwable; /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index cf2a9d4b..7691753d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -174,6 +174,10 @@ public void addCommands( return defaultCommand; } + public @Nullable Command getCommand(final @NotNull String name) { + return commands.get(name); + } + @Override public @NotNull Settings getCommandSettings() { return settings; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index f38e50c9..dc870828 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -32,6 +32,7 @@ import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.processor.CommandProcessor; import dev.triumphteam.cmd.core.processor.ParentCommandProcessor; +import dev.triumphteam.cmd.core.util.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -41,6 +42,7 @@ import java.util.List; import java.util.Map; import java.util.function.BiFunction; +import java.util.function.Function; import java.util.function.Supplier; /** @@ -89,10 +91,8 @@ public ParentSubCommand( public void execute( final @NotNull S sender, final @Nullable Supplier instanceSupplier, - final @NotNull Deque arguments, - final @NotNull Map extra + final @NotNull Deque arguments ) throws Throwable { - // Test all requirements before continuing if (!getSettings().testRequirements(getMessageRegistry(), sender, getMeta(), getSenderExtension())) return; @@ -133,8 +133,31 @@ public void execute( command.execute( sender, () -> instance, - arguments, - extra + arguments + ); + } + + @Override + public void executeNonLinear( + final @NotNull S sender, + final @Nullable Supplier instanceSupplier, + final @NotNull Deque commands, + final @NotNull Map, Pair>> arguments + ) throws Throwable { + // Test all requirements before continuing + if (!getSettings().testRequirements(getMessageRegistry(), sender, getMeta(), getSenderExtension())) return; + + final Command command = findCommand(sender, commands, true); + if (command == null) return; + + final Object instance = createInstance(instanceSupplier); + + // Simply execute the command with the given instance + command.executeNonLinear( + sender, + () -> instance, + commands, + arguments ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java index cbd50d58..6db7f8e7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -25,6 +25,7 @@ import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.processor.RootCommandProcessor; +import dev.triumphteam.cmd.core.util.Pair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -32,6 +33,7 @@ import java.util.Deque; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.function.Supplier; public class RootCommand extends ParentCommand { @@ -54,8 +56,7 @@ public RootCommand(final @NotNull RootCommandProcessor processor) { public void execute( final @NotNull S sender, final @Nullable Supplier instanceSupplier, - final @NotNull Deque arguments, - final @NotNull Map extra + final @NotNull Deque arguments ) { // Test all requirements before continuing if (!getSettings().testRequirements(getMessageRegistry(), sender, getMeta(), getSenderExtension())) return; @@ -68,8 +69,34 @@ public void execute( command.execute( sender, null, - arguments, - extra + arguments + ); + } catch (final @NotNull Throwable exception) { + throw new CommandExecutionException("An error occurred while executing the command") + .initCause(exception instanceof InvocationTargetException ? exception.getCause() : exception); + } + } + + @Override + public void executeNonLinear( + final @NotNull S sender, + final @Nullable Supplier instanceSupplier, + final @NotNull Deque commands, + final @NotNull Map, Pair>> arguments + ) { + // Test all requirements before continuing + if (!getSettings().testRequirements(getMessageRegistry(), sender, getMeta(), getSenderExtension())) return; + + final Command command = findCommand(sender, commands, true); + if (command == null) return; + + // Executing the command and catch all exceptions to rethrow with better message + try { + command.executeNonLinear( + sender, + null, + commands, + arguments ); } catch (final @NotNull Throwable exception) { throw new CommandExecutionException("An error occurred while executing the command") diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 2af8006d..3b19bbe6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -46,16 +46,21 @@ import org.jetbrains.annotations.Nullable; import java.lang.reflect.Method; +import java.util.ArrayDeque; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.Deque; import java.util.List; import java.util.Map; import java.util.function.BiFunction; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; import static java.util.Collections.emptyList; +@SuppressWarnings("unchecked") public class SubCommand implements Command { private final Class senderType; @@ -118,8 +123,7 @@ public SubCommand( public void execute( final @NotNull S sender, final @Nullable Supplier instanceSupplier, - final @NotNull Deque arguments, - final @NotNull Map extra + final @NotNull Deque arguments ) throws Throwable { final ValidationResult> validationResult = senderExtension.validate(meta, senderType, sender); @@ -156,6 +160,62 @@ public void execute( ); } + @Override + public void executeNonLinear( + final @NotNull S sender, + final @Nullable Supplier instanceSupplier, + final @NotNull Deque commands, + final @NotNull Map, Pair>> arguments + ) throws Throwable { + // TODO DRY + final ValidationResult> validationResult = senderExtension.validate(meta, senderType, sender); + + // If the result is invalid for a reason given by the validator, we stop the execution and use its key to send + // a message to the sender + if (validationResult instanceof ValidationResult.Invalid) { + messageRegistry.sendMessage( + ((ValidationResult.Invalid>) validationResult).getMessage(), + sender, + new SyntaxMessageContext(meta, syntax) + ); + return; + } + + // Testing if all requirements pass before we continue + if (!settings.testRequirements(messageRegistry, sender, meta, senderExtension)) return; + + // Creates the invoking arguments list + final List invokeArguments = new ArrayList<>(); + invokeArguments.add(sender); + + argumentList.forEach(it -> { + final Function, Pair> function = arguments.get(it.getName()); + // Should only really happen on optional arguments + if (function == null) { + invokeArguments.add(null); + return; + } + + final Pair pair = function.apply(it.getType()); + + final Deque raw; + if (it instanceof LimitlessInternalArgument) { + raw = new ArrayDeque<>(Arrays.asList(pair.first().split(""))); + } else { + raw = new ArrayDeque<>(Collections.singleton(pair.first())); + } + + validateAndCollectArgument(sender, invokeArguments, raw, it, pair.second()); + }); + + commandExecutor.execute( + meta, + instanceSupplier == null ? invocationInstance : instanceSupplier.get(), + method, + invokeArguments + ); + } + @Override public @NotNull List suggestions( final @NotNull S sender, @@ -194,57 +254,70 @@ public void execute( * @param commandArgs The command arguments type. * @return False if any internalArgument fails to pass. */ - @SuppressWarnings("unchecked") private boolean validateAndCollectArguments( final @NotNull S sender, final @NotNull List invokeArguments, final @NotNull Deque commandArgs ) { for (final InternalArgument internalArgument : argumentList) { - final Result> result; - if (internalArgument instanceof LimitlessInternalArgument) { - final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument; - - // From this point on [commandArgs] is treated as a simple Collection instead of Deque - result = limitlessArgument.resolve(sender, commandArgs); - } else if (internalArgument instanceof StringInternalArgument) { - final StringInternalArgument stringArgument = (StringInternalArgument) internalArgument; - final String arg = commandArgs.peek(); - - if (arg == null || arg.isEmpty()) { - if (internalArgument.isOptional()) { - invokeArguments.add(null); - continue; - } - - messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new SyntaxMessageContext(meta, syntax)); - return false; - } - - // Pop the command out - commandArgs.pop(); - result = stringArgument.resolve(sender, arg); - } else { - // Should never happen, this should be a sealed type ... but hey, it's Java 8 - throw new CommandExecutionException("Found unsupported argument", "", name); + if (!validateAndCollectArgument(sender, invokeArguments, commandArgs, internalArgument, null)) { + return false; } + } + + return true; + } + + private boolean validateAndCollectArgument( + final @NotNull S sender, + final @NotNull List invokeArguments, + final @NotNull Deque commandArgs, + final @NotNull InternalArgument internalArgument, + final @Nullable Object provided + ) { + final Result> result; + if (internalArgument instanceof LimitlessInternalArgument) { + final LimitlessInternalArgument limitlessArgument = (LimitlessInternalArgument) internalArgument; + + // From this point on [commandArgs] is treated as a simple Collection instead of Deque + result = limitlessArgument.resolve(sender, commandArgs, provided); + } else if (internalArgument instanceof StringInternalArgument) { + final StringInternalArgument stringArgument = (StringInternalArgument) internalArgument; + final String arg = commandArgs.peek(); + + if (arg == null || arg.isEmpty()) { + if (internalArgument.isOptional()) { + invokeArguments.add(null); + return true; + } - // In case of failure we send the Sender a message - if (result instanceof Result.Failure) { - messageRegistry.sendMessage( - MessageKey.INVALID_ARGUMENT, - sender, - ((Result.Failure>) result) - .getFail() - .apply(meta, syntax) - ); + messageRegistry.sendMessage(MessageKey.NOT_ENOUGH_ARGUMENTS, sender, new SyntaxMessageContext(meta, syntax)); return false; } - // In case of success we add the results - if (result instanceof Result.Success) { - invokeArguments.add(((Result.Success>) result).getValue()); - } + // Pop the command out + commandArgs.pop(); + result = stringArgument.resolve(sender, arg, provided); + } else { + // Should never happen, this should be a sealed type ... but hey, it's Java 8 + throw new CommandExecutionException("Found unsupported argument", "", name); + } + + // In case of failure we send the Sender a message + if (result instanceof Result.Failure) { + messageRegistry.sendMessage( + MessageKey.INVALID_ARGUMENT, + sender, + ((Result.Failure>) result) + .getFail() + .apply(meta, syntax) + ); + return false; + } + + // In case of success we add the results + if (result instanceof Result.Success) { + invokeArguments.add(((Result.Success>) result).getValue()); } return true; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/ArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/ArgumentRegistry.java index 3ac9e8f5..6225cdd9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/ArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/ArgumentRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -28,6 +28,7 @@ import com.google.common.primitives.Ints; import com.google.common.primitives.Longs; import dev.triumphteam.cmd.core.argument.ArgumentResolver; +import dev.triumphteam.cmd.core.argument.InternalArgument; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -44,6 +45,7 @@ public final class ArgumentRegistry implements Registry { private final Map, ArgumentResolver> arguments = new HashMap<>(); + private final Map, InternalArgument.Factory> internals = new HashMap<>(); @SuppressWarnings("UnstableApiUsage") public ArgumentRegistry() { @@ -78,14 +80,15 @@ public void register(final @NotNull Class clazz, final @NotNull ArgumentResol arguments.put(clazz, argument); } - /** - * Gets an argument resolver from the Map. - * - * @param clazz The {@link Class} type the argument. - * @return An {@link ArgumentResolver} or null if it doesn't exist. - */ + public void register(final @NotNull Class clazz, final @NotNull InternalArgument.Factory factory) { + internals.put(clazz, factory); + } + public @Nullable ArgumentResolver getResolver(final @NotNull Class clazz) { return arguments.get(clazz); } + public @Nullable InternalArgument.Factory getFactory(final @NotNull Class clazz) { + return internals.get(clazz); + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 94bb2c2f..e713adde 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -303,6 +303,11 @@ public String getDescription() { ); } + final InternalArgument.Factory factory = argumentRegistry.getFactory(type); + if (factory != null) { + return factory.create(name, description, type, suggestion, optional); + } + return new UnknownInternalArgument<>(type); } return new ResolverInternalArgument<>( diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaMappingUtil.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java similarity index 76% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaMappingUtil.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java index 8f51c44e..c1b4db41 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/util/JdaMappingUtil.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash.util; +package dev.triumphteam.cmd.slash; import com.google.common.collect.ImmutableMap; import dev.triumphteam.cmd.core.argument.InternalArgument; @@ -29,13 +29,17 @@ import dev.triumphteam.cmd.core.command.ParentSubCommand; import dev.triumphteam.cmd.core.command.RootCommand; import dev.triumphteam.cmd.core.command.SubCommand; +import dev.triumphteam.cmd.core.util.Pair; import dev.triumphteam.cmd.slash.sender.SlashSender; +import net.dv8tion.jda.api.entities.IMentionable; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.Commands; import net.dv8tion.jda.api.interactions.commands.build.OptionData; @@ -48,33 +52,13 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.function.Function; import java.util.stream.Collectors; -public final class JdaMappingUtil { +final class JdaMappingUtil { - private static final Map, OptionType> OPTION_TYPE_MAP; - - static { - final Map, OptionType> map = new HashMap<>(); - map.put(Short.class, OptionType.INTEGER); - map.put(short.class, OptionType.INTEGER); - map.put(Integer.class, OptionType.INTEGER); - map.put(int.class, OptionType.INTEGER); - map.put(Long.class, OptionType.INTEGER); - map.put(long.class, OptionType.INTEGER); - map.put(Double.class, OptionType.NUMBER); - map.put(double.class, OptionType.NUMBER); - map.put(Boolean.class, OptionType.BOOLEAN); - map.put(boolean.class, OptionType.BOOLEAN); - map.put(Role.class, OptionType.ROLE); - map.put(User.class, OptionType.USER); - map.put(Member.class, OptionType.USER); - map.put(TextChannel.class, OptionType.CHANNEL); - map.put(MessageChannel.class, OptionType.CHANNEL); - map.put(Message.Attachment.class, OptionType.ATTACHMENT); - - OPTION_TYPE_MAP = ImmutableMap.copyOf(map); - } + private static final Map, OptionType> OPTION_TYPE_MAP = createTypeMap(); + private static final Map, Function> MAPPING_MAP = createMappingsMap(); private JdaMappingUtil() {} @@ -82,6 +66,18 @@ private JdaMappingUtil() {} return OPTION_TYPE_MAP.getOrDefault(type, OptionType.STRING); } + public static @NotNull Pair parsedValueFromType( + final @NotNull Class type, + final @NotNull OptionMapping option + ) { + final String raw = option.getAsString(); + + final Function mapper = MAPPING_MAP.get(type); + if (mapper == null) return new Pair<>(raw, raw); + + return new Pair<>(raw, mapper.apply(option)); + } + public static @NotNull SlashCommandData mapCommand(final @NotNull RootCommand rootCommand) { final String name = rootCommand.getName(); final String description = rootCommand.getDescription(); @@ -141,11 +137,57 @@ private JdaMappingUtil() {} final String name = argument.getName(); final String description = argument.getDescription(); + final boolean enableSuggestions; + if (argument instanceof ProvidedInternalArgument) { + enableSuggestions = false; + } else { + // TODO choices + enableSuggestions = argument.canSuggest(); + } + return new OptionData( fromType(argument.getType()), name, description.isEmpty() ? name : description, - !argument.isOptional() + !argument.isOptional(), + enableSuggestions ); } + + private static Map, OptionType> createTypeMap() { + final Map, OptionType> map = new HashMap<>(); + map.put(Short.class, OptionType.INTEGER); + map.put(short.class, OptionType.INTEGER); + map.put(Integer.class, OptionType.INTEGER); + map.put(int.class, OptionType.INTEGER); + map.put(Long.class, OptionType.INTEGER); + map.put(long.class, OptionType.INTEGER); + map.put(Double.class, OptionType.NUMBER); + map.put(double.class, OptionType.NUMBER); + map.put(Boolean.class, OptionType.BOOLEAN); + map.put(boolean.class, OptionType.BOOLEAN); + map.put(Role.class, OptionType.ROLE); + map.put(User.class, OptionType.USER); + map.put(Member.class, OptionType.USER); + map.put(TextChannel.class, OptionType.CHANNEL); + map.put(MessageChannel.class, OptionType.CHANNEL); + map.put(Message.Attachment.class, OptionType.ATTACHMENT); + + return ImmutableMap.copyOf(map); + } + + private static Map, Function> createMappingsMap() { + final Map, Function> map = new HashMap<>(); + + map.put(Role.class, OptionMapping::getAsRole); + map.put(User.class, OptionMapping::getAsUser); + map.put(Member.class, OptionMapping::getAsMember); + map.put(GuildChannel.class, OptionMapping::getAsChannel); + map.put(TextChannel.class, OptionMapping::getAsChannel); + map.put(MessageChannel.class, OptionMapping::getAsChannel); + map.put(Message.Attachment.class, OptionMapping::getAsAttachment); + map.put(IMentionable.class, OptionMapping::getAsMentionable); + + return ImmutableMap.copyOf(map); + } } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java new file mode 100644 index 00000000..127547f0 --- /dev/null +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java @@ -0,0 +1,36 @@ +package dev.triumphteam.cmd.slash; + +import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; +import dev.triumphteam.cmd.core.suggestion.Suggestion; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiFunction; + +class ProvidedInternalArgument extends StringInternalArgument { + + public ProvidedInternalArgument( + final @NotNull String name, + final @NotNull String description, + final @NotNull Class type, + final @NotNull Suggestion suggestion, + final boolean optional + ) { + super(name, description, type, suggestion, optional); + } + + @Override + public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull String value, + final @Nullable Object provided + ) { + if (provided == null) { + return invalid((meta, syntax) -> new InvalidArgumentContext(meta, syntax, value, getName(), getType())); + } + return success(provided); + } +} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java index 507df379..8470f6f1 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java @@ -24,25 +24,38 @@ package dev.triumphteam.cmd.slash; import dev.triumphteam.cmd.core.CommandManager; +import dev.triumphteam.cmd.core.argument.InternalArgument; import dev.triumphteam.cmd.core.command.RootCommand; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.processor.RootCommandProcessor; +import dev.triumphteam.cmd.core.util.Pair; import dev.triumphteam.cmd.slash.choices.ChoiceKey; import dev.triumphteam.cmd.slash.sender.SlashSender; -import dev.triumphteam.cmd.slash.util.JdaMappingUtil; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.IMentionable; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.Message; +import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; +import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; +import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import java.util.ArrayDeque; +import java.util.Arrays; import java.util.Collections; +import java.util.Deque; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.function.Consumer; +import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -71,8 +84,17 @@ public SlashCommandManager( this.jda = jda; this.registryContainer = registryContainer; - registerArgument(User.class, (sender, arg) -> ""); - // jda.addEventListener(new SlashCommandListener<>(this, senderMapper)); + // All use the same factory + final InternalArgument.Factory jdaArgumentFactory = ProvidedInternalArgument::new; + registerArgument(User.class, jdaArgumentFactory); + registerArgument(Role.class, jdaArgumentFactory); + registerArgument(User.class, jdaArgumentFactory); + registerArgument(Member.class, jdaArgumentFactory); + registerArgument(GuildChannel.class, jdaArgumentFactory); + registerArgument(TextChannel.class, jdaArgumentFactory); + registerArgument(MessageChannel.class, jdaArgumentFactory); + registerArgument(Message.Attachment.class, jdaArgumentFactory); + registerArgument(IMentionable.class, jdaArgumentFactory); } @Contract("_, _, _ -> new") @@ -122,11 +144,21 @@ public void execute(final @NotNull SlashCommandInteractionEvent event) { .getOrDefault(guild.getIdLong(), Collections.emptyMap()) .get(name); + final Deque commands = new ArrayDeque<>(Arrays.asList(event.getFullCommandName().split(" "))); + + // Immediately pop the main command out, to remove itself from it + commands.pop(); + final SenderExtension senderExtension = getCommandOptions().getSenderExtension(); final S sender = senderExtension.map(new SlashCommandSender(event)); + // Mapping of arguments + final Map, Pair>> arguments = new HashMap<>(); + for (final OptionMapping option : event.getOptions()) { + arguments.put(option.getName(), type -> JdaMappingUtil.parsedValueFromType(type, option)); + } - // TODO continue + command.executeNonLinear(sender, null, commands, arguments); } @Override diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java index a99e2388..0e547fb7 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java @@ -2,6 +2,9 @@ import dev.triumphteam.cmd.slash.SlashCommandManager; import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.slash.example.commands.ExampleCommand; +import dev.triumphteam.slash.example.commands.ExampleCommandGroup; +import dev.triumphteam.slash.example.commands.ExampleSubCommand; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; @@ -11,9 +14,16 @@ public static void main(String[] args) throws InterruptedException { final JDA jda = JDABuilder.createDefault(args[0]).build().awaitReady(); final SlashCommandManager commandManager = SlashCommandManager.create(jda); + + // Registering commands commandManager.registerCommand(820696172477677628L, new ExampleCommand()); commandManager.registerCommand(820696172477677628L, new ExampleCommandGroup()); commandManager.registerCommand(820696172477677628L, new ExampleSubCommand()); + + // Adding listener for the manager + jda.addEventListener(new Listener(commandManager)); + + // Push all commands if you want to change or add them commandManager.pushCommands(); } } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java new file mode 100644 index 00000000..b75f360c --- /dev/null +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java @@ -0,0 +1,21 @@ +package dev.triumphteam.slash.example; + +import dev.triumphteam.cmd.slash.SlashCommandManager; +import dev.triumphteam.cmd.slash.sender.SlashSender; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.jetbrains.annotations.NotNull; + +public class Listener extends ListenerAdapter { + + private final SlashCommandManager commandManager; + + public Listener(final @NotNull SlashCommandManager commandManager) { + this.commandManager = commandManager; + } + + @Override + public void onSlashCommandInteraction(@NotNull final SlashCommandInteractionEvent event) { + commandManager.execute(event); + } +} diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java similarity index 68% rename from examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommand.java rename to examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java index 7b4b374d..3f32adcb 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java @@ -1,4 +1,4 @@ -package dev.triumphteam.slash.example; +package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.slash.sender.SlashSender; @@ -9,6 +9,6 @@ public class ExampleCommand { @Command public void execute(final SlashSender sender, final String name, final User user) { - + sender.reply("OH SHIT, " + name + " OH FUCK " + user.getName() + " OH PISS!").queue(); } } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommandGroup.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java similarity index 71% rename from examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommandGroup.java rename to examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java index a43902cf..f82ca17a 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleCommandGroup.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java @@ -1,4 +1,4 @@ -package dev.triumphteam.slash.example; +package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.slash.sender.SlashSender; @@ -12,12 +12,12 @@ public class Group { @Command("first") public void first(final SlashSender sender) { - + sender.reply("OH SHIT").queue(); } @Command("second") public void second(final SlashSender sender, final User user) { - + sender.reply("OH SHIT, OH FUCK " + user.getName() + " OH PISS!").queue(); } } } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleSubCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java similarity index 69% rename from examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleSubCommand.java rename to examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java index bd3d5f1b..f3706096 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/ExampleSubCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java @@ -1,4 +1,4 @@ -package dev.triumphteam.slash.example; +package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.slash.sender.SlashSender; @@ -9,11 +9,11 @@ public class ExampleSubCommand { @Command("first") public void first(final SlashSender sender) { - + sender.reply("OH PISS!").queue(); } @Command("second") public void second(final SlashSender sender, final User user) { - + sender.reply("OH SHIT, " + user.getName() + " OH PISS!").queue(); } } diff --git a/examples/discord/jda/slash/src/main/resources/log4j2.xml b/examples/discord/jda/slash/src/main/resources/log4j2.xml index f6ff3dfb..44007cbc 100644 --- a/examples/discord/jda/slash/src/main/resources/log4j2.xml +++ b/examples/discord/jda/slash/src/main/resources/log4j2.xml @@ -9,9 +9,5 @@ - - - - diff --git a/gradle.properties b/gradle.properties index 9ad49154..e6397c60 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ kotlin.stdlib.default.dependency=false -version=2.0.0-ALPHA-1 +version=2.0.0-ALPHA-2 group=dev.triumphteam From 223956ac374d896d90165da7e784bb8f6da5029a Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 29 Jan 2023 22:15:06 -0600 Subject: [PATCH 080/101] feature: Basic suggestions --- .../cmd/core/command/SubCommand.java | 13 ++- ...der.java => InteractionCommandSender.java} | 6 +- .../cmd/slash/SlashCommandManager.java | 53 ++++++++- .../cmd/slash/SlashSenderExtension.java | 3 +- .../cmd/slash/SuggestionCommandSender.java | 74 ++++++++++++ .../cmd/slash/sender/SlashCommandSender.java | 106 ++++++++++++++++++ .../cmd/slash/sender/SlashSender.java | 75 +------------ .../triumphteam/slash/example/Listener.java | 6 + .../example/commands/ExampleCommand.java | 5 +- .../example/commands/ExampleCommandGroup.java | 6 +- .../example/commands/ExampleSubCommand.java | 6 +- 11 files changed, 266 insertions(+), 87 deletions(-) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/{SlashCommandSender.java => InteractionCommandSender.java} (94%) create mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java create mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 3b19bbe6..6026dcab 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -59,6 +59,7 @@ import java.util.stream.Collectors; import static java.util.Collections.emptyList; +import static java.util.Collections.singleton; @SuppressWarnings("unchecked") public class SubCommand implements Command { @@ -242,7 +243,17 @@ public void executeNonLinear( return argumentList.get(index); } - public @Nullable InternalArgument getArgumentFromName(final @NotNull String name) { + public @NotNull List suggest( + final @NotNull S sender, + final @NotNull String name, + final @NotNull String value + ) { + final InternalArgument argument = getArgumentFromName(name); + if (argument == null) return emptyList(); + return argument.suggestions(sender, new ArrayDeque<>(singleton(value))); + } + + private @Nullable InternalArgument getArgumentFromName(final @NotNull String name) { return argumentMap.get(name); } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/InteractionCommandSender.java similarity index 94% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/InteractionCommandSender.java index 17a0160c..6194f25d 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/InteractionCommandSender.java @@ -23,7 +23,7 @@ */ package dev.triumphteam.cmd.slash; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.slash.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.MessageEmbed; @@ -38,11 +38,11 @@ import java.util.Collection; -final class SlashCommandSender implements SlashSender { +final class InteractionCommandSender implements SlashCommandSender { private final SlashCommandInteractionEvent event; - public SlashCommandSender(final @NotNull SlashCommandInteractionEvent event) { + public InteractionCommandSender(final @NotNull SlashCommandInteractionEvent event) { this.event = event; } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java index 8470f6f1..76cc1cfe 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java @@ -25,7 +25,10 @@ import dev.triumphteam.cmd.core.CommandManager; import dev.triumphteam.cmd.core.argument.InternalArgument; +import dev.triumphteam.cmd.core.command.Command; +import dev.triumphteam.cmd.core.command.ParentCommand; import dev.triumphteam.cmd.core.command.RootCommand; +import dev.triumphteam.cmd.core.command.SubCommand; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.core.processor.RootCommandProcessor; @@ -42,10 +45,13 @@ import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; +import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.AutoCompleteQuery; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.ArrayDeque; import java.util.Arrays; @@ -150,7 +156,7 @@ public void execute(final @NotNull SlashCommandInteractionEvent event) { commands.pop(); final SenderExtension senderExtension = getCommandOptions().getSenderExtension(); - final S sender = senderExtension.map(new SlashCommandSender(event)); + final S sender = senderExtension.map(new InteractionCommandSender(event)); // Mapping of arguments final Map, Pair>> arguments = new HashMap<>(); @@ -161,6 +167,30 @@ public void execute(final @NotNull SlashCommandInteractionEvent event) { command.executeNonLinear(sender, null, commands, arguments); } + public void suggest(final @NotNull CommandAutoCompleteInteractionEvent event) { + final Guild guild = event.getGuild(); + if (guild == null) return; + + final String name = event.getName(); + final RootCommand command = guildCommands + .getOrDefault(guild.getIdLong(), Collections.emptyMap()) + .get(name); + + final Deque commands = new ArrayDeque<>(Arrays.asList(event.getFullCommandName().split(" "))); + + // Immediately pop the main command out, to remove itself from it + commands.pop(); + + final SenderExtension senderExtension = getCommandOptions().getSenderExtension(); + final S sender = senderExtension.map(new SuggestionCommandSender(event)); + final SubCommand subCommand = findExecutable(commands, command); + if (subCommand == null) return; + + final AutoCompleteQuery option = event.getFocusedOption(); + final List suggestions = subCommand.suggest(sender, option.getName(), option.getValue()); + event.replyChoiceStrings(suggestions.stream().limit(25).collect(Collectors.toList())).queue(); + } + @Override public void registerCommand(final @NotNull Object command) { @@ -206,4 +236,25 @@ public void unregisterCommand(final @NotNull Object command) { protected @NotNull SlashRegistryContainer getRegistryContainer() { return registryContainer; } + + private @Nullable SubCommand findExecutable( + final @NotNull Deque commands, + final @NotNull Command command + ) { + + // If it's empty we're talking about a default from Root + if (commands.isEmpty() && command instanceof ParentCommand) { + return (SubCommand) ((ParentCommand) command).getDefaultCommand(); + } + + Command current = command; + while (true) { + if (current == null) return null; + if (current instanceof SubCommand) return (SubCommand) current; + if (commands.isEmpty()) return null; + + final ParentCommand parentCommand = (ParentCommand) current; + current = parentCommand.getCommand(commands.pop()); + } + } } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java index 1fda2107..78a36192 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java @@ -25,6 +25,7 @@ import com.google.common.collect.ImmutableSet; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.slash.sender.SlashCommandSender; import dev.triumphteam.cmd.slash.sender.SlashSender; import org.jetbrains.annotations.NotNull; @@ -37,6 +38,6 @@ final class SlashSenderExtension implements SenderExtension.Default @Override public @NotNull Set> getAllowedSenders() { - return ImmutableSet.of(SlashSender.class); + return ImmutableSet.of(SlashSender.class, SlashCommandSender.class); } } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java new file mode 100644 index 00000000..02b9bff7 --- /dev/null +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java @@ -0,0 +1,74 @@ +/** + * MIT License + *

    + * Copyright (c) 2019-2021 Matt + *

    + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

    + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

    + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.slash; + +import dev.triumphteam.cmd.slash.sender.SlashSender; +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion; +import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +final class SuggestionCommandSender implements SlashSender { + + private final CommandAutoCompleteInteractionEvent event; + + public SuggestionCommandSender(final @NotNull CommandAutoCompleteInteractionEvent event) { + this.event = event; + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Guild getGuild() { + return event.getGuild(); + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable MessageChannelUnion getChannel() { + return event.getChannel(); + } + + /** + * {@inheritDoc} + */ + @Override + public @NotNull User getUser() { + return event.getUser(); + } + + /** + * {@inheritDoc} + */ + @Override + public @Nullable Member getMember() { + return event.getMember(); + } +} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java new file mode 100644 index 00000000..6b181072 --- /dev/null +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java @@ -0,0 +1,106 @@ +/** + * MIT License + *

    + * Copyright (c) 2019-2021 Matt + *

    + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

    + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

    + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.slash.sender; + +import net.dv8tion.jda.api.entities.MessageEmbed; +import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.interactions.InteractionHook; +import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; + +/** + * Works like a shortcut for most things present on {@link SlashCommandInteractionEvent}. + * Contains the more useful methods from it, but still allows you to get the original event if more is needed. + */ +public interface SlashCommandSender extends SlashSender { + + @Override + @NotNull MessageChannelUnion getChannel(); + + /** + * Gets the original event if more options are needed. + * + * @return The original event. + */ + @NotNull SlashCommandInteractionEvent getEvent(); + + /** + * Gets the interaction hook for the command. + * + * @return The interaction hook. + */ + @NotNull InteractionHook getHook(); + + /** + * Replies to the command with a string message. + * + * @param message The message to reply with. + * @return The reply action. + */ + @NotNull ReplyCallbackAction reply(final @NotNull String message); + + /** + * Replies to the command with a message. + * + * @param message The message to reply with. + * @return The reply action. + */ + @NotNull ReplyCallbackAction reply(final @NotNull MessageCreateData message); + + /** + * Replies to the command with a message embed. + * + * @param embed The embed to reply with. + * @param embeds The additional embeds. + * @return The reply action. + */ + @NotNull ReplyCallbackAction reply(final @NotNull MessageEmbed embed, final @NotNull MessageEmbed @NotNull ... embeds); + + /** + * Replies to the command with a message embeds. + * + * @param embeds The embeds to reply with. + * @return The reply action. + */ + @NotNull ReplyCallbackAction reply(final @NotNull Collection embeds); + + /** + * Defers the reply to the command. + * + * @return The reply action. + */ + @NotNull ReplyCallbackAction deferReply(); + + /** + * Defers the reply to the command but ephemeral. + * + * @param ephemeral Whether the message should be ephemeral. + * @return The reply action. + */ + @NotNull ReplyCallbackAction deferReply(final boolean ephemeral); +} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java index 7d62509d..0c035357 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java @@ -25,31 +25,16 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion; -import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; -import net.dv8tion.jda.api.interactions.InteractionHook; -import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; -import net.dv8tion.jda.api.utils.messages.MessageCreateData; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Collection; - /** - * Works like a shortcut for most things present on {@link SlashCommandInteractionEvent}. - * Contains the more useful methods from it, but still allows you to get the original event if more is needed. + * Simpler sender, used for suggestions and commands. */ public interface SlashSender { - /** - * Gets the original event if more options are needed. - * - * @return The original event. - */ - @NotNull SlashCommandInteractionEvent getEvent(); - /** * Gets the guild that the command was sent in or null if it was sent in a private message. * @@ -62,7 +47,7 @@ public interface SlashSender { * * @return The channel. */ - @NotNull MessageChannelUnion getChannel(); + @Nullable MessageChannelUnion getChannel(); /** * Gets the user that sent the command. @@ -77,60 +62,4 @@ public interface SlashSender { * @return The member. */ @Nullable Member getMember(); - - /** - * Gets the interaction hook for the command. - * - * @return The interaction hook. - */ - @NotNull InteractionHook getHook(); - - /** - * Replies to the command with a string message. - * - * @param message The message to reply with. - * @return The reply action. - */ - @NotNull ReplyCallbackAction reply(final @NotNull String message); - - /** - * Replies to the command with a message. - * - * @param message The message to reply with. - * @return The reply action. - */ - @NotNull ReplyCallbackAction reply(final @NotNull MessageCreateData message); - - /** - * Replies to the command with a message embed. - * - * @param embed The embed to reply with. - * @param embeds The additional embeds. - * @return The reply action. - */ - @NotNull ReplyCallbackAction reply(final @NotNull MessageEmbed embed, final @NotNull MessageEmbed @NotNull ... embeds); - - /** - * Replies to the command with a message embeds. - * - * @param embeds The embeds to reply with. - * @return The reply action. - */ - @NotNull ReplyCallbackAction reply(final @NotNull Collection embeds); - - /** - * Defers the reply to the command. - * - * @return The reply action. - */ - @NotNull ReplyCallbackAction deferReply(); - - /** - * Defers the reply to the command but ephemeral. - * - * @param ephemeral Whether the message should be ephemeral. - * @return The reply action. - */ - @NotNull ReplyCallbackAction deferReply(final boolean ephemeral); - } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java index b75f360c..7bb384ee 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java @@ -2,6 +2,7 @@ import dev.triumphteam.cmd.slash.SlashCommandManager; import dev.triumphteam.cmd.slash.sender.SlashSender; +import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; import org.jetbrains.annotations.NotNull; @@ -18,4 +19,9 @@ public Listener(final @NotNull SlashCommandManager commandManager) public void onSlashCommandInteraction(@NotNull final SlashCommandInteractionEvent event) { commandManager.execute(event); } + + @Override + public void onCommandAutoCompleteInteraction(@NotNull final CommandAutoCompleteInteractionEvent event) { + commandManager.suggest(event); + } } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java index 3f32adcb..507120f0 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java @@ -1,14 +1,15 @@ package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.core.annotations.Suggestion; +import dev.triumphteam.cmd.slash.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.User; @Command("example") public class ExampleCommand { @Command - public void execute(final SlashSender sender, final String name, final User user) { + public void execute(final SlashCommandSender sender, @Suggestion("ass") final String name, final User user) { sender.reply("OH SHIT, " + name + " OH FUCK " + user.getName() + " OH PISS!").queue(); } } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java index f82ca17a..1a874329 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java @@ -1,7 +1,7 @@ package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.slash.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.User; @Command("group") @@ -11,12 +11,12 @@ public class ExampleCommandGroup { public class Group { @Command("first") - public void first(final SlashSender sender) { + public void first(final SlashCommandSender sender) { sender.reply("OH SHIT").queue(); } @Command("second") - public void second(final SlashSender sender, final User user) { + public void second(final SlashCommandSender sender, final User user) { sender.reply("OH SHIT, OH FUCK " + user.getName() + " OH PISS!").queue(); } } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java index f3706096..af84a957 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java @@ -1,19 +1,19 @@ package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.slash.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.User; @Command("sub") public class ExampleSubCommand { @Command("first") - public void first(final SlashSender sender) { + public void first(final SlashCommandSender sender) { sender.reply("OH PISS!").queue(); } @Command("second") - public void second(final SlashSender sender, final User user) { + public void second(final SlashCommandSender sender, final User user) { sender.reply("OH SHIT, " + user.getName() + " OH PISS!").queue(); } } From a9af9d7be494c75a6bcc539854fcad770aaab349 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 29 Jan 2023 22:52:42 -0600 Subject: [PATCH 081/101] feature: JDA Choices --- .../argument/AbstractInternalArgument.java | 18 +++++-- .../argument/CollectionInternalArgument.java | 3 +- .../core/argument/EnumInternalArgument.java | 3 +- .../cmd/core/argument/InternalArgument.java | 4 +- .../JoinedStringInternalArgument.java | 3 +- .../argument/LimitlessInternalArgument.java | 4 +- .../argument/ResolverInternalArgument.java | 3 +- .../argument/SplitStringInternalArgument.java | 3 +- .../core/argument/StringInternalArgument.java | 4 +- .../argument/UnknownInternalArgument.java | 2 +- .../argument/keyed/KeyedInternalArgument.java | 3 +- .../annotation/AnnotationProcessor.java | 2 + .../defaults/AsyncAnnotationProcessor.java | 3 ++ .../processor/AbstractCommandProcessor.java | 38 +++++++++++---- .../cmd/core/processor/CommandProcessor.java | 2 +- .../core/processor/RootCommandProcessor.java | 5 ++ .../core/processor/SubCommandProcessor.java | 12 +++-- .../triumphteam/cmd/slash/JdaMappingUtil.java | 18 +++++-- .../cmd/slash/ProvidedInternalArgument.java | 3 +- .../cmd/slash/SlashCommandOptions.java | 13 +++-- .../cmd/slash/annotation/Choice.java | 8 ++-- .../cmd/slash/annotation/Choices.java | 37 -------------- .../cmd/slash/choices/EmptyChoice.java | 45 ----------------- ...numChoice.java => EnumInternalChoice.java} | 6 +-- .../{Choice.java => InternalChoice.java} | 2 +- .../choices/InternalChoiceProcessor.java | 48 +++++++++++++++++++ ...eChoice.java => SimpleInternalChoice.java} | 6 +-- .../triumphteam/slash/example/Example.java | 5 ++ .../example/commands/ExampleCommand.java | 6 +-- .../example/commands/ExampleCommandGroup.java | 4 +- .../example/commands/ExampleSubCommand.java | 4 +- 31 files changed, 180 insertions(+), 137 deletions(-) delete mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java delete mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/{EnumChoice.java => EnumInternalChoice.java} (92%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/{Choice.java => InternalChoice.java} (97%) create mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoiceProcessor.java rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/{SimpleChoice.java => SimpleInternalChoice.java} (90%) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java index 19b08391..25ba958d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.suggestion.EmptySuggestion; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; @@ -40,6 +41,8 @@ */ public abstract class AbstractInternalArgument implements InternalArgument { + private final CommandMeta meta; + private final String name; private final String description; private final Class type; @@ -47,12 +50,14 @@ public abstract class AbstractInternalArgument implements InternalArgument private final Suggestion suggestion; public AbstractInternalArgument( + final @NotNull CommandMeta meta, final @NotNull String name, final @NotNull String description, final @NotNull Class type, final @NotNull Suggestion suggestion, final boolean optional ) { + this.meta = meta; this.name = name; this.description = description; this.type = type; @@ -69,6 +74,11 @@ public AbstractInternalArgument( return getSuggestion().getSuggestions(sender, current == null ? "" : current, new ArrayList<>(arguments)); } + @Override + public @NotNull CommandMeta getMeta() { + return meta; + } + /** * Gets the name of the internalArgument. * This will be either the parameter name or arg1, arg2, etc. diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java index 265eb2fc..9766cada 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/CollectionInternalArgument.java @@ -49,6 +49,7 @@ public final class CollectionInternalArgument extends LimitlessInternalArgume private final Class collectionType; public CollectionInternalArgument( + final @NotNull CommandMeta meta, final @NotNull String name, final @NotNull String description, final @NotNull InternalArgument internalArgument, @@ -56,7 +57,7 @@ public CollectionInternalArgument( final @NotNull Suggestion suggestion, final boolean optional ) { - super(name, description, String.class, suggestion, optional); + super(meta, name, description, String.class, suggestion, optional); this.internalArgument = internalArgument; this.collectionType = collectionType; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java index 4e5fa693..65d3b3bb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/EnumInternalArgument.java @@ -47,13 +47,14 @@ public final class EnumInternalArgument extends StringInternalArgument { private final Class> enumType; public EnumInternalArgument( + final @NotNull CommandMeta meta, final @NotNull String name, final @NotNull String description, final @NotNull Class> type, final @NotNull Suggestion suggestion, final boolean optional ) { - super(name, description, type, suggestion, optional); + super(meta, name, description, type, suggestion, optional); this.enumType = type; // Populates on creation to reduce runtime of first run for certain enums, like Bukkit's Material. diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index 1c09bc86..33e80a92 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -25,6 +25,7 @@ import dev.triumphteam.cmd.core.extention.Result; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.extention.meta.CommandMetaContainer; import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; @@ -40,7 +41,7 @@ * @param The sender type. * @param The Argument type. */ -public interface InternalArgument { +public interface InternalArgument extends CommandMetaContainer { /** * Gets the name of the argument. @@ -129,6 +130,7 @@ public interface InternalArgument { interface Factory { @NotNull StringInternalArgument create( + final @NotNull CommandMeta meta, final @NotNull String name, final @NotNull String description, final @NotNull Class type, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java index c9238589..79d9592a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/JoinedStringInternalArgument.java @@ -45,13 +45,14 @@ public final class JoinedStringInternalArgument extends LimitlessInternalArgu private final CharSequence delimiter; public JoinedStringInternalArgument( + final @NotNull CommandMeta meta, final @NotNull String name, final @NotNull String description, final @NotNull CharSequence delimiter, final @NotNull Suggestion suggestion, final boolean optional ) { - super(name, description, String.class, suggestion, optional); + super(meta, name, description, String.class, suggestion, optional); this.delimiter = delimiter; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java index 23c2dd09..676b4b5d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/LimitlessInternalArgument.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; @@ -37,13 +38,14 @@ public abstract class LimitlessInternalArgument extends AbstractInternalArgument> { public LimitlessInternalArgument( + final @NotNull CommandMeta meta, final @NotNull String name, final @NotNull String description, final @NotNull Class type, final @NotNull Suggestion suggestion, final boolean isOptional ) { - super(name, description, type, suggestion, isOptional); + super(meta, name, description, type, suggestion, isOptional); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java index 6ee6502e..da1a1e7b 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java @@ -46,6 +46,7 @@ public final class ResolverInternalArgument extends StringInternalArgument private final ArgumentResolver resolver; public ResolverInternalArgument( + final @NotNull CommandMeta meta, final @NotNull String name, final @NotNull String description, final @NotNull Class type, @@ -53,7 +54,7 @@ public ResolverInternalArgument( final @NotNull Suggestion suggestion, final boolean optional ) { - super(name, description, type, suggestion, optional); + super(meta, name, description, type, suggestion, optional); this.resolver = resolver; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java index 1fc4f5ac..ebe7231c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/SplitStringInternalArgument.java @@ -52,6 +52,7 @@ public final class SplitStringInternalArgument extends StringInternalArgument private final Class collectionType; public SplitStringInternalArgument( + final @NotNull CommandMeta meta, final @NotNull String name, final @NotNull String description, final @NotNull String regex, @@ -60,7 +61,7 @@ public SplitStringInternalArgument( final @NotNull Suggestion suggestion, final boolean optional ) { - super(name, description, String.class, suggestion, optional); + super(meta, name, description, String.class, suggestion, optional); this.regex = regex; this.internalArgument = internalArgument; this.collectionType = collectionType; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java index 604083bb..f17bf65d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/StringInternalArgument.java @@ -23,6 +23,7 @@ */ package dev.triumphteam.cmd.core.argument; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.core.suggestion.Suggestion; import org.jetbrains.annotations.NotNull; @@ -35,13 +36,14 @@ public abstract class StringInternalArgument extends AbstractInternalArgument { public StringInternalArgument( + final @NotNull CommandMeta meta, final @NotNull String name, final @NotNull String description, final @NotNull Class type, final @NotNull Suggestion suggestion, final boolean optional ) { - super(name, description, type, suggestion, optional); + super(meta, name, description, type, suggestion, optional); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index 03384afa..e66793fa 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -39,7 +39,7 @@ public final class UnknownInternalArgument extends StringInternalArgument { public UnknownInternalArgument(final @NotNull Class type) { - super("unknown", "unknown.", type, new EmptySuggestion<>(), false); + super(null, "unknown", "unknown.", type, new EmptySuggestion<>(), false); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java index b863c416..ce16868a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/keyed/KeyedInternalArgument.java @@ -53,6 +53,7 @@ public final class KeyedInternalArgument extends LimitlessInternalArgument private final ArgumentParser argumentParser; public KeyedInternalArgument( + final @NotNull CommandMeta meta, final @NotNull String name, final @NotNull String description, final @NotNull Map> flagInternalArguments, @@ -60,7 +61,7 @@ public KeyedInternalArgument( final @NotNull ArgumentGroup flagGroup, final @NotNull ArgumentGroup argumentGroup ) { - super(name, description, Flags.class, new EmptySuggestion<>(), true); + super(meta, name, description, Flags.class, new EmptySuggestion<>(), true); this.flagInternalArguments = flagInternalArguments; this.argumentInternalArguments = argumentInternalArguments; this.argumentParser = new ArgumentParser(flagGroup, argumentGroup); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java index f3ed67fa..d2fa4ed3 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/annotation/AnnotationProcessor.java @@ -27,12 +27,14 @@ import org.jetbrains.annotations.NotNull; import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; public interface AnnotationProcessor { void process( final @NotNull A annotation, final @NotNull ProcessorTarget target, + final @NotNull AnnotatedElement element, final @NotNull CommandMeta.Builder meta ); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java index 03c90455..be030aa7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/defaults/AsyncAnnotationProcessor.java @@ -29,12 +29,15 @@ import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.AnnotatedElement; + public final class AsyncAnnotationProcessor implements AnnotationProcessor { @Override public void process( final @NotNull Async annotation, final @NotNull ProcessorTarget target, + final @NotNull AnnotatedElement element, final @NotNull CommandMeta.@NotNull Builder meta ) { if (target != ProcessorTarget.COMMAND) return; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index e713adde..0b7230f2 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -184,6 +184,7 @@ public String getDescription() { } protected @NotNull InternalArgument argumentFromParameter( + final @NotNull CommandMeta meta, final @NotNull Parameter parameter, final @NotNull List argDescriptions, final @NotNull Map> suggestions, @@ -201,6 +202,7 @@ public String getDescription() { if (SUPPORTED_COLLECTIONS.stream().anyMatch(it -> it.isAssignableFrom(type))) { final Class collectionType = getGenericType(parameter); final InternalArgument argument = createSimpleArgument( + meta, collectionType, argumentName, argumentDescription, @@ -216,6 +218,7 @@ public String getDescription() { if (parameter.isAnnotationPresent(Split.class)) { final Split splitAnnotation = parameter.getAnnotation(Split.class); return new SplitStringInternalArgument<>( + meta, argumentName, argumentDescription, splitAnnotation.value(), @@ -227,6 +230,7 @@ public String getDescription() { } return new CollectionInternalArgument<>( + meta, argumentName, argumentDescription, argument, @@ -240,6 +244,7 @@ public String getDescription() { if (type == String.class && parameter.isAnnotationPresent(Join.class)) { final Join joinAnnotation = parameter.getAnnotation(Join.class); return new JoinedStringInternalArgument<>( + meta, argumentName, argumentDescription, joinAnnotation.value(), @@ -262,10 +267,11 @@ public String getDescription() { } return new KeyedInternalArgument<>( + meta, argumentName, argumentDescription, - createFlagInternals(flagGroup), - createNamedArgumentInternals(argumentGroup), + createFlagInternals(meta, flagGroup), + createNamedArgumentInternals(meta, argumentGroup), flagGroup, argumentGroup ); @@ -273,6 +279,7 @@ public String getDescription() { // No more exceptions found so now just create simple argument return createSimpleArgument( + meta, type, argumentName, argumentDescription, @@ -282,6 +289,7 @@ public String getDescription() { } protected @NotNull StringInternalArgument createSimpleArgument( + final @NotNull CommandMeta meta, final @NotNull Class type, final @NotNull String name, final @NotNull String description, @@ -295,6 +303,7 @@ public String getDescription() { if (Enum.class.isAssignableFrom(type)) { //noinspection unchecked return new EnumInternalArgument<>( + meta, name, description, (Class>) type, @@ -305,12 +314,13 @@ public String getDescription() { final InternalArgument.Factory factory = argumentRegistry.getFactory(type); if (factory != null) { - return factory.create(name, description, type, suggestion, optional); + return factory.create(meta, name, description, type, suggestion, optional); } return new UnknownInternalArgument<>(type); } return new ResolverInternalArgument<>( + meta, name, description, type, @@ -320,7 +330,10 @@ public String getDescription() { ); } - private Map> createFlagInternals(final @NotNull ArgumentGroup group) { + private Map> createFlagInternals( + final @NotNull CommandMeta meta, + final @NotNull ArgumentGroup group + ) { final Map> internalArguments = new HashMap<>(); for (final Flag flag : group.getAll()) { @@ -332,6 +345,7 @@ private Map> createFlagInternals(final @NotNull internalArguments.put( flag, createSimpleArgument( + meta, argType, "", flag.getDescription(), @@ -344,7 +358,10 @@ private Map> createFlagInternals(final @NotNull return internalArguments; } - private Map> createNamedArgumentInternals(final @NotNull ArgumentGroup group) { + private Map> createNamedArgumentInternals( + final @NotNull CommandMeta meta, + final @NotNull ArgumentGroup group + ) { final Map> internalArguments = new HashMap<>(); for (final Argument argument : group.getAll()) { @@ -356,6 +373,7 @@ private Map> createNamedArgumentInternals(fi final ListArgument listArgument = (ListArgument) argument; final InternalArgument internalArgument = createSimpleArgument( + meta, listArgument.getType(), listArgument.getName(), listArgument.getDescription(), @@ -366,6 +384,7 @@ private Map> createNamedArgumentInternals(fi internalArguments.put( argument, new SplitStringInternalArgument<>( + meta, listArgument.getName(), listArgument.getDescription(), listArgument.getSeparator(), @@ -382,6 +401,7 @@ private Map> createNamedArgumentInternals(fi internalArguments.put( argument, createSimpleArgument( + meta, argType, argument.getName(), argument.getDescription(), diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java index 7c01f4b3..8f78bc5d 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/CommandProcessor.java @@ -91,7 +91,7 @@ default void processAnnotations( // No processors available if (annotationProcessor == null) continue; - annotationProcessor.process(annotation, target, meta); + annotationProcessor.process(annotation, target, element, meta); } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java index c5e94e65..6b9f3b63 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/RootCommandProcessor.java @@ -224,7 +224,12 @@ public RootCommandProcessor( } final Parameter parameter = isStatic ? parameters[0] : parameters[1]; + + final CommandMeta.Builder meta = new CommandMeta.Builder(null); + processAnnotations(getCommandOptions().getCommandExtensions(), parameter, ProcessorTarget.ARGUMENT, meta); + argument = processor.argumentFromParameter( + meta.build(), parameter, emptyList(), emptyMap(), diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index d0dd421b..031b29fb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -182,7 +182,14 @@ public final class SubCommandProcessor extends AbstractCommandProcessor argument = argumentFromParameter( + meta, parameter, argDescriptions, suggestions, @@ -191,11 +198,6 @@ public final class SubCommandProcessor extends AbstractCommandProcessor result = getCommandOptions().getCommandExtensions().getArgumentValidator().validate(meta, argument, i, last); // If the result is invalid we throw the exception with the passed message diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java index c1b4db41..90eefaa6 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java @@ -30,6 +30,8 @@ import dev.triumphteam.cmd.core.command.RootCommand; import dev.triumphteam.cmd.core.command.SubCommand; import dev.triumphteam.cmd.core.util.Pair; +import dev.triumphteam.cmd.slash.annotation.Choice; +import dev.triumphteam.cmd.slash.choices.InternalChoice; import dev.triumphteam.cmd.slash.sender.SlashSender; import net.dv8tion.jda.api.entities.IMentionable; import net.dv8tion.jda.api.entities.Member; @@ -52,6 +54,7 @@ import java.util.HashMap; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.function.Function; import java.util.stream.Collectors; @@ -137,21 +140,30 @@ private JdaMappingUtil() {} final String name = argument.getName(); final String description = argument.getDescription(); + final @NotNull Optional choice = argument.getMeta().get(Choice.CHOICE_META_KEY); + final boolean enableSuggestions; - if (argument instanceof ProvidedInternalArgument) { + if (argument instanceof ProvidedInternalArgument || choice.isPresent()) { enableSuggestions = false; } else { - // TODO choices enableSuggestions = argument.canSuggest(); } - return new OptionData( + final OptionData data = new OptionData( fromType(argument.getType()), name, description.isEmpty() ? name : description, !argument.isOptional(), enableSuggestions ); + + choice.ifPresent(internalChoice -> data.addChoices( + internalChoice.getChoices().stream() + .map(it -> new net.dv8tion.jda.api.interactions.commands.Command.Choice(it, it)) + .collect(Collectors.toList()) + )); + + return data; } private static Map, OptionType> createTypeMap() { diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java index 127547f0..106d5e82 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java @@ -13,13 +13,14 @@ class ProvidedInternalArgument extends StringInternalArgument { public ProvidedInternalArgument( + final @NotNull CommandMeta meta, final @NotNull String name, final @NotNull String description, final @NotNull Class type, final @NotNull Suggestion suggestion, final boolean optional ) { - super(name, description, type, suggestion, optional); + super(meta, name, description, type, suggestion, optional); } @Override diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java index 2fab36d1..98174bb1 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -29,6 +29,8 @@ import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.slash.annotation.Choice; +import dev.triumphteam.cmd.slash.choices.InternalChoiceProcessor; import dev.triumphteam.cmd.slash.sender.SlashSender; import org.jetbrains.annotations.NotNull; @@ -49,13 +51,14 @@ public Setup(final @NotNull RegistryContainer registryContainer) public static final class Builder extends CommandOptions.Builder, Setup, Builder> { - public Builder(final @NotNull RegistryContainer registryContainer) { + public Builder(final @NotNull SlashRegistryContainer registryContainer) { super(new Setup<>(registryContainer)); // Setters have to be done first thing, so they can be overriden. extensions(extension -> { extension.setArgumentValidator(new DefaultArgumentValidator<>()); extension.setCommandExecutor(new DefaultCommandExecutor()); + extension.addAnnotationProcessor(Choice.class, new InternalChoiceProcessor(registryContainer.getChoiceRegistry())); }); } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java index 94441a0f..b066ad28 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java @@ -23,17 +23,19 @@ */ package dev.triumphteam.cmd.slash.annotation; +import dev.triumphteam.cmd.core.extention.meta.MetaKey; +import dev.triumphteam.cmd.slash.choices.InternalChoice; + import java.lang.annotation.ElementType; -import java.lang.annotation.Repeatable; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.PARAMETER}) -@Repeatable(Choices.class) +@Target(ElementType.PARAMETER) public @interface Choice { String value(); + MetaKey CHOICE_META_KEY = MetaKey.of("choice", InternalChoice.class); } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java deleted file mode 100644 index facee2c3..00000000 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choices.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.slash.annotation; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.METHOD, ElementType.PARAMETER}) -public @interface Choices { - - Choice[] value(); - -} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java deleted file mode 100644 index 87f7687d..00000000 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EmptyChoice.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * MIT License - *

    - * Copyright (c) 2019-2021 Matt - *

    - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - *

    - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - *

    - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.cmd.slash.choices; - -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -import static java.util.Collections.emptyList; - -public final class EmptyChoice implements Choice { - - public static final EmptyChoice INSTANCE = new EmptyChoice(); - - @Override - public @NotNull List getChoices() { - return emptyList(); - } - - @Override - public @NotNull String toString() { - return "EmptyChoice{}"; - } -} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumInternalChoice.java similarity index 92% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumInternalChoice.java index cfec8c46..982788d6 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumChoice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumInternalChoice.java @@ -33,11 +33,11 @@ import static dev.triumphteam.cmd.core.util.EnumUtils.populateCache; -public final class EnumChoice implements Choice { +public final class EnumInternalChoice implements InternalChoice { private final Class> enumType; - public EnumChoice(final @NotNull Class> enumType) { + public EnumInternalChoice(final @NotNull Class> enumType) { this.enumType = enumType; populateCache(enumType); } @@ -60,7 +60,7 @@ public EnumChoice(final @NotNull Class> enumType) { public boolean equals(final @Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - final EnumChoice that = (EnumChoice) o; + final EnumInternalChoice that = (EnumInternalChoice) o; return enumType.equals(that.enumType); } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoice.java similarity index 97% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoice.java index 97c8c545..dcd264f1 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/Choice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoice.java @@ -27,7 +27,7 @@ import java.util.List; -public interface Choice { +public interface InternalChoice { @NotNull List getChoices(); diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoiceProcessor.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoiceProcessor.java new file mode 100644 index 00000000..aea599d0 --- /dev/null +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoiceProcessor.java @@ -0,0 +1,48 @@ +package dev.triumphteam.cmd.slash.choices; + +import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; +import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.slash.annotation.Choice; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.AnnotatedElement; +import java.lang.reflect.Parameter; +import java.util.List; +import java.util.function.Supplier; + +@SuppressWarnings("unchecked") +public class InternalChoiceProcessor implements AnnotationProcessor { + + private final ChoiceRegistry choiceRegistry; + + public InternalChoiceProcessor(final @NotNull ChoiceRegistry choiceRegistry) { + this.choiceRegistry = choiceRegistry; + } + + @Override + public void process( + final @NotNull Choice annotation, + final @NotNull ProcessorTarget target, + final @NotNull AnnotatedElement element, + final CommandMeta.@NotNull Builder meta + ) { + final String keyValue = annotation.value(); + final ChoiceKey choiceKey = ChoiceKey.of(keyValue); + + if (!(element instanceof Parameter)) return; + + final Class type = ((Parameter) element).getType(); + + final InternalChoice internalChoice; + if (Enum.class.isAssignableFrom(type)) { + internalChoice = new EnumInternalChoice((Class>) type); + } else { + final Supplier> supplier = choiceRegistry.getChoiceResolver(choiceKey); + if (supplier == null) return; + internalChoice = new SimpleInternalChoice(supplier); + } + + meta.add(Choice.CHOICE_META_KEY, internalChoice); + } +} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleInternalChoice.java similarity index 90% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleInternalChoice.java index ffbc03c0..343c6524 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleChoice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleInternalChoice.java @@ -30,11 +30,11 @@ import java.util.Objects; import java.util.function.Supplier; -public final class SimpleChoice implements Choice { +public final class SimpleInternalChoice implements InternalChoice { private final Supplier> resolver; - public SimpleChoice(final @NotNull Supplier> resolver) { + public SimpleInternalChoice(final @NotNull Supplier> resolver) { this.resolver = resolver; } @@ -47,7 +47,7 @@ public SimpleChoice(final @NotNull Supplier> resolver) { public boolean equals(final @Nullable Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; - final SimpleChoice that = (SimpleChoice) o; + final SimpleInternalChoice that = (SimpleInternalChoice) o; return resolver.equals(that.resolver); } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java index 0e547fb7..0512078f 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java @@ -1,6 +1,7 @@ package dev.triumphteam.slash.example; import dev.triumphteam.cmd.slash.SlashCommandManager; +import dev.triumphteam.cmd.slash.choices.ChoiceKey; import dev.triumphteam.cmd.slash.sender.SlashSender; import dev.triumphteam.slash.example.commands.ExampleCommand; import dev.triumphteam.slash.example.commands.ExampleCommandGroup; @@ -8,6 +9,8 @@ import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; +import java.util.Arrays; + public class Example { public static void main(String[] args) throws InterruptedException { @@ -15,6 +18,8 @@ public static void main(String[] args) throws InterruptedException { final SlashCommandManager commandManager = SlashCommandManager.create(jda); + commandManager.registerChoices(ChoiceKey.of("hello"), () -> Arrays.asList("1", "2", "3", "4")); + // Registering commands commandManager.registerCommand(820696172477677628L, new ExampleCommand()); commandManager.registerCommand(820696172477677628L, new ExampleCommandGroup()); diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java index 507120f0..0deb7d94 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java @@ -1,7 +1,7 @@ package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; -import dev.triumphteam.cmd.core.annotations.Suggestion; +import dev.triumphteam.cmd.slash.annotation.Choice; import dev.triumphteam.cmd.slash.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.User; @@ -9,7 +9,7 @@ public class ExampleCommand { @Command - public void execute(final SlashCommandSender sender, @Suggestion("ass") final String name, final User user) { - sender.reply("OH SHIT, " + name + " OH FUCK " + user.getName() + " OH PISS!").queue(); + public void execute(final SlashCommandSender sender, @Choice("hello") final String name, final User user) { + sender.reply("Command sent was /example <" + name + "> <" + user.getName() + ">").queue(); } } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java index 1a874329..5e0a6dfe 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java @@ -12,12 +12,12 @@ public class Group { @Command("first") public void first(final SlashCommandSender sender) { - sender.reply("OH SHIT").queue(); + sender.reply("Command sent was /group test first").queue(); } @Command("second") public void second(final SlashCommandSender sender, final User user) { - sender.reply("OH SHIT, OH FUCK " + user.getName() + " OH PISS!").queue(); + sender.reply("Command sent was /group test second <" + user.getName() + ">").queue(); } } } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java index af84a957..18b936f9 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java @@ -9,11 +9,11 @@ public class ExampleSubCommand { @Command("first") public void first(final SlashCommandSender sender) { - sender.reply("OH PISS!").queue(); + sender.reply("Command sent was /sub first").queue(); } @Command("second") public void second(final SlashCommandSender sender, final User user) { - sender.reply("OH SHIT, " + user.getName() + " OH PISS!").queue(); + sender.reply("Command sent was /sub second <" + user.getName() + ">").queue(); } } From 704faa4662e9911f913784896a0ab57c401ad180 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 1 Feb 2023 20:00:25 -0600 Subject: [PATCH 082/101] feature: NSFW Commands for JDA and "finished" slash platform --- .../triumphteam/cmd/core/CommandManager.java | 8 +- .../cmd/core/extention/CommandOptions.java | 16 +-- ...iceProcessor.java => ChoiceProcessor.java} | 13 ++- .../triumphteam/cmd/slash/JdaMappingUtil.java | 11 +- .../triumphteam/cmd/slash/NsfwProcessor.java | 23 ++++ .../cmd/slash/SlashCommandManager.java | 110 ++++++++++++++---- .../cmd/slash/SlashCommandOptions.java | 35 +++++- .../cmd/slash/SlashCommandsListener.java | 25 ++++ .../cmd/slash/SuggestionCommandSender.java | 35 ++++++ .../cmd/slash/annotation/Choice.java | 6 +- .../cmd/slash/annotation/NSFW.java | 42 +++++++ .../cmd/slash/choices/ChoiceRegistry.java | 7 +- .../cmd/slash/sender/SlashCommandSender.java | 53 --------- .../cmd/slash/sender/SlashSender.java | 53 +++++++++ .../triumphteam/slash/example/Example.java | 3 +- .../example/commands/ExampleCommand.java | 2 + .../triumphteam/cmd/bukkit/BukkitCommand.java | 4 +- .../cmd/bukkit/BukkitCommandManager.java | 2 +- .../cmds/simple/SimpleCommandManager.java | 3 +- 19 files changed, 343 insertions(+), 108 deletions(-) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/{choices/InternalChoiceProcessor.java => ChoiceProcessor.java} (74%) create mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/NsfwProcessor.java create mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandsListener.java create mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/NSFW.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index a1afbabc..6cb0f2c9 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -51,11 +51,11 @@ * @param The default sender type. * @param The sender type. */ -public abstract class CommandManager { +public abstract class CommandManager> { - private final CommandOptions commandOptions; + private final O commandOptions; - public CommandManager(final @NotNull CommandOptions commandOptions) { + public CommandManager(final @NotNull O commandOptions) { this.commandOptions = commandOptions; } @@ -197,7 +197,7 @@ public final void registerRequirement( protected abstract @NotNull RegistryContainer getRegistryContainer(); - protected @NotNull CommandOptions getCommandOptions() { + protected @NotNull O getCommandOptions() { return commandOptions; } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java index 99c5d453..cc598a27 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java @@ -115,7 +115,7 @@ public Setup(final @NotNull RegistryContainer registryContainer) { } @Contract("_, _ -> new") - public I message( + public @NotNull I message( final @NotNull MessageKey messageKey, final @NotNull MessageResolver resolver ) { @@ -124,7 +124,7 @@ public I message( } @Contract("_, _ -> new") - public I argument( + public @NotNull I argument( final @NotNull Class type, final @NotNull ArgumentResolver resolver ) { @@ -133,7 +133,7 @@ public I argument( } @Contract("_, _ -> new") - public I suggestion( + public @NotNull I suggestion( final @NotNull Class type, final @NotNull SuggestionResolver resolver ) { @@ -142,7 +142,7 @@ public I suggestion( } @Contract("_, _ -> new") - public I suggestion( + public @NotNull I suggestion( final @NotNull SuggestionKey key, final @NotNull SuggestionResolver resolver ) { @@ -151,7 +151,7 @@ public I suggestion( } @Contract("_, _ -> new") - public I namedArguments( + public @NotNull I namedArguments( final @NotNull ArgumentKey key, final @NotNull List arguments ) { @@ -160,7 +160,7 @@ public I namedArguments( } @Contract("_, _ -> new") - public I namedArguments( + public @NotNull I namedArguments( final @NotNull ArgumentKey key, final @NotNull Argument @NotNull ... arguments ) { @@ -168,7 +168,7 @@ public I namedArguments( } @Contract("_, _ -> new") - public I flags( + public @NotNull I flags( final @NotNull FlagKey key, final @NotNull List flags ) { @@ -177,7 +177,7 @@ public I flags( } @Contract("_, _ -> new") - public I flags( + public @NotNull I flags( final @NotNull FlagKey key, final @NotNull Flag @NotNull ... flags ) { diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoiceProcessor.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ChoiceProcessor.java similarity index 74% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoiceProcessor.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ChoiceProcessor.java index aea599d0..2f8d1ede 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoiceProcessor.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ChoiceProcessor.java @@ -1,9 +1,14 @@ -package dev.triumphteam.cmd.slash.choices; +package dev.triumphteam.cmd.slash; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; import dev.triumphteam.cmd.slash.annotation.Choice; +import dev.triumphteam.cmd.slash.choices.ChoiceKey; +import dev.triumphteam.cmd.slash.choices.ChoiceRegistry; +import dev.triumphteam.cmd.slash.choices.EnumInternalChoice; +import dev.triumphteam.cmd.slash.choices.InternalChoice; +import dev.triumphteam.cmd.slash.choices.SimpleInternalChoice; import org.jetbrains.annotations.NotNull; import java.lang.reflect.AnnotatedElement; @@ -12,11 +17,11 @@ import java.util.function.Supplier; @SuppressWarnings("unchecked") -public class InternalChoiceProcessor implements AnnotationProcessor { +class ChoiceProcessor implements AnnotationProcessor { private final ChoiceRegistry choiceRegistry; - public InternalChoiceProcessor(final @NotNull ChoiceRegistry choiceRegistry) { + public ChoiceProcessor(final @NotNull ChoiceRegistry choiceRegistry) { this.choiceRegistry = choiceRegistry; } @@ -43,6 +48,6 @@ public void process( internalChoice = new SimpleInternalChoice(supplier); } - meta.add(Choice.CHOICE_META_KEY, internalChoice); + meta.add(Choice.META_KEY, internalChoice); } } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java index 90eefaa6..62d7ca32 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java @@ -31,6 +31,7 @@ import dev.triumphteam.cmd.core.command.SubCommand; import dev.triumphteam.cmd.core.util.Pair; import dev.triumphteam.cmd.slash.annotation.Choice; +import dev.triumphteam.cmd.slash.annotation.NSFW; import dev.triumphteam.cmd.slash.choices.InternalChoice; import dev.triumphteam.cmd.slash.sender.SlashSender; import net.dv8tion.jda.api.entities.IMentionable; @@ -85,12 +86,15 @@ private JdaMappingUtil() {} final String name = rootCommand.getName(); final String description = rootCommand.getDescription(); - final SlashCommandData commandData = Commands.slash(name, description.isEmpty() ? name : description); + final SlashCommandData commandData = Commands + .slash(name, description.isEmpty() ? name : description) + .setNSFW(rootCommand.getMeta().isPresent(NSFW.META_KEY)); final Command defaultCommand = rootCommand.getDefaultCommand(); if (defaultCommand != null) { // Safe to cast because only subcommands can be default final SubCommand subCommand = (SubCommand) defaultCommand; + return commandData.addOptions( subCommand.getArgumentList().stream().map(JdaMappingUtil::mapOption).collect(Collectors.toList()) ); @@ -140,7 +144,7 @@ private JdaMappingUtil() {} final String name = argument.getName(); final String description = argument.getDescription(); - final @NotNull Optional choice = argument.getMeta().get(Choice.CHOICE_META_KEY); + final @NotNull Optional choice = argument.getMeta().get(Choice.META_KEY); final boolean enableSuggestions; if (argument instanceof ProvidedInternalArgument || choice.isPresent()) { @@ -176,6 +180,8 @@ private static Map, OptionType> createTypeMap() { map.put(long.class, OptionType.INTEGER); map.put(Double.class, OptionType.NUMBER); map.put(double.class, OptionType.NUMBER); + map.put(Float.class, OptionType.NUMBER); + map.put(float.class, OptionType.NUMBER); map.put(Boolean.class, OptionType.BOOLEAN); map.put(boolean.class, OptionType.BOOLEAN); map.put(Role.class, OptionType.ROLE); @@ -184,6 +190,7 @@ private static Map, OptionType> createTypeMap() { map.put(TextChannel.class, OptionType.CHANNEL); map.put(MessageChannel.class, OptionType.CHANNEL); map.put(Message.Attachment.class, OptionType.ATTACHMENT); + map.put(IMentionable.class, OptionType.MENTIONABLE); return ImmutableMap.copyOf(map); } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/NsfwProcessor.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/NsfwProcessor.java new file mode 100644 index 00000000..1c11b56f --- /dev/null +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/NsfwProcessor.java @@ -0,0 +1,23 @@ +package dev.triumphteam.cmd.slash; + +import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; +import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.slash.annotation.NSFW; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.AnnotatedElement; + +class NsfwProcessor implements AnnotationProcessor { + + @Override + public void process( + final @NotNull NSFW annotation, + final @NotNull ProcessorTarget target, + final @NotNull AnnotatedElement element, + final CommandMeta.@NotNull Builder meta + ) { + if (target != ProcessorTarget.ROOT_COMMAND) return; + meta.add(NSFW.META_KEY, true); + } +} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java index 76cc1cfe..fe382506 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java @@ -31,6 +31,7 @@ import dev.triumphteam.cmd.core.command.SubCommand; import dev.triumphteam.cmd.core.extention.registry.MessageRegistry; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; +import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import dev.triumphteam.cmd.core.util.Pair; import dev.triumphteam.cmd.slash.choices.ChoiceKey; @@ -48,6 +49,7 @@ import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.AutoCompleteQuery; +import net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -72,7 +74,7 @@ * * @param The sender type. */ -public final class SlashCommandManager extends CommandManager { +public final class SlashCommandManager extends CommandManager> { private final JDA jda; @@ -92,6 +94,7 @@ public SlashCommandManager( // All use the same factory final InternalArgument.Factory jdaArgumentFactory = ProvidedInternalArgument::new; + registerArgument(User.class, jdaArgumentFactory); registerArgument(Role.class, jdaArgumentFactory); registerArgument(User.class, jdaArgumentFactory); @@ -101,6 +104,15 @@ public SlashCommandManager( registerArgument(MessageChannel.class, jdaArgumentFactory); registerArgument(Message.Attachment.class, jdaArgumentFactory); registerArgument(IMentionable.class, jdaArgumentFactory); + + if (commandOptions.autoRegisterListener()) { + try { + jda.awaitReady(); + jda.addEventListener(new SlashCommandsListener(this)); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } } @Contract("_, _, _ -> new") @@ -125,7 +137,7 @@ public SlashCommandManager( // Setup defaults for Bukkit final MessageRegistry messageRegistry = registryContainer.getMessageRegistry(); - // setUpDefaults(messageRegistry); + setUpDefaults(messageRegistry); // Then accept configured values builder.accept(extensionBuilder); @@ -142,16 +154,10 @@ public void registerChoices(final @NotNull ChoiceKey key, final @NotNull Supplie } public void execute(final @NotNull SlashCommandInteractionEvent event) { - final Guild guild = event.getGuild(); - if (guild == null) return; - - final String name = event.getName(); - final RootCommand command = guildCommands - .getOrDefault(guild.getIdLong(), Collections.emptyMap()) - .get(name); + final RootCommand command = getCommand(event, event.getName()); + if (command == null) return; final Deque commands = new ArrayDeque<>(Arrays.asList(event.getFullCommandName().split(" "))); - // Immediately pop the main command out, to remove itself from it commands.pop(); @@ -168,16 +174,10 @@ public void execute(final @NotNull SlashCommandInteractionEvent event) { } public void suggest(final @NotNull CommandAutoCompleteInteractionEvent event) { - final Guild guild = event.getGuild(); - if (guild == null) return; - - final String name = event.getName(); - final RootCommand command = guildCommands - .getOrDefault(guild.getIdLong(), Collections.emptyMap()) - .get(name); + final RootCommand command = getCommand(event, event.getName()); + if (command == null) return; final Deque commands = new ArrayDeque<>(Arrays.asList(event.getFullCommandName().split(" "))); - // Immediately pop the main command out, to remove itself from it commands.pop(); @@ -193,14 +193,50 @@ public void suggest(final @NotNull CommandAutoCompleteInteractionEvent event) { @Override public void registerCommand(final @NotNull Object command) { + final RootCommandProcessor processor = new RootCommandProcessor<>( + command, + getRegistryContainer(), + getCommandOptions() + ); + + final String name = processor.getName(); + // Get or add command, then add its sub commands + final RootCommand rootCommand = globalCommands + .computeIfAbsent(name, it -> new RootCommand<>(processor)); + + rootCommand.addCommands(command, processor.commands(rootCommand)); } - public void registerCommand(final Guild guild, final @NotNull Object command) { + public void registerCommand(final @NotNull Guild guild, final @NotNull List<@NotNull Object> commands) { + for (final Object command : commands) { + registerCommand(guild.getIdLong(), command); + } + } + + public void registerCommand(final @NotNull Guild guild, final @NotNull Object @NotNull ... commands) { + for (final Object command : commands) { + registerCommand(guild.getIdLong(), command); + } + } + + public void registerCommand(final @NotNull Guild guild, final @NotNull Object command) { registerCommand(guild.getIdLong(), command); } - public void registerCommand(final Long guildId, final @NotNull Object command) { + public void registerCommand(final @NotNull Long guildId, final @NotNull List<@NotNull Object> commands) { + for (final Object command : commands) { + registerCommand(guildId, command); + } + } + + public void registerCommand(final @NotNull Long guildId, final @NotNull Object @NotNull ... commands) { + for (final Object command : commands) { + registerCommand(guildId, command); + } + } + + public void registerCommand(final @NotNull Long guildId, final @NotNull Object command) { final RootCommandProcessor processor = new RootCommandProcessor<>( command, getRegistryContainer(), @@ -217,7 +253,7 @@ public void registerCommand(final Long guildId, final @NotNull Object command) { rootCommand.addCommands(command, processor.commands(rootCommand)); } - public void pushCommands() { + public void pushGuildCommands() { guildCommands.forEach((key, value) -> { final Guild guild = jda.getGuildById(key); if (guild == null) return; @@ -227,6 +263,17 @@ public void pushCommands() { }); } + public void pushGlobalCommands() { + jda.updateCommands() + .addCommands(globalCommands.values().stream().map(JdaMappingUtil::mapCommand).collect(Collectors.toList())) + .queue(); + } + + public void pushCommands() { + pushGlobalCommands(); + pushGuildCommands(); + } + @Override public void unregisterCommand(final @NotNull Object command) { @@ -237,6 +284,20 @@ public void unregisterCommand(final @NotNull Object command) { return registryContainer; } + private @Nullable RootCommand getCommand( + final @NotNull CommandInteractionPayload event, + final @NotNull String name + ) { + if (event.isGlobalCommand()) return globalCommands.get(name); + + final Guild guild = event.getGuild(); + // Should never be null here + if (guild == null) return null; + return guildCommands + .getOrDefault(guild.getIdLong(), Collections.emptyMap()) + .get(name); + } + private @Nullable SubCommand findExecutable( final @NotNull Deque commands, final @NotNull Command command @@ -257,4 +318,11 @@ public void unregisterCommand(final @NotNull Object command) { current = parentCommand.getCommand(commands.pop()); } } + + private static void setUpDefaults(final @NotNull MessageRegistry registry) { + registry.register(MessageKey.UNKNOWN_COMMAND, (sender, context) -> sender.reply("Unknown command: `" + context.getInvalidInput() + "`.").setEphemeral(true).queue()); + registry.register(MessageKey.TOO_MANY_ARGUMENTS, (sender, context) -> sender.reply("Invalid usage.").setEphemeral(true).queue()); + registry.register(MessageKey.NOT_ENOUGH_ARGUMENTS, (sender, context) -> sender.reply("Invalid usage.").setEphemeral(true).queue()); + registry.register(MessageKey.INVALID_ARGUMENT, (sender, context) -> sender.reply("Invalid argument `" + context.getInvalidInput() + "` for type `" + context.getArgumentType().getSimpleName() + "`.").setEphemeral(true).queue()); + } } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java index 98174bb1..12fc54ee 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java @@ -30,17 +30,28 @@ import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import dev.triumphteam.cmd.slash.annotation.Choice; -import dev.triumphteam.cmd.slash.choices.InternalChoiceProcessor; +import dev.triumphteam.cmd.slash.annotation.NSFW; import dev.triumphteam.cmd.slash.sender.SlashSender; +import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; public final class SlashCommandOptions extends CommandOptions { + private final boolean autoRegisterListener; + public SlashCommandOptions( final @NotNull SenderExtension senderExtension, - final @NotNull CommandExtensions commandExtensions + final @NotNull CommandExtensions commandExtensions, + final boolean autoRegisterListener ) { super(senderExtension, commandExtensions); + this.autoRegisterListener = autoRegisterListener; + } + + public boolean autoRegisterListener() { + return autoRegisterListener; } public static final class Setup extends CommandOptions.Setup> { @@ -51,6 +62,8 @@ public Setup(final @NotNull RegistryContainer registryContainer) public static final class Builder extends CommandOptions.Builder, Setup, Builder> { + private boolean autoRegisterListener = true; + public Builder(final @NotNull SlashRegistryContainer registryContainer) { super(new Setup<>(registryContainer)); @@ -58,13 +71,27 @@ public Builder(final @NotNull SlashRegistryContainer registryContainer) { extensions(extension -> { extension.setArgumentValidator(new DefaultArgumentValidator<>()); extension.setCommandExecutor(new DefaultCommandExecutor()); - extension.addAnnotationProcessor(Choice.class, new InternalChoiceProcessor(registryContainer.getChoiceRegistry())); + extension.addAnnotationProcessor(Choice.class, new ChoiceProcessor(registryContainer.getChoiceRegistry())); + extension.addAnnotationProcessor(NSFW.class, new NsfwProcessor()); }); } + /** + * Disables the auto registering of listeners, meaning you'll have to do your own listeners. + * Run command with {@link SlashCommandManager#execute(SlashCommandInteractionEvent)}. + * Run auto complete with {@link SlashCommandManager#suggest(CommandAutoCompleteInteractionEvent)}. + * + * @return This builder. + */ + @Contract(" -> this") + public @NotNull Builder disableAutoRegisterListener() { + autoRegisterListener = false; + return this; + } + @Override public @NotNull SlashCommandOptions build(final @NotNull SenderExtension senderExtension) { - return new SlashCommandOptions<>(senderExtension, getCommandExtensions()); + return new SlashCommandOptions<>(senderExtension, getCommandExtensions(), autoRegisterListener); } } } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandsListener.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandsListener.java new file mode 100644 index 00000000..0a2e5a96 --- /dev/null +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandsListener.java @@ -0,0 +1,25 @@ +package dev.triumphteam.cmd.slash; + +import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; +import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; +import net.dv8tion.jda.api.hooks.ListenerAdapter; +import org.jetbrains.annotations.NotNull; + +class SlashCommandsListener extends ListenerAdapter { + + private final SlashCommandManager commandManager; + + public SlashCommandsListener(final @NotNull SlashCommandManager commandManager) { + this.commandManager = commandManager; + } + + @Override + public void onSlashCommandInteraction(@NotNull final SlashCommandInteractionEvent event) { + commandManager.execute(event); + } + + @Override + public void onCommandAutoCompleteInteraction(@NotNull final CommandAutoCompleteInteractionEvent event) { + commandManager.suggest(event); + } +} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java index 02b9bff7..8dd6853d 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java @@ -26,12 +26,17 @@ import dev.triumphteam.cmd.slash.sender.SlashSender; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; +import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; + final class SuggestionCommandSender implements SlashSender { private final CommandAutoCompleteInteractionEvent event; @@ -71,4 +76,34 @@ public SuggestionCommandSender(final @NotNull CommandAutoCompleteInteractionEven public @Nullable Member getMember() { return event.getMember(); } + + @Override + public @NotNull ReplyCallbackAction reply(final @NotNull String message) { + throw new UnsupportedOperationException(); + } + + @Override + public @NotNull ReplyCallbackAction reply(final @NotNull MessageCreateData message) { + throw new UnsupportedOperationException(); + } + + @Override + public @NotNull ReplyCallbackAction reply(final @NotNull MessageEmbed embed, final @NotNull MessageEmbed @NotNull ... embeds) { + throw new UnsupportedOperationException(); + } + + @Override + public @NotNull ReplyCallbackAction reply(final @NotNull Collection embeds) { + throw new UnsupportedOperationException(); + } + + @Override + public @NotNull ReplyCallbackAction deferReply() { + throw new UnsupportedOperationException(); + } + + @Override + public @NotNull ReplyCallbackAction deferReply(final boolean ephemeral) { + throw new UnsupportedOperationException(); + } } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java index b066ad28..c551a273 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java @@ -26,16 +26,20 @@ import dev.triumphteam.cmd.core.extention.meta.MetaKey; import dev.triumphteam.cmd.slash.choices.InternalChoice; +import java.lang.annotation.Documented; import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +@Documented @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) +@Inherited public @interface Choice { String value(); - MetaKey CHOICE_META_KEY = MetaKey.of("choice", InternalChoice.class); + MetaKey META_KEY = MetaKey.of("choice", InternalChoice.class); } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/NSFW.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/NSFW.java new file mode 100644 index 00000000..168c438c --- /dev/null +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/NSFW.java @@ -0,0 +1,42 @@ +/** + * MIT License + *

    + * Copyright (c) 2019-2021 Matt + *

    + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

    + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

    + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.slash.annotation; + +import dev.triumphteam.cmd.core.extention.meta.MetaKey; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +@Inherited +public @interface NSFW { + + MetaKey META_KEY = MetaKey.of("nsfw", Boolean.class); +} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java index 4f68072a..423e562a 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java @@ -33,14 +33,13 @@ public final class ChoiceRegistry { - private final Map>> suggestions = new HashMap<>(); + private final Map>> choices = new HashMap<>(); public void register(final @NotNull ChoiceKey key, final @NotNull Supplier> resolver) { - suggestions.put(key, resolver); + choices.put(key, resolver); } public @Nullable Supplier> getChoiceResolver(final @NotNull ChoiceKey key) { - return suggestions.get(key); + return choices.get(key); } - } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java index 6b181072..c29b37f8 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java @@ -23,16 +23,11 @@ */ package dev.triumphteam.cmd.slash.sender; -import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.interactions.InteractionHook; -import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; -import net.dv8tion.jda.api.utils.messages.MessageCreateData; import org.jetbrains.annotations.NotNull; -import java.util.Collection; - /** * Works like a shortcut for most things present on {@link SlashCommandInteractionEvent}. * Contains the more useful methods from it, but still allows you to get the original event if more is needed. @@ -55,52 +50,4 @@ public interface SlashCommandSender extends SlashSender { * @return The interaction hook. */ @NotNull InteractionHook getHook(); - - /** - * Replies to the command with a string message. - * - * @param message The message to reply with. - * @return The reply action. - */ - @NotNull ReplyCallbackAction reply(final @NotNull String message); - - /** - * Replies to the command with a message. - * - * @param message The message to reply with. - * @return The reply action. - */ - @NotNull ReplyCallbackAction reply(final @NotNull MessageCreateData message); - - /** - * Replies to the command with a message embed. - * - * @param embed The embed to reply with. - * @param embeds The additional embeds. - * @return The reply action. - */ - @NotNull ReplyCallbackAction reply(final @NotNull MessageEmbed embed, final @NotNull MessageEmbed @NotNull ... embeds); - - /** - * Replies to the command with a message embeds. - * - * @param embeds The embeds to reply with. - * @return The reply action. - */ - @NotNull ReplyCallbackAction reply(final @NotNull Collection embeds); - - /** - * Defers the reply to the command. - * - * @return The reply action. - */ - @NotNull ReplyCallbackAction deferReply(); - - /** - * Defers the reply to the command but ephemeral. - * - * @param ephemeral Whether the message should be ephemeral. - * @return The reply action. - */ - @NotNull ReplyCallbackAction deferReply(final boolean ephemeral); } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java index 0c035357..6ecfe160 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java @@ -25,11 +25,16 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.MessageEmbed; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion; +import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; +import net.dv8tion.jda.api.utils.messages.MessageCreateData; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collection; + /** * Simpler sender, used for suggestions and commands. */ @@ -62,4 +67,52 @@ public interface SlashSender { * @return The member. */ @Nullable Member getMember(); + + /** + * Replies to the command with a string message. + * + * @param message The message to reply with. + * @return The reply action. + */ + @NotNull ReplyCallbackAction reply(final @NotNull String message); + + /** + * Replies to the command with a message. + * + * @param message The message to reply with. + * @return The reply action. + */ + @NotNull ReplyCallbackAction reply(final @NotNull MessageCreateData message); + + /** + * Replies to the command with a message embed. + * + * @param embed The embed to reply with. + * @param embeds The additional embeds. + * @return The reply action. + */ + @NotNull ReplyCallbackAction reply(final @NotNull MessageEmbed embed, final @NotNull MessageEmbed @NotNull ... embeds); + + /** + * Replies to the command with a message embeds. + * + * @param embeds The embeds to reply with. + * @return The reply action. + */ + @NotNull ReplyCallbackAction reply(final @NotNull Collection embeds); + + /** + * Defers the reply to the command. + * + * @return The reply action. + */ + @NotNull ReplyCallbackAction deferReply(); + + /** + * Defers the reply to the command but ephemeral. + * + * @param ephemeral Whether the message should be ephemeral. + * @return The reply action. + */ + @NotNull ReplyCallbackAction deferReply(final boolean ephemeral); } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java index 0512078f..ece7b8d6 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java @@ -1,6 +1,7 @@ package dev.triumphteam.slash.example; import dev.triumphteam.cmd.slash.SlashCommandManager; +import dev.triumphteam.cmd.slash.SlashCommandOptions; import dev.triumphteam.cmd.slash.choices.ChoiceKey; import dev.triumphteam.cmd.slash.sender.SlashSender; import dev.triumphteam.slash.example.commands.ExampleCommand; @@ -16,7 +17,7 @@ public class Example { public static void main(String[] args) throws InterruptedException { final JDA jda = JDABuilder.createDefault(args[0]).build().awaitReady(); - final SlashCommandManager commandManager = SlashCommandManager.create(jda); + final SlashCommandManager commandManager = SlashCommandManager.create(jda, SlashCommandOptions.Builder::disableAutoRegisterListener); commandManager.registerChoices(ChoiceKey.of("hello"), () -> Arrays.asList("1", "2", "3", "4")); diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java index 0deb7d94..be8c61cb 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java @@ -2,9 +2,11 @@ import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.slash.annotation.Choice; +import dev.triumphteam.cmd.slash.annotation.NSFW; import dev.triumphteam.cmd.slash.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.User; +@NSFW @Command("example") public class ExampleCommand { diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index f2594db6..2b230ea8 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -32,7 +32,6 @@ import java.util.ArrayDeque; import java.util.Arrays; -import java.util.Collections; import java.util.List; final class BukkitCommand extends Command { @@ -56,8 +55,7 @@ public boolean execute( rootCommand.execute( senderExtension.map(sender), null, - new ArrayDeque<>(Arrays.asList(args)), - Collections.emptyMap() + new ArrayDeque<>(Arrays.asList(args)) ); return true; } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java index c2cb6ed0..98c22f9a 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandManager.java @@ -52,7 +52,7 @@ import java.util.function.Consumer; import java.util.stream.Collectors; -public final class BukkitCommandManager extends CommandManager { +public final class BukkitCommandManager extends CommandManager> { private final Plugin plugin; private final RegistryContainer registryContainer; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index 644791d7..e4e513e0 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -36,7 +36,6 @@ import org.jetbrains.annotations.NotNull; import java.util.ArrayDeque; -import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -116,6 +115,6 @@ public void executeCommand(final @NotNull S sender, final @NotNull List return; } - command.execute(sender, null, new ArrayDeque<>(args.subList(1, args.size())), Collections.emptyMap()); + command.execute(sender, null, new ArrayDeque<>(args.subList(1, args.size()))); } } From 936fdeef5ab167143b2b8a8d2e19ea6ea9ca7206 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 1 Feb 2023 20:02:49 -0600 Subject: [PATCH 083/101] chore: Bump version and fix compile issue --- gradle.properties | 2 +- .../triumphteam/cmds/simple/SimpleCommandManager.java | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index e6397c60..3a8424df 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ kotlin.stdlib.default.dependency=false -version=2.0.0-ALPHA-2 +version=2.0.0-ALPHA-3 group=dev.triumphteam diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index e4e513e0..bc7e1ab6 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -41,7 +41,7 @@ import java.util.Map; import java.util.function.Consumer; -public final class SimpleCommandManager extends CommandManager { +public final class SimpleCommandManager extends CommandManager> { private final Map> commands = new HashMap<>(); From c6f11d6accc3fe6bb9849a745150f549ef4d8cc5 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 1 Feb 2023 20:16:53 -0600 Subject: [PATCH 084/101] feature: Suggest lower case enum option --- .../argument/AbstractInternalArgument.java | 2 +- .../cmd/core/extention/CommandOptions.java | 31 +++++++++++++------ .../processor/AbstractCommandProcessor.java | 4 ++- .../cmd/core/suggestion/EnumSuggestion.java | 18 +++++++---- .../cmd/slash/SlashCommandOptions.java | 10 +++--- .../cmd/bukkit/BukkitCommandOptions.java | 7 ++--- .../cmds/simple/SimpleOptionsBuilder.java | 2 +- 7 files changed, 45 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java index 25ba958d..e006e9b0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java @@ -71,7 +71,7 @@ public AbstractInternalArgument( final @NotNull Deque arguments ) { final String current = arguments.peekLast(); - return getSuggestion().getSuggestions(sender, current == null ? "" : current, new ArrayList<>(arguments)); + return suggestion.getSuggestions(sender, current == null ? "" : current, new ArrayList<>(arguments)); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java index cc598a27..c3a1c21c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -52,13 +52,15 @@ public class CommandOptions { private final CommandExtensions commandExtensions; private final SenderExtension senderExtension; + private final boolean suggestLowercaseEnum; public CommandOptions( final @NotNull SenderExtension senderExtension, - final @NotNull CommandExtensions commandExtensions + final @NotNull Builder builder ) { this.senderExtension = senderExtension; - this.commandExtensions = commandExtensions; + this.commandExtensions = builder.extensionBuilder.build(); + this.suggestLowercaseEnum = builder.suggestLowercaseEnum; } public @NotNull CommandExtensions getCommandExtensions() { @@ -69,8 +71,13 @@ public CommandOptions( return senderExtension; } + public boolean suggestLowercaseEnum() { + return suggestLowercaseEnum; + } + public static abstract class Builder, I extends Setup, B extends Builder> { + private boolean suggestLowercaseEnum = false; private final ExtensionBuilder extensionBuilder = new ExtensionBuilder<>(); private final I setup; @@ -78,21 +85,25 @@ public Builder(final @NotNull I setup) { this.setup = setup; } + @Contract("_ -> this") public @NotNull B setup(final @NotNull Consumer consumer) { consumer.accept(setup); return (B) this; } + @Contract("_ -> this") public @NotNull B extensions(final @NotNull Consumer> consumer) { consumer.accept(extensionBuilder); return (B) this; } - public abstract @NotNull O build(final @NotNull SenderExtension senderExtension); - - protected @NotNull CommandExtensions getCommandExtensions() { - return extensionBuilder.build(); + @Contract(" -> this") + public @NotNull B suggestLowercaseEnum() { + this.suggestLowercaseEnum = true; + return (B) this; } + + public abstract @NotNull O build(final @NotNull SenderExtension senderExtension); } public static abstract class Setup> { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 0b7230f2..1c2e3035 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -478,7 +478,9 @@ private Map> createNamedArgumentInternals( protected @NotNull Suggestion createSuggestion(final @Nullable SuggestionKey suggestionKey, final @NotNull Class type) { if (suggestionKey == null || suggestionKey.getKey().isEmpty()) { - if (Enum.class.isAssignableFrom(type)) return new EnumSuggestion<>((Class>) type); + if (Enum.class.isAssignableFrom(type)) { + return new EnumSuggestion<>((Class>) type, commandOptions.suggestLowercaseEnum()); + } final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(type); if (resolver != null) return new SimpleSuggestion<>(resolver); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java index 6c90aad4..3dd9163c 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -34,9 +34,14 @@ public final class EnumSuggestion implements Suggestion { private final Class> enumType; + private final boolean suggestLowercase; - public EnumSuggestion(final @NotNull Class> enumType) { + public EnumSuggestion( + final @NotNull Class> enumType, + final boolean suggestLowercase + ) { this.enumType = enumType; + this.suggestLowercase = suggestLowercase; EnumUtils.populateCache(enumType); } @@ -53,7 +58,8 @@ public EnumSuggestion(final @NotNull Class> enumType) { .map(it -> { final Enum constant = it.get(); if (constant == null) return null; - return constant.name(); + final String name = constant.name(); + return suggestLowercase ? name.toLowerCase() : name; }) .filter(Objects::nonNull) .filter(it -> it.toLowerCase().startsWith(current.toLowerCase())) diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java index 12fc54ee..9c089f7c 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java @@ -23,7 +23,6 @@ */ package dev.triumphteam.cmd.slash; -import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; @@ -43,11 +42,10 @@ public final class SlashCommandOptions extends CommandOptions public SlashCommandOptions( final @NotNull SenderExtension senderExtension, - final @NotNull CommandExtensions commandExtensions, - final boolean autoRegisterListener + final @NotNull Builder builder ) { - super(senderExtension, commandExtensions); - this.autoRegisterListener = autoRegisterListener; + super(senderExtension, builder); + this.autoRegisterListener = builder.autoRegisterListener; } public boolean autoRegisterListener() { @@ -91,7 +89,7 @@ public Builder(final @NotNull SlashRegistryContainer registryContainer) { @Override public @NotNull SlashCommandOptions build(final @NotNull SenderExtension senderExtension) { - return new SlashCommandOptions<>(senderExtension, getCommandExtensions(), autoRegisterListener); + return new SlashCommandOptions<>(senderExtension, this); } } } diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java index f3d1e0ab..ac0d6f80 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommandOptions.java @@ -23,7 +23,6 @@ */ package dev.triumphteam.cmd.bukkit; -import dev.triumphteam.cmd.core.extention.CommandExtensions; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; @@ -39,9 +38,9 @@ public final class BukkitCommandOptions extends CommandOptions senderExtension, - final @NotNull CommandExtensions commandExtensions + final @NotNull Builder builder ) { - super(senderExtension, commandExtensions); + super(senderExtension, builder); } public static final class Setup extends CommandOptions.Setup> { @@ -96,7 +95,7 @@ public Builder setGlobalPermission( // Add permissions extensions(extension -> extension.addProcessor(new PermissionProcessor<>(globalPermission))); - return new BukkitCommandOptions<>(senderExtension, getCommandExtensions()); + return new BukkitCommandOptions<>(senderExtension, this); } } } diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java index f1fdb211..b070bc0f 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleOptionsBuilder.java @@ -43,6 +43,6 @@ public SimpleOptionsBuilder(final @NotNull RegistryContainer registryConta @Override public @NotNull CommandOptions build(final @NotNull SenderExtension senderExtension) { - return new CommandOptions<>(senderExtension, getCommandExtensions()); + return new CommandOptions<>(senderExtension, this); } } From 306da17c872ebd4e78d8527156e760dca3b5a224 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 1 Feb 2023 20:21:10 -0600 Subject: [PATCH 085/101] chore: License format --- .../argument/AbstractInternalArgument.java | 8 +++---- .../cmd/core/argument/InternalArgument.java | 8 +++---- .../triumphteam/cmd/core/command/Command.java | 8 +++---- .../cmd/core/command/ParentSubCommand.java | 8 +++---- .../cmd/core/command/RootCommand.java | 8 +++---- .../cmd/core/command/SubCommand.java | 8 +++---- .../cmd/core/extention/CommandOptions.java | 8 +++---- .../extention/registry/ArgumentRegistry.java | 8 +++---- .../processor/AbstractCommandProcessor.java | 8 +++---- .../cmd/core/suggestion/EnumSuggestion.java | 8 +++---- .../cmd/slash/ChoiceProcessor.java | 23 +++++++++++++++++++ .../cmd/slash/InteractionCommandSender.java | 8 +++---- .../triumphteam/cmd/slash/JdaMappingUtil.java | 8 +++---- .../triumphteam/cmd/slash/NsfwProcessor.java | 23 +++++++++++++++++++ .../cmd/slash/ProvidedInternalArgument.java | 23 +++++++++++++++++++ .../cmd/slash/SlashCommandManager.java | 8 +++---- .../cmd/slash/SlashCommandOptions.java | 8 +++---- .../cmd/slash/SlashCommandsListener.java | 23 +++++++++++++++++++ .../cmd/slash/SlashRegistryContainer.java | 8 +++---- .../cmd/slash/SlashSenderExtension.java | 8 +++---- .../cmd/slash/SuggestionCommandSender.java | 8 +++---- .../cmd/slash/annotation/Choice.java | 8 +++---- .../cmd/slash/annotation/NSFW.java | 8 +++---- .../cmd/slash/choices/ChoiceKey.java | 8 +++---- .../cmd/slash/choices/ChoiceRegistry.java | 8 +++---- .../cmd/slash/choices/EnumInternalChoice.java | 8 +++---- .../cmd/slash/choices/InternalChoice.java | 8 +++---- .../slash/choices/SimpleInternalChoice.java | 8 +++---- .../cmd/slash/sender/SlashCommandSender.java | 8 +++---- .../cmd/slash/sender/SlashSender.java | 8 +++---- .../triumphteam/slash/example/Example.java | 23 +++++++++++++++++++ .../triumphteam/slash/example/Listener.java | 23 +++++++++++++++++++ .../example/commands/ExampleCommand.java | 23 +++++++++++++++++++ .../example/commands/ExampleCommandGroup.java | 23 +++++++++++++++++++ .../example/commands/ExampleSubCommand.java | 23 +++++++++++++++++++ .../cmds/simple/SimpleCommandManager.java | 8 +++---- 36 files changed, 315 insertions(+), 108 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java index e006e9b0..f55860eb 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/AbstractInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java index 33e80a92..002ee8f0 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/InternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index 86092436..f1b22049 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index dc870828..831ea6f6 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java index 6db7f8e7..21afe0fe 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 6026dcab..6b281bcd 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java index c3a1c21c..565964fa 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/ArgumentRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/ArgumentRegistry.java index 6225cdd9..899f90ff 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/ArgumentRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/registry/ArgumentRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 1c2e3035..1412d791 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java index 3dd9163c..333752c5 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/EnumSuggestion.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ChoiceProcessor.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ChoiceProcessor.java index 2f8d1ede..8672c8ea 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ChoiceProcessor.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ChoiceProcessor.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.slash; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/InteractionCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/InteractionCommandSender.java index 6194f25d..feca9b23 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/InteractionCommandSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/InteractionCommandSender.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java index 62d7ca32..26fd2c4c 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/NsfwProcessor.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/NsfwProcessor.java index 1c11b56f..2ea22c5e 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/NsfwProcessor.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/NsfwProcessor.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.slash; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java index 106d5e82..86e3aa2e 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.slash; import dev.triumphteam.cmd.core.argument.StringInternalArgument; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java index fe382506..0b438719 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java index 9c089f7c..88f40483 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandsListener.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandsListener.java index 0a2e5a96..cc226017 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandsListener.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandsListener.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmd.slash; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java index a5f47419..44fbd3cb 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java index 78a36192..93f41e88 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java index 8dd6853d..3aa9381d 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java index c551a273..666de17e 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/NSFW.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/NSFW.java index 168c438c..9e858fc2 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/NSFW.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/NSFW.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java index fafddc5a..d22dd45d 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java index 423e562a..3704a8f7 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumInternalChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumInternalChoice.java index 982788d6..60b4e99b 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumInternalChoice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumInternalChoice.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoice.java index dcd264f1..a556443b 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoice.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleInternalChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleInternalChoice.java index 343c6524..92f6f769 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleInternalChoice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleInternalChoice.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java index c29b37f8..92937a01 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java index 6ecfe160..f1fb6154 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java index ece7b8d6..4bab88f0 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.slash.example; import dev.triumphteam.cmd.slash.SlashCommandManager; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java index 7bb384ee..c476a5b9 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.slash.example; import dev.triumphteam.cmd.slash.SlashCommandManager; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java index be8c61cb..96a6a793 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java index 5e0a6dfe..a9ff5071 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java index 18b936f9..0a2c0fa9 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; diff --git a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java index bc7e1ab6..a3c40cc6 100644 --- a/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java +++ b/simple/src/main/java/dev/triumphteam/cmds/simple/SimpleCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE From 18d4a6f4a69463bcd54f4f14b6c4e34247ef0651 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 1 Feb 2023 20:46:02 -0600 Subject: [PATCH 086/101] chore: Renamed jda slash packages --- .../cmd/{slash => jda}/ChoiceProcessor.java | 14 +++++++------- .../{slash => jda}/InteractionCommandSender.java | 4 ++-- .../cmd/{slash => jda}/JdaMappingUtil.java | 10 +++++----- .../cmd/{slash => jda}/NsfwProcessor.java | 4 ++-- .../{slash => jda}/ProvidedInternalArgument.java | 2 +- .../cmd/{slash => jda}/SlashCommandManager.java | 6 +++--- .../cmd/{slash => jda}/SlashCommandOptions.java | 8 ++++---- .../cmd/{slash => jda}/SlashCommandsListener.java | 2 +- .../cmd/{slash => jda}/SlashRegistryContainer.java | 6 +++--- .../cmd/{slash => jda}/SlashSenderExtension.java | 6 +++--- .../{slash => jda}/SuggestionCommandSender.java | 4 ++-- .../cmd/{slash => jda}/annotation/Choice.java | 4 ++-- .../cmd/{slash => jda}/annotation/NSFW.java | 2 +- .../cmd/{slash => jda}/choices/ChoiceKey.java | 2 +- .../cmd/{slash => jda}/choices/ChoiceRegistry.java | 2 +- .../{slash => jda}/choices/EnumInternalChoice.java | 2 +- .../cmd/{slash => jda}/choices/InternalChoice.java | 2 +- .../choices/SimpleInternalChoice.java | 2 +- .../{slash => jda}/sender/SlashCommandSender.java | 2 +- .../cmd/{slash => jda}/sender/SlashSender.java | 2 +- .../dev/triumphteam/slash/example/Example.java | 8 ++++---- .../dev/triumphteam/slash/example/Listener.java | 4 ++-- .../slash/example/commands/ExampleCommand.java | 6 +++--- .../example/commands/ExampleCommandGroup.java | 2 +- .../slash/example/commands/ExampleSubCommand.java | 2 +- 25 files changed, 54 insertions(+), 54 deletions(-) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/ChoiceProcessor.java (87%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/InteractionCommandSender.java (97%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/JdaMappingUtil.java (97%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/NsfwProcessor.java (95%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/ProvidedInternalArgument.java (98%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/SlashCommandManager.java (99%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/SlashCommandOptions.java (95%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/SlashCommandsListener.java (98%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/SlashRegistryContainer.java (91%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/SlashSenderExtension.java (91%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/SuggestionCommandSender.java (97%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/annotation/Choice.java (94%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/annotation/NSFW.java (97%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/choices/ChoiceKey.java (98%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/choices/ChoiceRegistry.java (97%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/choices/EnumInternalChoice.java (98%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/choices/InternalChoice.java (96%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/choices/SimpleInternalChoice.java (98%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/sender/SlashCommandSender.java (97%) rename discord/jda/slash/src/main/java/dev/triumphteam/cmd/{slash => jda}/sender/SlashSender.java (98%) diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ChoiceProcessor.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ChoiceProcessor.java similarity index 87% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ChoiceProcessor.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ChoiceProcessor.java index 8672c8ea..8f9ca197 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ChoiceProcessor.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ChoiceProcessor.java @@ -21,17 +21,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash; +package dev.triumphteam.cmd.jda; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; -import dev.triumphteam.cmd.slash.annotation.Choice; -import dev.triumphteam.cmd.slash.choices.ChoiceKey; -import dev.triumphteam.cmd.slash.choices.ChoiceRegistry; -import dev.triumphteam.cmd.slash.choices.EnumInternalChoice; -import dev.triumphteam.cmd.slash.choices.InternalChoice; -import dev.triumphteam.cmd.slash.choices.SimpleInternalChoice; +import dev.triumphteam.cmd.jda.annotation.Choice; +import dev.triumphteam.cmd.jda.choices.ChoiceKey; +import dev.triumphteam.cmd.jda.choices.ChoiceRegistry; +import dev.triumphteam.cmd.jda.choices.EnumInternalChoice; +import dev.triumphteam.cmd.jda.choices.InternalChoice; +import dev.triumphteam.cmd.jda.choices.SimpleInternalChoice; import org.jetbrains.annotations.NotNull; import java.lang.reflect.AnnotatedElement; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/InteractionCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/InteractionCommandSender.java similarity index 97% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/InteractionCommandSender.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/InteractionCommandSender.java index feca9b23..84fbf308 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/InteractionCommandSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/InteractionCommandSender.java @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash; +package dev.triumphteam.cmd.jda; -import dev.triumphteam.cmd.slash.sender.SlashCommandSender; +import dev.triumphteam.cmd.jda.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.MessageEmbed; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/JdaMappingUtil.java similarity index 97% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/JdaMappingUtil.java index 26fd2c4c..11e370d1 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/JdaMappingUtil.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/JdaMappingUtil.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash; +package dev.triumphteam.cmd.jda; import com.google.common.collect.ImmutableMap; import dev.triumphteam.cmd.core.argument.InternalArgument; @@ -30,10 +30,10 @@ import dev.triumphteam.cmd.core.command.RootCommand; import dev.triumphteam.cmd.core.command.SubCommand; import dev.triumphteam.cmd.core.util.Pair; -import dev.triumphteam.cmd.slash.annotation.Choice; -import dev.triumphteam.cmd.slash.annotation.NSFW; -import dev.triumphteam.cmd.slash.choices.InternalChoice; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.jda.annotation.Choice; +import dev.triumphteam.cmd.jda.annotation.NSFW; +import dev.triumphteam.cmd.jda.choices.InternalChoice; +import dev.triumphteam.cmd.jda.sender.SlashSender; import net.dv8tion.jda.api.entities.IMentionable; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/NsfwProcessor.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/NsfwProcessor.java similarity index 95% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/NsfwProcessor.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/NsfwProcessor.java index 2ea22c5e..aea821f4 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/NsfwProcessor.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/NsfwProcessor.java @@ -21,12 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash; +package dev.triumphteam.cmd.jda; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; -import dev.triumphteam.cmd.slash.annotation.NSFW; +import dev.triumphteam.cmd.jda.annotation.NSFW; import org.jetbrains.annotations.NotNull; import java.lang.reflect.AnnotatedElement; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedInternalArgument.java similarity index 98% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedInternalArgument.java index 86e3aa2e..b138a565 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/ProvidedInternalArgument.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash; +package dev.triumphteam.cmd.jda; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.extention.Result; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java similarity index 99% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java index 0b438719..9d5f1d07 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandManager.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash; +package dev.triumphteam.cmd.jda; import dev.triumphteam.cmd.core.CommandManager; import dev.triumphteam.cmd.core.argument.InternalArgument; @@ -34,8 +34,8 @@ import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import dev.triumphteam.cmd.core.util.Pair; -import dev.triumphteam.cmd.slash.choices.ChoiceKey; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.jda.choices.ChoiceKey; +import dev.triumphteam.cmd.jda.sender.SlashSender; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.IMentionable; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandOptions.java similarity index 95% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandOptions.java index 88f40483..08258511 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandOptions.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandOptions.java @@ -21,16 +21,16 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash; +package dev.triumphteam.cmd.jda; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; -import dev.triumphteam.cmd.slash.annotation.Choice; -import dev.triumphteam.cmd.slash.annotation.NSFW; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.jda.annotation.Choice; +import dev.triumphteam.cmd.jda.annotation.NSFW; +import dev.triumphteam.cmd.jda.sender.SlashSender; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import org.jetbrains.annotations.Contract; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandsListener.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandsListener.java similarity index 98% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandsListener.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandsListener.java index cc226017..f08adb1c 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashCommandsListener.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandsListener.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash; +package dev.triumphteam.cmd.jda; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashRegistryContainer.java similarity index 91% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashRegistryContainer.java index 44fbd3cb..47505f83 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashRegistryContainer.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashRegistryContainer.java @@ -21,11 +21,11 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash; +package dev.triumphteam.cmd.jda; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import dev.triumphteam.cmd.slash.choices.ChoiceRegistry; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.jda.choices.ChoiceRegistry; +import dev.triumphteam.cmd.jda.sender.SlashSender; import org.jetbrains.annotations.NotNull; // TODO: Comments diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashSenderExtension.java similarity index 91% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashSenderExtension.java index 93f41e88..d7255b3f 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SlashSenderExtension.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashSenderExtension.java @@ -21,12 +21,12 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash; +package dev.triumphteam.cmd.jda; import com.google.common.collect.ImmutableSet; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; -import dev.triumphteam.cmd.slash.sender.SlashCommandSender; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.jda.sender.SlashCommandSender; +import dev.triumphteam.cmd.jda.sender.SlashSender; import org.jetbrains.annotations.NotNull; import java.util.Set; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SuggestionCommandSender.java similarity index 97% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SuggestionCommandSender.java index 3aa9381d..95fc8e9b 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/SuggestionCommandSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SuggestionCommandSender.java @@ -21,9 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash; +package dev.triumphteam.cmd.jda; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.jda.sender.SlashSender; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.MessageEmbed; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/Choice.java similarity index 94% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/Choice.java index 666de17e..32c6035d 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/Choice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/Choice.java @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash.annotation; +package dev.triumphteam.cmd.jda.annotation; import dev.triumphteam.cmd.core.extention.meta.MetaKey; -import dev.triumphteam.cmd.slash.choices.InternalChoice; +import dev.triumphteam.cmd.jda.choices.InternalChoice; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/NSFW.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/NSFW.java similarity index 97% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/NSFW.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/NSFW.java index 9e858fc2..3eda26c3 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/annotation/NSFW.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/NSFW.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash.annotation; +package dev.triumphteam.cmd.jda.annotation; import dev.triumphteam.cmd.core.extention.meta.MetaKey; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceKey.java similarity index 98% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceKey.java index d22dd45d..5af6c700 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceKey.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceKey.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash.choices; +package dev.triumphteam.cmd.jda.choices; import dev.triumphteam.cmd.core.extention.StringKey; import org.jetbrains.annotations.Contract; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceRegistry.java similarity index 97% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceRegistry.java index 3704a8f7..49daaab9 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/ChoiceRegistry.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceRegistry.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash.choices; +package dev.triumphteam.cmd.jda.choices; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumInternalChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/EnumInternalChoice.java similarity index 98% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumInternalChoice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/EnumInternalChoice.java index 60b4e99b..08972e44 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/EnumInternalChoice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/EnumInternalChoice.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash.choices; +package dev.triumphteam.cmd.jda.choices; import dev.triumphteam.cmd.core.util.EnumUtils; import org.jetbrains.annotations.NotNull; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/InternalChoice.java similarity index 96% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/InternalChoice.java index a556443b..ea43d3b4 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/InternalChoice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/InternalChoice.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash.choices; +package dev.triumphteam.cmd.jda.choices; import org.jetbrains.annotations.NotNull; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleInternalChoice.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/SimpleInternalChoice.java similarity index 98% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleInternalChoice.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/SimpleInternalChoice.java index 92f6f769..8cc78fa2 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/choices/SimpleInternalChoice.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/SimpleInternalChoice.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash.choices; +package dev.triumphteam.cmd.jda.choices; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/sender/SlashCommandSender.java similarity index 97% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/sender/SlashCommandSender.java index 92937a01..3329b6c4 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashCommandSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/sender/SlashCommandSender.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash.sender; +package dev.triumphteam.cmd.jda.sender; import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/sender/SlashSender.java similarity index 98% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java rename to discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/sender/SlashSender.java index f1fb6154..cff68ecc 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/slash/sender/SlashSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/sender/SlashSender.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.slash.sender; +package dev.triumphteam.cmd.jda.sender; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java index 4bab88f0..b77222f4 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java @@ -23,10 +23,10 @@ */ package dev.triumphteam.slash.example; -import dev.triumphteam.cmd.slash.SlashCommandManager; -import dev.triumphteam.cmd.slash.SlashCommandOptions; -import dev.triumphteam.cmd.slash.choices.ChoiceKey; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.jda.SlashCommandManager; +import dev.triumphteam.cmd.jda.SlashCommandOptions; +import dev.triumphteam.cmd.jda.choices.ChoiceKey; +import dev.triumphteam.cmd.jda.sender.SlashSender; import dev.triumphteam.slash.example.commands.ExampleCommand; import dev.triumphteam.slash.example.commands.ExampleCommandGroup; import dev.triumphteam.slash.example.commands.ExampleSubCommand; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java index c476a5b9..181f88a0 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java @@ -23,8 +23,8 @@ */ package dev.triumphteam.slash.example; -import dev.triumphteam.cmd.slash.SlashCommandManager; -import dev.triumphteam.cmd.slash.sender.SlashSender; +import dev.triumphteam.cmd.jda.SlashCommandManager; +import dev.triumphteam.cmd.jda.sender.SlashSender; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java index 96a6a793..5e904b78 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java @@ -24,9 +24,9 @@ package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; -import dev.triumphteam.cmd.slash.annotation.Choice; -import dev.triumphteam.cmd.slash.annotation.NSFW; -import dev.triumphteam.cmd.slash.sender.SlashCommandSender; +import dev.triumphteam.cmd.jda.annotation.Choice; +import dev.triumphteam.cmd.jda.annotation.NSFW; +import dev.triumphteam.cmd.jda.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.User; @NSFW diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java index a9ff5071..cd887c21 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java @@ -24,7 +24,7 @@ package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; -import dev.triumphteam.cmd.slash.sender.SlashCommandSender; +import dev.triumphteam.cmd.jda.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.User; @Command("group") diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java index 0a2c0fa9..62b97231 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java @@ -24,7 +24,7 @@ package dev.triumphteam.slash.example.commands; import dev.triumphteam.cmd.core.annotations.Command; -import dev.triumphteam.cmd.slash.sender.SlashCommandSender; +import dev.triumphteam.cmd.jda.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.User; @Command("sub") From d6185f28db84d1524eb4a90ada0308c5ca761ccd Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 1 Feb 2023 20:49:50 -0600 Subject: [PATCH 087/101] kord: Kord? Kord! --- discord/kord/slash/build.gradle.kts | 10 ++++++++++ .../dev/triumphteam/cmds/kord/KordCommandManager.kt | 6 ++++++ examples/discord/kord/slash/build.gradle.kts | 8 ++++++++ .../dev/triumphteam/kord/example/Application.kt | 2 ++ .../kord/slash/src/main/resources/log4j2.xml | 13 +++++++++++++ gradle.properties | 2 +- gradle/libs.versions.toml | 2 ++ settings.gradle.kts | 2 ++ 8 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 discord/kord/slash/build.gradle.kts create mode 100644 discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordCommandManager.kt create mode 100644 examples/discord/kord/slash/build.gradle.kts create mode 100644 examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt create mode 100644 examples/discord/kord/slash/src/main/resources/log4j2.xml diff --git a/discord/kord/slash/build.gradle.kts b/discord/kord/slash/build.gradle.kts new file mode 100644 index 00000000..67701f22 --- /dev/null +++ b/discord/kord/slash/build.gradle.kts @@ -0,0 +1,10 @@ +plugins { + id("cmds.base-conventions") + id("cmds.library-conventions") +} + +dependencies { + api(kotlin("stdlib")) + api(libs.kord) + api(projects.triumphCmdCore) +} diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordCommandManager.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordCommandManager.kt new file mode 100644 index 00000000..536fa32c --- /dev/null +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordCommandManager.kt @@ -0,0 +1,6 @@ +package dev.triumphteam.cmds.kord + +import dev.triumphteam.cmd.core.CommandManager + +public class KordCommandManager : CommandManager<> { +} diff --git a/examples/discord/kord/slash/build.gradle.kts b/examples/discord/kord/slash/build.gradle.kts new file mode 100644 index 00000000..cbe71888 --- /dev/null +++ b/examples/discord/kord/slash/build.gradle.kts @@ -0,0 +1,8 @@ +plugins { + id("cmds.base-conventions") + id("cmds.logger-conventions") +} + +dependencies { + api(projects.triumphCmdKordSlash) +} diff --git a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt new file mode 100644 index 00000000..49d1d260 --- /dev/null +++ b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt @@ -0,0 +1,2 @@ +package dev.triumphteam.kord.example + diff --git a/examples/discord/kord/slash/src/main/resources/log4j2.xml b/examples/discord/kord/slash/src/main/resources/log4j2.xml new file mode 100644 index 00000000..44007cbc --- /dev/null +++ b/examples/discord/kord/slash/src/main/resources/log4j2.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/gradle.properties b/gradle.properties index 3a8424df..1173de72 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ kotlin.stdlib.default.dependency=false -version=2.0.0-ALPHA-3 +version=2.0.0-ALPHA-4 group=dev.triumphteam diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d2fa5a74..e08dbf77 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,6 +18,7 @@ spigot = "1.18.2-R0.1-SNAPSHOT" # Discord jda = "5.0.0-beta.3" +kord = "0.8.0-M17" # Formatting spotless = "6.12.0" @@ -42,6 +43,7 @@ spigot = { module = "org.spigotmc:spigot-api", version.ref = "spigot" } # Discord jda = { module = "net.dv8tion:JDA", version.ref = "jda" } +kord = { module = "dev.kord:kord-core", version.ref = "kord" } # Kotlin coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" } diff --git a/settings.gradle.kts b/settings.gradle.kts index cbf8f2a2..bc83d177 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -18,6 +18,7 @@ listOf( "discord/jda/common" to "jda-common", // "discord/jda-prefixed" to "jda-prefixed", "discord/jda/slash" to "jda-slash", + "discord/kord/slash" to "kord-slash", "kotlin/coroutines" to "kotlin-coroutines", "kotlin/extensions" to "kotlin-extensions", @@ -31,6 +32,7 @@ listOf( // "discord/jda-prefixed" to "jda-prefixed", "examples/discord/jda/slash" to "jda-slash-examples", + "examples/discord/kord/slash" to "kord-slash-examples", ).forEach { includeProjectFolders(it.first, it.second) } From 0196244c1067f8ae435ca3bfcb0c84563f9c6c2c Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 1 Feb 2023 20:59:10 -0600 Subject: [PATCH 088/101] feature: Base for Kord support --- .../cmds/kord/KordCommandManager.kt | 6 ----- .../cmds/kord/SlashCommandManager.kt | 24 ++++++++++++++++++ .../cmds/kord/SlashCommandOptions.kt | 25 +++++++++++++++++++ .../cmds/kord/sender/SlashSender.kt | 4 +++ .../{slash => jda}/example/Example.java | 8 +++--- .../{slash => jda}/example/Listener.java | 2 +- .../example/commands/ExampleCommand.java | 2 +- .../example/commands/ExampleCommandGroup.java | 2 +- .../example/commands/ExampleSubCommand.java | 2 +- 9 files changed, 61 insertions(+), 14 deletions(-) delete mode 100644 discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordCommandManager.kt create mode 100644 discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt create mode 100644 discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt create mode 100644 discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt rename examples/discord/jda/slash/src/main/java/dev/triumphteam/{slash => jda}/example/Example.java (91%) rename examples/discord/jda/slash/src/main/java/dev/triumphteam/{slash => jda}/example/Listener.java (98%) rename examples/discord/jda/slash/src/main/java/dev/triumphteam/{slash => jda}/example/commands/ExampleCommand.java (97%) rename examples/discord/jda/slash/src/main/java/dev/triumphteam/{slash => jda}/example/commands/ExampleCommandGroup.java (97%) rename examples/discord/jda/slash/src/main/java/dev/triumphteam/{slash => jda}/example/commands/ExampleSubCommand.java (97%) diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordCommandManager.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordCommandManager.kt deleted file mode 100644 index 536fa32c..00000000 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordCommandManager.kt +++ /dev/null @@ -1,6 +0,0 @@ -package dev.triumphteam.cmds.kord - -import dev.triumphteam.cmd.core.CommandManager - -public class KordCommandManager : CommandManager<> { -} diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt new file mode 100644 index 00000000..afb78004 --- /dev/null +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt @@ -0,0 +1,24 @@ +package dev.triumphteam.cmds.kord + +import dev.kord.core.Kord +import dev.triumphteam.cmd.core.CommandManager +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer +import dev.triumphteam.cmds.kord.sender.SlashSender + +public class SlashCommandManager( + private val kord: Kord, + commandOptions: SlashCommandOptions, +) : CommandManager>(commandOptions) { + + override fun registerCommand(command: Any) { + TODO("Not yet implemented") + } + + override fun unregisterCommand(command: Any) { + TODO("Not yet implemented") + } + + override fun getRegistryContainer(): RegistryContainer { + TODO("Not yet implemented") + } +} diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt new file mode 100644 index 00000000..da7d0d64 --- /dev/null +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt @@ -0,0 +1,25 @@ +package dev.triumphteam.cmds.kord + +import dev.triumphteam.cmd.core.extention.CommandOptions +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer +import dev.triumphteam.cmd.core.extention.sender.SenderExtension +import dev.triumphteam.cmds.kord.sender.SlashSender + +public class SlashCommandOptions( + senderExtension: SenderExtension, + builder: Builder, +) : CommandOptions(senderExtension, builder) { + + public class Setup(registryContainer: RegistryContainer) : + CommandOptions.Setup>(registryContainer) + + public class Builder(registryContainer: RegistryContainer) : + CommandOptions.Builder, Setup, Builder>( + Setup(registryContainer) + ) { + + override fun build(senderExtension: SenderExtension): SlashCommandOptions { + return SlashCommandOptions(senderExtension, this) + } + } +} diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt new file mode 100644 index 00000000..2e7d2952 --- /dev/null +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt @@ -0,0 +1,4 @@ +package dev.triumphteam.cmds.kord.sender + +public interface SlashSender { +} diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/Example.java similarity index 91% rename from examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java rename to examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/Example.java index b77222f4..1e101b97 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Example.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/Example.java @@ -21,15 +21,15 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.slash.example; +package dev.triumphteam.jda.example; import dev.triumphteam.cmd.jda.SlashCommandManager; import dev.triumphteam.cmd.jda.SlashCommandOptions; import dev.triumphteam.cmd.jda.choices.ChoiceKey; import dev.triumphteam.cmd.jda.sender.SlashSender; -import dev.triumphteam.slash.example.commands.ExampleCommand; -import dev.triumphteam.slash.example.commands.ExampleCommandGroup; -import dev.triumphteam.slash.example.commands.ExampleSubCommand; +import dev.triumphteam.jda.example.commands.ExampleCommandGroup; +import dev.triumphteam.jda.example.commands.ExampleSubCommand; +import dev.triumphteam.jda.example.commands.ExampleCommand; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/Listener.java similarity index 98% rename from examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java rename to examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/Listener.java index 181f88a0..22c6135c 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/Listener.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/Listener.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.slash.example; +package dev.triumphteam.jda.example; import dev.triumphteam.cmd.jda.SlashCommandManager; import dev.triumphteam.cmd.jda.sender.SlashSender; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommand.java similarity index 97% rename from examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java rename to examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommand.java index 5e904b78..5c79f71e 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommand.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.slash.example.commands; +package dev.triumphteam.jda.example.commands; import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.jda.annotation.Choice; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommandGroup.java similarity index 97% rename from examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java rename to examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommandGroup.java index cd887c21..5897db9c 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleCommandGroup.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommandGroup.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.slash.example.commands; +package dev.triumphteam.jda.example.commands; import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.jda.sender.SlashCommandSender; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleSubCommand.java similarity index 97% rename from examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java rename to examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleSubCommand.java index 62b97231..3f565e61 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/slash/example/commands/ExampleSubCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleSubCommand.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.slash.example.commands; +package dev.triumphteam.jda.example.commands; import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.jda.sender.SlashCommandSender; From 7fd308bfbc9fdda9508f60cfdf41f83ecb3e1091 Mon Sep 17 00:00:00 2001 From: Matt Date: Thu, 2 Feb 2023 19:39:15 -0600 Subject: [PATCH 089/101] feature: Barebones Kord support --- .../argument/ResolverInternalArgument.java | 2 - .../triumphteam/cmd/core/command/Command.java | 3 +- .../cmd/core/command/ParentSubCommand.java | 3 +- .../cmd/core/command/RootCommand.java | 3 +- .../cmd/core/command/SubCommand.java | 9 +- discord/common/slash/build.gradle.kts | 9 + .../cmd/discord}/ChoiceProcessor.java | 16 +- .../cmd/discord}/NsfwProcessor.java | 6 +- .../discord}/ProvidedInternalArgument.java | 4 +- .../cmd/discord}/annotation/Choice.java | 4 +- .../cmd/discord}/annotation/NSFW.java | 2 +- .../cmd/discord}/choices/ChoiceKey.java | 2 +- .../cmd/discord}/choices/ChoiceRegistry.java | 2 +- .../discord}/choices/EnumInternalChoice.java | 6 +- .../cmd/discord}/choices/InternalChoice.java | 3 +- .../choices/SimpleInternalChoice.java | 2 +- .../jda/annotation/Privileges.java | 2 +- .../{ => discord}/jda/annotation/Roles.java | 2 +- discord/jda/slash/build.gradle.kts | 2 + .../triumphteam/cmd/jda/JdaMappingUtil.java | 81 +++++--- .../cmd/jda/ProvidedUserInternalArgument.java | 67 ++++++ .../cmd/jda/SlashCommandManager.java | 19 +- .../cmd/jda/SlashCommandOptions.java | 6 +- .../cmd/jda/SlashRegistryContainer.java | 2 +- discord/kord/slash/build.gradle.kts | 4 +- .../dev/triumphteam/cmds/kord/DummySender.kt | 13 ++ .../dev/triumphteam/cmds/kord/KordExt.kt | 95 +++++++++ .../cmds/kord/SlashCommandManager.kt | 195 +++++++++++++++++- .../cmds/kord/SlashCommandOptions.kt | 23 ++- .../cmds/kord/SlashRegistryContainer.kt | 34 +++ .../cmds/kord/SlashSenderExtension.kt | 11 + .../cmds/kord/sender/SlashSender.kt | 2 + .../dev/triumphteam/jda/example/Example.java | 4 +- .../jda/example/commands/ExampleCommand.java | 4 +- .../example/commands/ExampleCommandGroup.java | 5 +- .../triumphteam/kord/example/Application.kt | 20 ++ .../kord/example/commands/ExampleCommand.kt | 17 ++ .../example/commands/ExampleCommandGroup.kt | 21 ++ .../example/commands/ExampleSubCommand.kt | 18 ++ .../cmds/CoroutinesCommandExtension.kt | 6 +- settings.gradle.kts | 1 + 41 files changed, 627 insertions(+), 103 deletions(-) create mode 100644 discord/common/slash/build.gradle.kts rename discord/{jda/slash/src/main/java/dev/triumphteam/cmd/jda => common/slash/src/main/java/dev/triumphteam/cmd/discord}/ChoiceProcessor.java (85%) rename discord/{jda/slash/src/main/java/dev/triumphteam/cmd/jda => common/slash/src/main/java/dev/triumphteam/cmd/discord}/NsfwProcessor.java (91%) rename discord/{jda/slash/src/main/java/dev/triumphteam/cmd/jda => common/slash/src/main/java/dev/triumphteam/cmd/discord}/ProvidedInternalArgument.java (95%) rename discord/{jda/slash/src/main/java/dev/triumphteam/cmd/jda => common/slash/src/main/java/dev/triumphteam/cmd/discord}/annotation/Choice.java (93%) rename discord/{jda/slash/src/main/java/dev/triumphteam/cmd/jda => common/slash/src/main/java/dev/triumphteam/cmd/discord}/annotation/NSFW.java (97%) rename discord/{jda/slash/src/main/java/dev/triumphteam/cmd/jda => common/slash/src/main/java/dev/triumphteam/cmd/discord}/choices/ChoiceKey.java (98%) rename discord/{jda/slash/src/main/java/dev/triumphteam/cmd/jda => common/slash/src/main/java/dev/triumphteam/cmd/discord}/choices/ChoiceRegistry.java (97%) rename discord/{jda/slash/src/main/java/dev/triumphteam/cmd/jda => common/slash/src/main/java/dev/triumphteam/cmd/discord}/choices/EnumInternalChoice.java (94%) rename discord/{jda/slash/src/main/java/dev/triumphteam/cmd/jda => common/slash/src/main/java/dev/triumphteam/cmd/discord}/choices/InternalChoice.java (96%) rename discord/{jda/slash/src/main/java/dev/triumphteam/cmd/jda => common/slash/src/main/java/dev/triumphteam/cmd/discord}/choices/SimpleInternalChoice.java (97%) rename discord/jda/common/src/main/java/dev/triumphteam/cmd/{ => discord}/jda/annotation/Privileges.java (96%) rename discord/jda/common/src/main/java/dev/triumphteam/cmd/{ => discord}/jda/annotation/Roles.java (96%) create mode 100644 discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedUserInternalArgument.java create mode 100644 discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/DummySender.kt create mode 100644 discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordExt.kt create mode 100644 discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashRegistryContainer.kt create mode 100644 discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashSenderExtension.kt create mode 100644 examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommand.kt create mode 100644 examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommandGroup.kt create mode 100644 examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java index da1a1e7b..d8e1994f 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/ResolverInternalArgument.java @@ -71,8 +71,6 @@ public ResolverInternalArgument( final @NotNull String value, final @Nullable Object provided ) { - if (provided != null) return success(provided); - final Object result = resolver.resolve(sender, value); if (result == null) { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java index f1b22049..a2119d92 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/Command.java @@ -32,7 +32,6 @@ import java.util.Deque; import java.util.List; import java.util.Map; -import java.util.function.Function; import java.util.function.Supplier; /** @@ -61,7 +60,7 @@ void executeNonLinear( final @NotNull S sender, final @Nullable Supplier instanceSupplier, final @NotNull Deque commands, - final @NotNull Map, Pair>> arguments + final @NotNull Map> arguments ) throws Throwable; /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java index 831ea6f6..abf22cc1 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentSubCommand.java @@ -42,7 +42,6 @@ import java.util.List; import java.util.Map; import java.util.function.BiFunction; -import java.util.function.Function; import java.util.function.Supplier; /** @@ -142,7 +141,7 @@ public void executeNonLinear( final @NotNull S sender, final @Nullable Supplier instanceSupplier, final @NotNull Deque commands, - final @NotNull Map, Pair>> arguments + final @NotNull Map> arguments ) throws Throwable { // Test all requirements before continuing if (!getSettings().testRequirements(getMessageRegistry(), sender, getMeta(), getSenderExtension())) return; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java index 21afe0fe..9c2dd245 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/RootCommand.java @@ -33,7 +33,6 @@ import java.util.Deque; import java.util.List; import java.util.Map; -import java.util.function.Function; import java.util.function.Supplier; public class RootCommand extends ParentCommand { @@ -82,7 +81,7 @@ public void executeNonLinear( final @NotNull S sender, final @Nullable Supplier instanceSupplier, final @NotNull Deque commands, - final @NotNull Map, Pair>> arguments + final @NotNull Map> arguments ) { // Test all requirements before continuing if (!getSettings().testRequirements(getMessageRegistry(), sender, getMeta(), getSenderExtension())) return; diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index 6b281bcd..bc828b20 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -54,7 +54,6 @@ import java.util.List; import java.util.Map; import java.util.function.BiFunction; -import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -166,7 +165,7 @@ public void executeNonLinear( final @NotNull S sender, final @Nullable Supplier instanceSupplier, final @NotNull Deque commands, - final @NotNull Map, Pair>> arguments + final @NotNull Map> arguments ) throws Throwable { // TODO DRY final ValidationResult> validationResult = senderExtension.validate(meta, senderType, sender); @@ -190,15 +189,13 @@ public void executeNonLinear( invokeArguments.add(sender); argumentList.forEach(it -> { - final Function, Pair> function = arguments.get(it.getName()); + final Pair pair = arguments.get(it.getName()); // Should only really happen on optional arguments - if (function == null) { + if (pair == null) { invokeArguments.add(null); return; } - final Pair pair = function.apply(it.getType()); - final Deque raw; if (it instanceof LimitlessInternalArgument) { raw = new ArrayDeque<>(Arrays.asList(pair.first().split(""))); diff --git a/discord/common/slash/build.gradle.kts b/discord/common/slash/build.gradle.kts new file mode 100644 index 00000000..8396e63d --- /dev/null +++ b/discord/common/slash/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + id("cmds.base-conventions") + id("cmds.library-conventions") +} + +dependencies { + api(projects.triumphCmdCore) + api(libs.guava) +} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ChoiceProcessor.java b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/ChoiceProcessor.java similarity index 85% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ChoiceProcessor.java rename to discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/ChoiceProcessor.java index 8f9ca197..6136ea0b 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ChoiceProcessor.java +++ b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/ChoiceProcessor.java @@ -21,17 +21,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda; +package dev.triumphteam.cmd.discord; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; -import dev.triumphteam.cmd.jda.annotation.Choice; -import dev.triumphteam.cmd.jda.choices.ChoiceKey; -import dev.triumphteam.cmd.jda.choices.ChoiceRegistry; -import dev.triumphteam.cmd.jda.choices.EnumInternalChoice; -import dev.triumphteam.cmd.jda.choices.InternalChoice; -import dev.triumphteam.cmd.jda.choices.SimpleInternalChoice; +import dev.triumphteam.cmd.discord.annotation.Choice; +import dev.triumphteam.cmd.discord.choices.ChoiceKey; +import dev.triumphteam.cmd.discord.choices.ChoiceRegistry; +import dev.triumphteam.cmd.discord.choices.EnumInternalChoice; +import dev.triumphteam.cmd.discord.choices.InternalChoice; +import dev.triumphteam.cmd.discord.choices.SimpleInternalChoice; import org.jetbrains.annotations.NotNull; import java.lang.reflect.AnnotatedElement; @@ -40,7 +40,7 @@ import java.util.function.Supplier; @SuppressWarnings("unchecked") -class ChoiceProcessor implements AnnotationProcessor { +public class ChoiceProcessor implements AnnotationProcessor { private final ChoiceRegistry choiceRegistry; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/NsfwProcessor.java b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/NsfwProcessor.java similarity index 91% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/NsfwProcessor.java rename to discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/NsfwProcessor.java index aea821f4..092ef6d0 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/NsfwProcessor.java +++ b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/NsfwProcessor.java @@ -21,17 +21,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda; +package dev.triumphteam.cmd.discord; +import dev.triumphteam.cmd.discord.annotation.NSFW; import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.annotation.ProcessorTarget; import dev.triumphteam.cmd.core.extention.meta.CommandMeta; -import dev.triumphteam.cmd.jda.annotation.NSFW; import org.jetbrains.annotations.NotNull; import java.lang.reflect.AnnotatedElement; -class NsfwProcessor implements AnnotationProcessor { +public class NsfwProcessor implements AnnotationProcessor { @Override public void process( diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedInternalArgument.java b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/ProvidedInternalArgument.java similarity index 95% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedInternalArgument.java rename to discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/ProvidedInternalArgument.java index b138a565..b3029af2 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedInternalArgument.java +++ b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/ProvidedInternalArgument.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda; +package dev.triumphteam.cmd.discord; import dev.triumphteam.cmd.core.argument.StringInternalArgument; import dev.triumphteam.cmd.core.extention.Result; @@ -33,7 +33,7 @@ import java.util.function.BiFunction; -class ProvidedInternalArgument extends StringInternalArgument { +public class ProvidedInternalArgument extends StringInternalArgument { public ProvidedInternalArgument( final @NotNull CommandMeta meta, diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/Choice.java b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/annotation/Choice.java similarity index 93% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/Choice.java rename to discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/annotation/Choice.java index 32c6035d..15315b4d 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/Choice.java +++ b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/annotation/Choice.java @@ -21,10 +21,10 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda.annotation; +package dev.triumphteam.cmd.discord.annotation; +import dev.triumphteam.cmd.discord.choices.InternalChoice; import dev.triumphteam.cmd.core.extention.meta.MetaKey; -import dev.triumphteam.cmd.jda.choices.InternalChoice; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/NSFW.java b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/annotation/NSFW.java similarity index 97% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/NSFW.java rename to discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/annotation/NSFW.java index 3eda26c3..d60f7868 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/annotation/NSFW.java +++ b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/annotation/NSFW.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda.annotation; +package dev.triumphteam.cmd.discord.annotation; import dev.triumphteam.cmd.core.extention.meta.MetaKey; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceKey.java b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/ChoiceKey.java similarity index 98% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceKey.java rename to discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/ChoiceKey.java index 5af6c700..28d01b76 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceKey.java +++ b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/ChoiceKey.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda.choices; +package dev.triumphteam.cmd.discord.choices; import dev.triumphteam.cmd.core.extention.StringKey; import org.jetbrains.annotations.Contract; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceRegistry.java b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/ChoiceRegistry.java similarity index 97% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceRegistry.java rename to discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/ChoiceRegistry.java index 49daaab9..4dde9453 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/ChoiceRegistry.java +++ b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/ChoiceRegistry.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda.choices; +package dev.triumphteam.cmd.discord.choices; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/EnumInternalChoice.java b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/EnumInternalChoice.java similarity index 94% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/EnumInternalChoice.java rename to discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/EnumInternalChoice.java index 08972e44..03316b60 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/EnumInternalChoice.java +++ b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/EnumInternalChoice.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda.choices; +package dev.triumphteam.cmd.discord.choices; import dev.triumphteam.cmd.core.util.EnumUtils; import org.jetbrains.annotations.NotNull; @@ -31,15 +31,13 @@ import java.util.Objects; import java.util.stream.Collectors; -import static dev.triumphteam.cmd.core.util.EnumUtils.populateCache; - public final class EnumInternalChoice implements InternalChoice { private final Class> enumType; public EnumInternalChoice(final @NotNull Class> enumType) { this.enumType = enumType; - populateCache(enumType); + EnumUtils.populateCache(enumType); } @Override diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/InternalChoice.java b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/InternalChoice.java similarity index 96% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/InternalChoice.java rename to discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/InternalChoice.java index ea43d3b4..5032ca03 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/InternalChoice.java +++ b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/InternalChoice.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda.choices; +package dev.triumphteam.cmd.discord.choices; import org.jetbrains.annotations.NotNull; @@ -30,5 +30,4 @@ public interface InternalChoice { @NotNull List getChoices(); - } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/SimpleInternalChoice.java b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/SimpleInternalChoice.java similarity index 97% rename from discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/SimpleInternalChoice.java rename to discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/SimpleInternalChoice.java index 8cc78fa2..7cf35b15 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/choices/SimpleInternalChoice.java +++ b/discord/common/slash/src/main/java/dev/triumphteam/cmd/discord/choices/SimpleInternalChoice.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda.choices; +package dev.triumphteam.cmd.discord.choices; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; diff --git a/discord/jda/common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java b/discord/jda/common/src/main/java/dev/triumphteam/cmd/discord/jda/annotation/Privileges.java similarity index 96% rename from discord/jda/common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java rename to discord/jda/common/src/main/java/dev/triumphteam/cmd/discord/jda/annotation/Privileges.java index 25daa866..38c925b1 100644 --- a/discord/jda/common/src/main/java/dev/triumphteam/cmd/jda/annotation/Privileges.java +++ b/discord/jda/common/src/main/java/dev/triumphteam/cmd/discord/jda/annotation/Privileges.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda.annotation; +package dev.triumphteam.cmd.discord.jda.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; diff --git a/discord/jda/common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java b/discord/jda/common/src/main/java/dev/triumphteam/cmd/discord/jda/annotation/Roles.java similarity index 96% rename from discord/jda/common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java rename to discord/jda/common/src/main/java/dev/triumphteam/cmd/discord/jda/annotation/Roles.java index 683feb15..42bede1b 100644 --- a/discord/jda/common/src/main/java/dev/triumphteam/cmd/jda/annotation/Roles.java +++ b/discord/jda/common/src/main/java/dev/triumphteam/cmd/discord/jda/annotation/Roles.java @@ -21,7 +21,7 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -package dev.triumphteam.cmd.jda.annotation; +package dev.triumphteam.cmd.discord.jda.annotation; import java.lang.annotation.ElementType; import java.lang.annotation.Inherited; diff --git a/discord/jda/slash/build.gradle.kts b/discord/jda/slash/build.gradle.kts index 2c16e3d2..af5bca14 100644 --- a/discord/jda/slash/build.gradle.kts +++ b/discord/jda/slash/build.gradle.kts @@ -5,4 +5,6 @@ plugins { dependencies { api(projects.triumphCmdJdaCommon) + api(projects.triumphCmdDiscordSlashCommon) + compileOnly("net.sf.trove4j:trove4j:3.0.3") } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/JdaMappingUtil.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/JdaMappingUtil.java index 11e370d1..b9d52c94 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/JdaMappingUtil.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/JdaMappingUtil.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -29,18 +29,20 @@ import dev.triumphteam.cmd.core.command.ParentSubCommand; import dev.triumphteam.cmd.core.command.RootCommand; import dev.triumphteam.cmd.core.command.SubCommand; +import dev.triumphteam.cmd.core.exceptions.CommandExecutionException; import dev.triumphteam.cmd.core.util.Pair; -import dev.triumphteam.cmd.jda.annotation.Choice; -import dev.triumphteam.cmd.jda.annotation.NSFW; -import dev.triumphteam.cmd.jda.choices.InternalChoice; +import dev.triumphteam.cmd.discord.ProvidedInternalArgument; +import dev.triumphteam.cmd.discord.annotation.Choice; +import dev.triumphteam.cmd.discord.annotation.NSFW; +import dev.triumphteam.cmd.discord.choices.InternalChoice; import dev.triumphteam.cmd.jda.sender.SlashSender; +import gnu.trove.map.TLongObjectMap; import net.dv8tion.jda.api.entities.IMentionable; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Message; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.entities.channel.concrete.TextChannel; -import net.dv8tion.jda.api.entities.channel.middleman.GuildChannel; import net.dv8tion.jda.api.entities.channel.middleman.MessageChannel; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -51,18 +53,38 @@ import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData; import org.jetbrains.annotations.NotNull; +import java.lang.reflect.Field; import java.util.Collection; +import java.util.EnumSet; import java.util.HashMap; import java.util.Map; import java.util.Objects; import java.util.Optional; -import java.util.function.Function; +import java.util.Set; import java.util.stream.Collectors; final class JdaMappingUtil { private static final Map, OptionType> OPTION_TYPE_MAP = createTypeMap(); - private static final Map, Function> MAPPING_MAP = createMappingsMap(); + private static final Set STRING_OPTIONS = EnumSet.of( + OptionType.STRING, + OptionType.INTEGER, + OptionType.NUMBER, + OptionType.BOOLEAN, + OptionType.UNKNOWN + ); + + private static final Field RESOLVED_FILED; + + static { + try { + RESOLVED_FILED = OptionMapping.class.getDeclaredField("resolved"); + RESOLVED_FILED.setAccessible(true); + } catch (NoSuchFieldException exception) { + exception.printStackTrace(); + throw new CommandExecutionException("An error occurred while trying to get resolved values from OptionMapper."); + } + } private JdaMappingUtil() {} @@ -70,16 +92,18 @@ private JdaMappingUtil() {} return OPTION_TYPE_MAP.getOrDefault(type, OptionType.STRING); } - public static @NotNull Pair parsedValueFromType( - final @NotNull Class type, - final @NotNull OptionMapping option - ) { + @SuppressWarnings("unchecked") + public static @NotNull Pair parsedValueFromType(final @NotNull OptionMapping option) { final String raw = option.getAsString(); - final Function mapper = MAPPING_MAP.get(type); - if (mapper == null) return new Pair<>(raw, raw); + if (isStringType(option.getType())) return new Pair<>(raw, raw); - return new Pair<>(raw, mapper.apply(option)); + try { + final TLongObjectMap map = (TLongObjectMap) RESOLVED_FILED.get(option); + return new Pair<>(raw, map.get(option.getAsLong())); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } } public static @NotNull SlashCommandData mapCommand(final @NotNull RootCommand rootCommand) { @@ -170,14 +194,18 @@ private JdaMappingUtil() {} return data; } + public static boolean isStringType(final @NotNull OptionType type) { + return STRING_OPTIONS.contains(type); + } + private static Map, OptionType> createTypeMap() { final Map, OptionType> map = new HashMap<>(); map.put(Short.class, OptionType.INTEGER); map.put(short.class, OptionType.INTEGER); map.put(Integer.class, OptionType.INTEGER); map.put(int.class, OptionType.INTEGER); - map.put(Long.class, OptionType.INTEGER); - map.put(long.class, OptionType.INTEGER); + map.put(Long.class, OptionType.NUMBER); + map.put(long.class, OptionType.NUMBER); map.put(Double.class, OptionType.NUMBER); map.put(double.class, OptionType.NUMBER); map.put(Float.class, OptionType.NUMBER); @@ -194,19 +222,4 @@ private static Map, OptionType> createTypeMap() { return ImmutableMap.copyOf(map); } - - private static Map, Function> createMappingsMap() { - final Map, Function> map = new HashMap<>(); - - map.put(Role.class, OptionMapping::getAsRole); - map.put(User.class, OptionMapping::getAsUser); - map.put(Member.class, OptionMapping::getAsMember); - map.put(GuildChannel.class, OptionMapping::getAsChannel); - map.put(TextChannel.class, OptionMapping::getAsChannel); - map.put(MessageChannel.class, OptionMapping::getAsChannel); - map.put(Message.Attachment.class, OptionMapping::getAsAttachment); - map.put(IMentionable.class, OptionMapping::getAsMentionable); - - return ImmutableMap.copyOf(map); - } } diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedUserInternalArgument.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedUserInternalArgument.java new file mode 100644 index 00000000..5237741b --- /dev/null +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedUserInternalArgument.java @@ -0,0 +1,67 @@ +/** + * MIT License + *

    + * Copyright (c) 2019-2021 Matt + *

    + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + *

    + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + *

    + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmd.jda; + +import dev.triumphteam.cmd.core.argument.StringInternalArgument; +import dev.triumphteam.cmd.core.extention.Result; +import dev.triumphteam.cmd.core.extention.meta.CommandMeta; +import dev.triumphteam.cmd.core.message.context.InvalidArgumentContext; +import dev.triumphteam.cmd.core.suggestion.Suggestion; +import net.dv8tion.jda.api.entities.Member; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.function.BiFunction; + +class ProvidedUserInternalArgument extends StringInternalArgument { + + public ProvidedUserInternalArgument( + final @NotNull CommandMeta meta, + final @NotNull String name, + final @NotNull String description, + final @NotNull Class type, + final @NotNull Suggestion suggestion, + final boolean optional + ) { + super(meta, name, description, type, suggestion, optional); + } + + @Override + public @NotNull Result<@Nullable Object, BiFunction<@NotNull CommandMeta, @NotNull String, @NotNull InvalidArgumentContext>> resolve( + final @NotNull S sender, + final @NotNull String value, + final @Nullable Object provided + ) { + if (provided == null) { + return invalid((meta, syntax) -> new InvalidArgumentContext(meta, syntax, value, getName(), getType())); + } + + // Bit of a hack around JDA member not being an User for some reason + if (provided instanceof Member) { + return success(((Member) provided).getUser()); + } + + return success(provided); + } +} diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java index 9d5f1d07..68693b27 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -34,7 +34,8 @@ import dev.triumphteam.cmd.core.message.MessageKey; import dev.triumphteam.cmd.core.processor.RootCommandProcessor; import dev.triumphteam.cmd.core.util.Pair; -import dev.triumphteam.cmd.jda.choices.ChoiceKey; +import dev.triumphteam.cmd.discord.ProvidedInternalArgument; +import dev.triumphteam.cmd.discord.choices.ChoiceKey; import dev.triumphteam.cmd.jda.sender.SlashSender; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; @@ -63,7 +64,6 @@ import java.util.List; import java.util.Map; import java.util.function.Consumer; -import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -95,9 +95,8 @@ public SlashCommandManager( // All use the same factory final InternalArgument.Factory jdaArgumentFactory = ProvidedInternalArgument::new; - registerArgument(User.class, jdaArgumentFactory); + registerArgument(User.class, ProvidedUserInternalArgument::new); registerArgument(Role.class, jdaArgumentFactory); - registerArgument(User.class, jdaArgumentFactory); registerArgument(Member.class, jdaArgumentFactory); registerArgument(GuildChannel.class, jdaArgumentFactory); registerArgument(TextChannel.class, jdaArgumentFactory); @@ -165,9 +164,9 @@ public void execute(final @NotNull SlashCommandInteractionEvent event) { final S sender = senderExtension.map(new InteractionCommandSender(event)); // Mapping of arguments - final Map, Pair>> arguments = new HashMap<>(); + final Map> arguments = new HashMap<>(); for (final OptionMapping option : event.getOptions()) { - arguments.put(option.getName(), type -> JdaMappingUtil.parsedValueFromType(type, option)); + arguments.put(option.getName(), JdaMappingUtil.parsedValueFromType(option)); } command.executeNonLinear(sender, null, commands, arguments); diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandOptions.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandOptions.java index 08258511..eaea9b46 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandOptions.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandOptions.java @@ -23,13 +23,15 @@ */ package dev.triumphteam.cmd.jda; +import dev.triumphteam.cmd.discord.ChoiceProcessor; +import dev.triumphteam.cmd.discord.NsfwProcessor; +import dev.triumphteam.cmd.discord.annotation.Choice; +import dev.triumphteam.cmd.discord.annotation.NSFW; import dev.triumphteam.cmd.core.extention.CommandOptions; import dev.triumphteam.cmd.core.extention.defaults.DefaultArgumentValidator; import dev.triumphteam.cmd.core.extention.defaults.DefaultCommandExecutor; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; import dev.triumphteam.cmd.core.extention.sender.SenderExtension; -import dev.triumphteam.cmd.jda.annotation.Choice; -import dev.triumphteam.cmd.jda.annotation.NSFW; import dev.triumphteam.cmd.jda.sender.SlashSender; import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashRegistryContainer.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashRegistryContainer.java index 47505f83..87f6a662 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashRegistryContainer.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashRegistryContainer.java @@ -23,8 +23,8 @@ */ package dev.triumphteam.cmd.jda; +import dev.triumphteam.cmd.discord.choices.ChoiceRegistry; import dev.triumphteam.cmd.core.extention.registry.RegistryContainer; -import dev.triumphteam.cmd.jda.choices.ChoiceRegistry; import dev.triumphteam.cmd.jda.sender.SlashSender; import org.jetbrains.annotations.NotNull; diff --git a/discord/kord/slash/build.gradle.kts b/discord/kord/slash/build.gradle.kts index 67701f22..dc539663 100644 --- a/discord/kord/slash/build.gradle.kts +++ b/discord/kord/slash/build.gradle.kts @@ -6,5 +6,7 @@ plugins { dependencies { api(kotlin("stdlib")) api(libs.kord) - api(projects.triumphCmdCore) + api(projects.triumphCmdDiscordSlashCommon) + api(projects.triumphCmdKotlinCoroutines) + api(projects.triumphCmdKotlinExtensions) } diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/DummySender.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/DummySender.kt new file mode 100644 index 00000000..ae0b73d6 --- /dev/null +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/DummySender.kt @@ -0,0 +1,13 @@ +package dev.triumphteam.cmds.kord + +import dev.kord.core.behavior.interaction.respondPublic +import dev.kord.core.event.interaction.ChatInputCommandInteractionCreateEvent +import dev.triumphteam.cmds.kord.sender.SlashSender + +internal class DummySender(private val event: ChatInputCommandInteractionCreateEvent) : SlashSender { + override suspend fun reply(message: String) { + event.interaction.respondPublic { + content = message + } + } +} diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordExt.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordExt.kt new file mode 100644 index 00000000..a0f9b3b7 --- /dev/null +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordExt.kt @@ -0,0 +1,95 @@ +package dev.triumphteam.cmds.kord + +import dev.kord.core.entity.Attachment +import dev.kord.core.entity.Entity +import dev.kord.core.entity.Member +import dev.kord.core.entity.Role +import dev.kord.core.entity.User +import dev.kord.core.entity.channel.GuildChannel +import dev.kord.core.entity.channel.MessageChannel +import dev.kord.core.entity.channel.TextChannel +import dev.kord.rest.builder.interaction.AttachmentBuilder +import dev.kord.rest.builder.interaction.BooleanBuilder +import dev.kord.rest.builder.interaction.ChannelBuilder +import dev.kord.rest.builder.interaction.IntegerOptionBuilder +import dev.kord.rest.builder.interaction.MentionableBuilder +import dev.kord.rest.builder.interaction.NumberOptionBuilder +import dev.kord.rest.builder.interaction.OptionsBuilder +import dev.kord.rest.builder.interaction.RoleBuilder +import dev.kord.rest.builder.interaction.StringChoiceBuilder +import dev.kord.rest.builder.interaction.UserBuilder +import dev.triumphteam.cmd.core.argument.InternalArgument +import dev.triumphteam.cmd.core.command.Command +import dev.triumphteam.cmd.core.command.SubCommand +import dev.triumphteam.cmd.discord.ProvidedInternalArgument +import dev.triumphteam.cmd.discord.annotation.Choice + +private val optionsMap: Map, (InternalArgument<*, *>) -> OptionsBuilder> = mapOf( + Int::class.java to { argument -> + IntegerOptionBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + Short::class.java to { argument -> + IntegerOptionBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + Long::class.java to { argument -> + NumberOptionBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + Double::class.java to { argument -> + NumberOptionBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + Float::class.java to { argument -> + NumberOptionBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + Boolean::class.java to { argument -> + BooleanBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + Role::class.java to { argument -> + RoleBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + User::class.java to { argument -> + UserBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + Member::class.java to { argument -> + UserBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + TextChannel::class.java to { argument -> + ChannelBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + MessageChannel::class.java to { argument -> + ChannelBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + GuildChannel::class.java to { argument -> + ChannelBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + Attachment::class.java to { argument -> + AttachmentBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, + Entity::class.java to { argument -> + MentionableBuilder(argument.name, argument.desc).apply { defaults(argument) } + }, +) + +private val InternalArgument<*, *>.desc + get() = description.ifEmpty { name } + +internal val Command<*, *>.desc + get() = description.ifEmpty { name } + +private fun OptionsBuilder.defaults(argument: InternalArgument<*, *>) { + required = !argument.isOptional + autocomplete = argument.shouldAutoComplete() +} + +private fun InternalArgument<*, *>.shouldAutoComplete(): Boolean { + if (meta.isPresent(Choice.META_KEY) || this is ProvidedInternalArgument) return false + return canSuggest() +} + +private fun InternalArgument<*, *>.toKordOption(): OptionsBuilder = + optionsMap[type]?.invoke(this) ?: StringChoiceBuilder( + name, + desc + ).apply { defaults(this@toKordOption) } + +internal fun SubCommand<*, *>.mapArgumentsToKord(): MutableList = + argumentList.map { arg -> arg.toKordOption() }.toMutableList() diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt index afb78004..8a25d71f 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt @@ -1,24 +1,217 @@ package dev.triumphteam.cmds.kord +import dev.kord.common.entity.Snowflake import dev.kord.core.Kord +import dev.kord.core.entity.Attachment +import dev.kord.core.entity.Entity +import dev.kord.core.entity.Guild +import dev.kord.core.entity.Member +import dev.kord.core.entity.Role +import dev.kord.core.entity.User +import dev.kord.core.entity.channel.GuildChannel +import dev.kord.core.entity.channel.MessageChannel +import dev.kord.core.entity.channel.TextChannel +import dev.kord.core.entity.interaction.AutoCompleteInteraction +import dev.kord.core.entity.interaction.GroupCommand +import dev.kord.core.entity.interaction.ResolvableOptionValue +import dev.kord.core.event.gateway.ReadyEvent +import dev.kord.core.event.interaction.ChatInputCommandInteractionCreateEvent +import dev.kord.core.on +import dev.kord.rest.builder.interaction.group +import dev.kord.rest.builder.interaction.subCommand import dev.triumphteam.cmd.core.CommandManager +import dev.triumphteam.cmd.core.argument.InternalArgument +import dev.triumphteam.cmd.core.command.ParentSubCommand +import dev.triumphteam.cmd.core.command.RootCommand +import dev.triumphteam.cmd.core.command.SubCommand import dev.triumphteam.cmd.core.extention.registry.RegistryContainer +import dev.triumphteam.cmd.core.extention.sender.SenderExtension +import dev.triumphteam.cmd.core.processor.RootCommandProcessor +import dev.triumphteam.cmd.core.util.Pair +import dev.triumphteam.cmd.discord.ProvidedInternalArgument import dev.triumphteam.cmds.kord.sender.SlashSender +import kotlinx.coroutines.launch +import java.util.ArrayDeque + +public fun SlashCommandManager( + kord: Kord, + builder: SlashCommandOptions.Builder.() -> Unit = {}, +): SlashCommandManager = SlashCommandManager(kord, SlashSenderExtension(), builder) + +public fun SlashCommandManager( + kord: Kord, + senderExtension: SenderExtension, + builder: SlashCommandOptions.Builder.() -> Unit = {}, +): SlashCommandManager { + val registryContainer = SlashRegistryContainer() + return SlashCommandManager( + kord, + SlashCommandOptions + .Builder(registryContainer, kord) + .apply(builder) + .build(senderExtension), + registryContainer + ) +} public class SlashCommandManager( private val kord: Kord, commandOptions: SlashCommandOptions, + private val registryContainer: SlashRegistryContainer, ) : CommandManager>(commandOptions) { + private val globalCommands: MutableMap> = mutableMapOf() + private val guildCommands: MutableMap>> = mutableMapOf() + + private val commandQueue: MutableList Unit> = mutableListOf() + + private var isKordReady = false + + init { + kord.on(consumer = ::execute) + kord.on { + // Sets kord to ready + isKordReady = true + commandQueue.forEach { it.invoke() } + } + + // All use the same factory + val jdaArgumentFactory = InternalArgument.Factory { meta, name, description, type, suggestion, optional -> + ProvidedInternalArgument(meta, name, description, type, suggestion, optional) + } + + registerArgument(User::class.java, jdaArgumentFactory) + registerArgument(Role::class.java, jdaArgumentFactory) + registerArgument(Member::class.java, jdaArgumentFactory) + registerArgument(GuildChannel::class.java, jdaArgumentFactory) + registerArgument(TextChannel::class.java, jdaArgumentFactory) + registerArgument(MessageChannel::class.java, jdaArgumentFactory) + registerArgument(Attachment::class.java, jdaArgumentFactory) + registerArgument(Entity::class.java, jdaArgumentFactory) + } + override fun registerCommand(command: Any) { TODO("Not yet implemented") } + public fun registerCommand(guild: Guild, commands: List): Unit = commands.forEach { + registerCommand(guild, it) + } + + public fun registerCommand(guild: Guild, vararg commands: Any): Unit = commands.forEach { + registerCommand(guild, it) + } + + public fun registerCommand(guild: Guild, command: Any) { + registerCommand(guild.id, command) + } + + public fun registerCommand(guildId: Snowflake, command: Any) { + val processor: RootCommandProcessor = RootCommandProcessor( + command, + registryContainer, + commandOptions + ) + + val name = processor.name + + // Get or add command, then add its sub commands + val rootCommand: RootCommand = guildCommands + .getOrPut(guildId) { mutableMapOf() } + .getOrPut(name) { RootCommand(processor) } + + rootCommand.addCommands(command, processor.commands(rootCommand)) + + if (!isKordReady) { + commandQueue.add { registerKordCommand(guildId, rootCommand) } + return + } + + kord.launch { + registerKordCommand(guildId, rootCommand) + } + } + override fun unregisterCommand(command: Any) { TODO("Not yet implemented") } override fun getRegistryContainer(): RegistryContainer { - TODO("Not yet implemented") + return registryContainer + } + + private suspend fun execute(event: ChatInputCommandInteractionCreateEvent) { + val command = event.interaction.command + + val name = command.rootName + + val commands = ArrayDeque() + if (command is dev.kord.core.entity.interaction.SubCommand) { + commands.add(command.name) + } + + if (command is GroupCommand) { + commands.add(command.groupName) + commands.add(command.name) + } + + val rootCommand = guildCommands[event.interaction.invokedCommandGuildId]?.get(name) ?: return + + val sender = commandOptions.senderExtension.map(DummySender(event)) + + // Mapping all arguments + val arguments: Map> = command.options.map { (key, value) -> + when (value) { + is ResolvableOptionValue<*> -> { + val resolvedObject = value.resolvedObject + key to Pair(resolvedObject.toString(), resolvedObject as Any) + } + else -> { + val wrappedValue = value.value + key to Pair(wrappedValue.toString(), wrappedValue.toString() as Any) + } + } + }.toMap() + + rootCommand.executeNonLinear(sender, null, commands, arguments) + } + + private suspend fun suggest(event: AutoCompleteInteraction) { + TODO("implement this correctly") + } + + private suspend fun registerKordCommand(guildId: Snowflake, rootCommand: RootCommand) { + kord.createGuildChatInputCommand( + guildId, + rootCommand.name, + rootCommand.desc + ) { + + // If only default then register with no groups or sub commands + rootCommand.defaultCommand?.let { + if (it is SubCommand) { + options = it.mapArgumentsToKord() + } + return@createGuildChatInputCommand + } + + val commands = rootCommand.commands.values + + commands.filterIsInstance>().forEach { + subCommand(it.name, it.desc) { + options = it.mapArgumentsToKord() + } + } + + commands.filterIsInstance>().forEach { + group(it.name, it.desc) { + it.commands.values.filterIsInstance>().forEach { sub -> + subCommand(sub.name, sub.desc) { + options = sub.mapArgumentsToKord() + } + } + } + } + } } } diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt index da7d0d64..30ab6553 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt @@ -1,23 +1,40 @@ package dev.triumphteam.cmds.kord +import dev.kord.core.Kord import dev.triumphteam.cmd.core.extention.CommandOptions -import dev.triumphteam.cmd.core.extention.registry.RegistryContainer import dev.triumphteam.cmd.core.extention.sender.SenderExtension +import dev.triumphteam.cmd.discord.ChoiceProcessor +import dev.triumphteam.cmd.discord.NsfwProcessor +import dev.triumphteam.cmd.discord.annotation.Choice +import dev.triumphteam.cmd.discord.annotation.NSFW import dev.triumphteam.cmds.kord.sender.SlashSender +import dev.triumphteam.cmds.useCoroutines public class SlashCommandOptions( senderExtension: SenderExtension, builder: Builder, ) : CommandOptions(senderExtension, builder) { - public class Setup(registryContainer: RegistryContainer) : + public class Setup(registryContainer: SlashRegistryContainer) : CommandOptions.Setup>(registryContainer) - public class Builder(registryContainer: RegistryContainer) : + public class Builder( + registryContainer: SlashRegistryContainer, + kord: Kord, + ) : CommandOptions.Builder, Setup, Builder>( Setup(registryContainer) ) { + init { + // Setters have to be done first thing, so they can be overriden. + extensions { extension -> + extension.useCoroutines(coroutineScope = kord, coroutineContext = kord.coroutineContext) + extension.addAnnotationProcessor(Choice::class.java, ChoiceProcessor(registryContainer.choiceRegistry)) + extension.addAnnotationProcessor(NSFW::class.java, NsfwProcessor()) + } + } + override fun build(senderExtension: SenderExtension): SlashCommandOptions { return SlashCommandOptions(senderExtension, this) } diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashRegistryContainer.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashRegistryContainer.kt new file mode 100644 index 00000000..db0dda95 --- /dev/null +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashRegistryContainer.kt @@ -0,0 +1,34 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package dev.triumphteam.cmds.kord + +import dev.triumphteam.cmd.core.extention.registry.RegistryContainer +import dev.triumphteam.cmd.discord.choices.ChoiceRegistry +import dev.triumphteam.cmds.kord.sender.SlashSender + +// TODO: Comments +public class SlashRegistryContainer : RegistryContainer() { + + public val choiceRegistry: ChoiceRegistry = ChoiceRegistry() +} diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashSenderExtension.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashSenderExtension.kt new file mode 100644 index 00000000..da81e412 --- /dev/null +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashSenderExtension.kt @@ -0,0 +1,11 @@ +package dev.triumphteam.cmds.kord + +import dev.triumphteam.cmd.core.extention.sender.SenderExtension +import dev.triumphteam.cmds.kord.sender.SlashSender + +internal class SlashSenderExtension : SenderExtension.Default { + + override fun getAllowedSenders(): Set> { + return setOf(SlashSender::class.java) + } +} diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt index 2e7d2952..81b93c95 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt @@ -1,4 +1,6 @@ package dev.triumphteam.cmds.kord.sender public interface SlashSender { + + public suspend fun reply(message: String) } diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/Example.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/Example.java index 1e101b97..5ffd7682 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/Example.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/Example.java @@ -23,13 +23,13 @@ */ package dev.triumphteam.jda.example; +import dev.triumphteam.cmd.discord.choices.ChoiceKey; import dev.triumphteam.cmd.jda.SlashCommandManager; import dev.triumphteam.cmd.jda.SlashCommandOptions; -import dev.triumphteam.cmd.jda.choices.ChoiceKey; import dev.triumphteam.cmd.jda.sender.SlashSender; +import dev.triumphteam.jda.example.commands.ExampleCommand; import dev.triumphteam.jda.example.commands.ExampleCommandGroup; import dev.triumphteam.jda.example.commands.ExampleSubCommand; -import dev.triumphteam.jda.example.commands.ExampleCommand; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.JDABuilder; diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommand.java index 5c79f71e..3d0730a9 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommand.java @@ -24,12 +24,10 @@ package dev.triumphteam.jda.example.commands; import dev.triumphteam.cmd.core.annotations.Command; -import dev.triumphteam.cmd.jda.annotation.Choice; -import dev.triumphteam.cmd.jda.annotation.NSFW; +import dev.triumphteam.cmd.discord.annotation.Choice; import dev.triumphteam.cmd.jda.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.User; -@NSFW @Command("example") public class ExampleCommand { diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommandGroup.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommandGroup.java index 5897db9c..7075004a 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommandGroup.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleCommandGroup.java @@ -25,7 +25,6 @@ import dev.triumphteam.cmd.core.annotations.Command; import dev.triumphteam.cmd.jda.sender.SlashCommandSender; -import net.dv8tion.jda.api.entities.User; @Command("group") public class ExampleCommandGroup { @@ -39,8 +38,8 @@ public void first(final SlashCommandSender sender) { } @Command("second") - public void second(final SlashCommandSender sender, final User user) { - sender.reply("Command sent was /group test second <" + user.getName() + ">").queue(); + public void second(final SlashCommandSender sender, final int user) { + sender.reply("Command sent was /group test second <" + user + ">").queue(); } } } diff --git a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt index 49d1d260..ebe435c6 100644 --- a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt +++ b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt @@ -1,2 +1,22 @@ package dev.triumphteam.kord.example +import dev.kord.common.entity.Snowflake +import dev.kord.core.Kord +import dev.triumphteam.cmds.kord.SlashCommandManager +import dev.triumphteam.kord.example.commands.ExampleCommand +import dev.triumphteam.kord.example.commands.ExampleCommandGroup +import dev.triumphteam.kord.example.commands.ExampleSubCommand + +public suspend fun main(args: Array) { + val kord = Kord(args[0]) + + val manager = SlashCommandManager(kord) + + manager.apply { + registerCommand(Snowflake(820696172477677628), ExampleCommand()) + registerCommand(Snowflake(820696172477677628), ExampleCommandGroup()) + registerCommand(Snowflake(820696172477677628), ExampleSubCommand()) + } + + kord.login() +} diff --git a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommand.kt b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommand.kt new file mode 100644 index 00000000..790eb519 --- /dev/null +++ b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommand.kt @@ -0,0 +1,17 @@ +package dev.triumphteam.kord.example.commands + +import dev.kord.core.entity.Attachment +import dev.kord.core.entity.Member +import dev.kord.core.entity.User +import dev.triumphteam.cmd.core.annotations.Command +import dev.triumphteam.cmd.discord.annotation.NSFW +import dev.triumphteam.cmds.kord.sender.SlashSender + +@NSFW +@Command("example") +public class ExampleCommand { + @Command + public suspend fun execute(sender: SlashSender, member: Member, user: User, attachment: Attachment) { + sender.reply("Command sent was /example <${member.username}> <${user.username}> <${attachment.filename}>") + } +} diff --git a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommandGroup.kt b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommandGroup.kt new file mode 100644 index 00000000..1c63ff19 --- /dev/null +++ b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommandGroup.kt @@ -0,0 +1,21 @@ +package dev.triumphteam.kord.example.commands + +import dev.kord.core.entity.User +import dev.triumphteam.cmd.core.annotations.Command +import dev.triumphteam.cmds.kord.sender.SlashSender + +@Command("group") +public class ExampleCommandGroup { + @Command("test") + public inner class Group { + @Command("first") + public suspend fun first(sender: SlashSender) { + sender.reply("Command sent was /group test first") + } + + @Command("second") + public suspend fun second(sender: SlashSender, user: User) { + sender.reply("Command sent was /group test second <$user>") + } + } +} diff --git a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt new file mode 100644 index 00000000..fe20a6bb --- /dev/null +++ b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt @@ -0,0 +1,18 @@ +package dev.triumphteam.kord.example.commands + +import dev.kord.core.entity.User +import dev.triumphteam.cmd.core.annotations.Command +import dev.triumphteam.cmds.kord.sender.SlashSender + +@Command("sub") +public class ExampleSubCommand { + @Command("first") + public suspend fun first(sender: SlashSender) { + sender.reply("Command sent was /sub first") + } + + @Command("second") + public suspend fun second(sender: SlashSender, user: User) { + sender.reply("Command sent was /sub second <${user.username}>") + } +} diff --git a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt index f3be6858..0aba5e04 100644 --- a/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt +++ b/kotlin/coroutines/src/main/kotlin/dev/triumphteam/cmds/CoroutinesCommandExtension.kt @@ -46,8 +46,8 @@ import kotlin.reflect.full.callSuspend import kotlin.reflect.jvm.kotlinFunction public fun > B.useCoroutines( - coroutineScope: CoroutineScope = CoroutineScope(Dispatchers.Default), coroutineContext: CoroutineContext = Dispatchers.Default, + coroutineScope: CoroutineScope = CoroutineScope(coroutineContext), ) { val kotlinArgumentExtension = CoroutinesCommandExtension(coroutineScope, coroutineContext) addProcessor(kotlinArgumentExtension) @@ -58,7 +58,9 @@ public fun > B.useCoroutines( public class CoroutinesCommandExtension( private val coroutineScope: CoroutineScope, private val coroutineContext: CoroutineContext, -) : Processor, ArgumentValidator, CommandExecutor { +) : Processor, + ArgumentValidator, + CommandExecutor { private companion object { /** The key that'll represent a suspending function. */ diff --git a/settings.gradle.kts b/settings.gradle.kts index bc83d177..af16a675 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -15,6 +15,7 @@ listOf( listOf( "minecraft/bukkit" to "bukkit", + "discord/common/slash" to "discord-slash-common", "discord/jda/common" to "jda-common", // "discord/jda-prefixed" to "jda-prefixed", "discord/jda/slash" to "jda-slash", From 07e158dcd982612eca23894e9a295ded4c13c522 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 13 Feb 2023 17:18:52 -0600 Subject: [PATCH 090/101] chore: More Kord --- .../argument/UnknownInternalArgument.java | 10 +++--- .../triumphteam/cmd/jda/JdaMappingUtil.java | 8 ++--- .../cmd/jda/ProvidedUserInternalArgument.java | 8 ++--- .../cmd/jda/SlashCommandManager.java | 8 ++--- .../dev/triumphteam/cmds/kord/DummySender.kt | 23 +++++++++++++ .../dev/triumphteam/cmds/kord/KordExt.kt | 23 +++++++++++++ .../cmds/kord/SlashCommandManager.kt | 34 +++++++++++++++++-- .../cmds/kord/SlashCommandOptions.kt | 23 +++++++++++++ .../cmds/kord/SlashSenderExtension.kt | 23 +++++++++++++ .../cmds/kord/sender/SlashSender.kt | 23 +++++++++++++ .../example/commands/ExampleSubCommand.java | 4 ++- .../triumphteam/kord/example/Application.kt | 24 +++++++++++++ .../kord/example/commands/ExampleCommand.kt | 23 +++++++++++++ .../example/commands/ExampleCommandGroup.kt | 23 +++++++++++++ .../example/commands/ExampleSubCommand.kt | 28 +++++++++++++-- 15 files changed, 261 insertions(+), 24 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index e66793fa..f1ab2022 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -39,7 +39,7 @@ public final class UnknownInternalArgument extends StringInternalArgument { public UnknownInternalArgument(final @NotNull Class type) { - super(null, "unknown", "unknown.", type, new EmptySuggestion<>(), false); + super(new CommandMeta.Builder(null).build(), "unknown", "unknown.", type, new EmptySuggestion<>(), false); } @Override diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/JdaMappingUtil.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/JdaMappingUtil.java index b9d52c94..b4a285b7 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/JdaMappingUtil.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/JdaMappingUtil.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedUserInternalArgument.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedUserInternalArgument.java index 5237741b..f032bf70 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedUserInternalArgument.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/ProvidedUserInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java index 68693b27..017bdf91 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/DummySender.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/DummySender.kt index ae0b73d6..3974ce29 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/DummySender.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/DummySender.kt @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmds.kord import dev.kord.core.behavior.interaction.respondPublic diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordExt.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordExt.kt index a0f9b3b7..2ed03fae 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordExt.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/KordExt.kt @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmds.kord import dev.kord.core.entity.Attachment diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt index 8a25d71f..83bfc271 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt @@ -1,7 +1,31 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmds.kord import dev.kord.common.entity.Snowflake import dev.kord.core.Kord +import dev.kord.core.behavior.interaction.suggestString import dev.kord.core.entity.Attachment import dev.kord.core.entity.Entity import dev.kord.core.entity.Guild @@ -11,11 +35,11 @@ import dev.kord.core.entity.User import dev.kord.core.entity.channel.GuildChannel import dev.kord.core.entity.channel.MessageChannel import dev.kord.core.entity.channel.TextChannel -import dev.kord.core.entity.interaction.AutoCompleteInteraction import dev.kord.core.entity.interaction.GroupCommand import dev.kord.core.entity.interaction.ResolvableOptionValue import dev.kord.core.event.gateway.ReadyEvent import dev.kord.core.event.interaction.ChatInputCommandInteractionCreateEvent +import dev.kord.core.event.interaction.GuildAutoCompleteInteractionCreateEvent import dev.kord.core.on import dev.kord.rest.builder.interaction.group import dev.kord.rest.builder.interaction.subCommand @@ -69,6 +93,7 @@ public class SlashCommandManager( init { kord.on(consumer = ::execute) + kord.on(consumer = ::suggest) kord.on { // Sets kord to ready isKordReady = true @@ -176,8 +201,11 @@ public class SlashCommandManager( rootCommand.executeNonLinear(sender, null, commands, arguments) } - private suspend fun suggest(event: AutoCompleteInteraction) { - TODO("implement this correctly") + private suspend fun suggest(event: GuildAutoCompleteInteractionCreateEvent) { + println("huh?") + event.interaction.suggestString { + choice("hello", "test") + } } private suspend fun registerKordCommand(guildId: Snowflake, rootCommand: RootCommand) { diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt index 30ab6553..3b0d0e43 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandOptions.kt @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmds.kord import dev.kord.core.Kord diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashSenderExtension.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashSenderExtension.kt index da81e412..7f96af0a 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashSenderExtension.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashSenderExtension.kt @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmds.kord import dev.triumphteam.cmd.core.extention.sender.SenderExtension diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt index 81b93c95..a6e7017f 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/sender/SlashSender.kt @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.cmds.kord.sender public interface SlashSender { diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleSubCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleSubCommand.java index 3f565e61..0b9e4120 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleSubCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleSubCommand.java @@ -27,6 +27,8 @@ import dev.triumphteam.cmd.jda.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.User; +import java.util.Optional; + @Command("sub") public class ExampleSubCommand { @@ -36,7 +38,7 @@ public void first(final SlashCommandSender sender) { } @Command("second") - public void second(final SlashCommandSender sender, final User user) { + public void second(final SlashCommandSender sender, final User user, final Optional test) { sender.reply("Command sent was /sub second <" + user.getName() + ">").queue(); } } diff --git a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt index ebe435c6..15cc8bd4 100644 --- a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt +++ b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/Application.kt @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.kord.example import dev.kord.common.entity.Snowflake @@ -11,6 +34,7 @@ public suspend fun main(args: Array) { val kord = Kord(args[0]) val manager = SlashCommandManager(kord) + manager.registerSuggestion(String::class.java) { _, _ -> listOf("ass", "ss") } manager.apply { registerCommand(Snowflake(820696172477677628), ExampleCommand()) diff --git a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommand.kt b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommand.kt index 790eb519..cafc6b40 100644 --- a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommand.kt +++ b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommand.kt @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.kord.example.commands import dev.kord.core.entity.Attachment diff --git a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommandGroup.kt b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommandGroup.kt index 1c63ff19..b7736553 100644 --- a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommandGroup.kt +++ b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleCommandGroup.kt @@ -1,3 +1,26 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.kord.example.commands import dev.kord.core.entity.User diff --git a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt index fe20a6bb..eb5b5229 100644 --- a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt +++ b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt @@ -1,6 +1,28 @@ +/** + * MIT License + * + * Copyright (c) 2019-2021 Matt + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ package dev.triumphteam.kord.example.commands -import dev.kord.core.entity.User import dev.triumphteam.cmd.core.annotations.Command import dev.triumphteam.cmds.kord.sender.SlashSender @@ -12,7 +34,7 @@ public class ExampleSubCommand { } @Command("second") - public suspend fun second(sender: SlashSender, user: User) { - sender.reply("Command sent was /sub second <${user.username}>") + public suspend fun second(sender: SlashSender, text: String) { + sender.reply("Command sent was /sub second <${text}>") } } From 0cb390b10a3304a66bc1c808b9131a08438edf6f Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 13 Feb 2023 17:37:34 -0600 Subject: [PATCH 091/101] chore: Gradle 8 --- .../argument/UnknownInternalArgument.java | 8 +- .../cmds/kord/SlashCommandManager.kt | 1 - .../example/commands/ExampleSubCommand.kt | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- .../kotlin/dev/triumphteam/tests/Sender.kt | 48 ------------ .../fail/command registration fail test.kt | 75 ------------------- 6 files changed, 6 insertions(+), 130 deletions(-) delete mode 100644 simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt delete mode 100644 simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt diff --git a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java index f1ab2022..7f4eea26 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/argument/UnknownInternalArgument.java @@ -1,18 +1,18 @@ /** * MIT License - *

    + * * Copyright (c) 2019-2021 Matt - *

    + * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - *

    + * * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - *

    + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt index 83bfc271..23adc65a 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt @@ -214,7 +214,6 @@ public class SlashCommandManager( rootCommand.name, rootCommand.desc ) { - // If only default then register with no groups or sub commands rootCommand.defaultCommand?.let { if (it is SubCommand) { diff --git a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt index eb5b5229..40751c40 100644 --- a/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt +++ b/examples/discord/kord/slash/src/main/kotlin/dev/triumphteam/kord/example/commands/ExampleSubCommand.kt @@ -35,6 +35,6 @@ public class ExampleSubCommand { @Command("second") public suspend fun second(sender: SlashSender, text: String) { - sender.reply("Command sent was /sub second <${text}>") + sender.reply("Command sent was /sub second <$text>") } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 070cb702..da1db5f0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt b/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt deleted file mode 100644 index 51b82c63..00000000 --- a/simple/src/test/kotlin/dev/triumphteam/tests/Sender.kt +++ /dev/null @@ -1,48 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.tests - -import dev.triumphteam.cmd.core.extention.registry.MessageRegistry -import dev.triumphteam.cmd.core.extention.sender.SenderMapper -import dev.triumphteam.cmd.core.extention.sender.SenderValidator -import dev.triumphteam.cmd.core.subcommand.OldSubCommand - -class TestSender - -class TestSenderMapper : - SenderMapper { - - override fun map(defaultSender: TestSender): TestSender = defaultSender -} - -class TestSenderValidator : SenderValidator { - - override fun getAllowedSenders(): Set> = setOf(TestSender::class.java) - - override fun validate( - messageRegistry: MessageRegistry, - subCommand: OldSubCommand, - sender: TestSender, - ): Boolean = true -} diff --git a/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt b/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt deleted file mode 100644 index f929680c..00000000 --- a/simple/src/test/kotlin/dev/triumphteam/tests/fail/command registration fail test.kt +++ /dev/null @@ -1,75 +0,0 @@ -/** - * MIT License - * - * Copyright (c) 2019-2021 Matt - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ -package dev.triumphteam.tests.fail - -import dev.triumphteam.cmd.core.AnnotatedCommand -import dev.triumphteam.cmd.core.annotations.Command -import dev.triumphteam.cmd.core.exceptions.CommandRegistrationException -import dev.triumphteam.cmds.simple.SimpleCommandManager -import dev.triumphteam.tests.TestSender -import dev.triumphteam.tests.TestSenderMapper -import dev.triumphteam.tests.TestSenderValidator -import org.assertj.core.api.Assertions.assertThatThrownBy -import org.junit.jupiter.api.Test -import org.junit.jupiter.api.TestInstance - -@Suppress("ClassName") -@TestInstance(TestInstance.Lifecycle.PER_CLASS) -class `command registration fail test` { - - private val commandManager: SimpleCommandManager = - SimpleCommandManager.create(TestSenderMapper(), TestSenderValidator()) - - @Test - fun `no command registration fail`() { - assertThatThrownBy { - commandManager.registerCommand(NoCommand()) - }.isInstanceOf(CommandRegistrationException::class.java) - .hasMessageContaining("Command name or \"@${Command::class.java.simpleName}\" annotation missing") - } - - @Test - fun `empty command registration fail`() { - assertThatThrownBy { - commandManager.registerCommand(EmptyCommandAnnotation()) - println("test") - }.isInstanceOf(CommandRegistrationException::class.java) - .hasMessageContaining("Command name must not be empty") - } - - @Test - fun `empty extend command registration fail`() { - assertThatThrownBy { - commandManager.registerCommand(EmptyCommandSuper()) - }.isInstanceOf(CommandRegistrationException::class.java) - .hasMessageContaining("Command name must not be empty") - } -} - -class NoCommand : AnnotatedCommand() - -@Command -class EmptyCommandAnnotation : AnnotatedCommand() - -class EmptyCommandSuper : AnnotatedCommand("") From b23965051ab71d849e113376ceed6ff9413fc447 Mon Sep 17 00:00:00 2001 From: Matt Date: Mon, 13 Feb 2023 17:38:45 -0600 Subject: [PATCH 092/101] chore(dep): Bump Kotlin --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index e08dbf77..74309cbc 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] # kotlin -kotlin = "1.8.0" +kotlin = "1.8.10" coroutines = "1.6.4" license = "0.16.1" From 7785da8dacee8c9c19275218d400ded4128c5cbd Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 15 Feb 2023 16:05:57 -0600 Subject: [PATCH 093/101] feature: Configurable suggestion resolution method --- .../triumphteam/cmd/core/CommandManager.java | 43 ++++++++++++++++--- .../cmd/core/extention/CommandOptions.java | 5 ++- .../processor/AbstractCommandProcessor.java | 20 +++++---- .../cmd/core/suggestion/SimpleSuggestion.java | 38 +++++++++++----- .../cmd/core/suggestion/SuggestionMethod.java | 8 ++++ .../core/suggestion/SuggestionRegistry.java | 35 +++++++++------ .../cmds/kord/SlashCommandManager.kt | 1 - gradle.properties | 2 +- 8 files changed, 111 insertions(+), 41 deletions(-) create mode 100644 core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionMethod.java diff --git a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java index 6cb0f2c9..4c617a91 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/CommandManager.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -39,6 +39,7 @@ import dev.triumphteam.cmd.core.requirement.RequirementKey; import dev.triumphteam.cmd.core.requirement.RequirementResolver; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; +import dev.triumphteam.cmd.core.suggestion.SuggestionMethod; import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; import org.jetbrains.annotations.NotNull; @@ -116,7 +117,22 @@ public final void registerArgument(final @NotNull Class clazz, final @NotNull * @param resolver The {@link SuggestionResolver} with the suggestion resolution. */ public void registerSuggestion(final @NotNull SuggestionKey key, final @NotNull SuggestionResolver resolver) { - getRegistryContainer().getSuggestionRegistry().register(key, resolver); + registerSuggestion(key, SuggestionMethod.STARTS_WITH, resolver); + } + + /** + * Registers a suggestion to be used for specific arguments. + * + * @param key The {@link SuggestionKey} that identifies the registered suggestion. + * @param method The resolution method to use for suggestions. + * @param resolver The {@link SuggestionResolver} with the suggestion resolution. + */ + public void registerSuggestion( + final @NotNull SuggestionKey key, + final @NotNull SuggestionMethod method, + final @NotNull SuggestionResolver resolver + ) { + getRegistryContainer().getSuggestionRegistry().register(key, resolver, method); } /** @@ -126,7 +142,22 @@ public void registerSuggestion(final @NotNull SuggestionKey key, final @NotNull * @param resolver The {@link SuggestionResolver} with the suggestion resolution. */ public void registerSuggestion(final @NotNull Class type, final @NotNull SuggestionResolver resolver) { - getRegistryContainer().getSuggestionRegistry().register(type, resolver); + registerSuggestion(type, SuggestionMethod.STARTS_WITH, resolver); + } + + /** + * Registers a suggestion to be used for all arguments of a specific type. + * + * @param type Using specific {@link Class} types as target for suggestions instead of keys. + * @param method The resolution method to use for suggestions. + * @param resolver The {@link SuggestionResolver} with the suggestion resolution. + */ + public void registerSuggestion( + final @NotNull Class type, + final @NotNull SuggestionMethod method, + final @NotNull SuggestionResolver resolver + ) { + getRegistryContainer().getSuggestionRegistry().register(type, resolver, method); } /** diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java index 565964fa..dbfefeb4 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java @@ -38,6 +38,7 @@ import dev.triumphteam.cmd.core.message.MessageResolver; import dev.triumphteam.cmd.core.message.context.MessageContext; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; +import dev.triumphteam.cmd.core.suggestion.SuggestionMethod; import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; import org.jetbrains.annotations.Contract; @@ -148,7 +149,7 @@ public Setup(final @NotNull RegistryContainer registryContainer) { final @NotNull Class type, final @NotNull SuggestionResolver resolver ) { - suggestionRegistry.register(type, resolver); + suggestionRegistry.register(type, resolver, SuggestionMethod.STARTS_WITH); return (I) this; } @@ -157,7 +158,7 @@ public Setup(final @NotNull RegistryContainer registryContainer) { final @NotNull SuggestionKey key, final @NotNull SuggestionResolver resolver ) { - suggestionRegistry.register(key, resolver); + suggestionRegistry.register(key, resolver, SuggestionMethod.STARTS_WITH); return (I) this; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java index 1412d791..31954cc8 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/AbstractCommandProcessor.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -58,8 +58,10 @@ import dev.triumphteam.cmd.core.suggestion.SimpleSuggestion; import dev.triumphteam.cmd.core.suggestion.Suggestion; import dev.triumphteam.cmd.core.suggestion.SuggestionKey; +import dev.triumphteam.cmd.core.suggestion.SuggestionMethod; import dev.triumphteam.cmd.core.suggestion.SuggestionRegistry; import dev.triumphteam.cmd.core.suggestion.SuggestionResolver; +import dev.triumphteam.cmd.core.util.Pair; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -482,17 +484,17 @@ private Map> createNamedArgumentInternals( return new EnumSuggestion<>((Class>) type, commandOptions.suggestLowercaseEnum()); } - final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(type); - if (resolver != null) return new SimpleSuggestion<>(resolver); + final Pair, SuggestionMethod> pair = suggestionRegistry.getSuggestionResolver(type); + if (pair != null) return new SimpleSuggestion<>(pair.first(), pair.second()); return new EmptySuggestion<>(); } - final SuggestionResolver resolver = suggestionRegistry.getSuggestionResolver(suggestionKey); - if (resolver == null) { + final Pair, SuggestionMethod> pair = suggestionRegistry.getSuggestionResolver(suggestionKey); + if (pair == null) { throw createException("Cannot find the suggestion key `" + suggestionKey + "`"); } - return new SimpleSuggestion<>(resolver); + return new SimpleSuggestion<>(pair.first(), pair.second()); } private @NotNull Suggestion suggestionFromParam(final @NotNull Parameter parameter) { diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java index 2edf71b4..6ab47951 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SimpleSuggestion.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -29,13 +29,19 @@ import java.util.List; import java.util.Objects; import java.util.stream.Collectors; +import java.util.stream.Stream; public final class SimpleSuggestion implements Suggestion { private final SuggestionResolver resolver; + private final SuggestionMethod method; - public SimpleSuggestion(final @NotNull SuggestionResolver resolver) { + public SimpleSuggestion( + final @NotNull SuggestionResolver resolver, + final @NotNull SuggestionMethod method + ) { this.resolver = resolver; + this.method = method; } @Override @@ -44,11 +50,23 @@ public SimpleSuggestion(final @NotNull SuggestionResolver resolver) { final @NotNull String current, final @NotNull List arguments ) { - return resolver - .resolve(sender, arguments) - .stream() - .filter(it -> it.toLowerCase().startsWith(current.toLowerCase())) - .collect(Collectors.toList()); + Stream stream = resolver.resolve(sender, arguments).stream(); + + switch (method) { + case STARTS_WITH: { + stream = stream.filter(it -> it.toLowerCase().startsWith(current.toLowerCase())); + break; + } + + case CONTAINS: { + stream = stream.filter(it -> it.toLowerCase().contains(current.toLowerCase())); + break; + } + + default: break; + } + + return stream.collect(Collectors.toList()); } @Override diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionMethod.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionMethod.java new file mode 100644 index 00000000..fecfe6c8 --- /dev/null +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionMethod.java @@ -0,0 +1,8 @@ +package dev.triumphteam.cmd.core.suggestion; + +public enum SuggestionMethod { + + STARTS_WITH, + CONTAINS, + NONE; +} diff --git a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java index 735622e0..a7ba5360 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/suggestion/SuggestionRegistry.java @@ -1,18 +1,18 @@ /** * MIT License - * + *

    * Copyright (c) 2019-2021 Matt - * + *

    * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: - * + *

    * The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - * + *

    * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -24,6 +24,7 @@ package dev.triumphteam.cmd.core.suggestion; import dev.triumphteam.cmd.core.extention.registry.Registry; +import dev.triumphteam.cmd.core.util.Pair; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -38,17 +39,22 @@ */ public final class SuggestionRegistry implements Registry { - private final Map> suggestions = new HashMap<>(); - private final Map, SuggestionResolver> typeSuggestions = new HashMap<>(); + private final Map, SuggestionMethod>> suggestions = new HashMap<>(); + private final Map, Pair, SuggestionMethod>> typeSuggestions = new HashMap<>(); /** * Registers a new {@link SuggestionResolver} for the specific Key. * * @param key The suggestion key. * @param resolver The action to get the suggestions. + * @param method The method os suggestion to be used. */ - public void register(final @NotNull SuggestionKey key, final @NotNull SuggestionResolver resolver) { - suggestions.put(key, resolver); + public void register( + final @NotNull SuggestionKey key, + final @NotNull SuggestionResolver resolver, + final @NotNull SuggestionMethod method + ) { + suggestions.put(key, new Pair<>(resolver, method)); } /** @@ -56,9 +62,14 @@ public void register(final @NotNull SuggestionKey key, final @NotNull Suggestion * * @param type The type to suggest for. * @param resolver The action to get the suggestions. + * @param method The method os suggestion to be used. */ - public void register(final @NotNull Class type, final @NotNull SuggestionResolver resolver) { - typeSuggestions.put(type, resolver); + public void register( + final @NotNull Class type, + final @NotNull SuggestionResolver resolver, + final @NotNull SuggestionMethod method + ) { + typeSuggestions.put(type, new Pair<>(resolver, method)); } /** @@ -68,7 +79,7 @@ public void register(final @NotNull Class type, final @NotNull SuggestionReso * @return A saved {@link SuggestionResolver}. */ @Contract("null -> null") - public @Nullable SuggestionResolver getSuggestionResolver(final @Nullable SuggestionKey key) { + public @Nullable Pair, SuggestionMethod> getSuggestionResolver(final @Nullable SuggestionKey key) { if (key == null) return null; return suggestions.get(key); } @@ -79,7 +90,7 @@ public void register(final @NotNull Class type, final @NotNull SuggestionReso * @param type The specific type. * @return A saved {@link SuggestionResolver}. */ - public @Nullable SuggestionResolver getSuggestionResolver(final @NotNull Class type) { + public @Nullable Pair, SuggestionMethod> getSuggestionResolver(final @NotNull Class type) { return typeSuggestions.get(type); } } diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt index 23adc65a..5ddd0850 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt @@ -202,7 +202,6 @@ public class SlashCommandManager( } private suspend fun suggest(event: GuildAutoCompleteInteractionCreateEvent) { - println("huh?") event.interaction.suggestString { choice("hello", "test") } diff --git a/gradle.properties b/gradle.properties index 1173de72..90d4e524 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ kotlin.stdlib.default.dependency=false -version=2.0.0-ALPHA-4 +version=2.0.0-ALPHA-6 group=dev.triumphteam From 9b75dfc7826708f9eef72a1d47783e2ae0bb0387 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 15 Apr 2023 01:29:18 +0100 Subject: [PATCH 094/101] feature: Re-adding custom senders --- .../triumphteam/cmd/core/command/ParentCommand.java | 2 +- .../dev/triumphteam/cmd/core/command/SubCommand.java | 2 +- .../cmd/core/extention/CommandExtensions.java | 8 ++++++++ .../cmd/core/extention/CommandOptions.java | 9 ++------- .../cmd/core/extention/ExtensionBuilder.java | 11 ++++++++++- .../cmd/core/processor/SubCommandProcessor.java | 2 +- .../dev/triumphteam/cmd/jda/SlashCommandManager.java | 4 ++-- .../dev/triumphteam/cmds/kord/SlashCommandManager.kt | 2 +- .../dev/triumphteam/cmd/bukkit/BukkitCommand.java | 2 +- 9 files changed, 27 insertions(+), 15 deletions(-) diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java index 7691753d..efc0e5f7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/ParentCommand.java @@ -69,7 +69,7 @@ public ParentCommand(final @NotNull CommandProcessor processor) { this.meta = processor.createMeta(settingsBuilder); this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); - this.senderExtension = processor.getCommandOptions().getSenderExtension(); + this.senderExtension = processor.getCommandOptions().getCommandExtensions().getSenderExtension(); this.settings = settingsBuilder.build(); } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java index bc828b20..6ec75bbc 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/command/SubCommand.java @@ -111,7 +111,7 @@ public SubCommand( final CommandOptions commandOptions = processor.getCommandOptions(); this.messageRegistry = processor.getRegistryContainer().getMessageRegistry(); - this.senderExtension = commandOptions.getSenderExtension(); + this.senderExtension = commandOptions.getCommandExtensions().getSenderExtension(); this.commandExecutor = commandOptions.getCommandExtensions().getCommandExecutor(); this.syntax = createSyntax(parentCommand, processor); diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java index d45f1375..b68d81cf 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandExtensions.java @@ -27,6 +27,7 @@ import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; import dev.triumphteam.cmd.core.extention.command.Processor; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.NotNull; import java.lang.annotation.Annotation; @@ -38,15 +39,18 @@ public final class CommandExtensions { private final Map, AnnotationProcessor> annotationProcessors; private final List> processors; + private final SenderExtension senderExtension; private final ArgumentValidator argumentValidator; private final CommandExecutor commandExecutor; public CommandExtensions( + final @NotNull SenderExtension senderExtension, final @NotNull Map, AnnotationProcessor> annotationProcessors, final @NotNull List> processors, final @NotNull ArgumentValidator argumentValidator, final @NotNull CommandExecutor commandExecutor ) { + this.senderExtension = senderExtension; this.annotationProcessors = annotationProcessors; this.processors = processors; this.argumentValidator = argumentValidator; @@ -68,4 +72,8 @@ public CommandExtensions( public @NotNull CommandExecutor getCommandExecutor() { return commandExecutor; } + + public @NotNull SenderExtension getSenderExtension() { + return senderExtension; + } } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java index dbfefeb4..5ea9f71a 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/CommandOptions.java @@ -52,15 +52,14 @@ public class CommandOptions { private final CommandExtensions commandExtensions; - private final SenderExtension senderExtension; private final boolean suggestLowercaseEnum; public CommandOptions( final @NotNull SenderExtension senderExtension, final @NotNull Builder builder ) { - this.senderExtension = senderExtension; - this.commandExtensions = builder.extensionBuilder.build(); + + this.commandExtensions = builder.extensionBuilder.build(senderExtension); this.suggestLowercaseEnum = builder.suggestLowercaseEnum; } @@ -68,10 +67,6 @@ public CommandOptions( return commandExtensions; } - public @NotNull SenderExtension getSenderExtension() { - return senderExtension; - } - public boolean suggestLowercaseEnum() { return suggestLowercaseEnum; } diff --git a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java index 8d0a3e29..539dd506 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/extention/ExtensionBuilder.java @@ -28,6 +28,7 @@ import dev.triumphteam.cmd.core.extention.annotation.AnnotationProcessor; import dev.triumphteam.cmd.core.extention.argument.ArgumentValidator; import dev.triumphteam.cmd.core.extention.command.Processor; +import dev.triumphteam.cmd.core.extention.sender.SenderExtension; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; @@ -42,6 +43,7 @@ public final class ExtensionBuilder { private final Map, AnnotationProcessor> annotationProcessors = new HashMap<>(); private final List> processors = new ArrayList<>(); + private SenderExtension senderExtension = null; private ArgumentValidator argumentValidator = null; private CommandExecutor commandExecutor = null; @@ -72,7 +74,13 @@ public final class ExtensionBuilder { return this; } - public @NotNull CommandExtensions build() { + @Contract("_ -> this") + public @NotNull ExtensionBuilder setSenderExtension(final @NotNull SenderExtension senderExtension) { + this.senderExtension = senderExtension; + return this; + } + + public @NotNull CommandExtensions build(final @NotNull SenderExtension defaultExtension) { if (argumentValidator == null) { throw new CommandRegistrationException("No argument validator was added to Command Manager."); } @@ -82,6 +90,7 @@ public final class ExtensionBuilder { } return new CommandExtensions<>( + senderExtension == null ? defaultExtension : senderExtension, annotationProcessors, processors, argumentValidator, diff --git a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java index 031b29fb..f5e6fae7 100644 --- a/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java +++ b/core/src/main/java/dev/triumphteam/cmd/core/processor/SubCommandProcessor.java @@ -132,7 +132,7 @@ public final class SubCommandProcessor extends AbstractCommandProcessor type = parameters[0].getType(); - final Set> allowedSenders = getCommandOptions().getSenderExtension().getAllowedSenders(); + final Set> allowedSenders = getCommandOptions().getCommandExtensions().getSenderExtension().getAllowedSenders(); if (!allowedSenders.contains(type)) { throw createException( diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java index 017bdf91..0f32ff9c 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/SlashCommandManager.java @@ -160,7 +160,7 @@ public void execute(final @NotNull SlashCommandInteractionEvent event) { // Immediately pop the main command out, to remove itself from it commands.pop(); - final SenderExtension senderExtension = getCommandOptions().getSenderExtension(); + final SenderExtension senderExtension = getCommandOptions().getCommandExtensions().getSenderExtension(); final S sender = senderExtension.map(new InteractionCommandSender(event)); // Mapping of arguments @@ -180,7 +180,7 @@ public void suggest(final @NotNull CommandAutoCompleteInteractionEvent event) { // Immediately pop the main command out, to remove itself from it commands.pop(); - final SenderExtension senderExtension = getCommandOptions().getSenderExtension(); + final SenderExtension senderExtension = getCommandOptions().getCommandExtensions().getSenderExtension(); final S sender = senderExtension.map(new SuggestionCommandSender(event)); final SubCommand subCommand = findExecutable(commands, command); if (subCommand == null) return; diff --git a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt index 5ddd0850..010e71cb 100644 --- a/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt +++ b/discord/kord/slash/src/main/kotlin/dev/triumphteam/cmds/kord/SlashCommandManager.kt @@ -182,7 +182,7 @@ public class SlashCommandManager( val rootCommand = guildCommands[event.interaction.invokedCommandGuildId]?.get(name) ?: return - val sender = commandOptions.senderExtension.map(DummySender(event)) + val sender = commandOptions.commandExtensions.senderExtension.map(DummySender(event)) // Mapping all arguments val arguments: Map> = command.options.map { (key, value) -> diff --git a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java index 2b230ea8..b7191796 100644 --- a/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java +++ b/minecraft/bukkit/src/main/java/dev/triumphteam/cmd/bukkit/BukkitCommand.java @@ -43,7 +43,7 @@ final class BukkitCommand extends Command { super(processor.getName(), processor.getDescription(), "", processor.getAliases()); this.rootCommand = new RootCommand<>(processor); - this.senderExtension = processor.getCommandOptions().getSenderExtension(); + this.senderExtension = processor.getCommandOptions().getCommandExtensions().getSenderExtension(); } @Override From 688006842eeaad7ab67a7e1d5c1e0448aecd0823 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 15 Apr 2023 01:45:01 +0100 Subject: [PATCH 095/101] chore: Bump alpha version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 90d4e524..d28de075 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ kotlin.stdlib.default.dependency=false -version=2.0.0-ALPHA-6 +version=2.0.0-ALPHA-8 group=dev.triumphteam From fc9b739d2192a3a6ebfa6aff24fe2e74e71b2750 Mon Sep 17 00:00:00 2001 From: "Mr. Afonso" <44532605+xMrAfonso@users.noreply.github.com> Date: Thu, 27 Apr 2023 20:55:06 +0200 Subject: [PATCH 096/101] chore: Updated JDA to beta 8 5.0.0-beta.3 -> 5.0.0-beta.8 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 74309cbc..fc214a19 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -17,7 +17,7 @@ assertj = "3.23.1" spigot = "1.18.2-R0.1-SNAPSHOT" # Discord -jda = "5.0.0-beta.3" +jda = "5.0.0-beta.8" kord = "0.8.0-M17" # Formatting From f1e991e9baa8cf658c0b911c28ef3990d6985a46 Mon Sep 17 00:00:00 2001 From: kazuryy <121773704+kazuryyx@users.noreply.github.com> Date: Wed, 13 Sep 2023 23:42:13 +0200 Subject: [PATCH 097/101] chore: Update JDA to beta 13 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index fc214a19..be3e7106 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -17,7 +17,7 @@ assertj = "3.23.1" spigot = "1.18.2-R0.1-SNAPSHOT" # Discord -jda = "5.0.0-beta.8" +jda = "5.0.0-beta.13" kord = "0.8.0-M17" # Formatting From d8561468424b9a78f25f7c18fe3e40845913d076 Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 13 Sep 2023 22:46:41 +0100 Subject: [PATCH 098/101] chore: Bump project version to alpha-9 --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index d28de075..24d8a6a6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ kotlin.stdlib.default.dependency=false -version=2.0.0-ALPHA-8 +version=2.0.0-ALPHA-9 group=dev.triumphteam From 1012e59794ffbb43cbd27e6310aca9cbbd743101 Mon Sep 17 00:00:00 2001 From: Matt Date: Sun, 17 Sep 2023 20:42:30 +0100 Subject: [PATCH 099/101] fix: Remove optional from example command --- .../triumphteam/jda/example/commands/ExampleSubCommand.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleSubCommand.java b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleSubCommand.java index 0b9e4120..0310f6c6 100644 --- a/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleSubCommand.java +++ b/examples/discord/jda/slash/src/main/java/dev/triumphteam/jda/example/commands/ExampleSubCommand.java @@ -27,8 +27,6 @@ import dev.triumphteam.cmd.jda.sender.SlashCommandSender; import net.dv8tion.jda.api.entities.User; -import java.util.Optional; - @Command("sub") public class ExampleSubCommand { @@ -38,7 +36,7 @@ public void first(final SlashCommandSender sender) { } @Command("second") - public void second(final SlashCommandSender sender, final User user, final Optional test) { + public void second(final SlashCommandSender sender, final User user, final String test) { sender.reply("Command sent was /sub second <" + user.getName() + ">").queue(); } } From 3980fb2ff674fc20a6a35c691a881fb165cca0e8 Mon Sep 17 00:00:00 2001 From: "Mr. Afonso" Date: Tue, 9 Apr 2024 11:58:03 +0200 Subject: [PATCH 100/101] chore: Update JDA version to 5.0.0-beta.22 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index be3e7106..60d22828 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -17,7 +17,7 @@ assertj = "3.23.1" spigot = "1.18.2-R0.1-SNAPSHOT" # Discord -jda = "5.0.0-beta.13" +jda = "5.0.0-beta.22" kord = "0.8.0-M17" # Formatting From 7be8b65fbfaa96fdb426fe62b494902c6ba18adb Mon Sep 17 00:00:00 2001 From: Sparky <87631423+Sparky983@users.noreply.github.com> Date: Tue, 9 Apr 2024 19:58:57 +1000 Subject: [PATCH 101/101] chore: Add `@CheckReturnValue` to action-returning methods --- .../java/dev/triumphteam/cmd/jda/sender/SlashSender.java | 7 +++++++ gradle/libs.versions.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/sender/SlashSender.java b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/sender/SlashSender.java index cff68ecc..b881e76e 100644 --- a/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/sender/SlashSender.java +++ b/discord/jda/slash/src/main/java/dev/triumphteam/cmd/jda/sender/SlashSender.java @@ -30,6 +30,7 @@ import net.dv8tion.jda.api.entities.channel.unions.MessageChannelUnion; import net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction; import net.dv8tion.jda.api.utils.messages.MessageCreateData; +import org.jetbrains.annotations.CheckReturnValue; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -74,6 +75,7 @@ public interface SlashSender { * @param message The message to reply with. * @return The reply action. */ + @CheckReturnValue @NotNull ReplyCallbackAction reply(final @NotNull String message); /** @@ -82,6 +84,7 @@ public interface SlashSender { * @param message The message to reply with. * @return The reply action. */ + @CheckReturnValue @NotNull ReplyCallbackAction reply(final @NotNull MessageCreateData message); /** @@ -91,6 +94,7 @@ public interface SlashSender { * @param embeds The additional embeds. * @return The reply action. */ + @CheckReturnValue @NotNull ReplyCallbackAction reply(final @NotNull MessageEmbed embed, final @NotNull MessageEmbed @NotNull ... embeds); /** @@ -99,6 +103,7 @@ public interface SlashSender { * @param embeds The embeds to reply with. * @return The reply action. */ + @CheckReturnValue @NotNull ReplyCallbackAction reply(final @NotNull Collection embeds); /** @@ -106,6 +111,7 @@ public interface SlashSender { * * @return The reply action. */ + @CheckReturnValue @NotNull ReplyCallbackAction deferReply(); /** @@ -114,5 +120,6 @@ public interface SlashSender { * @param ephemeral Whether the message should be ephemeral. * @return The reply action. */ + @CheckReturnValue @NotNull ReplyCallbackAction deferReply(final boolean ephemeral); } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 60d22828..91cd5bee 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,7 +7,7 @@ license = "0.16.1" # Core guava = "31.1-jre" -annotations = "23.0.0" +annotations = "24.1.0" # Testing junit = "5.9.1"