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
-
-[](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
+
+[](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 extends C> 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 extends C> 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 extends C> 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 extends C> 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 extends C> 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 extends C> 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