From 8b0a650b4884e602d7fbf1835e7a342b9adaffbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Thu, 17 Sep 2020 13:19:31 +0200 Subject: [PATCH] component->argument --- README.md | 172 +++++++++--------- .../intellectualsites/commands/Command.java | 126 ++++++------- .../commands/CommandManager.java | 24 +-- .../commands/CommandTree.java | 122 ++++++------- .../commands/annotations/specifier/Range.java | 2 +- .../annotations/specifier/package-info.java | 4 +- .../CommandArgument.java} | 150 +++++++-------- .../CommandSyntaxFormatter.java | 8 +- .../StandardCommandSyntaxFormatter.java | 24 +-- .../StaticArgument.java} | 62 +++---- .../package-info.java | 4 +- .../parser/ArgumentParseResult.java} | 16 +- .../parser/ArgumentParser.java} | 8 +- .../parser/ParserParameter.java | 2 +- .../parser/ParserParameters.java | 2 +- .../parser/ParserRegistry.java | 12 +- .../parser/StandardParameters.java | 2 +- .../parser/StandardParserRegistry.java | 64 +++---- .../parser/package-info.java | 4 +- .../standard/BooleanArgument.java} | 78 ++++---- .../standard/ByteArgument.java} | 70 +++---- .../standard/CharArgument.java} | 74 ++++---- .../standard/DoubleArgument.java} | 76 ++++---- .../standard/EnumArgument.java} | 76 ++++---- .../standard/FloatArgument.java} | 76 ++++---- .../standard/IntegerArgument.java} | 76 ++++---- .../standard/LongArgument.java} | 78 ++++---- .../standard/ShortArgument.java} | 68 +++---- .../standard/StringArgument.java} | 86 ++++----- .../standard/package-info.java | 4 +- .../exceptions/AmbiguousNodeException.java | 22 +-- ...ption.java => ArgumentParseException.java} | 10 +- .../exceptions/CommandParseException.java | 10 +- .../InvalidCommandSenderException.java | 4 +- .../exceptions/InvalidSyntaxException.java | 4 +- .../exceptions/NoCommandInLeafException.java | 22 +-- .../exceptions/NoPermissionException.java | 4 +- .../exceptions/NoSuchCommandException.java | 10 +- .../commands/CommandPreProcessorTest.java | 4 +- .../commands/CommandSuggestionsTest.java | 20 +- .../commands/CommandTest.java | 10 +- .../commands/CommandTreeTest.java | 14 +- .../commands/ParserRegistryTest.java | 22 +-- .../commands/jline/JLineCommandManager.java | 12 +- .../brigadier/CloudBrigadierManager.java | 156 ++++++++-------- .../commands/BukkitTest.java | 52 +++--- .../commands/BukkitCommand.java | 6 +- .../commands/BukkitCommandManager.java | 4 +- .../BukkitPluginRegistrationHandler.java | 22 +-- ...WorldComponent.java => WorldArgument.java} | 72 ++++---- .../commands/parsers/package-info.java | 2 +- .../commands/PaperBrigadierListener.java | 4 +- 52 files changed, 1032 insertions(+), 1024 deletions(-) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/CommandComponent.java => arguments/CommandArgument.java} (65%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components => arguments}/CommandSyntaxFormatter.java (83%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components => arguments}/StandardCommandSyntaxFormatter.java (66%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/StaticComponent.java => arguments/StaticArgument.java} (58%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components => arguments}/package-info.java (90%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/parser/ComponentParseResult.java => arguments/parser/ArgumentParseResult.java} (85%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/parser/ComponentParser.java => arguments/parser/ArgumentParser.java} (88%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components => arguments}/parser/ParserParameter.java (97%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components => arguments}/parser/ParserParameters.java (98%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components => arguments}/parser/ParserRegistry.java (89%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components => arguments}/parser/StandardParameters.java (97%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components => arguments}/parser/StandardParserRegistry.java (73%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components => arguments}/parser/package-info.java (92%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/standard/BooleanComponent.java => arguments/standard/BooleanArgument.java} (67%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/standard/ByteComponent.java => arguments/standard/ByteArgument.java} (71%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/standard/CharComponent.java => arguments/standard/CharArgument.java} (55%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/standard/DoubleComponent.java => arguments/standard/DoubleArgument.java} (68%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/standard/EnumComponent.java => arguments/standard/EnumArgument.java} (71%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/standard/FloatComponent.java => arguments/standard/FloatArgument.java} (68%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/standard/IntegerComponent.java => arguments/standard/IntegerArgument.java} (70%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/standard/LongComponent.java => arguments/standard/LongArgument.java} (66%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/standard/ShortComponent.java => arguments/standard/ShortArgument.java} (70%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components/standard/StringComponent.java => arguments/standard/StringArgument.java} (72%) rename cloud-core/src/main/java/com/intellectualsites/commands/{components => arguments}/standard/package-info.java (92%) rename cloud-core/src/main/java/com/intellectualsites/commands/exceptions/{ComponentParseException.java => ArgumentParseException.java} (82%) rename cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/parsers/{WorldComponent.java => WorldArgument.java} (60%) diff --git a/README.md b/README.md index d240ec0f..f00fbcb6 100644 --- a/README.md +++ b/README.md @@ -1,84 +1,92 @@ -
- -
-# cloud command framework - -[![CodeFactor](https://www.codefactor.io/repository/github/sauilitired/cloud/badge)](https://www.codefactor.io/repository/github/sauilitired/cloud) - -This is going to be a general-purpose Java command dispatcher & framework. -It will allow programmers to define command chains that users can use to execute pre-defined actions. - -The library was named cloud because using it makes you feel like you're floating around on a cloud in heaven. It's an experience of pure bliss and joy. -This is unlike the experience of using **a**ny **c**ommand **f**ramework that currently exists for the JVM, which can be compared to drowning in a pool of lava while watching your family get eaten by a pack of wolves. - -Its feature set is derived from **a**lready existing **c**ommand **f**rameworks, while being less restrictive, opinionated and confusing. -CLOUD is built to be completely deterministic and your commands will behave exactly as you've programmed them to. No fluff and no mess, just a smooth cloud-like experience. - -The code is based on a paper that can be found [here](https://github.com/Sauilitired/Sauilitired/blob/master/AS_2020_09_Commands.pdf). - -## goals - -- Allow for commands to be defined using builder patterns -- Allow for commands to be defined using annotated methods -- Allow for command pre-processing -- Allow for command suggestion outputs - -Once the core functionality is present, the framework will offer implementation modules, supporting a wide variety of platforms. - -### implementations - -- Minecraft: - - Generic Brigadier module - - Bukkit module - - Paper module, with optional Brigadier support - - Sponge module - - Cloudburst - - Bungee module - - Velocity module - -- Create a Discord implementation (JDA) -- Create a Java CLI implementation (JLine3) - -## links - -- Discord: https://discord.gg/KxkjDVg - -## develop & build - -To clone the repository, use `git clone --recursive https://github.com/Sauilitired/cloud.git`. -To then build it, use `mvn clean package`. If you've already cloned the repository without -doing it recursively, use `git submodule update --remote` to update the submodule. This is -only needed the first time, as Maven will perform this operation when building. - -There is a bash script (`build.sh`) that performs the submodule updating & builds the project. -Feel free to use this if you want to. - -## maven - -cloud is available from [IntellectualSites](https://intellectualsites.com)' maven repository: - -```xml - - intellectualsites-snapshots - https://mvn.intellectualsites.com/content/repositories/snapshots - -``` - -```xml - - com.intellectualsites - - - -``` - -### attributions, links & acknowledgements - -This library is licensed under the MIT license, and the code copyright -belongs to Alexander Söderberg. The implementation is based on a paper written by the copyright holder, and this paper exists -under the CC Attribution 4 license. - -The Cloud icon was created by by -Thanga Vignesh P on Iconscout +
+ +
+ +# cloud command framework + +[![CodeFactor](https://www.codefactor.io/repository/github/sauilitired/cloud/badge)](https://www.codefactor.io/repository/github/sauilitired/cloud) + +This is going to be a general-purpose Java command dispatcher & framework. +It will allow programmers to define command chains that users can use to execute pre-defined actions. + +The library was named cloud because using it makes you feel like you're floating around on a cloud in heaven. It's an experience of pure bliss and joy. +This is unlike the experience of using **a**ny **c**ommand **f**ramework that currently exists for the JVM, which can be compared to drowning in a pool of lava while watching your family get eaten by a pack of wolves. + +Its feature set is derived from **a**lready existing **c**ommand **f**rameworks, while being less restrictive, opinionated and confusing. +CLOUD is built to be completely deterministic and your commands will behave exactly as you've programmed them to. No fluff and no mess, just a smooth cloud-like experience. + +The code is based on a paper that can be found [here](https://github.com/Sauilitired/Sauilitired/blob/master/AS_2020_09_Commands.pdf). + +## goals + +- Allow for commands to be defined using builder patterns +- Allow for commands to be defined using annotated methods +- Allow for command pre-processing +- Allow for command suggestion outputs + +Once the core functionality is present, the framework will offer implementation modules, supporting a wide variety of platforms. + +### implementations + +- Minecraft: + - Generic Brigadier module + - Bukkit module + - Paper module, with optional Brigadier support + - Sponge module + - Cloudburst + - Bungee module + - Velocity module + +- Create a Discord implementation (JDA) +- Create a Java CLI implementation (JLine3) + +## nomenclature +- **sender**: someone who is able to produce input +- **argument**: an argument is something that can be parsed from a string +- **required argument**: a required argument is an argument that must be provided by the sender +- **optional argument**: an optional argument is an argument that can be omitted (may have a default value) +- **static argument**: a string literal +- **command**: a command is a chain of arguments and a handler that acts on the parsed arguments +- **command tree**: structure that contains all commands and is used to parse input into arguments + +## links + +- Discord: https://discord.gg/KxkjDVg + +## develop & build + +To clone the repository, use `git clone --recursive https://github.com/Sauilitired/cloud.git`. +To then build it, use `mvn clean package`. If you've already cloned the repository without +doing it recursively, use `git submodule update --remote` to update the submodule. This is +only needed the first time, as Maven will perform this operation when building. + +There is a bash script (`build.sh`) that performs the submodule updating & builds the project. +Feel free to use this if you want to. + +## maven + +cloud is available from [IntellectualSites](https://intellectualsites.com)' maven repository: + +```xml + + intellectualsites-snapshots + https://mvn.intellectualsites.com/content/repositories/snapshots + +``` + +```xml + + com.intellectualsites + +``` + +### attributions, links & acknowledgements + +This library is licensed under the MIT license, and the code copyright +belongs to Alexander Söderberg. The implementation is based on a paper written by the copyright holder, and this paper exists +under the CC Attribution 4 license. + +The Cloud icon was created by by +Thanga Vignesh P on Iconscout and Digital rights were purchased under a premium plan. diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/Command.java b/cloud-core/src/main/java/com/intellectualsites/commands/Command.java index 456968a9..e3fe2682 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/Command.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/Command.java @@ -23,8 +23,8 @@ // package com.intellectualsites.commands; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.StaticComponent; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.StaticArgument; import com.intellectualsites.commands.execution.CommandExecutionHandler; import com.intellectualsites.commands.meta.CommandMeta; import com.intellectualsites.commands.sender.CommandSender; @@ -39,7 +39,7 @@ import java.util.Optional; import java.util.function.Consumer; /** - * A command consists out of a chain of {@link com.intellectualsites.commands.components.CommandComponent command components}. + * A command consists out of a chain of {@link CommandArgument command arguments}. * * @param Command sender type * @param Command meta type @@ -47,7 +47,7 @@ import java.util.function.Consumer; @SuppressWarnings("unused") public class Command { - @Nonnull private final List> components; + @Nonnull private final List> arguments; @Nonnull private final CommandExecutionHandler commandExecutionHandler; @Nullable private final Class senderType; @Nonnull private final String commandPermission; @@ -56,32 +56,32 @@ public class Command { /** * Construct a new command * - * @param commandComponents Command components + * @param commandArguments Command arguments * @param commandExecutionHandler Execution handler * @param senderType Required sender type. May be {@code null} * @param commandPermission Command permission * @param commandMeta Command meta instance */ - public Command(@Nonnull final List> commandComponents, + public Command(@Nonnull final List> commandArguments, @Nonnull final CommandExecutionHandler commandExecutionHandler, @Nullable final Class senderType, @Nonnull final String commandPermission, @Nonnull final M commandMeta) { - this.components = Objects.requireNonNull(commandComponents, "Command components may not be null"); - if (this.components.size() == 0) { - throw new IllegalArgumentException("At least one command component is required"); + this.arguments = Objects.requireNonNull(commandArguments, "Command arguments may not be null"); + if (this.arguments.size() == 0) { + throw new IllegalArgumentException("At least one command argument is required"); } - // Enforce ordering of command components + // Enforce ordering of command arguments boolean foundOptional = false; - for (final CommandComponent component : this.components) { - if (component.getName().isEmpty()) { - throw new IllegalArgumentException("Component names may not be empty"); + for (final CommandArgument argument : this.arguments) { + if (argument.getName().isEmpty()) { + throw new IllegalArgumentException("Argument names may not be empty"); } - if (foundOptional && component.isRequired()) { + if (foundOptional && argument.isRequired()) { throw new IllegalArgumentException( - String.format("Command component '%s' cannot be placed after an optional component", - component.getName())); - } else if (!component.isRequired()) { + String.format("Command argument '%s' cannot be placed after an optional argument", + argument.getName())); + } else if (!argument.isRequired()) { foundOptional = true; } } @@ -94,37 +94,37 @@ public class Command { /** * Construct a new command * - * @param commandComponents Command components + * @param commandArguments Command arguments * @param commandExecutionHandler Execution handler * @param senderType Required sender type. May be {@code null} * @param commandMeta Command meta instance */ - public Command(@Nonnull final List> commandComponents, + public Command(@Nonnull final List> commandArguments, @Nonnull final CommandExecutionHandler commandExecutionHandler, @Nullable final Class senderType, @Nonnull final M commandMeta) { - this(commandComponents, commandExecutionHandler, senderType, "", commandMeta); + this(commandArguments, commandExecutionHandler, senderType, "", commandMeta); } /** * Construct a new command * - * @param commandComponents Command components + * @param commandArguments Command arguments * @param commandExecutionHandler Execution handler * @param commandPermission Command permission * @param commandMeta Command meta instance */ - public Command(@Nonnull final List> commandComponents, + public Command(@Nonnull final List> commandArguments, @Nonnull final CommandExecutionHandler commandExecutionHandler, @Nonnull final String commandPermission, @Nonnull final M commandMeta) { - this(commandComponents, commandExecutionHandler, null, "", commandMeta); + this(commandArguments, commandExecutionHandler, null, "", commandMeta); } /** * Create a new command builder * - * @param commandName Base command component + * @param commandName Base command argument * @param commandMeta Command meta instance * @param aliases Command aliases * @param Command sender type @@ -136,18 +136,18 @@ public class Command { @Nonnull final M commandMeta, @Nonnull final String... aliases) { return new Builder<>(null, commandMeta, null, - Collections.singletonList(StaticComponent.required(commandName, aliases)), + Collections.singletonList(StaticArgument.required(commandName, aliases)), new CommandExecutionHandler.NullCommandExecutionHandler<>(), ""); } /** - * Return a copy of the command component array + * Return a copy of the command argument array * - * @return Copy of the command component array + * @return Copy of the command argument array */ @Nonnull - public List> getComponents() { - return Collections.unmodifiableList(this.components); + public List> getArguments() { + return Collections.unmodifiableList(this.arguments); } /** @@ -191,22 +191,22 @@ public class Command { } /** - * Get the longest chain of similar components for + * Get the longest chain of similar arguments for * two commands * * @param other Command to compare to - * @return List containing the longest shared component chain + * @return List containing the longest shared argument chain */ - public List> getSharedComponentChain(@Nonnull final Command other) { - final List> commandComponents = new LinkedList<>(); - for (int i = 0; i < this.components.size() && i < other.components.size(); i++) { - if (this.components.get(i).equals(other.components.get(i))) { - commandComponents.add(this.components.get(i)); + public List> getSharedArgumentChain(@Nonnull final Command other) { + final List> commandArguments = new LinkedList<>(); + for (int i = 0; i < this.arguments.size() && i < other.arguments.size(); i++) { + if (this.arguments.get(i).equals(other.arguments.get(i))) { + commandArguments.add(this.arguments.get(i)); } else { break; } } - return commandComponents; + return commandArguments; } @@ -220,7 +220,7 @@ public class Command { public static final class Builder { @Nonnull private final M commandMeta; - @Nonnull private final List> commandComponents; + @Nonnull private final List> commandArguments; @Nonnull private final CommandExecutionHandler commandExecutionHandler; @Nullable private final Class senderType; @Nonnull private final String commandPermission; @@ -229,12 +229,12 @@ public class Command { private Builder(@Nullable final CommandManager commandManager, @Nonnull final M commandMeta, @Nullable final Class senderType, - @Nonnull final List> commandComponents, + @Nonnull final List> commandArguments, @Nonnull final CommandExecutionHandler commandExecutionHandler, @Nonnull final String commandPermission) { this.commandManager = commandManager; this.senderType = senderType; - this.commandComponents = Objects.requireNonNull(commandComponents, "Components may not be null"); + this.commandArguments = Objects.requireNonNull(commandArguments, "Arguments may not be null"); this.commandExecutionHandler = Objects.requireNonNull(commandExecutionHandler, "Execution handler may not be null"); this.commandPermission = Objects.requireNonNull(commandPermission, "Permission may not be null"); this.commandMeta = Objects.requireNonNull(commandMeta, "Meta may not be null"); @@ -242,7 +242,7 @@ public class Command { /** * Supply a command manager instance to the builder. This will be used when attempting to - * retrieve command component parsers, in the case that they're needed. This + * retrieve command argument parsers, in the case that they're needed. This * is optional * * @param commandManager Command manager @@ -250,44 +250,44 @@ public class Command { */ @Nonnull public Builder manager(@Nullable final CommandManager commandManager) { - return new Builder<>(commandManager, this.commandMeta, this.senderType, this.commandComponents, + return new Builder<>(commandManager, this.commandMeta, this.senderType, this.commandArguments, this.commandExecutionHandler, this.commandPermission); } /** - * Add a new command component to the command + * Add a new command argument to the command * - * @param component Component to add - * @param Component type - * @return New builder instance with the command component inserted into the component list + * @param argument Argument to add + * @param Argument type + * @return New builder instance with the command argument inserted into the argument list */ @Nonnull - public Builder component(@Nonnull final CommandComponent component) { - final List> commandComponents = new LinkedList<>(this.commandComponents); - commandComponents.add(component); - return new Builder<>(this.commandManager, this.commandMeta, this.senderType, commandComponents, + public Builder argument(@Nonnull final CommandArgument argument) { + final List> commandArguments = new LinkedList<>(this.commandArguments); + commandArguments.add(argument); + return new Builder<>(this.commandManager, this.commandMeta, this.senderType, commandArguments, this.commandExecutionHandler, this.commandPermission); } /** - * Add a new command component by interacting with a constructed command component builder + * Add a new command argument by interacting with a constructed command argument builder * - * @param clazz Component class - * @param name Component name + * @param clazz Argument class + * @param name Argument name * @param builderConsumer Builder consumer - * @param Component type - * @return New builder instance with the command component inserted into the component list + * @param Argument type + * @return New builder instance with the command argument inserted into the argument list */ @Nonnull - public Builder component(@Nonnull final Class clazz, + public Builder argument(@Nonnull final Class clazz, @Nonnull final String name, - @Nonnull final Consumer> builderConsumer) { - final CommandComponent.Builder builder = CommandComponent.ofType(clazz, name); + @Nonnull final Consumer> builderConsumer) { + final CommandArgument.Builder builder = CommandArgument.ofType(clazz, name); if (this.commandManager != null) { builder.manager(this.commandManager); } builderConsumer.accept(builder); - return this.component(builder.build()); + return this.argument(builder.build()); } /** @@ -298,7 +298,7 @@ public class Command { */ @Nonnull public Builder handler(@Nonnull final CommandExecutionHandler commandExecutionHandler) { - return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandComponents, + return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandArguments, commandExecutionHandler, this.commandPermission); } @@ -310,7 +310,7 @@ public class Command { */ @Nonnull public Builder withSenderType(@Nonnull final Class senderType) { - return new Builder<>(this.commandManager, this.commandMeta, senderType, this.commandComponents, + return new Builder<>(this.commandManager, this.commandMeta, senderType, this.commandArguments, this.commandExecutionHandler, this.commandPermission); } @@ -322,7 +322,7 @@ public class Command { */ @Nonnull public Builder withPermission(@Nonnull final String permission) { - return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandComponents, + return new Builder<>(this.commandManager, this.commandMeta, this.senderType, this.commandArguments, this.commandExecutionHandler, permission); } @@ -333,7 +333,7 @@ public class Command { */ @Nonnull public Command build() { - return new Command<>(Collections.unmodifiableList(this.commandComponents), + return new Command<>(Collections.unmodifiableList(this.commandArguments), this.commandExecutionHandler, this.senderType, this.commandPermission, this.commandMeta); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/CommandManager.java b/cloud-core/src/main/java/com/intellectualsites/commands/CommandManager.java index a684096e..047dc955 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/CommandManager.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/CommandManager.java @@ -24,11 +24,11 @@ package com.intellectualsites.commands; import com.google.common.reflect.TypeToken; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.CommandSyntaxFormatter; -import com.intellectualsites.commands.components.StandardCommandSyntaxFormatter; -import com.intellectualsites.commands.components.parser.ParserRegistry; -import com.intellectualsites.commands.components.parser.StandardParserRegistry; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.CommandSyntaxFormatter; +import com.intellectualsites.commands.arguments.StandardCommandSyntaxFormatter; +import com.intellectualsites.commands.arguments.parser.ParserRegistry; +import com.intellectualsites.commands.arguments.parser.StandardParserRegistry; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.context.CommandContextFactory; import com.intellectualsites.commands.context.StandardCommandContextFactory; @@ -236,16 +236,16 @@ public abstract class CommandManager Generic component name - * @return Component builder + * @param type Argument type + * @param name Argument name + * @param Generic argument name + * @return Argument builder */ @Nonnull - public CommandComponent.Builder componentBuilder(@Nonnull final Class type, @Nonnull final String name) { - return CommandComponent.ofType(type, name).manager(this); + public CommandArgument.Builder argumentBuilder(@Nonnull final Class type, @Nonnull final String name) { + return CommandArgument.ofType(type, name).manager(this); } /** diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java b/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java index 41d5c8e9..a7986a32 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/CommandTree.java @@ -23,12 +23,12 @@ // package com.intellectualsites.commands; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.StaticComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.StaticArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.exceptions.AmbiguousNodeException; -import com.intellectualsites.commands.exceptions.ComponentParseException; +import com.intellectualsites.commands.exceptions.ArgumentParseException; import com.intellectualsites.commands.exceptions.InvalidCommandSenderException; import com.intellectualsites.commands.exceptions.InvalidSyntaxException; import com.intellectualsites.commands.exceptions.NoCommandInLeafException; @@ -63,7 +63,7 @@ public final class CommandTree { private final Object commandLock = new Object(); - private final Node> internalTree = new Node<>(null); + private final Node> internalTree = new Node<>(null); private final CommandManager commandManager; private final CommandRegistrationHandler commandRegistrationHandler; @@ -113,7 +113,7 @@ public final class CommandTree { private Optional> parseCommand(@Nonnull final CommandContext commandContext, @Nonnull final Queue commandQueue, - @Nonnull final Node> root) { + @Nonnull final Node> root) { String permission = this.isPermitted(commandContext.getSender(), root); if (permission != null) { throw new NoPermissionException(permission, commandContext.getSender(), this.getChain(root) @@ -128,7 +128,7 @@ public final class CommandTree { return parsedChild; } - /* There are 0 or more static components as children. No variable child components are present */ + /* There are 0 or more static arguments as children. No variable child arguments are present */ if (root.children.isEmpty()) { /* We are at the bottom. Check if there's a command attached, in which case we're done */ if (root.getValue() != null && root.getValue().getOwningCommand() != null) { @@ -139,7 +139,7 @@ public final class CommandTree { throw new InvalidSyntaxException(this.commandManager.getCommandSyntaxFormatter() .apply(root.getValue() .getOwningCommand() - .getComponents()), + .getArguments()), commandContext.getSender(), this.getChain(root) .stream() .map(Node::getValue) @@ -151,19 +151,19 @@ public final class CommandTree { .apply(Objects.requireNonNull( Objects.requireNonNull(root.getValue()) .getOwningCommand()) - .getComponents()), + .getArguments()), commandContext.getSender(), this.getChain(root) .stream() .map(Node::getValue) .collect(Collectors.toList())); } } else { - final Iterator>> childIterator = root.getChildren().iterator(); + final Iterator>> childIterator = root.getChildren().iterator(); if (childIterator.hasNext()) { while (childIterator.hasNext()) { - final Node> child = childIterator.next(); + final Node> child = childIterator.next(); if (child.getValue() != null) { - final ComponentParseResult result = child.getValue().getParser().parse(commandContext, commandQueue); + final ArgumentParseResult result = child.getValue().getParser().parse(commandContext, commandQueue); if (result.getParsedValue().isPresent()) { return this.parseCommand(commandContext, commandQueue, child); } /*else if (result.getFailure().isPresent() && root.children.size() == 1) { @@ -180,13 +180,13 @@ public final class CommandTree { @Nullable private Optional> attemptParseUnambiguousChild(@Nonnull final CommandContext commandContext, - @Nonnull final Node> root, + @Nonnull final Node> root, @Nonnull final Queue commandQueue) { String permission; - final List>> children = root.getChildren(); - if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticComponent)) { + final List>> children = root.getChildren(); + if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticArgument)) { // The value has to be a variable - final Node> child = children.get(0); + final Node> child = children.get(0); permission = this.isPermitted(commandContext.getSender(), child); if (permission != null) { throw new NoPermissionException(permission, commandContext.getSender(), this.getChain(child) @@ -205,7 +205,7 @@ public final class CommandTree { throw new InvalidSyntaxException(this.commandManager.getCommandSyntaxFormatter() .apply(Objects.requireNonNull( child.getValue().getOwningCommand()) - .getComponents()), + .getArguments()), commandContext.getSender(), this.getChain(root) .stream() .map(Node::getValue) @@ -219,7 +219,7 @@ public final class CommandTree { ""); } } - final ComponentParseResult result = child.getValue().getParser().parse(commandContext, commandQueue); + final ArgumentParseResult result = child.getValue().getParser().parse(commandContext, commandQueue); if (result.getParsedValue().isPresent()) { commandContext.store(child.getValue().getName(), result.getParsedValue().get()); if (child.isLeaf()) { @@ -230,7 +230,7 @@ public final class CommandTree { throw new InvalidSyntaxException(this.commandManager.getCommandSyntaxFormatter() .apply(Objects.requireNonNull(child.getValue() .getOwningCommand()) - .getComponents()), + .getArguments()), commandContext.getSender(), this.getChain(root) .stream() .map(Node::getValue) @@ -241,8 +241,8 @@ public final class CommandTree { return this.parseCommand(commandContext, commandQueue, child); } } else if (result.getFailure().isPresent()) { - throw new ComponentParseException(result.getFailure().get(), commandContext.getSender(), - this.getChain(child) + throw new ArgumentParseException(result.getFailure().get(), commandContext.getSender(), + this.getChain(child) .stream() .map(Node::getValue) .collect(Collectors.toList())); @@ -268,16 +268,16 @@ public final class CommandTree { @Nonnull private List getSuggestions(@Nonnull final CommandContext commandContext, @Nonnull final Queue commandQueue, - @Nonnull final Node> root) { + @Nonnull final Node> root) { /* If the sender isn't allowed to access the root node, no suggestions are needed */ if (this.isPermitted(commandContext.getSender(), root) != null) { return Collections.emptyList(); } - final List>> children = root.getChildren(); - if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticComponent)) { + final List>> children = root.getChildren(); + if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticArgument)) { // The value has to be a variable - final Node> child = children.get(0); + final Node> child = children.get(0); if (child.getValue() != null) { if (commandQueue.isEmpty()) { return Collections.emptyList(); @@ -287,7 +287,7 @@ public final class CommandTree { } else if (child.isLeaf()) { return Collections.emptyList(); } - final ComponentParseResult result = child.getValue().getParser().parse(commandContext, commandQueue); + final ArgumentParseResult result = child.getValue().getParser().parse(commandContext, commandQueue); if (result.getParsedValue().isPresent()) { commandContext.store(child.getValue().getName(), result.getParsedValue().get()); return this.getSuggestions(commandContext, commandQueue, child); @@ -296,16 +296,16 @@ public final class CommandTree { } } } - /* There are 0 or more static components as children. No variable child components are present */ + /* There are 0 or more static arguments as children. No variable child arguments are present */ if (children.isEmpty() || commandQueue.isEmpty()) { return Collections.emptyList(); } else { - final Iterator>> childIterator = root.getChildren().iterator(); + final Iterator>> childIterator = root.getChildren().iterator(); if (childIterator.hasNext()) { while (childIterator.hasNext()) { - final Node> child = childIterator.next(); + final Node> child = childIterator.next(); if (child.getValue() != null) { - final ComponentParseResult result = child.getValue().getParser().parse(commandContext, commandQueue); + final ArgumentParseResult result = child.getValue().getParser().parse(commandContext, commandQueue); if (result.getParsedValue().isPresent()) { return this.getSuggestions(commandContext, commandQueue, child); } /* else if (result.getFailure().isPresent() && root.children.size() == 1) { @@ -314,12 +314,12 @@ public final class CommandTree { } } final List suggestions = new LinkedList<>(); - for (final Node> component : root.getChildren()) { - if (component.getValue() == null || this.isPermitted(commandContext.getSender(), component) != null) { + for (final Node> argument : root.getChildren()) { + if (argument.getValue() == null || this.isPermitted(commandContext.getSender(), argument) != null) { continue; } suggestions.addAll( - component.getValue().getParser().suggestions(commandContext, stringOrEmpty(commandQueue.peek()))); + argument.getValue().getParser().suggestions(commandContext, stringOrEmpty(commandQueue.peek()))); } return suggestions; } @@ -341,14 +341,14 @@ public final class CommandTree { @SuppressWarnings("unchecked") public void insertCommand(@Nonnull final Command command) { synchronized (this.commandLock) { - Node> node = this.internalTree; - for (final CommandComponent component : command.getComponents()) { - Node> tempNode = node.getChild(component); + Node> node = this.internalTree; + for (final CommandArgument argument : command.getArguments()) { + Node> tempNode = node.getChild(argument); if (tempNode == null) { - tempNode = node.addChild(component); - } else if (component instanceof StaticComponent && tempNode.getValue() != null) { - for (final String alias : ((StaticComponent) component).getAliases()) { - ((StaticComponent) tempNode.getValue()).registerAlias(alias); + tempNode = node.addChild(argument); + } else if (argument instanceof StaticArgument && tempNode.getValue() != null) { + for (final String alias : ((StaticArgument) argument).getAliases()) { + ((StaticArgument) tempNode.getValue()).registerAlias(alias); } } if (node.children.size() > 0) { @@ -366,7 +366,7 @@ public final class CommandTree { } @Nullable - private String isPermitted(@Nonnull final C sender, @Nonnull final Node> node) { + private String isPermitted(@Nonnull final C sender, @Nonnull final Node> node) { final String permission = node.nodeMeta.get("permission"); if (permission != null) { return sender.hasPermission(permission) ? null : permission; @@ -382,7 +382,7 @@ public final class CommandTree { chain to execute, and so we allow them to execute the root */ final List missingPermissions = new LinkedList<>(); - for (final Node> child : node.getChildren()) { + for (final Node> child : node.getChildren()) { final String check = this.isPermitted(sender, child); if (check == null) { return null; @@ -399,9 +399,9 @@ public final class CommandTree { */ public void verifyAndRegister() { // All top level commands are supposed to be registered in the command manager - this.internalTree.children.stream().map(Node::getValue).forEach(commandComponent -> { - if (!(commandComponent instanceof StaticComponent)) { - throw new IllegalStateException("Top level command component cannot be a variable"); + this.internalTree.children.stream().map(Node::getValue).forEach(commandArgument -> { + if (!(commandArgument instanceof StaticArgument)) { + throw new IllegalStateException("Top level command argument cannot be a variable"); } }); @@ -424,29 +424,29 @@ public final class CommandTree { // noinspection all node.nodeMeta.put("permission", node.getValue().getOwningCommand().getCommandPermission()); // Get chain and order it tail->head then skip the tail (leaf node) - List>> chain = this.getChain(node); + List>> chain = this.getChain(node); Collections.reverse(chain); chain = chain.subList(1, chain.size()); // Go through all nodes from the tail upwards until a collision occurs - for (final Node> commandComponentNode : chain) { - if (commandComponentNode.nodeMeta.containsKey("permission") && !commandComponentNode.nodeMeta.get("permission") + for (final Node> commandArgumentNode : chain) { + if (commandArgumentNode.nodeMeta.containsKey("permission") && !commandArgumentNode.nodeMeta.get("permission") .equalsIgnoreCase( node.nodeMeta .get("permission"))) { - commandComponentNode.nodeMeta.put("permission", ""); + commandArgumentNode.nodeMeta.put("permission", ""); } else { - commandComponentNode.nodeMeta.put("permission", node.nodeMeta.get("permission")); + commandArgumentNode.nodeMeta.put("permission", node.nodeMeta.get("permission")); } } }); } - private void checkAmbiguity(@Nonnull final Node> node) throws AmbiguousNodeException { + private void checkAmbiguity(@Nonnull final Node> node) throws AmbiguousNodeException { if (node.isLeaf()) { return; } final int size = node.children.size(); - for (final Node> child : node.children) { + for (final Node> child : node.children) { if (child.getValue() != null && !child.getValue().isRequired() && size > 1) { throw new AmbiguousNodeException(node.getValue(), child.getValue(), @@ -456,8 +456,8 @@ public final class CommandTree { node.children.forEach(this::checkAmbiguity); } - private List>> getLeavesRaw(@Nonnull final Node> node) { - final List>> leaves = new LinkedList<>(); + private List>> getLeavesRaw(@Nonnull final Node> node) { + final List>> leaves = new LinkedList<>(); if (node.isLeaf()) { if (node.getValue() != null) { leaves.add(node); @@ -468,8 +468,8 @@ public final class CommandTree { return leaves; } - private List> getLeaves(@Nonnull final Node> node) { - final List> leaves = new LinkedList<>(); + private List> getLeaves(@Nonnull final Node> node) { + final List> leaves = new LinkedList<>(); if (node.isLeaf()) { if (node.getValue() != null) { leaves.add(node.getValue()); @@ -480,9 +480,9 @@ public final class CommandTree { return leaves; } - private List>> getChain(@Nullable final Node> end) { - final List>> chain = new LinkedList<>(); - Node> tail = end; + private List>> getChain(@Nullable final Node> end) { + final List>> chain = new LinkedList<>(); + Node> tail = end; while (tail != null) { chain.add(tail); tail = tail.getParent(); @@ -507,7 +507,7 @@ public final class CommandTree { * @return Root nodes */ @Nonnull - public Collection>> getRootNodes() { + public Collection>> getRootNodes() { return this.internalTree.getChildren(); } @@ -518,7 +518,7 @@ public final class CommandTree { * @return Root node, or {@code null} */ @Nullable - public Node> getNamedNode(@Nullable final String name) { + public Node> getNamedNode(@Nullable final String name) { return this.getRootNodes().stream().filter(node -> node.getValue() != null && node.getValue().getName().equalsIgnoreCase(name)).findAny().orElse(null); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/Range.java b/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/Range.java index 6f1e6794..1fb50eba 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/Range.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/Range.java @@ -31,7 +31,7 @@ import java.lang.annotation.Target; /** * Used to specify min and max values of numerical - * {@link com.intellectualsites.commands.components.parser.ComponentParser parsers} + * {@link com.intellectualsites.commands.arguments.parser.ArgumentParser parsers} */ @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.PARAMETER) diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/package-info.java index 9fef4f45..8b77ee77 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/package-info.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/annotations/specifier/package-info.java @@ -23,7 +23,7 @@ // /** - * Standard annotations used to match {@link com.intellectualsites.commands.components.parser.ComponentParser} - * in {@link com.intellectualsites.commands.components.parser.ParserRegistry} + * Standard annotations used to match {@link com.intellectualsites.commands.arguments.parser.ArgumentParser} + * in {@link com.intellectualsites.commands.arguments.parser.ParserRegistry} */ package com.intellectualsites.commands.annotations.specifier; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/CommandArgument.java similarity index 65% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/CommandArgument.java index 00567ee5..295a63e0 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/CommandComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/CommandArgument.java @@ -21,14 +21,14 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components; +package com.intellectualsites.commands.arguments; import com.google.common.reflect.TypeToken; import com.intellectualsites.commands.Command; import com.intellectualsites.commands.CommandManager; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; -import com.intellectualsites.commands.components.parser.ParserParameters; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; +import com.intellectualsites.commands.arguments.parser.ParserParameters; import com.intellectualsites.commands.sender.CommandSender; import javax.annotation.Nonnull; @@ -37,29 +37,29 @@ import java.util.Objects; import java.util.regex.Pattern; /** - * A component that belongs to a command + * A argument that belongs to a command * * @param Command sender type - * @param The type that the component parses into + * @param The type that the argument parses into */ @SuppressWarnings("unused") -public class CommandComponent implements Comparable> { +public class CommandArgument implements Comparable> { /** - * Pattern for command component names + * Pattern for command argument names */ private static final Pattern NAME_PATTERN = Pattern.compile("[A-Za-z0-9]+"); /** - * Indicates whether or not the component is required - * or not. All components prior to any other required - * component must also be required, such that the predicate + * Indicates whether or not the argument is required + * or not. All arguments prior to any other required + * argument must also be required, such that the predicate * (∀ c_i ∈ required)({c_0, ..., c_i-1} ⊂ required) holds true, - * where {c_0, ..., c_n-1} is the set of command components. + * where {c_0, ..., c_n-1} is the set of command arguments. */ private final boolean required; /** - * The command component name. This might be exposed + * The command argument name. This might be exposed * to command senders and so should be chosen carefully. */ private final String name; @@ -67,32 +67,32 @@ public class CommandComponent implements Comparable< * The parser that is used to parse the command input * into the corresponding command type */ - private final ComponentParser parser; + private final ArgumentParser parser; /** * Default value, will be empty if none was supplied */ private final String defaultValue; /** - * The type that is produces by the component's parser + * The type that is produces by the argument's parser */ private final Class valueType; private Command owningCommand; /** - * Construct a new command component + * Construct a new command argument * - * @param required Whether or not the component is required - * @param name The component name - * @param parser The component parser + * @param required Whether or not the argument is required + * @param name The argument name + * @param parser The argument parser * @param defaultValue Default value used when no value is provided by the command sender * @param valueType Type produced by the parser */ - public CommandComponent(final boolean required, - @Nonnull final String name, - @Nonnull final ComponentParser parser, - @Nonnull final String defaultValue, - @Nonnull final Class valueType) { + public CommandArgument(final boolean required, + @Nonnull final String name, + @Nonnull final ArgumentParser parser, + @Nonnull final String defaultValue, + @Nonnull final Class valueType) { this.required = required; this.name = Objects.requireNonNull(name, "Name may not be null"); if (!NAME_PATTERN.asPredicate().test(name)) { @@ -104,48 +104,48 @@ public class CommandComponent implements Comparable< } /** - * Construct a new command component + * Construct a new command argument * - * @param required Whether or not the component is required - * @param name The component name - * @param parser The component parser + * @param required Whether or not the argument is required + * @param name The argument name + * @param parser The argument parser * @param valueType Type produced by the parser */ - public CommandComponent(final boolean required, - @Nonnull final String name, - @Nonnull final ComponentParser parser, - @Nonnull final Class valueType) { + public CommandArgument(final boolean required, + @Nonnull final String name, + @Nonnull final ArgumentParser parser, + @Nonnull final Class valueType) { this(required, name, parser, "", valueType); } /** - * Create a new command component + * Create a new command argument * * @param clazz Argument class - * @param name Component name + * @param name Argument name * @param Command sender type * @param Argument Type. Used to make the compiler happy. - * @return Component builder + * @return Argument builder */ @Nonnull - public static CommandComponent.Builder ofType(@Nonnull final Class clazz, - @Nonnull final String name) { + public static CommandArgument.Builder ofType(@Nonnull final Class clazz, + @Nonnull final String name) { return new Builder<>(clazz, name); } /** - * Check whether or not the command component is required + * Check whether or not the command argument is required * - * @return {@code true} if the component is required, {@code false} if not + * @return {@code true} if the argument is required, {@code false} if not */ public boolean isRequired() { return this.required; } /** - * Get the command component name; + * Get the command argument name; * - * @return Component name + * @return Argument name */ @Nonnull public String getName() { @@ -159,14 +159,14 @@ public class CommandComponent implements Comparable< * @return Command parser */ @Nonnull - public ComponentParser getParser() { + public ArgumentParser getParser() { return this.parser; } @Nonnull @Override public final String toString() { - return String.format("CommandComponent{name=%s}", this.name); + return String.format("CommandArgument{name=%s}", this.name); } /** @@ -199,7 +199,7 @@ public class CommandComponent implements Comparable< if (o == null || getClass() != o.getClass()) { return false; } - final CommandComponent that = (CommandComponent) o; + final CommandArgument that = (CommandArgument) o; return isRequired() == that.isRequired() && Objects.equals(getName(), that.getName()); } @@ -209,15 +209,15 @@ public class CommandComponent implements Comparable< } @Override - public final int compareTo(@Nonnull final CommandComponent o) { - if (this instanceof StaticComponent) { - if (o instanceof StaticComponent) { + public final int compareTo(@Nonnull final CommandArgument o) { + if (this instanceof StaticArgument) { + if (o instanceof StaticArgument) { return (this.getName().compareTo(o.getName())); } else { return -1; } } else { - if (o instanceof StaticComponent) { + if (o instanceof StaticArgument) { return 1; } else { return 0; @@ -236,9 +236,9 @@ public class CommandComponent implements Comparable< } /** - * Check if the component has a default value + * Check if the argument has a default value * - * @return {@code true} if the component has a default value, {@code false} if not + * @return {@code true} if the argument has a default value, {@code false} if not */ public boolean hasDefaultValue() { return !this.isRequired() @@ -246,7 +246,7 @@ public class CommandComponent implements Comparable< } /** - * Get the type of this component's value + * Get the type of this argument's value * * @return Value type */ @@ -256,10 +256,10 @@ public class CommandComponent implements Comparable< } /** - * Mutable builder for {@link CommandComponent} instances + * Mutable builder for {@link CommandArgument} instances * * @param Command sender type - * @param Component value type + * @param Argument value type */ public static class Builder { @@ -268,7 +268,7 @@ public class CommandComponent implements Comparable< private CommandManager manager; private boolean required = true; - private ComponentParser parser; + private ArgumentParser parser; private String defaultValue = ""; protected Builder(@Nonnull final Class valueType, @@ -291,11 +291,11 @@ public class CommandComponent implements Comparable< } /** - * Indicates that the component is required. - * All components prior to any other required - * component must also be required, such that the predicate + * Indicates that the argument is required. + * All arguments prior to any other required + * argument must also be required, such that the predicate * (∀ c_i ∈ required)({c_0, ..., c_i-1} ⊂ required) holds true, - * where {c_0, ..., c_n-1} is the set of command components. + * where {c_0, ..., c_n-1} is the set of command arguments. * * @return Builder instance */ @@ -306,11 +306,11 @@ public class CommandComponent implements Comparable< } /** - * Indicates that the component is optional. - * All components prior to any other required - * component must also be required, such that the predicate + * Indicates that the argument is optional. + * All arguments prior to any other required + * argument must also be required, such that the predicate * (∀ c_i ∈ required)({c_0, ..., c_i-1} ⊂ required) holds true, - * where {c_0, ..., c_n-1} is the set of command components. + * where {c_0, ..., c_n-1} is the set of command arguments. * * @return Builder instance */ @@ -321,11 +321,11 @@ public class CommandComponent implements Comparable< } /** - * Indicates that the component is optional. - * All components prior to any other required - * component must also be required, such that the predicate + * Indicates that the argument is optional. + * All arguments prior to any other required + * argument must also be required, such that the predicate * (∀ c_i ∈ required)({c_0, ..., c_i-1} ⊂ required) holds true, - * where {c_0, ..., c_n-1} is the set of command components. + * where {c_0, ..., c_n-1} is the set of command arguments. * * @param defaultValue Default value that will be used if none was supplied * @return Builder instance @@ -338,33 +338,33 @@ public class CommandComponent implements Comparable< } /** - * Set the component parser + * Set the argument parser * - * @param parser Component parser + * @param parser Argument parser * @return Builder instance */ @Nonnull - public Builder withParser(@Nonnull final ComponentParser parser) { + public Builder withParser(@Nonnull final ArgumentParser parser) { this.parser = Objects.requireNonNull(parser, "Parser may not be null"); return this; } /** - * Construct a command component from the builder settings + * Construct a command argument from the builder settings * - * @return Constructed component + * @return Constructed argument */ @Nonnull - public CommandComponent build() { + public CommandArgument build() { if (this.parser == null && this.manager != null) { this.parser = this.manager.getParserRegistry().createParser(TypeToken.of(valueType), ParserParameters.empty()) .orElse(null); } if (this.parser == null) { - this.parser = (c, i) -> ComponentParseResult + this.parser = (c, i) -> ArgumentParseResult .failure(new UnsupportedOperationException("No parser was specified")); } - return new CommandComponent<>(this.required, this.name, this.parser, this.defaultValue, this.valueType); + return new CommandArgument<>(this.required, this.name, this.parser, this.defaultValue, this.valueType); } @Nonnull @@ -377,7 +377,7 @@ public class CommandComponent implements Comparable< } @Nonnull - protected final ComponentParser getParser() { + protected final ArgumentParser getParser() { return this.parser; } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/CommandSyntaxFormatter.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/CommandSyntaxFormatter.java similarity index 83% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/CommandSyntaxFormatter.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/CommandSyntaxFormatter.java index e8025b9e..a9a779e5 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/CommandSyntaxFormatter.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/CommandSyntaxFormatter.java @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components; +package com.intellectualsites.commands.arguments; import com.intellectualsites.commands.sender.CommandSender; @@ -30,15 +30,15 @@ import java.util.List; import java.util.function.Function; /** - * Utility that formats chains of {@link CommandComponent command components} into syntax strings + * Utility that formats chains of {@link CommandArgument command arguments} into syntax strings * * @param Command sender type */ @FunctionalInterface -public interface CommandSyntaxFormatter extends Function>, String> { +public interface CommandSyntaxFormatter extends Function>, String> { @Override @Nonnull - String apply(@Nonnull List> commandComponents); + String apply(@Nonnull List> commandArguments); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/StandardCommandSyntaxFormatter.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/StandardCommandSyntaxFormatter.java similarity index 66% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/StandardCommandSyntaxFormatter.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/StandardCommandSyntaxFormatter.java index 66128ef9..49703011 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/StandardCommandSyntaxFormatter.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/StandardCommandSyntaxFormatter.java @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components; +package com.intellectualsites.commands.arguments; import com.intellectualsites.commands.sender.CommandSender; @@ -32,9 +32,9 @@ import java.util.List; /** * {@link CommandSyntaxFormatter} implementation that uses the following rules: *
    - *
  • static components are serialized as their name, without a bracket
  • - *
  • required components are serialized as their name, surrounded by angle brackets
  • - *
  • optional components are serialized as their name, surrounded by square brackets
  • + *
  • static arguments are serialized as their name, without a bracket
  • + *
  • required arguments are serialized as their name, surrounded by angle brackets
  • + *
  • optional arguments are serialized as their name, surrounded by square brackets
  • *
* * @param Command sender type @@ -43,18 +43,18 @@ public class StandardCommandSyntaxFormatter implements @Nonnull @Override - public final String apply(@Nonnull final List> commandComponents) { + public final String apply(@Nonnull final List> commandArguments) { final StringBuilder stringBuilder = new StringBuilder(); - final Iterator> iterator = commandComponents.iterator(); + final Iterator> iterator = commandArguments.iterator(); while (iterator.hasNext()) { - final CommandComponent commandComponent = iterator.next(); - if (commandComponent instanceof StaticComponent) { - stringBuilder.append(commandComponent.getName()); + final CommandArgument commandArgument = iterator.next(); + if (commandArgument instanceof StaticArgument) { + stringBuilder.append(commandArgument.getName()); } else { - if (commandComponent.isRequired()) { - stringBuilder.append("<").append(commandComponent.getName()).append(">"); + if (commandArgument.isRequired()) { + stringBuilder.append("<").append(commandArgument.getName()).append(">"); } else { - stringBuilder.append("[").append(commandComponent.getName()).append("]"); + stringBuilder.append("[").append(commandArgument.getName()).append("]"); } } if (iterator.hasNext()) { diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/StaticComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/StaticArgument.java similarity index 58% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/StaticComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/StaticArgument.java index 8bf92bfd..eb76661a 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/StaticComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/StaticArgument.java @@ -21,10 +21,10 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components; +package com.intellectualsites.commands.arguments; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.sender.CommandSender; @@ -37,42 +37,42 @@ import java.util.Queue; import java.util.Set; /** - * {@link CommandComponent} type that recognizes fixed strings. This type does not parse variables. + * {@link CommandArgument} type that recognizes fixed strings. This type does not parse variables. * * @param Command sender type */ -public final class StaticComponent extends CommandComponent { +public final class StaticArgument extends CommandArgument { - private StaticComponent(final boolean required, @Nonnull final String name, @Nonnull final String... aliases) { - super(required, name, new StaticComponentParser<>(name, aliases), String.class); + private StaticArgument(final boolean required, @Nonnull final String name, @Nonnull final String... aliases) { + super(required, name, new StaticArgumentParser<>(name, aliases), String.class); } /** - * Create a new static component instance for a required command component + * Create a new static argument instance for a required command argument * - * @param name Component name - * @param aliases Component aliases + * @param name Argument name + * @param aliases Argument aliases * @param Command sender type - * @return Constructed component + * @return Constructed argument */ @Nonnull - public static StaticComponent required(@Nonnull final String name, - @Nonnull final String... aliases) { - return new StaticComponent<>(true, name, aliases); + public static StaticArgument required(@Nonnull final String name, + @Nonnull final String... aliases) { + return new StaticArgument<>(true, name, aliases); } /** - * Create a new static component instance for an optional command component + * Create a new static argument instance for an optional command argument * - * @param name Component name - * @param aliases Component aliases + * @param name Argument name + * @param aliases Argument aliases * @param Command sender type - * @return Constructed component + * @return Constructed argument */ @Nonnull - public static StaticComponent optional(@Nonnull final String name, - @Nonnull final String... aliases) { - return new StaticComponent<>(false, name, aliases); + public static StaticArgument optional(@Nonnull final String name, + @Nonnull final String... aliases) { + return new StaticArgument<>(false, name, aliases); } /** @@ -81,26 +81,26 @@ public final class StaticComponent extends CommandCompo * @param alias New alias */ public void registerAlias(@Nonnull final String alias) { - ((StaticComponentParser) this.getParser()).acceptedStrings.add(alias); + ((StaticArgumentParser) this.getParser()).acceptedStrings.add(alias); } /** * Get an immutable view of the aliases * - * @return Immutable view of the component aliases + * @return Immutable view of the argument aliases */ @Nonnull public Set getAliases() { - return Collections.unmodifiableSet(((StaticComponentParser) this.getParser()).getAcceptedStrings()); + return Collections.unmodifiableSet(((StaticArgumentParser) this.getParser()).getAcceptedStrings()); } - private static final class StaticComponentParser implements ComponentParser { + private static final class StaticArgumentParser implements ArgumentParser { private final String name; private final Set acceptedStrings = new HashSet<>(); - private StaticComponentParser(@Nonnull final String name, @Nonnull final String... aliases) { + private StaticArgumentParser(@Nonnull final String name, @Nonnull final String... aliases) { this.name = name; this.acceptedStrings.add(this.name); this.acceptedStrings.addAll(Arrays.asList(aliases)); @@ -108,20 +108,20 @@ public final class StaticComponent extends CommandCompo @Nonnull @Override - public ComponentParseResult parse(@Nonnull final CommandContext commandContext, - @Nonnull final Queue inputQueue) { + public ArgumentParseResult parse(@Nonnull final CommandContext commandContext, + @Nonnull final Queue inputQueue) { final String string = inputQueue.peek(); if (string == null) { - return ComponentParseResult.failure(new NullPointerException("No input provided")); + return ArgumentParseResult.failure(new NullPointerException("No input provided")); } for (final String acceptedString : this.acceptedStrings) { if (string.equalsIgnoreCase(acceptedString)) { // Remove the head of the queue inputQueue.remove(); - return ComponentParseResult.success(this.name); + return ArgumentParseResult.success(this.name); } } - return ComponentParseResult.failure(new IllegalArgumentException(string)); + return ArgumentParseResult.failure(new IllegalArgumentException(string)); } @Nonnull diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/package-info.java similarity index 90% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/package-info.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/package-info.java index d21395da..306dcde3 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/package-info.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/package-info.java @@ -23,6 +23,6 @@ // /** - * Command components that are used to build command parsing chains + * Command arguments that are used to build command parsing chains */ -package com.intellectualsites.commands.components; +package com.intellectualsites.commands.arguments; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParseResult.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ArgumentParseResult.java similarity index 85% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParseResult.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ArgumentParseResult.java index 32d25fbe..d5e34941 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParseResult.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ArgumentParseResult.java @@ -21,19 +21,19 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.parser; +package com.intellectualsites.commands.arguments.parser; import javax.annotation.Nonnull; import java.util.Optional; /** - * Result of the parsing done by a {@link ComponentParser} + * Result of the parsing done by a {@link ArgumentParser} * * @param Parser return type */ -public abstract class ComponentParseResult { +public abstract class ArgumentParseResult { - private ComponentParseResult() { + private ArgumentParseResult() { } /** @@ -44,7 +44,7 @@ public abstract class ComponentParseResult { * @return Failed parse result */ @Nonnull - public static ComponentParseResult failure(@Nonnull final Throwable failure) { + public static ArgumentParseResult failure(@Nonnull final Throwable failure) { return new ParseFailure<>(failure); } @@ -56,7 +56,7 @@ public abstract class ComponentParseResult { * @return Succeeded parse result */ @Nonnull - public static ComponentParseResult success(@Nonnull final T value) { + public static ArgumentParseResult success(@Nonnull final T value) { return new ParseSuccess<>(value); } @@ -77,7 +77,7 @@ public abstract class ComponentParseResult { public abstract Optional getFailure(); - private static final class ParseSuccess extends ComponentParseResult { + private static final class ParseSuccess extends ArgumentParseResult { /** * Parsed value @@ -103,7 +103,7 @@ public abstract class ComponentParseResult { } - private static final class ParseFailure extends ComponentParseResult { + private static final class ParseFailure extends ArgumentParseResult { /** * Parse failure diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParser.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ArgumentParser.java similarity index 88% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParser.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ArgumentParser.java index de4eba20..3740abb7 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ComponentParser.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ArgumentParser.java @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.parser; +package com.intellectualsites.commands.arguments.parser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.sender.CommandSender; @@ -38,7 +38,7 @@ import java.util.Queue; * @param Value type */ @FunctionalInterface -public interface ComponentParser { +public interface ArgumentParser { /** * Parse command input into a command result @@ -48,7 +48,7 @@ public interface ComponentParser { * @return Parsed command result */ @Nonnull - ComponentParseResult parse(@Nonnull CommandContext commandContext, @Nonnull Queue inputQueue); + ArgumentParseResult parse(@Nonnull CommandContext commandContext, @Nonnull Queue inputQueue); /** * Get a list of suggested arguments that would be correctly parsed by this parser @@ -63,7 +63,7 @@ public interface ComponentParser { } /** - * Check whether or not this component parser is context free. A context free + * Check whether or not this argument parser is context free. A context free * parser will not use the provided command context, and so supports impromptu parsing * * @return {@code true} if the parser is context free, else {@code false} diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameter.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ParserParameter.java similarity index 97% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameter.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ParserParameter.java index 57f63d8e..2ce61fc2 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameter.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ParserParameter.java @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.parser; +package com.intellectualsites.commands.arguments.parser; import com.google.common.reflect.TypeToken; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameters.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ParserParameters.java similarity index 98% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameters.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ParserParameters.java index da496cef..a3f62f27 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserParameters.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ParserParameters.java @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.parser; +package com.intellectualsites.commands.arguments.parser; import com.google.common.collect.Maps; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserRegistry.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ParserRegistry.java similarity index 89% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserRegistry.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ParserRegistry.java index bc40dd01..65d39f16 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/ParserRegistry.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/ParserRegistry.java @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.parser; +package com.intellectualsites.commands.arguments.parser; import com.google.common.reflect.TypeToken; import com.intellectualsites.commands.sender.CommandSender; @@ -34,7 +34,7 @@ import java.util.function.BiFunction; import java.util.function.Function; /** - * Registry of {@link ComponentParser} that allows these components to be + * Registry of {@link ArgumentParser} that allows these arguments to be * referenced by a {@link Class} (or really, a {@link com.google.common.reflect.TypeToken}) * or a {@link String} key * @@ -51,7 +51,7 @@ public interface ParserRegistry { * @param Generic type specifying what is produced by the parser */ void registerParserSupplier(@Nonnull TypeToken type, - @Nonnull Function> supplier); + @Nonnull Function> supplier); /** * Register a mapper that maps annotation instances to a map of parameter-object pairs @@ -77,7 +77,7 @@ public interface ParserRegistry { ParserParameters parseAnnotations(@Nonnull TypeToken parsingType, @Nonnull Collection annotations); /** - * Attempt to create a {@link ComponentParser} for a specified type, using + * Attempt to create a {@link ArgumentParser} for a specified type, using * an instance of {@link ParserParameter} to configure the parser settings * * @param type Type that should be produced by the parser @@ -86,7 +86,7 @@ public interface ParserRegistry { * @return Parser, if one can be created */ @Nonnull - Optional> createParser(@Nonnull TypeToken type, - @Nonnull ParserParameters parserParameters); + Optional> createParser(@Nonnull TypeToken type, + @Nonnull ParserParameters parserParameters); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/StandardParameters.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/StandardParameters.java similarity index 97% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/parser/StandardParameters.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/StandardParameters.java index cf839548..cab11607 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/StandardParameters.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/StandardParameters.java @@ -21,7 +21,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.parser; +package com.intellectualsites.commands.arguments.parser; import com.google.common.reflect.TypeToken; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/StandardParserRegistry.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/StandardParserRegistry.java similarity index 73% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/parser/StandardParserRegistry.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/StandardParserRegistry.java index e6b31e86..86710be6 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/StandardParserRegistry.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/StandardParserRegistry.java @@ -21,20 +21,20 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.parser; +package com.intellectualsites.commands.arguments.parser; import com.google.common.collect.ImmutableMap; import com.google.common.reflect.TypeToken; import com.intellectualsites.commands.annotations.specifier.Range; -import com.intellectualsites.commands.components.standard.BooleanComponent; -import com.intellectualsites.commands.components.standard.ByteComponent; -import com.intellectualsites.commands.components.standard.CharComponent; -import com.intellectualsites.commands.components.standard.DoubleComponent; -import com.intellectualsites.commands.components.standard.EnumComponent; -import com.intellectualsites.commands.components.standard.FloatComponent; -import com.intellectualsites.commands.components.standard.IntegerComponent; -import com.intellectualsites.commands.components.standard.ShortComponent; -import com.intellectualsites.commands.components.standard.StringComponent; +import com.intellectualsites.commands.arguments.standard.BooleanArgument; +import com.intellectualsites.commands.arguments.standard.ByteArgument; +import com.intellectualsites.commands.arguments.standard.CharArgument; +import com.intellectualsites.commands.arguments.standard.DoubleArgument; +import com.intellectualsites.commands.arguments.standard.EnumArgument; +import com.intellectualsites.commands.arguments.standard.FloatArgument; +import com.intellectualsites.commands.arguments.standard.IntegerArgument; +import com.intellectualsites.commands.arguments.standard.ShortArgument; +import com.intellectualsites.commands.arguments.standard.StringArgument; import com.intellectualsites.commands.sender.CommandSender; import javax.annotation.Nonnull; @@ -65,7 +65,7 @@ public final class StandardParserRegistry implements Pa .put(boolean.class, Boolean.class) .build(); - private final Map, Function>> parserSuppliers = new HashMap<>(); + private final Map, Function>> parserSuppliers = new HashMap<>(); private final Map, BiFunction, ParserParameters>> annotationMappers = new HashMap<>(); @@ -79,31 +79,31 @@ public final class StandardParserRegistry implements Pa /* Register standard types */ this.registerParserSupplier(TypeToken.of(Byte.class), options -> - new ByteComponent.ByteParser((byte) options.get(StandardParameters.RANGE_MIN, Byte.MIN_VALUE), - (byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE))); + new ByteArgument.ByteParser((byte) options.get(StandardParameters.RANGE_MIN, Byte.MIN_VALUE), + (byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE))); this.registerParserSupplier(TypeToken.of(Short.class), options -> - new ShortComponent.ShortParser((short) options.get(StandardParameters.RANGE_MIN, Short.MIN_VALUE), - (short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE))); + new ShortArgument.ShortParser((short) options.get(StandardParameters.RANGE_MIN, Short.MIN_VALUE), + (short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE))); this.registerParserSupplier(TypeToken.of(Integer.class), options -> - new IntegerComponent.IntegerParser((int) options.get(StandardParameters.RANGE_MIN, Integer.MIN_VALUE), - (int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE))); + new IntegerArgument.IntegerParser((int) options.get(StandardParameters.RANGE_MIN, Integer.MIN_VALUE), + (int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE))); this.registerParserSupplier(TypeToken.of(Float.class), options -> - new FloatComponent.FloatParser((float) options.get(StandardParameters.RANGE_MIN, Float.MIN_VALUE), - (float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE))); + new FloatArgument.FloatParser((float) options.get(StandardParameters.RANGE_MIN, Float.MIN_VALUE), + (float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE))); this.registerParserSupplier(TypeToken.of(Double.class), options -> - new DoubleComponent.DoubleParser((double) options.get(StandardParameters.RANGE_MIN, Double.MIN_VALUE), - (double) options.get(StandardParameters.RANGE_MAX, Double.MAX_VALUE))); - this.registerParserSupplier(TypeToken.of(Character.class), options -> new CharComponent.CharacterParser()); + new DoubleArgument.DoubleParser((double) options.get(StandardParameters.RANGE_MIN, Double.MIN_VALUE), + (double) options.get(StandardParameters.RANGE_MAX, Double.MAX_VALUE))); + this.registerParserSupplier(TypeToken.of(Character.class), options -> new CharArgument.CharacterParser()); /* Make this one less awful */ - this.registerParserSupplier(TypeToken.of(String.class), options -> new StringComponent.StringParser( - StringComponent.StringMode.SINGLE, (context, s) -> Collections.emptyList())); + this.registerParserSupplier(TypeToken.of(String.class), options -> new StringArgument.StringParser( + StringArgument.StringMode.SINGLE, (context, s) -> Collections.emptyList())); /* Add options to this */ - this.registerParserSupplier(TypeToken.of(Boolean.class), options -> new BooleanComponent.BooleanParser<>(false)); + this.registerParserSupplier(TypeToken.of(Boolean.class), options -> new BooleanArgument.BooleanParser<>(false)); } @Override public void registerParserSupplier(@Nonnull final TypeToken type, - @Nonnull final Function> supplier) { + @Nonnull final Function> supplier) { this.parserSuppliers.put(type, supplier); } @@ -134,27 +134,27 @@ public final class StandardParserRegistry implements Pa @Nonnull @Override - public Optional> createParser(@Nonnull final TypeToken type, - @Nonnull final ParserParameters parserParameters) { + public Optional> createParser(@Nonnull final TypeToken type, + @Nonnull final ParserParameters parserParameters) { final TypeToken actualType; if (type.isPrimitive()) { actualType = TypeToken.of(PRIMITIVE_MAPPINGS.get(type.getRawType())); } else { actualType = type; } - final Function> producer = this.parserSuppliers.get(actualType); + final Function> producer = this.parserSuppliers.get(actualType); if (producer == null) { /* Give enums special treatment */ if (actualType.isSubtypeOf(Enum.class)) { @SuppressWarnings("all") - final EnumComponent.EnumParser enumComponent = new EnumComponent.EnumParser((Class) + final EnumArgument.EnumParser enumArgument = new EnumArgument.EnumParser((Class) actualType.getRawType()); // noinspection all - return Optional.of(enumComponent); + return Optional.of(enumArgument); } return Optional.empty(); } - @SuppressWarnings("unchecked") final ComponentParser parser = (ComponentParser) producer.apply( + @SuppressWarnings("unchecked") final ArgumentParser parser = (ArgumentParser) producer.apply( parserParameters); return Optional.of(parser); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/package-info.java similarity index 92% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/parser/package-info.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/package-info.java index ec7db600..8c01c78c 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/parser/package-info.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/parser/package-info.java @@ -23,6 +23,6 @@ // /** - * Parser classes used to parse {@link com.intellectualsites.commands.components.CommandComponent} + * Parser classes used to parse {@link com.intellectualsites.commands.arguments.CommandArgument} */ -package com.intellectualsites.commands.components.parser; +package com.intellectualsites.commands.arguments.parser; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/BooleanComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/BooleanArgument.java similarity index 67% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/standard/BooleanComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/BooleanArgument.java index e97d0ba2..85738733 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/BooleanComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/BooleanArgument.java @@ -21,11 +21,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.standard; +package com.intellectualsites.commands.arguments.standard; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.sender.CommandSender; @@ -35,11 +35,11 @@ import java.util.List; import java.util.Queue; @SuppressWarnings("unused") -public final class BooleanComponent extends CommandComponent { +public final class BooleanArgument extends CommandArgument { private final boolean liberal; - private BooleanComponent(final boolean required, @Nonnull final String name, - final boolean liberal, @Nonnull final String defaultValue) { + private BooleanArgument(final boolean required, @Nonnull final String name, + final boolean liberal, @Nonnull final String defaultValue) { super(required, name, new BooleanParser<>(liberal), defaultValue, Boolean.class); this.liberal = liberal; } @@ -47,7 +47,7 @@ public final class BooleanComponent extends CommandComp /** * Create a new builder * - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @return Created builder */ @@ -57,45 +57,45 @@ public final class BooleanComponent extends CommandComp } /** - * Create a new required command component + * Create a new required command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent required(@Nonnull final String name) { - return BooleanComponent.newBuilder(name).asRequired().build(); + public static CommandArgument required(@Nonnull final String name) { + return BooleanArgument.newBuilder(name).asRequired().build(); } /** - * Create a new optional command component + * Create a new optional command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name) { - return BooleanComponent.newBuilder(name).asOptional().build(); + public static CommandArgument optional(@Nonnull final String name) { + return BooleanArgument.newBuilder(name).asOptional().build(); } /** - * Create a new required command component with a default value + * Create a new required command argument with a default value * - * @param name Component name + * @param name Argument name * @param defaultNum Default num * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name, - final String defaultNum) { - return BooleanComponent.newBuilder(name).asOptionalWithDefault(defaultNum).build(); + public static CommandArgument optional(@Nonnull final String name, + final String defaultNum) { + return BooleanArgument.newBuilder(name).asOptionalWithDefault(defaultNum).build(); } - public static final class Builder extends CommandComponent.Builder { + public static final class Builder extends CommandArgument.Builder { private boolean liberal = false; @@ -116,14 +116,14 @@ public final class BooleanComponent extends CommandComp } /** - * Builder a new boolean component + * Builder a new boolean argument * - * @return Constructed component + * @return Constructed argument */ @Nonnull @Override - public BooleanComponent build() { - return new BooleanComponent<>(this.isRequired(), this.getName(), this.liberal, this.getDefaultValue()); + public BooleanArgument build() { + return new BooleanArgument<>(this.isRequired(), this.getName(), this.liberal, this.getDefaultValue()); } } @@ -138,7 +138,7 @@ public final class BooleanComponent extends CommandComp } - public static final class BooleanParser implements ComponentParser { + public static final class BooleanParser implements ArgumentParser { private static final List LIBERAL = Arrays.asList("TRUE", "YES", "ON", "FALSE", "NO", "OFF"); private static final List LIBERAL_TRUE = Arrays.asList("TRUE", "YES", "ON"); @@ -157,37 +157,37 @@ public final class BooleanComponent extends CommandComp @Nonnull @Override - public ComponentParseResult parse(@Nonnull final CommandContext commandContext, - @Nonnull final Queue inputQueue) { + public ArgumentParseResult parse(@Nonnull final CommandContext commandContext, + @Nonnull final Queue inputQueue) { final String input = inputQueue.peek(); if (input == null) { - return ComponentParseResult.failure(new NullPointerException("No input was provided")); + return ArgumentParseResult.failure(new NullPointerException("No input was provided")); } inputQueue.remove(); if (!liberal) { if (input.equalsIgnoreCase("true")) { - return ComponentParseResult.success(true); + return ArgumentParseResult.success(true); } if (input.equalsIgnoreCase("false")) { - return ComponentParseResult.success(false); + return ArgumentParseResult.success(false); } - return ComponentParseResult.failure(new BooleanParseException(input, false)); + return ArgumentParseResult.failure(new BooleanParseException(input, false)); } final String uppercaseInput = input.toUpperCase(); if (LIBERAL_TRUE.contains(uppercaseInput)) { - return ComponentParseResult.success(true); + return ArgumentParseResult.success(true); } if (LIBERAL_FALSE.contains(uppercaseInput)) { - return ComponentParseResult.success(false); + return ArgumentParseResult.success(false); } - return ComponentParseResult.failure(new BooleanParseException(input, true)); + return ArgumentParseResult.failure(new BooleanParseException(input, true)); } @Nonnull diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/ByteArgument.java similarity index 71% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/ByteArgument.java index ffaad36e..22cbd10f 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ByteComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/ByteArgument.java @@ -21,11 +21,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.standard; +package com.intellectualsites.commands.arguments.standard; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.exceptions.parsing.NumberParseException; import com.intellectualsites.commands.sender.CommandSender; @@ -34,13 +34,13 @@ import javax.annotation.Nonnull; import java.util.Queue; @SuppressWarnings("unused") -public final class ByteComponent extends CommandComponent { +public final class ByteArgument extends CommandArgument { private final byte min; private final byte max; - private ByteComponent(final boolean required, @Nonnull final String name, final byte min, - final byte max, final String defaultValue) { + private ByteArgument(final boolean required, @Nonnull final String name, final byte min, + final byte max, final String defaultValue) { super(required, name, new ByteParser<>(min, max), defaultValue, Byte.class); this.min = min; this.max = max; @@ -49,7 +49,7 @@ public final class ByteComponent extends CommandCompone /** * Create a new builder * - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @return Created builder */ @@ -59,44 +59,44 @@ public final class ByteComponent extends CommandCompone } /** - * Create a new required command component + * Create a new required command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent required(@Nonnull final String name) { - return ByteComponent.newBuilder(name).asRequired().build(); + public static CommandArgument required(@Nonnull final String name) { + return ByteArgument.newBuilder(name).asRequired().build(); } /** - * Create a new optional command component + * Create a new optional command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name) { - return ByteComponent.newBuilder(name).asOptional().build(); + public static CommandArgument optional(@Nonnull final String name) { + return ByteArgument.newBuilder(name).asOptional().build(); } /** - * Create a new required command component with a default value + * Create a new required command argument with a default value * - * @param name Component name + * @param name Argument name * @param defaultNum Default num * @param Command sender type - * @return Created component + * @return Created argument */ - @Nonnull public static CommandComponent optional(@Nonnull final String name, - final byte defaultNum) { - return ByteComponent.newBuilder(name).asOptionalWithDefault(Byte.toString(defaultNum)).build(); + @Nonnull public static CommandArgument optional(@Nonnull final String name, + final byte defaultNum) { + return ByteArgument.newBuilder(name).asOptionalWithDefault(Byte.toString(defaultNum)).build(); } - public static final class Builder extends CommandComponent.Builder { + public static final class Builder extends CommandArgument.Builder { private byte min = Byte.MIN_VALUE; private byte max = Byte.MAX_VALUE; @@ -130,14 +130,14 @@ public final class ByteComponent extends CommandCompone } /** - * Builder a new byte component + * Builder a new byte argument * - * @return Constructed component + * @return Constructed argument */ @Nonnull @Override - public ByteComponent build() { - return new ByteComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); + public ByteArgument build() { + return new ByteArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); } } @@ -162,7 +162,7 @@ public final class ByteComponent extends CommandCompone } - public static final class ByteParser implements ComponentParser { + public static final class ByteParser implements ArgumentParser { private final byte min; private final byte max; @@ -180,25 +180,25 @@ public final class ByteComponent extends CommandCompone @Nonnull @Override - public ComponentParseResult parse( + public ArgumentParseResult parse( @Nonnull final CommandContext commandContext, @Nonnull final Queue inputQueue) { final String input = inputQueue.peek(); if (input == null) { - return ComponentParseResult.failure(new NullPointerException("No input was provided")); + return ArgumentParseResult.failure(new NullPointerException("No input was provided")); } try { final byte value = Byte.parseByte(input); if (value < this.min || value > this.max) { - return ComponentParseResult.failure( + return ArgumentParseResult.failure( new ByteParseException(input, this.min, this.max)); } inputQueue.remove(); - return ComponentParseResult.success(value); + return ArgumentParseResult.success(value); } catch (final Exception e) { - return ComponentParseResult.failure( + return ArgumentParseResult.failure( new ByteParseException(input, this.min, this.max)); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/CharComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/CharArgument.java similarity index 55% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/standard/CharComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/CharArgument.java index 374d2968..75143f3d 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/CharComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/CharArgument.java @@ -21,11 +21,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.standard; +package com.intellectualsites.commands.arguments.standard; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.sender.CommandSender; @@ -33,100 +33,100 @@ import javax.annotation.Nonnull; import java.util.Queue; @SuppressWarnings("unused") -public final class CharComponent extends CommandComponent { +public final class CharArgument extends CommandArgument { - private CharComponent(final boolean required, @Nonnull final String name, - @Nonnull final String defaultValue) { + private CharArgument(final boolean required, @Nonnull final String name, + @Nonnull final String defaultValue) { super(required, name, new CharacterParser<>(), defaultValue, Character.class); } /** * Create a new builder * - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @return Created builder */ @Nonnull - public static CharComponent.Builder newBuilder(@Nonnull final String name) { - return new CharComponent.Builder<>(name); + public static CharArgument.Builder newBuilder(@Nonnull final String name) { + return new CharArgument.Builder<>(name); } /** - * Create a new required command component + * Create a new required command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent required(@Nonnull final String name) { - return CharComponent.newBuilder(name).asRequired().build(); + public static CommandArgument required(@Nonnull final String name) { + return CharArgument.newBuilder(name).asRequired().build(); } /** - * Create a new optional command component + * Create a new optional command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name) { - return CharComponent.newBuilder(name).asOptional().build(); + public static CommandArgument optional(@Nonnull final String name) { + return CharArgument.newBuilder(name).asOptional().build(); } /** - * Create a new required command component with a default value + * Create a new required command argument with a default value * - * @param name Component name + * @param name Argument name * @param defaultNum Default num * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name, - final String defaultNum) { - return CharComponent.newBuilder(name).asOptionalWithDefault(defaultNum).build(); + public static CommandArgument optional(@Nonnull final String name, + final String defaultNum) { + return CharArgument.newBuilder(name).asOptionalWithDefault(defaultNum).build(); } - public static final class Builder extends CommandComponent.Builder { + public static final class Builder extends CommandArgument.Builder { protected Builder(@Nonnull final String name) { super(Character.class, name); } /** - * Builder a new char component + * Builder a new char argument * - * @return Constructed component + * @return Constructed argument */ @Nonnull @Override - public CharComponent build() { - return new CharComponent<>(this.isRequired(), this.getName(), this.getDefaultValue()); + public CharArgument build() { + return new CharArgument<>(this.isRequired(), this.getName(), this.getDefaultValue()); } } - public static final class CharacterParser implements ComponentParser { + public static final class CharacterParser implements ArgumentParser { @Nonnull @Override - public ComponentParseResult parse(@Nonnull final CommandContext commandContext, - @Nonnull final Queue inputQueue) { + public ArgumentParseResult parse(@Nonnull final CommandContext commandContext, + @Nonnull final Queue inputQueue) { final String input = inputQueue.peek(); if (input == null) { - return ComponentParseResult.failure(new NullPointerException("No input was provided")); + return ArgumentParseResult.failure(new NullPointerException("No input was provided")); } if (input.length() != 1) { - return ComponentParseResult.failure(new CharParseException(input)); + return ArgumentParseResult.failure(new CharParseException(input)); } - return ComponentParseResult.success(input.charAt(0)); + return ArgumentParseResult.success(input.charAt(0)); } @Override diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/DoubleComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/DoubleArgument.java similarity index 68% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/standard/DoubleComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/DoubleArgument.java index efb6ff70..763ee99c 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/DoubleComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/DoubleArgument.java @@ -21,11 +21,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.standard; +package com.intellectualsites.commands.arguments.standard; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.exceptions.parsing.NumberParseException; import com.intellectualsites.commands.sender.CommandSender; @@ -34,16 +34,16 @@ import javax.annotation.Nonnull; import java.util.Queue; @SuppressWarnings("unused") -public final class DoubleComponent extends CommandComponent { +public final class DoubleArgument extends CommandArgument { private final double min; private final double max; - private DoubleComponent(final boolean required, - @Nonnull final String name, - final double min, - final double max, - final String defaultValue) { + private DoubleArgument(final boolean required, + @Nonnull final String name, + final double min, + final double max, + final String defaultValue) { super(required, name, new DoubleParser<>(min, max), defaultValue, Double.class); this.min = min; this.max = max; @@ -52,7 +52,7 @@ public final class DoubleComponent extends CommandCompo /** * Create a new builder * - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @return Created builder */ @@ -62,45 +62,45 @@ public final class DoubleComponent extends CommandCompo } /** - * Create a new required command component + * Create a new required command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent required(@Nonnull final String name) { - return DoubleComponent.newBuilder(name).asRequired().build(); + public static CommandArgument required(@Nonnull final String name) { + return DoubleArgument.newBuilder(name).asRequired().build(); } /** - * Create a new optional command component + * Create a new optional command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name) { - return DoubleComponent.newBuilder(name).asOptional().build(); + public static CommandArgument optional(@Nonnull final String name) { + return DoubleArgument.newBuilder(name).asOptional().build(); } /** - * Create a new required command component with a default value + * Create a new required command argument with a default value * - * @param name Component name + * @param name Argument name * @param defaultNum Default num * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name, - final double defaultNum) { - return DoubleComponent.newBuilder(name).asOptionalWithDefault(Double.toString(defaultNum)).build(); + public static CommandArgument optional(@Nonnull final String name, + final double defaultNum) { + return DoubleArgument.newBuilder(name).asOptionalWithDefault(Double.toString(defaultNum)).build(); } - public static final class Builder extends CommandComponent.Builder { + public static final class Builder extends CommandArgument.Builder { private double min = Double.MIN_VALUE; private double max = Double.MAX_VALUE; @@ -134,14 +134,14 @@ public final class DoubleComponent extends CommandCompo } /** - * Builder a new double component + * Builder a new double argument * - * @return Constructed component + * @return Constructed argument */ @Nonnull @Override - public DoubleComponent build() { - return new DoubleComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); + public DoubleArgument build() { + return new DoubleArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); } } @@ -166,7 +166,7 @@ public final class DoubleComponent extends CommandCompo } - public static final class DoubleParser implements ComponentParser { + public static final class DoubleParser implements ArgumentParser { private final double min; private final double max; @@ -184,22 +184,22 @@ public final class DoubleComponent extends CommandCompo @Nonnull @Override - public ComponentParseResult parse( + public ArgumentParseResult parse( @Nonnull final CommandContext commandContext, @Nonnull final Queue inputQueue) { final String input = inputQueue.peek(); if (input == null) { - return ComponentParseResult.failure(new NullPointerException("No input was provided")); + return ArgumentParseResult.failure(new NullPointerException("No input was provided")); } try { final double value = Double.parseDouble(input); if (value < this.min || value > this.max) { - return ComponentParseResult.failure(new DoubleParseException(input, this.min, this.max)); + return ArgumentParseResult.failure(new DoubleParseException(input, this.min, this.max)); } inputQueue.remove(); - return ComponentParseResult.success(value); + return ArgumentParseResult.success(value); } catch (final Exception e) { - return ComponentParseResult.failure(new DoubleParseException(input, this.min, this.max)); + return ArgumentParseResult.failure(new DoubleParseException(input, this.min, this.max)); } } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/EnumComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/EnumArgument.java similarity index 71% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/standard/EnumComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/EnumArgument.java index e22930e7..81dabb92 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/EnumComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/EnumArgument.java @@ -21,11 +21,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.standard; +package com.intellectualsites.commands.arguments.standard; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.sender.CommandSender; @@ -36,84 +36,84 @@ import java.util.Queue; import java.util.stream.Collectors; /** - * Component type that recognizes enums + * Argument type that recognizes enums * - * @param Component sender + * @param Argument sender * @param Enum type */ @SuppressWarnings("unused") -public class EnumComponent> extends CommandComponent { +public class EnumArgument> extends CommandArgument { - protected EnumComponent(@Nonnull final Class enumClass, - final boolean required, - @Nonnull final String name, - @Nonnull final String defaultValue) { + protected EnumArgument(@Nonnull final Class enumClass, + final boolean required, + @Nonnull final String name, + @Nonnull final String defaultValue) { super(required, name, new EnumParser<>(enumClass), defaultValue, enumClass); } /** * Create a new builder * - * @param name Name of the component + * @param name Name of the argument * @param enumClass Enum class * @param Command sender type * @param Enum type * @return Created builder */ @Nonnull - public static > EnumComponent.Builder newBuilder( + public static > EnumArgument.Builder newBuilder( @Nonnull final Class enumClass, @Nonnull final String name) { - return new EnumComponent.Builder<>(name, enumClass); + return new EnumArgument.Builder<>(name, enumClass); } /** - * Create a new required command component + * Create a new required command argument * * @param enumClass Enum class - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @param Enum type - * @return Created component + * @return Created argument */ @Nonnull - public static > CommandComponent required( + public static > CommandArgument required( @Nonnull final Class enumClass, @Nonnull final String name) { - return EnumComponent.newBuilder(enumClass, name).asRequired().build(); + return EnumArgument.newBuilder(enumClass, name).asRequired().build(); } /** - * Create a new optional command component + * Create a new optional command argument * * @param enumClass Enum class - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @param Enum type - * @return Created component + * @return Created argument */ @Nonnull - public static > CommandComponent optional( + public static > CommandArgument optional( @Nonnull final Class enumClass, @Nonnull final String name) { - return EnumComponent.newBuilder(enumClass, name).asOptional().build(); + return EnumArgument.newBuilder(enumClass, name).asOptional().build(); } /** - * Create a new optional command component with a default value + * Create a new optional command argument with a default value * * @param enumClass Enum class - * @param name Name of the component + * @param name Name of the argument * @param defaultValue Default value * @param Command sender type * @param Enum type - * @return Created component + * @return Created argument */ @Nonnull - public static > CommandComponent optional( + public static > CommandArgument optional( @Nonnull final Class enumClass, @Nonnull final String name, @Nonnull final E defaultValue) { - return EnumComponent.newBuilder(enumClass, name).asOptionalWithDefault(defaultValue.name().toLowerCase()).build(); + return EnumArgument.newBuilder(enumClass, name).asOptionalWithDefault(defaultValue.name().toLowerCase()).build(); } - public static final class Builder> extends CommandComponent.Builder { + public static final class Builder> extends CommandArgument.Builder { private final Class enumClass; @@ -124,13 +124,13 @@ public class EnumComponent> extends C @Nonnull @Override - public CommandComponent build() { - return new EnumComponent<>(this.enumClass, this.isRequired(), this.getName(), this.getDefaultValue()); + public CommandArgument build() { + return new EnumArgument<>(this.enumClass, this.isRequired(), this.getName(), this.getDefaultValue()); } } - public static final class EnumParser> implements ComponentParser { + public static final class EnumParser> implements ArgumentParser { private final Class enumClass; private final EnumSet allowedValues; @@ -147,21 +147,21 @@ public class EnumComponent> extends C @Nonnull @Override - public ComponentParseResult parse(@Nonnull final CommandContext commandContext, - @Nonnull final Queue inputQueue) { + public ArgumentParseResult parse(@Nonnull final CommandContext commandContext, + @Nonnull final Queue inputQueue) { final String input = inputQueue.peek(); if (input == null) { - return ComponentParseResult.failure(new NullPointerException("No input was provided")); + return ArgumentParseResult.failure(new NullPointerException("No input was provided")); } for (final E value : this.allowedValues) { if (value.name().equalsIgnoreCase(input)) { inputQueue.remove(); - return ComponentParseResult.success(value); + return ArgumentParseResult.success(value); } } - return ComponentParseResult.failure(new EnumParseException(input, this.enumClass)); + return ArgumentParseResult.failure(new EnumParseException(input, this.enumClass)); } @Nonnull diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/FloatComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/FloatArgument.java similarity index 68% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/standard/FloatComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/FloatArgument.java index 292b260d..37ada15e 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/FloatComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/FloatArgument.java @@ -21,11 +21,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.standard; +package com.intellectualsites.commands.arguments.standard; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.exceptions.parsing.NumberParseException; import com.intellectualsites.commands.sender.CommandSender; @@ -34,16 +34,16 @@ import javax.annotation.Nonnull; import java.util.Queue; @SuppressWarnings("unused") -public final class FloatComponent extends CommandComponent { +public final class FloatArgument extends CommandArgument { private final float min; private final float max; - private FloatComponent(final boolean required, - @Nonnull final String name, - final float min, - final float max, - final String defaultValue) { + private FloatArgument(final boolean required, + @Nonnull final String name, + final float min, + final float max, + final String defaultValue) { super(required, name, new FloatParser<>(min, max), defaultValue, Float.class); this.min = min; this.max = max; @@ -52,7 +52,7 @@ public final class FloatComponent extends CommandCompon /** * Create a new builder * - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @return Created builder */ @@ -62,45 +62,45 @@ public final class FloatComponent extends CommandCompon } /** - * Create a new required command component + * Create a new required command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent required(@Nonnull final String name) { - return FloatComponent.newBuilder(name).asRequired().build(); + public static CommandArgument required(@Nonnull final String name) { + return FloatArgument.newBuilder(name).asRequired().build(); } /** - * Create a new optional command component + * Create a new optional command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name) { - return FloatComponent.newBuilder(name).asOptional().build(); + public static CommandArgument optional(@Nonnull final String name) { + return FloatArgument.newBuilder(name).asOptional().build(); } /** - * Create a new required command component with a default value + * Create a new required command argument with a default value * - * @param name Component name + * @param name Argument name * @param defaultNum Default num * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name, - final float defaultNum) { - return FloatComponent.newBuilder(name).asOptionalWithDefault(Float.toString(defaultNum)).build(); + public static CommandArgument optional(@Nonnull final String name, + final float defaultNum) { + return FloatArgument.newBuilder(name).asOptionalWithDefault(Float.toString(defaultNum)).build(); } - public static final class Builder extends CommandComponent.Builder { + public static final class Builder extends CommandArgument.Builder { private float min = Float.MIN_VALUE; private float max = Float.MAX_VALUE; @@ -134,14 +134,14 @@ public final class FloatComponent extends CommandCompon } /** - * Builder a new float component + * Builder a new float argument * - * @return Constructed component + * @return Constructed argument */ @Nonnull @Override - public FloatComponent build() { - return new FloatComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); + public FloatArgument build() { + return new FloatArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); } } @@ -166,7 +166,7 @@ public final class FloatComponent extends CommandCompon } - public static final class FloatParser implements ComponentParser { + public static final class FloatParser implements ArgumentParser { private final float min; private final float max; @@ -184,22 +184,22 @@ public final class FloatComponent extends CommandCompon @Nonnull @Override - public ComponentParseResult parse( + public ArgumentParseResult parse( @Nonnull final CommandContext commandContext, @Nonnull final Queue inputQueue) { final String input = inputQueue.peek(); if (input == null) { - return ComponentParseResult.failure(new NullPointerException("No input was provided")); + return ArgumentParseResult.failure(new NullPointerException("No input was provided")); } try { final float value = Float.parseFloat(input); if (value < this.min || value > this.max) { - return ComponentParseResult.failure(new FloatParseException(input, this.min, this.max)); + return ArgumentParseResult.failure(new FloatParseException(input, this.min, this.max)); } inputQueue.remove(); - return ComponentParseResult.success(value); + return ArgumentParseResult.success(value); } catch (final Exception e) { - return ComponentParseResult.failure(new FloatParseException(input, this.min, this.max)); + return ArgumentParseResult.failure(new FloatParseException(input, this.min, this.max)); } } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/IntegerComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/IntegerArgument.java similarity index 70% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/standard/IntegerComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/IntegerArgument.java index bb40c394..c457b884 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/IntegerComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/IntegerArgument.java @@ -21,11 +21,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.standard; +package com.intellectualsites.commands.arguments.standard; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.exceptions.parsing.NumberParseException; import com.intellectualsites.commands.sender.CommandSender; @@ -34,16 +34,16 @@ import javax.annotation.Nonnull; import java.util.Queue; @SuppressWarnings("unused") -public final class IntegerComponent extends CommandComponent { +public final class IntegerArgument extends CommandArgument { private final int min; private final int max; - private IntegerComponent(final boolean required, - @Nonnull final String name, - final int min, - final int max, - final String defaultValue) { + private IntegerArgument(final boolean required, + @Nonnull final String name, + final int min, + final int max, + final String defaultValue) { super(required, name, new IntegerParser<>(min, max), defaultValue, Integer.class); this.min = min; this.max = max; @@ -52,7 +52,7 @@ public final class IntegerComponent extends CommandComp /** * Create a new builder * - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @return Created builder */ @@ -62,45 +62,45 @@ public final class IntegerComponent extends CommandComp } /** - * Create a new required command component + * Create a new required command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent required(@Nonnull final String name) { - return IntegerComponent.newBuilder(name).asRequired().build(); + public static CommandArgument required(@Nonnull final String name) { + return IntegerArgument.newBuilder(name).asRequired().build(); } /** - * Create a new optional command component + * Create a new optional command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name) { - return IntegerComponent.newBuilder(name).asOptional().build(); + public static CommandArgument optional(@Nonnull final String name) { + return IntegerArgument.newBuilder(name).asOptional().build(); } /** - * Create a new required command component with a default value + * Create a new required command argument with a default value * - * @param name Component name + * @param name Argument name * @param defaultNum Default num * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name, - final int defaultNum) { - return IntegerComponent.newBuilder(name).asOptionalWithDefault(Integer.toString(defaultNum)).build(); + public static CommandArgument optional(@Nonnull final String name, + final int defaultNum) { + return IntegerArgument.newBuilder(name).asOptionalWithDefault(Integer.toString(defaultNum)).build(); } - public static final class Builder extends CommandComponent.Builder { + public static final class Builder extends CommandArgument.Builder { private int min = Integer.MIN_VALUE; private int max = Integer.MAX_VALUE; @@ -134,14 +134,14 @@ public final class IntegerComponent extends CommandComp } /** - * Builder a new integer component + * Builder a new integer argument * - * @return Constructed component + * @return Constructed argument */ @Nonnull @Override - public IntegerComponent build() { - return new IntegerComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); + public IntegerArgument build() { + return new IntegerArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); } } @@ -166,7 +166,7 @@ public final class IntegerComponent extends CommandComp } - public static final class IntegerParser implements ComponentParser { + public static final class IntegerParser implements ArgumentParser { private final int min; private final int max; @@ -184,22 +184,22 @@ public final class IntegerComponent extends CommandComp @Nonnull @Override - public ComponentParseResult parse( + public ArgumentParseResult parse( @Nonnull final CommandContext commandContext, @Nonnull final Queue inputQueue) { final String input = inputQueue.peek(); if (input == null) { - return ComponentParseResult.failure(new NullPointerException("No input was provided")); + return ArgumentParseResult.failure(new NullPointerException("No input was provided")); } try { final int value = Integer.parseInt(input); if (value < this.min || value > this.max) { - return ComponentParseResult.failure(new IntegerParseException(input, this.min, this.max)); + return ArgumentParseResult.failure(new IntegerParseException(input, this.min, this.max)); } inputQueue.remove(); - return ComponentParseResult.success(value); + return ArgumentParseResult.success(value); } catch (final Exception e) { - return ComponentParseResult.failure(new IntegerParseException(input, this.min, this.max)); + return ArgumentParseResult.failure(new IntegerParseException(input, this.min, this.max)); } } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/LongComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/LongArgument.java similarity index 66% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/standard/LongComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/LongArgument.java index 60036595..545c01e4 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/LongComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/LongArgument.java @@ -21,11 +21,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.standard; +package com.intellectualsites.commands.arguments.standard; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.exceptions.parsing.NumberParseException; import com.intellectualsites.commands.sender.CommandSender; @@ -34,16 +34,16 @@ import javax.annotation.Nonnull; import java.util.Queue; @SuppressWarnings("unused") -public final class LongComponent extends CommandComponent { +public final class LongArgument extends CommandArgument { private final long min; private final long max; - private LongComponent(final boolean required, - @Nonnull final String name, - final long min, - final long max, - final String defaultValue) { + private LongArgument(final boolean required, + @Nonnull final String name, + final long min, + final long max, + final String defaultValue) { super(required, name, new LongParser<>(min, max), defaultValue, Long.class); this.min = min; this.max = max; @@ -52,55 +52,55 @@ public final class LongComponent extends CommandCompone /** * Create a new builder * - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @return Created builder */ @Nonnull - public static LongComponent.Builder newBuilder(@Nonnull final String name) { + public static LongArgument.Builder newBuilder(@Nonnull final String name) { return new Builder<>(name); } /** - * Create a new required command component + * Create a new required command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent required(@Nonnull final String name) { - return LongComponent.newBuilder(name).asRequired().build(); + public static CommandArgument required(@Nonnull final String name) { + return LongArgument.newBuilder(name).asRequired().build(); } /** - * Create a new optional command component + * Create a new optional command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name) { - return LongComponent.newBuilder(name).asOptional().build(); + public static CommandArgument optional(@Nonnull final String name) { + return LongArgument.newBuilder(name).asOptional().build(); } /** - * Create a new required command component with a default value + * Create a new required command argument with a default value * - * @param name Component name + * @param name Argument name * @param defaultNum Default num * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name, - final long defaultNum) { - return LongComponent.newBuilder(name).asOptionalWithDefault(Long.toString(defaultNum)).build(); + public static CommandArgument optional(@Nonnull final String name, + final long defaultNum) { + return LongArgument.newBuilder(name).asOptionalWithDefault(Long.toString(defaultNum)).build(); } - public static final class Builder extends CommandComponent.Builder { + public static final class Builder extends CommandArgument.Builder { private long min = Long.MIN_VALUE; private long max = Long.MAX_VALUE; @@ -134,14 +134,14 @@ public final class LongComponent extends CommandCompone } /** - * Builder a new long component + * Builder a new long argument * - * @return Constructed component + * @return Constructed argument */ @Nonnull @Override - public LongComponent build() { - return new LongComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); + public LongArgument build() { + return new LongArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); } } @@ -166,7 +166,7 @@ public final class LongComponent extends CommandCompone } - private static final class LongParser implements ComponentParser { + private static final class LongParser implements ArgumentParser { private final long min; private final long max; @@ -178,22 +178,22 @@ public final class LongComponent extends CommandCompone @Nonnull @Override - public ComponentParseResult parse( + public ArgumentParseResult parse( @Nonnull final CommandContext commandContext, @Nonnull final Queue inputQueue) { final String input = inputQueue.peek(); if (input == null) { - return ComponentParseResult.failure(new NullPointerException("No input was provided")); + return ArgumentParseResult.failure(new NullPointerException("No input was provided")); } try { final long value = Long.parseLong(input); if (value < this.min || value > this.max) { - return ComponentParseResult.failure(new LongParseException(input, this.min, this.max)); + return ArgumentParseResult.failure(new LongParseException(input, this.min, this.max)); } inputQueue.remove(); - return ComponentParseResult.success(value); + return ArgumentParseResult.success(value); } catch (final Exception e) { - return ComponentParseResult.failure(new LongParseException(input, this.min, this.max)); + return ArgumentParseResult.failure(new LongParseException(input, this.min, this.max)); } } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ShortComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/ShortArgument.java similarity index 70% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ShortComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/ShortArgument.java index 6ea7c900..983af5c7 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/ShortComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/ShortArgument.java @@ -21,11 +21,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.standard; +package com.intellectualsites.commands.arguments.standard; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.exceptions.parsing.NumberParseException; import com.intellectualsites.commands.sender.CommandSender; @@ -34,12 +34,12 @@ import javax.annotation.Nonnull; import java.util.Queue; @SuppressWarnings("unused") -public final class ShortComponent extends CommandComponent { +public final class ShortArgument extends CommandArgument { private final short min; private final short max; - private ShortComponent(final boolean required, + private ShortArgument(final boolean required, @Nonnull final String name, final short min, final short max, @@ -52,55 +52,55 @@ public final class ShortComponent extends CommandCompon /** * Create a new builder * - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @return Created builder */ @Nonnull - public static ShortComponent.Builder newBuilder(@Nonnull final String name) { + public static ShortArgument.Builder newBuilder(@Nonnull final String name) { return new Builder<>(name); } /** - * Create a new required command component + * Create a new required command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent required(@Nonnull final String name) { - return ShortComponent.newBuilder(name).asRequired().build(); + public static CommandArgument required(@Nonnull final String name) { + return ShortArgument.newBuilder(name).asRequired().build(); } /** - * Create a new optional command component + * Create a new optional command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name) { - return ShortComponent.newBuilder(name).asOptional().build(); + public static CommandArgument optional(@Nonnull final String name) { + return ShortArgument.newBuilder(name).asOptional().build(); } /** - * Create a new required command component with a default value + * Create a new required command argument with a default value * - * @param name Component name + * @param name Argument name * @param defaultNum Default num * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name, + public static CommandArgument optional(@Nonnull final String name, final short defaultNum) { - return ShortComponent.newBuilder(name).asOptionalWithDefault(Short.toString(defaultNum)).build(); + return ShortArgument.newBuilder(name).asOptionalWithDefault(Short.toString(defaultNum)).build(); } - public static final class Builder extends CommandComponent.Builder { + public static final class Builder extends CommandArgument.Builder { private short min = Short.MIN_VALUE; private short max = Short.MAX_VALUE; @@ -134,14 +134,14 @@ public final class ShortComponent extends CommandCompon } /** - * Builder a new short component + * Builder a new short argument * - * @return Constructed component + * @return Constructed argument */ @Nonnull @Override - public ShortComponent build() { - return new ShortComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); + public ShortArgument build() { + return new ShortArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue()); } } @@ -166,7 +166,7 @@ public final class ShortComponent extends CommandCompon } - public static final class ShortParser implements ComponentParser { + public static final class ShortParser implements ArgumentParser { private final short min; private final short max; @@ -184,22 +184,22 @@ public final class ShortComponent extends CommandCompon @Nonnull @Override - public ComponentParseResult parse( + public ArgumentParseResult parse( @Nonnull final CommandContext commandContext, @Nonnull final Queue inputQueue) { final String input = inputQueue.peek(); if (input == null) { - return ComponentParseResult.failure(new NullPointerException("No input was provided")); + return ArgumentParseResult.failure(new NullPointerException("No input was provided")); } try { final short value = Short.parseShort(input); if (value < this.min || value > this.max) { - return ComponentParseResult.failure(new ShortParseException(input, this.min, this.max)); + return ArgumentParseResult.failure(new ShortParseException(input, this.min, this.max)); } inputQueue.remove(); - return ComponentParseResult.success(value); + return ArgumentParseResult.success(value); } catch (final Exception e) { - return ComponentParseResult.failure(new ShortParseException(input, this.min, this.max)); + return ArgumentParseResult.failure(new ShortParseException(input, this.min, this.max)); } } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/StringComponent.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/StringArgument.java similarity index 72% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/standard/StringComponent.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/StringArgument.java index 5f0ff98f..7f18d73c 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/StringComponent.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/StringArgument.java @@ -21,11 +21,11 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // -package com.intellectualsites.commands.components.standard; +package com.intellectualsites.commands.arguments.standard; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.sender.CommandSender; @@ -37,15 +37,15 @@ import java.util.StringJoiner; import java.util.function.BiFunction; @SuppressWarnings("unused") -public final class StringComponent extends CommandComponent { +public final class StringArgument extends CommandArgument { private final StringMode stringMode; - private StringComponent(final boolean required, - @Nonnull final String name, - @Nonnull final StringMode stringMode, - @Nonnull final String defaultValue, - @Nonnull final BiFunction, String, List> suggestionsProvider) { + private StringArgument(final boolean required, + @Nonnull final String name, + @Nonnull final StringMode stringMode, + @Nonnull final String defaultValue, + @Nonnull final BiFunction, String, List> suggestionsProvider) { super(required, name, new StringParser<>(stringMode, suggestionsProvider), defaultValue, String.class); this.stringMode = stringMode; } @@ -53,51 +53,51 @@ public final class StringComponent extends CommandCompo /** * Create a new builder * - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @return Created builder */ @Nonnull - public static StringComponent.Builder newBuilder(@Nonnull final String name) { - return new StringComponent.Builder<>(name); + public static StringArgument.Builder newBuilder(@Nonnull final String name) { + return new StringArgument.Builder<>(name); } /** - * Create a new required command component + * Create a new required command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent required(@Nonnull final String name) { - return StringComponent.newBuilder(name).asRequired().build(); + public static CommandArgument required(@Nonnull final String name) { + return StringArgument.newBuilder(name).asRequired().build(); } /** - * Create a new optional command component + * Create a new optional command argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name) { - return StringComponent.newBuilder(name).asOptional().build(); + public static CommandArgument optional(@Nonnull final String name) { + return StringArgument.newBuilder(name).asOptional().build(); } /** - * Create a new required command component with a default value + * Create a new required command argument with a default value * - * @param name Component name + * @param name Argument name * @param defaultNum Default num * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name, - final String defaultNum) { - return StringComponent.newBuilder(name).asOptionalWithDefault(defaultNum).build(); + public static CommandArgument optional(@Nonnull final String name, + final String defaultNum) { + return StringArgument.newBuilder(name).asOptionalWithDefault(defaultNum).build(); } /** @@ -118,7 +118,7 @@ public final class StringComponent extends CommandCompo } - public static final class Builder extends CommandComponent.Builder { + public static final class Builder extends CommandArgument.Builder { private StringMode stringMode = StringMode.SINGLE; private BiFunction, String, List> suggestionsProvider = (v1, v2) -> Collections.emptyList(); @@ -174,21 +174,21 @@ public final class StringComponent extends CommandCompo } /** - * Builder a new string component + * Builder a new string argument * - * @return Constructed component + * @return Constructed argument */ @Nonnull @Override - public StringComponent build() { - return new StringComponent<>(this.isRequired(), this.getName(), this.stringMode, - this.getDefaultValue(), this.suggestionsProvider); + public StringArgument build() { + return new StringArgument<>(this.isRequired(), this.getName(), this.stringMode, + this.getDefaultValue(), this.suggestionsProvider); } } - public static final class StringParser implements ComponentParser { + public static final class StringParser implements ArgumentParser { private final StringMode stringMode; private final BiFunction, String, List> suggestionsProvider; @@ -207,16 +207,16 @@ public final class StringComponent extends CommandCompo @Nonnull @Override - public ComponentParseResult parse(@Nonnull final CommandContext commandContext, - @Nonnull final Queue inputQueue) { + public ArgumentParseResult parse(@Nonnull final CommandContext commandContext, + @Nonnull final Queue inputQueue) { final String input = inputQueue.peek(); if (input == null) { - return ComponentParseResult.failure(new NullPointerException("No input was provided")); + return ArgumentParseResult.failure(new NullPointerException("No input was provided")); } if (this.stringMode == StringMode.SINGLE) { inputQueue.remove(); - return ComponentParseResult.success(input); + return ArgumentParseResult.success(input); } final StringJoiner sj = new StringJoiner(" "); @@ -239,7 +239,7 @@ public final class StringComponent extends CommandCompo sj.add(string.substring(1)); started = true; } else { - return ComponentParseResult.failure(new StringParseException(string, StringMode.QUOTED)); + return ArgumentParseResult.failure(new StringParseException(string, StringMode.QUOTED)); } } else if (string.endsWith("\"")) { sj.add(string.substring(0, string.length() - 1)); @@ -253,10 +253,10 @@ public final class StringComponent extends CommandCompo } if (this.stringMode == StringMode.QUOTED && (!started || !finished)) { - return ComponentParseResult.failure(new StringParseException(sj.toString(), StringMode.GREEDY)); + return ArgumentParseResult.failure(new StringParseException(sj.toString(), StringMode.GREEDY)); } - return ComponentParseResult.success(sj.toString()); + return ArgumentParseResult.success(sj.toString()); } @Nonnull diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/package-info.java b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/package-info.java similarity index 92% rename from cloud-core/src/main/java/com/intellectualsites/commands/components/standard/package-info.java rename to cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/package-info.java index fa493350..c703eacd 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/components/standard/package-info.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/arguments/standard/package-info.java @@ -23,6 +23,6 @@ // /** - * Standard command component types + * Standard command argument types */ -package com.intellectualsites.commands.components.standard; +package com.intellectualsites.commands.arguments.standard; diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/AmbiguousNodeException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/AmbiguousNodeException.java index 30a1f2b5..988f9a68 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/AmbiguousNodeException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/AmbiguousNodeException.java @@ -23,7 +23,7 @@ // package com.intellectualsites.commands.exceptions; -import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.arguments.CommandArgument; import javax.annotation.Nonnull; import javax.annotation.Nullable; @@ -38,9 +38,9 @@ import java.util.List; @SuppressWarnings("unused") public final class AmbiguousNodeException extends IllegalStateException { - private final CommandComponent parentNode; - private final CommandComponent ambiguousNode; - private final List> children; + private final CommandArgument parentNode; + private final CommandArgument ambiguousNode; + private final List> children; /** * Construct a new ambiguous node exception @@ -49,9 +49,9 @@ public final class AmbiguousNodeException extends IllegalStateException { * @param ambiguousNode Node that caused exception * @param children All children of the parent */ - public AmbiguousNodeException(@Nullable final CommandComponent parentNode, - @Nonnull final CommandComponent ambiguousNode, - @Nonnull final List> children) { + public AmbiguousNodeException(@Nullable final CommandArgument parentNode, + @Nonnull final CommandArgument ambiguousNode, + @Nonnull final List> children) { this.parentNode = parentNode; this.ambiguousNode = ambiguousNode; this.children = children; @@ -63,7 +63,7 @@ public final class AmbiguousNodeException extends IllegalStateException { * @return Parent node */ @Nullable - public CommandComponent getParentNode() { + public CommandArgument getParentNode() { return this.parentNode; } @@ -73,7 +73,7 @@ public final class AmbiguousNodeException extends IllegalStateException { * @return Ambiguous node */ @Nonnull - public CommandComponent getAmbiguousNode() { + public CommandArgument getAmbiguousNode() { return this.ambiguousNode; } @@ -83,7 +83,7 @@ public final class AmbiguousNodeException extends IllegalStateException { * @return Child nodes */ @Nonnull - public List> getChildren() { + public List> getChildren() { return this.children; } @@ -94,7 +94,7 @@ public final class AmbiguousNodeException extends IllegalStateException { .append(" cannot be added as a child to ") .append(parentNode == null ? "" : parentNode.getName()) .append(" (All children: "); - final Iterator> childIterator = this.children.iterator(); + final Iterator> childIterator = this.children.iterator(); while (childIterator.hasNext()) { stringBuilder.append(childIterator.next().getName()); if (childIterator.hasNext()) { diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ArgumentParseException.java similarity index 82% rename from cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java rename to cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ArgumentParseException.java index 418f8436..dcee2c7b 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ComponentParseException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/ArgumentParseException.java @@ -23,13 +23,13 @@ // package com.intellectualsites.commands.exceptions; -import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.arguments.CommandArgument; import com.intellectualsites.commands.sender.CommandSender; import javax.annotation.Nonnull; import java.util.List; -public class ComponentParseException extends CommandParseException { +public class ArgumentParseException extends CommandParseException { private final Throwable cause; @@ -40,9 +40,9 @@ public class ComponentParseException extends CommandParseException { * @param commandSender Command sender * @param currentChain Chain leading up to the exception */ - public ComponentParseException(@Nonnull final Throwable throwable, - @Nonnull final CommandSender commandSender, - @Nonnull final List> currentChain) { + public ArgumentParseException(@Nonnull final Throwable throwable, + @Nonnull final CommandSender commandSender, + @Nonnull final List> currentChain) { super(commandSender, currentChain); this.cause = throwable; } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/CommandParseException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/CommandParseException.java index f48341b8..d6a0561c 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/CommandParseException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/CommandParseException.java @@ -23,7 +23,7 @@ // package com.intellectualsites.commands.exceptions; -import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.arguments.CommandArgument; import com.intellectualsites.commands.sender.CommandSender; import javax.annotation.Nonnull; @@ -37,7 +37,7 @@ import java.util.List; public class CommandParseException extends IllegalArgumentException { private final CommandSender commandSender; - private final List> currentChain; + private final List> currentChain; /** * Construct a new command parse exception @@ -46,7 +46,7 @@ public class CommandParseException extends IllegalArgumentException { * @param currentChain Chain leading up to the exception */ protected CommandParseException(@Nonnull final CommandSender commandSender, - @Nonnull final List> currentChain) { + @Nonnull final List> currentChain) { this.commandSender = commandSender; this.currentChain = currentChain; } @@ -64,10 +64,10 @@ public class CommandParseException extends IllegalArgumentException { /** * Get the command chain leading up to the exception * - * @return Unmodifiable list of command components + * @return Unmodifiable list of command arguments */ @Nonnull - public List> getCurrentChain() { + public List> getCurrentChain() { return Collections.unmodifiableList(this.currentChain); } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidCommandSenderException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidCommandSenderException.java index 971f56dc..fb8c9a53 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidCommandSenderException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidCommandSenderException.java @@ -23,7 +23,7 @@ // package com.intellectualsites.commands.exceptions; -import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.arguments.CommandArgument; import com.intellectualsites.commands.sender.CommandSender; import javax.annotation.Nonnull; @@ -45,7 +45,7 @@ public final class InvalidCommandSenderException extends CommandParseException { */ public InvalidCommandSenderException(@Nonnull final CommandSender commandSender, @Nonnull final Class requiredSender, - @Nonnull final List> currentChain) { + @Nonnull final List> currentChain) { super(commandSender, currentChain); this.requiredSender = requiredSender; } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java index c9e79c79..d6065162 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/InvalidSyntaxException.java @@ -23,7 +23,7 @@ // package com.intellectualsites.commands.exceptions; -import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.arguments.CommandArgument; import com.intellectualsites.commands.sender.CommandSender; import javax.annotation.Nonnull; @@ -46,7 +46,7 @@ public class InvalidSyntaxException extends CommandParseException { */ public InvalidSyntaxException(@Nonnull final String correctSyntax, @Nonnull final CommandSender commandSender, - @Nonnull final List> currentChain) { + @Nonnull final List> currentChain) { super(commandSender, currentChain); this.correctSyntax = correctSyntax; } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoCommandInLeafException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoCommandInLeafException.java index e72cb5f5..c4a08e33 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoCommandInLeafException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoCommandInLeafException.java @@ -23,37 +23,37 @@ // package com.intellectualsites.commands.exceptions; -import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.arguments.CommandArgument; import javax.annotation.Nonnull; /** - * Thrown when a {@link com.intellectualsites.commands.components.CommandComponent} + * Thrown when a {@link CommandArgument} * that is registered as a leaf node, does not contain an owning {@link com.intellectualsites.commands.Command} */ @SuppressWarnings("unused") public final class NoCommandInLeafException extends IllegalStateException { - private final CommandComponent commandComponent; + private final CommandArgument commandArgument; /** * Create a new no command in leaf exception instance * - * @param commandComponent Command component that caused the exception + * @param commandArgument Command argument that caused the exception */ - public NoCommandInLeafException(@Nonnull final CommandComponent commandComponent) { - super(String.format("Leaf node '%s' does not have associated owning command", commandComponent.getName())); - this.commandComponent = commandComponent; + public NoCommandInLeafException(@Nonnull final CommandArgument commandArgument) { + super(String.format("Leaf node '%s' does not have associated owning command", commandArgument.getName())); + this.commandArgument = commandArgument; } /** - * Get the command component + * Get the command argument * - * @return Command component + * @return Command argument */ @Nonnull - public CommandComponent getCommandComponent() { - return this.commandComponent; + public CommandArgument getCommandArgument() { + return this.commandArgument; } } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java index 87fff804..a1146d1b 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoPermissionException.java @@ -23,7 +23,7 @@ // package com.intellectualsites.commands.exceptions; -import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.arguments.CommandArgument; import com.intellectualsites.commands.sender.CommandSender; import javax.annotation.Nonnull; @@ -47,7 +47,7 @@ public class NoPermissionException extends CommandParseException { */ public NoPermissionException(@Nonnull final String missingPermission, @Nonnull final CommandSender commandSender, - @Nonnull final List> currentChain) { + @Nonnull final List> currentChain) { super(commandSender, currentChain); this.missingPermission = missingPermission; } diff --git a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoSuchCommandException.java b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoSuchCommandException.java index 0765a4ff..39d760a7 100644 --- a/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoSuchCommandException.java +++ b/cloud-core/src/main/java/com/intellectualsites/commands/exceptions/NoSuchCommandException.java @@ -23,7 +23,7 @@ // package com.intellectualsites.commands.exceptions; -import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.arguments.CommandArgument; import com.intellectualsites.commands.sender.CommandSender; import javax.annotation.Nonnull; @@ -46,7 +46,7 @@ public final class NoSuchCommandException extends CommandParseException { * @param command Entered command (following the command chain) */ public NoSuchCommandException(@Nonnull final CommandSender commandSender, - @Nonnull final List> currentChain, + @Nonnull final List> currentChain, @Nonnull final String command) { super(commandSender, currentChain); this.suppliedCommand = command; @@ -56,11 +56,11 @@ public final class NoSuchCommandException extends CommandParseException { @Override public String getMessage() { final StringBuilder builder = new StringBuilder(); - for (final CommandComponent commandComponent : this.getCurrentChain()) { - if (commandComponent == null) { + for (final CommandArgument commandArgument : this.getCurrentChain()) { + if (commandArgument == null) { continue; } - builder.append(" ").append(commandComponent.getName()); + builder.append(" ").append(commandArgument.getName()); } return String.format("Unrecognized command input '%s' following chain%s", this.suppliedCommand, builder.toString()); } diff --git a/cloud-core/src/test/java/com/intellectualsites/commands/CommandPreProcessorTest.java b/cloud-core/src/test/java/com/intellectualsites/commands/CommandPreProcessorTest.java index 1cefefe8..762a83ca 100644 --- a/cloud-core/src/test/java/com/intellectualsites/commands/CommandPreProcessorTest.java +++ b/cloud-core/src/test/java/com/intellectualsites/commands/CommandPreProcessorTest.java @@ -23,7 +23,7 @@ // package com.intellectualsites.commands; -import com.intellectualsites.commands.components.standard.EnumComponent; +import com.intellectualsites.commands.arguments.standard.EnumArgument; import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext; import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessor; import com.intellectualsites.commands.meta.SimpleCommandMeta; @@ -43,7 +43,7 @@ public class CommandPreProcessorTest { static void newTree() { manager = new TestCommandManager(); manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty()) - .component(EnumComponent.required(SampleEnum.class, "enum")) + .argument(EnumArgument.required(SampleEnum.class, "enum")) .handler( commandContext -> System.out.printf("enum = %s | integer = %d\n", commandContext.get( diff --git a/cloud-core/src/test/java/com/intellectualsites/commands/CommandSuggestionsTest.java b/cloud-core/src/test/java/com/intellectualsites/commands/CommandSuggestionsTest.java index ed664820..e918fb9b 100644 --- a/cloud-core/src/test/java/com/intellectualsites/commands/CommandSuggestionsTest.java +++ b/cloud-core/src/test/java/com/intellectualsites/commands/CommandSuggestionsTest.java @@ -23,9 +23,9 @@ // package com.intellectualsites.commands; -import com.intellectualsites.commands.components.StaticComponent; -import com.intellectualsites.commands.components.standard.EnumComponent; -import com.intellectualsites.commands.components.standard.StringComponent; +import com.intellectualsites.commands.arguments.StaticArgument; +import com.intellectualsites.commands.arguments.standard.EnumArgument; +import com.intellectualsites.commands.arguments.standard.StringArgument; import com.intellectualsites.commands.meta.SimpleCommandMeta; import com.intellectualsites.commands.sender.CommandSender; import org.junit.jupiter.api.Assertions; @@ -43,14 +43,14 @@ public class CommandSuggestionsTest { @BeforeAll static void setupManager() { manager = new TestCommandManager(); - manager.command(manager.commandBuilder("test").component(StaticComponent.required("one")).build()); - manager.command(manager.commandBuilder("test").component(StaticComponent.required("two")).build()); + manager.command(manager.commandBuilder("test").argument(StaticArgument.required("one")).build()); + manager.command(manager.commandBuilder("test").argument(StaticArgument.required("two")).build()); manager.command(manager.commandBuilder("test") - .component(StaticComponent.required("var")) - .component(StringComponent.newBuilder("str") - .withSuggestionsProvider((c, s) -> Arrays.asList("one", "two")) - .build()) - .component(EnumComponent.required(TestEnum.class, "enum")) + .argument(StaticArgument.required("var")) + .argument(StringArgument.newBuilder("str") + .withSuggestionsProvider((c, s) -> Arrays.asList("one", "two")) + .build()) + .argument(EnumArgument.required(TestEnum.class, "enum")) .build()); } diff --git a/cloud-core/src/test/java/com/intellectualsites/commands/CommandTest.java b/cloud-core/src/test/java/com/intellectualsites/commands/CommandTest.java index b4d42569..3487fe52 100644 --- a/cloud-core/src/test/java/com/intellectualsites/commands/CommandTest.java +++ b/cloud-core/src/test/java/com/intellectualsites/commands/CommandTest.java @@ -23,7 +23,7 @@ // package com.intellectualsites.commands; -import com.intellectualsites.commands.components.StaticComponent; +import com.intellectualsites.commands.arguments.StaticArgument; import com.intellectualsites.commands.meta.SimpleCommandMeta; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -31,15 +31,15 @@ import org.junit.jupiter.api.Test; class CommandTest { @Test() - void noComponents() { - Assertions.assertEquals(1, Command.newBuilder("test", SimpleCommandMeta.empty()).build().getComponents().size()); + void noArguments() { + Assertions.assertEquals(1, Command.newBuilder("test", SimpleCommandMeta.empty()).build().getArguments().size()); } @Test void ensureOrdering() { Assertions.assertThrows(IllegalArgumentException.class, () -> - Command.newBuilder("test", SimpleCommandMeta.empty()).component(StaticComponent.optional("something")) - .component(StaticComponent.required("somethingelse")).build()); + Command.newBuilder("test", SimpleCommandMeta.empty()).argument(StaticArgument.optional("something")) + .argument(StaticArgument.required("somethingelse")).build()); } } diff --git a/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java b/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java index e51b8a3a..c4e1d1f3 100644 --- a/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java +++ b/cloud-core/src/test/java/com/intellectualsites/commands/CommandTreeTest.java @@ -23,8 +23,8 @@ // package com.intellectualsites.commands; -import com.intellectualsites.commands.components.StaticComponent; -import com.intellectualsites.commands.components.standard.IntegerComponent; +import com.intellectualsites.commands.arguments.StaticArgument; +import com.intellectualsites.commands.arguments.standard.IntegerArgument; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.exceptions.NoPermissionException; import com.intellectualsites.commands.meta.SimpleCommandMeta; @@ -48,13 +48,13 @@ class CommandTreeTest { static void newTree() { manager = new TestCommandManager(); manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty()) - .component(StaticComponent.required("one")).build()) + .argument(StaticArgument.required("one")).build()) .command(manager.commandBuilder("test", SimpleCommandMeta.empty()) - .component(StaticComponent.required("two")).withPermission("no").build()) + .argument(StaticArgument.required("two")).withPermission("no").build()) .command(manager.commandBuilder("test", Collections.singleton("other"), SimpleCommandMeta.empty()) - .component(StaticComponent.required("opt", "öpt")) - .component(IntegerComponent + .argument(StaticArgument.required("opt", "öpt")) + .argument(IntegerArgument .optional("num", EXPECTED_INPUT_NUMBER)) .build()) .command(manager.commandBuilder("req").withSenderType(SpecificCommandSender.class).build()); @@ -106,7 +106,7 @@ class CommandTreeTest { void testDefaultParser() { manager.command( manager.commandBuilder("default") - .component(manager.componentBuilder(Integer.class, "int").build()) + .argument(manager.argumentBuilder(Integer.class, "int").build()) .handler(context -> { final int number = context.getRequired("int"); System.out.printf("Supplied number is: %d\n", number); diff --git a/cloud-core/src/test/java/com/intellectualsites/commands/ParserRegistryTest.java b/cloud-core/src/test/java/com/intellectualsites/commands/ParserRegistryTest.java index f85cc481..0af0ae4a 100644 --- a/cloud-core/src/test/java/com/intellectualsites/commands/ParserRegistryTest.java +++ b/cloud-core/src/test/java/com/intellectualsites/commands/ParserRegistryTest.java @@ -25,12 +25,12 @@ package com.intellectualsites.commands; import com.google.common.reflect.TypeToken; import com.intellectualsites.commands.annotations.specifier.Range; -import com.intellectualsites.commands.components.parser.ComponentParser; -import com.intellectualsites.commands.components.parser.ParserParameters; -import com.intellectualsites.commands.components.parser.ParserRegistry; -import com.intellectualsites.commands.components.parser.StandardParameters; -import com.intellectualsites.commands.components.parser.StandardParserRegistry; -import com.intellectualsites.commands.components.standard.IntegerComponent; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; +import com.intellectualsites.commands.arguments.parser.ParserParameters; +import com.intellectualsites.commands.arguments.parser.ParserRegistry; +import com.intellectualsites.commands.arguments.parser.StandardParameters; +import com.intellectualsites.commands.arguments.parser.StandardParserRegistry; +import com.intellectualsites.commands.arguments.standard.IntegerArgument; import com.intellectualsites.commands.sender.CommandSender; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -72,13 +72,13 @@ public class ParserRegistryTest { final ParserParameters parserParameters = parserRegistry.parseAnnotations(parsedType, Collections.singleton(range)); Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MIN)); Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MAX)); - final ComponentParser parser = parserRegistry.createParser(parsedType, - parserParameters) - .orElseThrow( + final ArgumentParser parser = parserRegistry.createParser(parsedType, + parserParameters) + .orElseThrow( () -> new NullPointerException("No parser found")); - Assertions.assertTrue(parser instanceof IntegerComponent.IntegerParser); + Assertions.assertTrue(parser instanceof IntegerArgument.IntegerParser); @SuppressWarnings("unchecked") - final IntegerComponent.IntegerParser integerParser = (IntegerComponent.IntegerParser) parser; + final IntegerArgument.IntegerParser integerParser = (IntegerArgument.IntegerParser) parser; Assertions.assertEquals(RANGE_MIN, integerParser.getMin()); Assertions.assertEquals(RANGE_MAX, integerParser.getMax()); } diff --git a/cloud-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandManager.java b/cloud-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandManager.java index eb151305..540cff3a 100644 --- a/cloud-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandManager.java +++ b/cloud-jline/src/main/java/com/intellectualsites/commands/jline/JLineCommandManager.java @@ -25,8 +25,8 @@ package com.intellectualsites.commands.jline; import com.intellectualsites.commands.CommandManager; import com.intellectualsites.commands.CommandTree; -import com.intellectualsites.commands.components.StaticComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; +import com.intellectualsites.commands.arguments.StaticArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; import com.intellectualsites.commands.exceptions.InvalidSyntaxException; import com.intellectualsites.commands.exceptions.NoSuchCommandException; import com.intellectualsites.commands.execution.CommandExecutionCoordinator; @@ -81,7 +81,7 @@ public class JLineCommandManager extends CommandManager + .argument(String.class, "string", builder -> builder.asRequired() .withParser(((commandContext, inputQueue) -> { final StringBuilder stringBuilder = @@ -92,7 +92,7 @@ public class JLineCommandManager extends CommandManager commandContext.get("string") @@ -100,11 +100,11 @@ public class JLineCommandManager extends CommandManager System.out.println("Test (1)")) .build()) .command(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty()) - .component(StaticComponent.required("two")) + .argument(StaticArgument.required("two")) .handler(commandContext -> System.out.println("Test (2)")) .build()); System.out.println("Ready..."); diff --git a/cloud-minecraft/cloud-brigadier/src/main/java/com/intellectualsites/commands/brigadier/CloudBrigadierManager.java b/cloud-minecraft/cloud-brigadier/src/main/java/com/intellectualsites/commands/brigadier/CloudBrigadierManager.java index f3c4e451..d98ce834 100644 --- a/cloud-minecraft/cloud-brigadier/src/main/java/com/intellectualsites/commands/brigadier/CloudBrigadierManager.java +++ b/cloud-minecraft/cloud-brigadier/src/main/java/com/intellectualsites/commands/brigadier/CloudBrigadierManager.java @@ -27,15 +27,15 @@ import com.google.common.collect.Maps; import com.google.common.reflect.TypeToken; import com.intellectualsites.commands.CommandManager; import com.intellectualsites.commands.CommandTree; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.StaticComponent; -import com.intellectualsites.commands.components.standard.BooleanComponent; -import com.intellectualsites.commands.components.standard.ByteComponent; -import com.intellectualsites.commands.components.standard.DoubleComponent; -import com.intellectualsites.commands.components.standard.FloatComponent; -import com.intellectualsites.commands.components.standard.IntegerComponent; -import com.intellectualsites.commands.components.standard.ShortComponent; -import com.intellectualsites.commands.components.standard.StringComponent; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.StaticArgument; +import com.intellectualsites.commands.arguments.standard.BooleanArgument; +import com.intellectualsites.commands.arguments.standard.ByteArgument; +import com.intellectualsites.commands.arguments.standard.DoubleArgument; +import com.intellectualsites.commands.arguments.standard.FloatArgument; +import com.intellectualsites.commands.arguments.standard.IntegerArgument; +import com.intellectualsites.commands.arguments.standard.ShortArgument; +import com.intellectualsites.commands.arguments.standard.StringArgument; import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext; import com.intellectualsites.commands.sender.CommandSender; import com.mojang.brigadier.LiteralMessage; @@ -77,7 +77,7 @@ import java.util.function.Supplier; */ public final class CloudBrigadierManager { - private final Map, Function, + private final Map, Function, ? extends ArgumentType>> mappers; private final Map, Supplier>> defaultArgumentTypeSuppliers; private final Supplier> dummyContextProvider; @@ -101,75 +101,75 @@ public final class CloudBrigadierManager { private void registerInternalMappings() { /* Map byte, short and int to IntegerArgumentType */ - this.registerMapping(new TypeToken>() { - }, component -> { - final boolean hasMin = component.getMin() != Byte.MIN_VALUE; - final boolean hasMax = component.getMax() != Byte.MAX_VALUE; + this.registerMapping(new TypeToken>() { + }, argument -> { + final boolean hasMin = argument.getMin() != Byte.MIN_VALUE; + final boolean hasMax = argument.getMax() != Byte.MAX_VALUE; if (hasMin) { - return IntegerArgumentType.integer(component.getMin(), component.getMax()); + return IntegerArgumentType.integer(argument.getMin(), argument.getMax()); } else if (hasMax) { - return IntegerArgumentType.integer(Byte.MIN_VALUE, component.getMax()); + return IntegerArgumentType.integer(Byte.MIN_VALUE, argument.getMax()); } else { return IntegerArgumentType.integer(); } }); - this.registerMapping(new TypeToken>() { - }, component -> { - final boolean hasMin = component.getMin() != Short.MIN_VALUE; - final boolean hasMax = component.getMax() != Short.MAX_VALUE; + this.registerMapping(new TypeToken>() { + }, argument -> { + final boolean hasMin = argument.getMin() != Short.MIN_VALUE; + final boolean hasMax = argument.getMax() != Short.MAX_VALUE; if (hasMin) { - return IntegerArgumentType.integer(component.getMin(), component.getMax()); + return IntegerArgumentType.integer(argument.getMin(), argument.getMax()); } else if (hasMax) { - return IntegerArgumentType.integer(Short.MIN_VALUE, component.getMax()); + return IntegerArgumentType.integer(Short.MIN_VALUE, argument.getMax()); } else { return IntegerArgumentType.integer(); } }); - this.registerMapping(new TypeToken>() { - }, component -> { - final boolean hasMin = component.getMin() != Integer.MIN_VALUE; - final boolean hasMax = component.getMax() != Integer.MAX_VALUE; + this.registerMapping(new TypeToken>() { + }, argument -> { + final boolean hasMin = argument.getMin() != Integer.MIN_VALUE; + final boolean hasMax = argument.getMax() != Integer.MAX_VALUE; if (hasMin) { - return IntegerArgumentType.integer(component.getMin(), component.getMax()); + return IntegerArgumentType.integer(argument.getMin(), argument.getMax()); } else if (hasMax) { - return IntegerArgumentType.integer(Integer.MIN_VALUE, component.getMax()); + return IntegerArgumentType.integer(Integer.MIN_VALUE, argument.getMax()); } else { return IntegerArgumentType.integer(); } }); /* Map float to FloatArgumentType */ - this.registerMapping(new TypeToken>() { - }, component -> { - final boolean hasMin = component.getMin() != Float.MIN_VALUE; - final boolean hasMax = component.getMax() != Float.MAX_VALUE; + this.registerMapping(new TypeToken>() { + }, argument -> { + final boolean hasMin = argument.getMin() != Float.MIN_VALUE; + final boolean hasMax = argument.getMax() != Float.MAX_VALUE; if (hasMin) { - return FloatArgumentType.floatArg(component.getMin(), component.getMax()); + return FloatArgumentType.floatArg(argument.getMin(), argument.getMax()); } else if (hasMax) { - return FloatArgumentType.floatArg(Float.MIN_VALUE, component.getMax()); + return FloatArgumentType.floatArg(Float.MIN_VALUE, argument.getMax()); } else { return FloatArgumentType.floatArg(); } }); /* Map double to DoubleArgumentType */ - this.registerMapping(new TypeToken>() { - }, component -> { - final boolean hasMin = component.getMin() != Double.MIN_VALUE; - final boolean hasMax = component.getMax() != Double.MAX_VALUE; + this.registerMapping(new TypeToken>() { + }, argument -> { + final boolean hasMin = argument.getMin() != Double.MIN_VALUE; + final boolean hasMax = argument.getMax() != Double.MAX_VALUE; if (hasMin) { - return DoubleArgumentType.doubleArg(component.getMin(), component.getMax()); + return DoubleArgumentType.doubleArg(argument.getMin(), argument.getMax()); } else if (hasMax) { - return DoubleArgumentType.doubleArg(Double.MIN_VALUE, component.getMax()); + return DoubleArgumentType.doubleArg(Double.MIN_VALUE, argument.getMax()); } else { return DoubleArgumentType.doubleArg(); } }); /* Map boolean to BoolArgumentType */ - this.registerMapping(new TypeToken>() { - }, component -> BoolArgumentType.bool()); + this.registerMapping(new TypeToken>() { + }, argument -> BoolArgumentType.bool()); /* Map String properly to StringArgumentType */ - this.registerMapping(new TypeToken>() { - }, component -> { - switch (component.getStringMode()) { + this.registerMapping(new TypeToken>() { + }, argument -> { + switch (argument.getStringMode()) { case QUOTED: return StringArgumentType.string(); case GREEDY: @@ -183,16 +183,16 @@ public final class CloudBrigadierManager { /** * Register a cloud-Brigadier mapping * - * @param componentType cloud component type + * @param argumentType cloud argument type * @param mapper mapper function - * @param cloud component value type - * @param cloud component type + * @param cloud argument value type + * @param cloud argument type * @param Brigadier argument type value */ - public , O> void registerMapping(@Nonnull final TypeToken componentType, - @Nonnull final Function, O> void registerMapping(@Nonnull final TypeToken argumentType, + @Nonnull final Function> mapper) { - this.mappers.put(componentType.getRawType(), mapper); + this.mappers.put(argumentType.getRawType(), mapper); } /** @@ -207,36 +207,36 @@ public final class CloudBrigadierManager { } /** - * Get a Brigadier {@link ArgumentType} from a cloud {@link CommandComponent} + * Get a Brigadier {@link ArgumentType} from a cloud {@link CommandArgument} * - * @param componentType cloud component type - * @param component cloud component - * @param cloud component value type (generic) - * @param cloud component type (generic) + * @param argumentType cloud argument type + * @param argument cloud argument + * @param cloud argument value type (generic) + * @param cloud argument type (generic) * @return Brigadier argument type */ @Nullable @SuppressWarnings("all") - private > Pair, Boolean> getArgument( - @Nonnull final TypeToken componentType, - @Nonnull final K component) { - final CommandComponent commandComponent = (CommandComponent) component; - Function function = this.mappers.get(componentType.getRawType()); + private > Pair, Boolean> getArgument( + @Nonnull final TypeToken argumentType, + @Nonnull final K argument) { + final CommandArgument commandArgument = (CommandArgument) argument; + Function function = this.mappers.get(argumentType.getRawType()); if (function == null) { - return this.createDefaultMapper(commandComponent); + return this.createDefaultMapper(commandArgument); } - return new Pair<>((ArgumentType) function.apply(commandComponent), !component.getValueType().equals(String.class)); + return new Pair<>((ArgumentType) function.apply(commandArgument), !argument.getValueType().equals(String.class)); } @Nonnull - private > Pair, Boolean> createDefaultMapper( - @Nonnull final CommandComponent - component) { - final Supplier> argumentTypeSupplier = this.defaultArgumentTypeSuppliers.get(component.getValueType()); + private > Pair, Boolean> createDefaultMapper( + @Nonnull final CommandArgument + argument) { + final Supplier> argumentTypeSupplier = this.defaultArgumentTypeSuppliers.get(argument.getValueType()); if (argumentTypeSupplier != null) { return new Pair<>(argumentTypeSupplier.get(), true); } - System.err.printf("Found not native mapping for '%s'\n", component.getValueType().getCanonicalName()); + System.err.printf("Found not native mapping for '%s'\n", argument.getValueType().getCanonicalName()); return new Pair<>(StringArgumentType.string(), false); } @@ -251,7 +251,7 @@ public final class CloudBrigadierManager { * @return Constructed literal command node */ @Nonnull - public LiteralCommandNode createLiteralCommandNode(@Nonnull final CommandTree.Node> cloudCommand, + public LiteralCommandNode createLiteralCommandNode(@Nonnull final CommandTree.Node> cloudCommand, @Nonnull final LiteralCommandNode root, @Nonnull final SuggestionProvider suggestionProvider, @Nonnull final com.mojang.brigadier.Command executor, @@ -262,19 +262,19 @@ public final class CloudBrigadierManager { literalArgumentBuilder.executes(executor); } final LiteralCommandNode constructedRoot = literalArgumentBuilder.build(); - for (final CommandTree.Node> child : cloudCommand.getChildren()) { + for (final CommandTree.Node> child : cloudCommand.getChildren()) { constructedRoot.addChild(this.constructCommandNode(child, permissionChecker, executor, suggestionProvider).build()); } return constructedRoot; } - private ArgumentBuilder constructCommandNode(@Nonnull final CommandTree.Node> root, + private ArgumentBuilder constructCommandNode(@Nonnull final CommandTree.Node> root, @Nonnull final BiPredicate permissionChecker, @Nonnull final com.mojang.brigadier.Command executor, @Nonnull final SuggestionProvider suggestionProvider) { ArgumentBuilder argumentBuilder; - if (root.getValue() instanceof StaticComponent) { + if (root.getValue() instanceof StaticArgument) { argumentBuilder = LiteralArgumentBuilder.literal(root.getValue().getName()) .requires(sender -> permissionChecker.test(sender, root.getNodeMeta().getOrDefault("permission", ""))) .executes(executor); @@ -290,14 +290,14 @@ public final class CloudBrigadierManager { if (root.isLeaf() || !root.getValue().isRequired()) { argumentBuilder.executes(executor); } - for (final CommandTree.Node> node : root.getChildren()) { + for (final CommandTree.Node> node : root.getChildren()) { argumentBuilder.then(constructCommandNode(node, permissionChecker, executor, suggestionProvider)); } return argumentBuilder; } @Nonnull - private CompletableFuture buildSuggestions(@Nonnull final CommandComponent component, + private CompletableFuture buildSuggestions(@Nonnull final CommandArgument argument, @Nonnull final CommandContext s, @Nonnull final SuggestionsBuilder builder) { final com.intellectualsites.commands.context.CommandContext commandContext = this.dummyContextProvider.get(); @@ -314,7 +314,7 @@ public final class CloudBrigadierManager { command = command.substring(1); } final List suggestions = this.commandManager.suggest(commandContext.getSender(), command); - /*component.getParser().suggestions(commandContext, builder.getInput());*/ + /*argument.getParser().suggestions(commandContext, builder.getInput());*/ for (final String suggestion : suggestions) { System.out.printf("- %s\n", suggestion); } @@ -327,9 +327,9 @@ public final class CloudBrigadierManager { System.out.printf("- %s\n", suggestion); }*/ for (final String suggestion : suggestions) { - String tooltip = component.getName(); - if (!(component instanceof StaticComponent)) { - if (component.isRequired()) { + String tooltip = argument.getName(); + if (!(argument instanceof StaticArgument)) { + if (argument.isRequired()) { tooltip = '<' + tooltip + '>'; } else { tooltip = '[' + tooltip + ']'; diff --git a/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java b/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java index 6a25e4bf..719eb974 100644 --- a/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java +++ b/cloud-minecraft/cloud-bukkit-test/src/main/java/com/intellectualsites/commands/BukkitTest.java @@ -23,16 +23,16 @@ // package com.intellectualsites.commands; -import com.intellectualsites.commands.components.StaticComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.standard.BooleanComponent; -import com.intellectualsites.commands.components.standard.DoubleComponent; -import com.intellectualsites.commands.components.standard.EnumComponent; -import com.intellectualsites.commands.components.standard.FloatComponent; -import com.intellectualsites.commands.components.standard.IntegerComponent; -import com.intellectualsites.commands.components.standard.StringComponent; +import com.intellectualsites.commands.arguments.StaticArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.standard.BooleanArgument; +import com.intellectualsites.commands.arguments.standard.DoubleArgument; +import com.intellectualsites.commands.arguments.standard.EnumArgument; +import com.intellectualsites.commands.arguments.standard.FloatArgument; +import com.intellectualsites.commands.arguments.standard.IntegerArgument; +import com.intellectualsites.commands.arguments.standard.StringArgument; import com.intellectualsites.commands.execution.CommandExecutionCoordinator; -import com.intellectualsites.commands.parsers.WorldComponent; +import com.intellectualsites.commands.parsers.WorldArgument; import org.bukkit.Bukkit; import org.bukkit.GameMode; import org.bukkit.Material; @@ -65,8 +65,8 @@ public final class BukkitTest extends JavaPlugin { BukkitCommandMetaBuilder.builder() .withDescription("Your ugli") .build()) - .component(EnumComponent.required(GameMode.class, "gamemode")) - .component(StringComponent.newBuilder("player") + .argument(EnumArgument.required(GameMode.class, "gamemode")) + .argument(StringArgument.newBuilder("player") .withSuggestionsProvider((v1, v2) -> { final List suggestions = new ArrayList<>( @@ -84,8 +84,8 @@ public final class BukkitTest extends JavaPlugin { .orElse(GameMode.SURVIVAL))) .build()) .command(mgr.commandBuilder("kenny") - .component(StaticComponent.required("sux")) - .component(IntegerComponent + .argument(StaticArgument.required("sux")) + .argument(IntegerArgument .newBuilder("perc") .withMin(PERC_MIN).withMax(PERC_MAX).build()) .handler(context -> { @@ -96,32 +96,32 @@ public final class BukkitTest extends JavaPlugin { }) .build()) .command(mgr.commandBuilder("test") - .component(StaticComponent.required("one")) + .argument(StaticArgument.required("one")) .handler(c -> c.getSender().sendMessage("One!")) .build()) .command(mgr.commandBuilder("test") - .component(StaticComponent.required("two")) + .argument(StaticArgument.required("two")) .handler(c -> c.getSender().sendMessage("Two!")) .build()) .command(mgr.commandBuilder("uuidtest") - .component(UUID.class, "uuid", builder -> builder + .argument(UUID.class, "uuid", builder -> builder .asRequired() .withParser((c, i) -> { final String string = i.peek(); try { final UUID uuid = UUID.fromString(string); i.remove(); - return ComponentParseResult.success(uuid); + return ArgumentParseResult.success(uuid); } catch (final Exception e) { - return ComponentParseResult.failure(e); + return ArgumentParseResult.failure(e); } }).build()) .handler(c -> c.getSender() .sendMessage(String.format("UUID: %s\n", c.get("uuid").orElse(null)))) .build()) .command(mgr.commandBuilder("give") - .component(EnumComponent.required(Material.class, "material")) - .component(IntegerComponent.required("amount")) + .argument(EnumArgument.required(Material.class, "material")) + .argument(IntegerArgument.required("amount")) .handler(c -> { final Material material = c.getRequired("material"); final int amount = c.getRequired("amount"); @@ -133,7 +133,7 @@ public final class BukkitTest extends JavaPlugin { .command(mgr.commandBuilder("worldtp", BukkitCommandMetaBuilder.builder() .withDescription("Teleport to a world") .build()) - .component(WorldComponent.required("world")) + .argument(WorldArgument.required("world")) .handler(c -> { final World world = c.getRequired("world"); c.getSender().asPlayer().teleport(world.getSpawnLocation()); @@ -141,11 +141,11 @@ public final class BukkitTest extends JavaPlugin { }) .build()) .command(mgr.commandBuilder("brigadier") - .component(FloatComponent.required("float")) - .component(DoubleComponent.required("double")) - .component(IntegerComponent.required("int")) - .component(BooleanComponent.required("bool")) - .component(StringComponent.required("string")) + .argument(FloatArgument.required("float")) + .argument(DoubleArgument.required("double")) + .argument(IntegerArgument.required("int")) + .argument(BooleanArgument.required("bool")) + .argument(StringArgument.required("string")) .handler(c -> c.getSender().sendMessage("Executed the command")) .build()); } catch (final Exception e) { diff --git a/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommand.java b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommand.java index 77830744..c3d93e03 100644 --- a/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommand.java +++ b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommand.java @@ -23,7 +23,7 @@ // package com.intellectualsites.commands; -import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.arguments.CommandArgument; import org.bukkit.ChatColor; import org.bukkit.command.CommandSender; import org.bukkit.command.PluginIdentifiableCommand; @@ -35,12 +35,12 @@ import java.util.List; final class BukkitCommand extends org.bukkit.command.Command implements PluginIdentifiableCommand { - private final CommandComponent command; + private final CommandArgument command; private final BukkitCommandManager bukkitCommandManager; private final com.intellectualsites.commands.Command cloudCommand; BukkitCommand(@Nonnull final com.intellectualsites.commands.Command cloudCommand, - @Nonnull final CommandComponent command, + @Nonnull final CommandArgument command, @Nonnull final BukkitCommandManager bukkitCommandManager) { super(command.getName()); this.command = command; diff --git a/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandManager.java b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandManager.java index 81b524b6..8427227d 100644 --- a/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandManager.java +++ b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitCommandManager.java @@ -25,7 +25,7 @@ package com.intellectualsites.commands; import com.google.common.reflect.TypeToken; import com.intellectualsites.commands.execution.CommandExecutionCoordinator; -import com.intellectualsites.commands.parsers.WorldComponent; +import com.intellectualsites.commands.parsers.WorldArgument; import org.bukkit.World; import org.bukkit.command.CommandSender; import org.bukkit.plugin.Plugin; @@ -64,7 +64,7 @@ public class BukkitCommandManager new WorldComponent.WorldParser<>()); + this.getParserRegistry().registerParserSupplier(TypeToken.of(World.class), params -> new WorldArgument.WorldParser<>()); } /** diff --git a/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitPluginRegistrationHandler.java b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitPluginRegistrationHandler.java index b8c3fea2..9dfcc69d 100644 --- a/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitPluginRegistrationHandler.java +++ b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/BukkitPluginRegistrationHandler.java @@ -23,7 +23,7 @@ // package com.intellectualsites.commands; -import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.arguments.CommandArgument; import com.intellectualsites.commands.internal.CommandRegistrationHandler; import com.intellectualsites.commands.sender.CommandSender; import org.bukkit.Bukkit; @@ -39,7 +39,7 @@ import java.util.Map; final class BukkitPluginRegistrationHandler implements CommandRegistrationHandler { - private final Map, org.bukkit.command.Command> registeredCommands = new HashMap<>(); + private final Map, org.bukkit.command.Command> registeredCommands = new HashMap<>(); private Map bukkitCommands; private BukkitCommandManager bukkitCommandManager; @@ -63,23 +63,23 @@ final class BukkitPluginRegistrationHandler implements @Override public boolean registerCommand(@Nonnull final Command command) { - /* We only care about the root command component */ - final CommandComponent commandComponent = command.getComponents().get(0); - if (this.registeredCommands.containsKey(commandComponent)) { + /* We only care about the root command argument */ + final CommandArgument commandArgument = command.getArguments().get(0); + if (this.registeredCommands.containsKey(commandArgument)) { return false; } final String label; - if (bukkitCommands.containsKey(commandComponent.getName())) { - label = String.format("%s:%s", this.bukkitCommandManager.getOwningPlugin().getName(), commandComponent.getName()); + if (bukkitCommands.containsKey(commandArgument.getName())) { + label = String.format("%s:%s", this.bukkitCommandManager.getOwningPlugin().getName(), commandArgument.getName()); } else { - label = commandComponent.getName(); + label = commandArgument.getName(); } @SuppressWarnings("unchecked") final BukkitCommand bukkitCommand = new BukkitCommand<>( (Command) command, - (CommandComponent) commandComponent, + (CommandArgument) commandArgument, this.bukkitCommandManager); - this.registeredCommands.put(commandComponent, bukkitCommand); - this.commandMap.register(commandComponent.getName(), this.bukkitCommandManager.getOwningPlugin().getName().toLowerCase(), + this.registeredCommands.put(commandArgument, bukkitCommand); + this.commandMap.register(commandArgument.getName(), this.bukkitCommandManager.getOwningPlugin().getName().toLowerCase(), bukkitCommand); return true; } diff --git a/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/parsers/WorldComponent.java b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/parsers/WorldArgument.java similarity index 60% rename from cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/parsers/WorldComponent.java rename to cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/parsers/WorldArgument.java index 05b9fb42..f7495e72 100644 --- a/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/parsers/WorldComponent.java +++ b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/parsers/WorldArgument.java @@ -23,9 +23,9 @@ // package com.intellectualsites.commands.parsers; -import com.intellectualsites.commands.components.CommandComponent; -import com.intellectualsites.commands.components.parser.ComponentParseResult; -import com.intellectualsites.commands.components.parser.ComponentParser; +import com.intellectualsites.commands.arguments.CommandArgument; +import com.intellectualsites.commands.arguments.parser.ArgumentParseResult; +import com.intellectualsites.commands.arguments.parser.ArgumentParser; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.sender.CommandSender; import org.bukkit.Bukkit; @@ -37,70 +37,70 @@ import java.util.Queue; import java.util.stream.Collectors; /** - * cloud component type that parses Bukkit {@link org.bukkit.World worlds} + * cloud argument type that parses Bukkit {@link org.bukkit.World worlds} * * @param Command sender type */ -public class WorldComponent extends CommandComponent { +public class WorldArgument extends CommandArgument { - protected WorldComponent(final boolean required, - @Nonnull final String name, - @Nonnull final String defaultValue) { + protected WorldArgument(final boolean required, + @Nonnull final String name, + @Nonnull final String defaultValue) { super(required, name, new WorldParser<>(), defaultValue, World.class); } /** * Create a new builder * - * @param name Name of the component + * @param name Name of the argument * @param Command sender type * @return Created builder */ @Nonnull - public static CommandComponent.Builder newBuilder(@Nonnull final String name) { - return new WorldComponent.Builder<>(name); + public static CommandArgument.Builder newBuilder(@Nonnull final String name) { + return new WorldArgument.Builder<>(name); } /** - * Create a new required component + * Create a new required argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent required(@Nonnull final String name) { - return WorldComponent.newBuilder(name).asRequired().build(); + public static CommandArgument required(@Nonnull final String name) { + return WorldArgument.newBuilder(name).asRequired().build(); } /** - * Create a new optional component + * Create a new optional argument * - * @param name Component name + * @param name Argument name * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name) { - return WorldComponent.newBuilder(name).asOptional().build(); + public static CommandArgument optional(@Nonnull final String name) { + return WorldArgument.newBuilder(name).asOptional().build(); } /** - * Create a new optional component with a default value + * Create a new optional argument with a default value * - * @param name Component name + * @param name Argument name * @param defaultValue Default value * @param Command sender type - * @return Created component + * @return Created argument */ @Nonnull - public static CommandComponent optional(@Nonnull final String name, - @Nonnull final String defaultValue) { - return WorldComponent.newBuilder(name).asOptionalWithDefault(defaultValue).build(); + public static CommandArgument optional(@Nonnull final String name, + @Nonnull final String defaultValue) { + return WorldArgument.newBuilder(name).asOptionalWithDefault(defaultValue).build(); } - public static final class Builder extends CommandComponent.Builder { + public static final class Builder extends CommandArgument.Builder { protected Builder(@Nonnull final String name) { super(World.class, name); @@ -108,30 +108,30 @@ public class WorldComponent extends CommandComponent build() { - return new WorldComponent<>(this.isRequired(), this.getName(), this.getDefaultValue()); + public CommandArgument build() { + return new WorldArgument<>(this.isRequired(), this.getName(), this.getDefaultValue()); } } - public static final class WorldParser implements ComponentParser { + public static final class WorldParser implements ArgumentParser { @Nonnull @Override - public ComponentParseResult parse(@Nonnull final CommandContext commandContext, - @Nonnull final Queue inputQueue) { + public ArgumentParseResult parse(@Nonnull final CommandContext commandContext, + @Nonnull final Queue inputQueue) { final String input = inputQueue.peek(); if (input == null) { - return ComponentParseResult.failure(new NullPointerException("No input was provided")); + return ArgumentParseResult.failure(new NullPointerException("No input was provided")); } final World world = Bukkit.getWorld(input); if (world == null) { - return ComponentParseResult.failure(new WorldParseException(input)); + return ArgumentParseResult.failure(new WorldParseException(input)); } inputQueue.remove(); - return ComponentParseResult.success(world); + return ArgumentParseResult.success(world); } @Nonnull diff --git a/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/parsers/package-info.java b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/parsers/package-info.java index 5c5f7f58..d29d0e41 100644 --- a/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/parsers/package-info.java +++ b/cloud-minecraft/cloud-bukkit/src/main/java/com/intellectualsites/commands/parsers/package-info.java @@ -23,6 +23,6 @@ // /** - * Bukkit specific command components + * Bukkit specific command arguments */ package com.intellectualsites.commands.parsers; diff --git a/cloud-minecraft/cloud-paper/src/main/java/com/intellectualsites/commands/PaperBrigadierListener.java b/cloud-minecraft/cloud-paper/src/main/java/com/intellectualsites/commands/PaperBrigadierListener.java index 52f909d2..27079609 100644 --- a/cloud-minecraft/cloud-paper/src/main/java/com/intellectualsites/commands/PaperBrigadierListener.java +++ b/cloud-minecraft/cloud-paper/src/main/java/com/intellectualsites/commands/PaperBrigadierListener.java @@ -26,7 +26,7 @@ package com.intellectualsites.commands; import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource; import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent; import com.intellectualsites.commands.brigadier.CloudBrigadierManager; -import com.intellectualsites.commands.components.CommandComponent; +import com.intellectualsites.commands.arguments.CommandArgument; import com.intellectualsites.commands.context.CommandContext; import com.intellectualsites.commands.sender.CommandSender; import com.mojang.brigadier.arguments.ArgumentType; @@ -112,7 +112,7 @@ class PaperBrigadierListener implements Listener { @EventHandler public void onCommandRegister(@Nonnull final CommandRegisteredEvent event) { final CommandTree commandTree = this.paperCommandManager.getCommandTree(); - final CommandTree.Node> node = commandTree.getNamedNode(event.getCommandLabel()); + final CommandTree.Node> node = commandTree.getNamedNode(event.getCommandLabel()); if (node == null) { return; }