component->argument

This commit is contained in:
Alexander Söderberg 2020-09-17 13:19:31 +02:00
parent b3d75496b5
commit 8b0a650b48
No known key found for this signature in database
GPG key ID: C0207FF7EA146678
52 changed files with 1032 additions and 1024 deletions

View file

@ -1,5 +1,6 @@
<div align="center">
<img src="icons/cloud.svg" width="300px"/>
<img src="icons/cloud.svg" width="300px"/>
</div>
# cloud command framework
@ -40,6 +41,15 @@ Once the core functionality is present, the framework will offer implementation
- 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
@ -60,17 +70,15 @@ cloud is available from [IntellectualSites](https://intellectualsites.com)' mave
```xml
<repository>
<id>intellectualsites-snapshots</id>
<url>https://mvn.intellectualsites.com/content/repositories/snapshots</url>
<id>intellectualsites-snapshots</id>
<url>https://mvn.intellectualsites.com/content/repositories/snapshots</url>
</repository>
```
```xml
<dependency>
<groupId>com.intellectualsites</groupId>
<artifactId></artifactId>
<version></version>
</dependency>
<groupId>com.intellectualsites</groupId>
<artifactId></artifactId> <version></version></dependency>
```
### attributions, links &amp; acknowledgements

View file

@ -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 <C> Command sender type
* @param <M> Command meta type
@ -47,7 +47,7 @@ import java.util.function.Consumer;
@SuppressWarnings("unused")
public class Command<C extends CommandSender, M extends CommandMeta> {
@Nonnull private final List<CommandComponent<C, ?>> components;
@Nonnull private final List<CommandArgument<C, ?>> arguments;
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
@Nullable private final Class<? extends C> senderType;
@Nonnull private final String commandPermission;
@ -56,32 +56,32 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
/**
* 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<CommandComponent<C, ?>> commandComponents,
public Command(@Nonnull final List<CommandArgument<C, ?>> commandArguments,
@Nonnull final CommandExecutionHandler<C> 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<C, ?> component : this.components) {
if (component.getName().isEmpty()) {
throw new IllegalArgumentException("Component names may not be empty");
for (final CommandArgument<C, ?> 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<C extends CommandSender, M extends CommandMeta> {
/**
* 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<CommandComponent<C, ?>> commandComponents,
public Command(@Nonnull final List<CommandArgument<C, ?>> commandArguments,
@Nonnull final CommandExecutionHandler<C> 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<CommandComponent<C, ?>> commandComponents,
public Command(@Nonnull final List<CommandArgument<C, ?>> commandArguments,
@Nonnull final CommandExecutionHandler<C> 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 <C> Command sender type
@ -136,18 +136,18 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
@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<CommandComponent<C, ?>> getComponents() {
return Collections.unmodifiableList(this.components);
public List<CommandArgument<C, ?>> getArguments() {
return Collections.unmodifiableList(this.arguments);
}
/**
@ -191,22 +191,22 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
}
/**
* 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<CommandComponent<C, ?>> getSharedComponentChain(@Nonnull final Command<C, M> other) {
final List<CommandComponent<C, ?>> 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<CommandArgument<C, ?>> getSharedArgumentChain(@Nonnull final Command<C, M> other) {
final List<CommandArgument<C, ?>> 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<C extends CommandSender, M extends CommandMeta> {
public static final class Builder<C extends CommandSender, M extends CommandMeta> {
@Nonnull private final M commandMeta;
@Nonnull private final List<CommandComponent<C, ?>> commandComponents;
@Nonnull private final List<CommandArgument<C, ?>> commandArguments;
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
@Nullable private final Class<? extends C> senderType;
@Nonnull private final String commandPermission;
@ -229,12 +229,12 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
private Builder(@Nullable final CommandManager<C, M> commandManager,
@Nonnull final M commandMeta,
@Nullable final Class<? extends C> senderType,
@Nonnull final List<CommandComponent<C, ?>> commandComponents,
@Nonnull final List<CommandArgument<C, ?>> commandArguments,
@Nonnull final CommandExecutionHandler<C> 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<C extends CommandSender, M extends CommandMeta> {
/**
* 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<C extends CommandSender, M extends CommandMeta> {
*/
@Nonnull
public Builder<C, M> manager(@Nullable final CommandManager<C, M> 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 <T> Component type
* @return New builder instance with the command component inserted into the component list
* @param argument Argument to add
* @param <T> Argument type
* @return New builder instance with the command argument inserted into the argument list
*/
@Nonnull
public <T> Builder<C, M> component(@Nonnull final CommandComponent<C, T> component) {
final List<CommandComponent<C, ?>> commandComponents = new LinkedList<>(this.commandComponents);
commandComponents.add(component);
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, commandComponents,
public <T> Builder<C, M> argument(@Nonnull final CommandArgument<C, T> argument) {
final List<CommandArgument<C, ?>> 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 <T> Component type
* @return New builder instance with the command component inserted into the component list
* @param <T> Argument type
* @return New builder instance with the command argument inserted into the argument list
*/
@Nonnull
public <T> Builder<C, M> component(@Nonnull final Class<T> clazz,
public <T> Builder<C, M> argument(@Nonnull final Class<T> clazz,
@Nonnull final String name,
@Nonnull final Consumer<CommandComponent.Builder<C, T>> builderConsumer) {
final CommandComponent.Builder<C, T> builder = CommandComponent.ofType(clazz, name);
@Nonnull final Consumer<CommandArgument.Builder<C, T>> builderConsumer) {
final CommandArgument.Builder<C, T> 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<C extends CommandSender, M extends CommandMeta> {
*/
@Nonnull
public Builder<C, M> handler(@Nonnull final CommandExecutionHandler<C> 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<C extends CommandSender, M extends CommandMeta> {
*/
@Nonnull
public Builder<C, M> 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<C extends CommandSender, M extends CommandMeta> {
*/
@Nonnull
public Builder<C, M> 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<C extends CommandSender, M extends CommandMeta> {
*/
@Nonnull
public Command<C, M> build() {
return new Command<>(Collections.unmodifiableList(this.commandComponents),
return new Command<>(Collections.unmodifiableList(this.commandArguments),
this.commandExecutionHandler, this.senderType, this.commandPermission, this.commandMeta);
}

View file

@ -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<C extends CommandSender, M extends CommandM
}
/**
* Create a new command component builder
* Create a new command argument builder
*
* @param type Component type
* @param name Component name
* @param <T> Generic component name
* @return Component builder
* @param type Argument type
* @param name Argument name
* @param <T> Generic argument name
* @return Argument builder
*/
@Nonnull
public <T> CommandComponent.Builder<C, T> componentBuilder(@Nonnull final Class<T> type, @Nonnull final String name) {
return CommandComponent.<C, T>ofType(type, name).manager(this);
public <T> CommandArgument.Builder<C, T> argumentBuilder(@Nonnull final Class<T> type, @Nonnull final String name) {
return CommandArgument.<C, T>ofType(type, name).manager(this);
}
/**

View file

@ -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<C extends CommandSender, M extends CommandMeta> {
private final Object commandLock = new Object();
private final Node<CommandComponent<C, ?>> internalTree = new Node<>(null);
private final Node<CommandArgument<C, ?>> internalTree = new Node<>(null);
private final CommandManager<C, M> commandManager;
private final CommandRegistrationHandler<M> commandRegistrationHandler;
@ -113,7 +113,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
private Optional<Command<C, M>> parseCommand(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> commandQueue,
@Nonnull final Node<CommandComponent<C, ?>> root) {
@Nonnull final Node<CommandArgument<C, ?>> 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<C extends CommandSender, M extends CommandMeta> {
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<C extends CommandSender, M extends CommandMeta> {
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<C extends CommandSender, M extends CommandMeta> {
.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<Node<CommandComponent<C, ?>>> childIterator = root.getChildren().iterator();
final Iterator<Node<CommandArgument<C, ?>>> childIterator = root.getChildren().iterator();
if (childIterator.hasNext()) {
while (childIterator.hasNext()) {
final Node<CommandComponent<C, ?>> child = childIterator.next();
final Node<CommandArgument<C, ?>> 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<C extends CommandSender, M extends CommandMeta> {
@Nullable
private Optional<Command<C, M>> attemptParseUnambiguousChild(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Node<CommandComponent<C, ?>> root,
@Nonnull final Node<CommandArgument<C, ?>> root,
@Nonnull final Queue<String> commandQueue) {
String permission;
final List<Node<CommandComponent<C, ?>>> children = root.getChildren();
if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticComponent)) {
final List<Node<CommandArgument<C, ?>>> children = root.getChildren();
if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticArgument)) {
// The value has to be a variable
final Node<CommandComponent<C, ?>> child = children.get(0);
final Node<CommandArgument<C, ?>> 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<C extends CommandSender, M extends CommandMeta> {
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<C extends CommandSender, M extends CommandMeta> {
"");
}
}
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<C extends CommandSender, M extends CommandMeta> {
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<C extends CommandSender, M extends CommandMeta> {
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<C extends CommandSender, M extends CommandMeta> {
@Nonnull
private List<String> getSuggestions(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> commandQueue,
@Nonnull final Node<CommandComponent<C, ?>> root) {
@Nonnull final Node<CommandArgument<C, ?>> 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<Node<CommandComponent<C, ?>>> children = root.getChildren();
if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticComponent)) {
final List<Node<CommandArgument<C, ?>>> children = root.getChildren();
if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticArgument)) {
// The value has to be a variable
final Node<CommandComponent<C, ?>> child = children.get(0);
final Node<CommandArgument<C, ?>> child = children.get(0);
if (child.getValue() != null) {
if (commandQueue.isEmpty()) {
return Collections.emptyList();
@ -287,7 +287,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
} 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<C extends CommandSender, M extends CommandMeta> {
}
}
}
/* 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<Node<CommandComponent<C, ?>>> childIterator = root.getChildren().iterator();
final Iterator<Node<CommandArgument<C, ?>>> childIterator = root.getChildren().iterator();
if (childIterator.hasNext()) {
while (childIterator.hasNext()) {
final Node<CommandComponent<C, ?>> child = childIterator.next();
final Node<CommandArgument<C, ?>> 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<C extends CommandSender, M extends CommandMeta> {
}
}
final List<String> suggestions = new LinkedList<>();
for (final Node<CommandComponent<C, ?>> component : root.getChildren()) {
if (component.getValue() == null || this.isPermitted(commandContext.getSender(), component) != null) {
for (final Node<CommandArgument<C, ?>> 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<C extends CommandSender, M extends CommandMeta> {
@SuppressWarnings("unchecked")
public void insertCommand(@Nonnull final Command<C, M> command) {
synchronized (this.commandLock) {
Node<CommandComponent<C, ?>> node = this.internalTree;
for (final CommandComponent<C, ?> component : command.getComponents()) {
Node<CommandComponent<C, ?>> tempNode = node.getChild(component);
Node<CommandArgument<C, ?>> node = this.internalTree;
for (final CommandArgument<C, ?> argument : command.getArguments()) {
Node<CommandArgument<C, ?>> tempNode = node.getChild(argument);
if (tempNode == null) {
tempNode = node.addChild(component);
} else if (component instanceof StaticComponent && tempNode.getValue() != null) {
for (final String alias : ((StaticComponent<C>) component).getAliases()) {
((StaticComponent<C>) tempNode.getValue()).registerAlias(alias);
tempNode = node.addChild(argument);
} else if (argument instanceof StaticArgument && tempNode.getValue() != null) {
for (final String alias : ((StaticArgument<C>) argument).getAliases()) {
((StaticArgument<C>) tempNode.getValue()).registerAlias(alias);
}
}
if (node.children.size() > 0) {
@ -366,7 +366,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
}
@Nullable
private String isPermitted(@Nonnull final C sender, @Nonnull final Node<CommandComponent<C, ?>> node) {
private String isPermitted(@Nonnull final C sender, @Nonnull final Node<CommandArgument<C, ?>> 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<C extends CommandSender, M extends CommandMeta> {
chain to execute, and so we allow them to execute the root
*/
final List<String> missingPermissions = new LinkedList<>();
for (final Node<CommandComponent<C, ?>> child : node.getChildren()) {
for (final Node<CommandArgument<C, ?>> child : node.getChildren()) {
final String check = this.isPermitted(sender, child);
if (check == null) {
return null;
@ -399,9 +399,9 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
*/
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<C extends CommandSender, M extends CommandMeta> {
// noinspection all
node.nodeMeta.put("permission", node.getValue().getOwningCommand().getCommandPermission());
// Get chain and order it tail->head then skip the tail (leaf node)
List<Node<CommandComponent<C, ?>>> chain = this.getChain(node);
List<Node<CommandArgument<C, ?>>> 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<CommandComponent<C, ?>> commandComponentNode : chain) {
if (commandComponentNode.nodeMeta.containsKey("permission") && !commandComponentNode.nodeMeta.get("permission")
for (final Node<CommandArgument<C, ?>> 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<CommandComponent<C, ?>> node) throws AmbiguousNodeException {
private void checkAmbiguity(@Nonnull final Node<CommandArgument<C, ?>> node) throws AmbiguousNodeException {
if (node.isLeaf()) {
return;
}
final int size = node.children.size();
for (final Node<CommandComponent<C, ?>> child : node.children) {
for (final Node<CommandArgument<C, ?>> 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<C extends CommandSender, M extends CommandMeta> {
node.children.forEach(this::checkAmbiguity);
}
private List<Node<CommandComponent<C, ?>>> getLeavesRaw(@Nonnull final Node<CommandComponent<C, ?>> node) {
final List<Node<CommandComponent<C, ?>>> leaves = new LinkedList<>();
private List<Node<CommandArgument<C, ?>>> getLeavesRaw(@Nonnull final Node<CommandArgument<C, ?>> node) {
final List<Node<CommandArgument<C, ?>>> leaves = new LinkedList<>();
if (node.isLeaf()) {
if (node.getValue() != null) {
leaves.add(node);
@ -468,8 +468,8 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
return leaves;
}
private List<CommandComponent<C, ?>> getLeaves(@Nonnull final Node<CommandComponent<C, ?>> node) {
final List<CommandComponent<C, ?>> leaves = new LinkedList<>();
private List<CommandArgument<C, ?>> getLeaves(@Nonnull final Node<CommandArgument<C, ?>> node) {
final List<CommandArgument<C, ?>> leaves = new LinkedList<>();
if (node.isLeaf()) {
if (node.getValue() != null) {
leaves.add(node.getValue());
@ -480,9 +480,9 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
return leaves;
}
private List<Node<CommandComponent<C, ?>>> getChain(@Nullable final Node<CommandComponent<C, ?>> end) {
final List<Node<CommandComponent<C, ?>>> chain = new LinkedList<>();
Node<CommandComponent<C, ?>> tail = end;
private List<Node<CommandArgument<C, ?>>> getChain(@Nullable final Node<CommandArgument<C, ?>> end) {
final List<Node<CommandArgument<C, ?>>> chain = new LinkedList<>();
Node<CommandArgument<C, ?>> tail = end;
while (tail != null) {
chain.add(tail);
tail = tail.getParent();
@ -507,7 +507,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
* @return Root nodes
*/
@Nonnull
public Collection<Node<CommandComponent<C, ?>>> getRootNodes() {
public Collection<Node<CommandArgument<C, ?>>> getRootNodes() {
return this.internalTree.getChildren();
}
@ -518,7 +518,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
* @return Root node, or {@code null}
*/
@Nullable
public Node<CommandComponent<C, ?>> getNamedNode(@Nullable final String name) {
public Node<CommandArgument<C, ?>> getNamedNode(@Nullable final String name) {
return this.getRootNodes().stream().filter(node -> node.getValue() != null
&& node.getValue().getName().equalsIgnoreCase(name)).findAny().orElse(null);
}

View file

@ -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)

View file

@ -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;

View file

@ -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 <C> Command sender type
* @param <T> The type that the component parses into
* @param <T> The type that the argument parses into
*/
@SuppressWarnings("unused")
public class CommandComponent<C extends CommandSender, T> implements Comparable<CommandComponent<?, ?>> {
public class CommandArgument<C extends CommandSender, T> implements Comparable<CommandArgument<?, ?>> {
/**
* 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<C extends CommandSender, T> implements Comparable<
* The parser that is used to parse the command input
* into the corresponding command type
*/
private final ComponentParser<C, T> parser;
private final ArgumentParser<C, T> 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<T> valueType;
private Command<C, ?> 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<C, T> parser,
@Nonnull final String defaultValue,
@Nonnull final Class<T> valueType) {
public CommandArgument(final boolean required,
@Nonnull final String name,
@Nonnull final ArgumentParser<C, T> parser,
@Nonnull final String defaultValue,
@Nonnull final Class<T> 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<C extends CommandSender, T> 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<C, T> parser,
@Nonnull final Class<T> valueType) {
public CommandArgument(final boolean required,
@Nonnull final String name,
@Nonnull final ArgumentParser<C, T> parser,
@Nonnull final Class<T> 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 <C> Command sender type
* @param <T> Argument Type. Used to make the compiler happy.
* @return Component builder
* @return Argument builder
*/
@Nonnull
public static <C extends CommandSender, T> CommandComponent.Builder<C, T> ofType(@Nonnull final Class<T> clazz,
@Nonnull final String name) {
public static <C extends CommandSender, T> CommandArgument.Builder<C, T> ofType(@Nonnull final Class<T> 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<C extends CommandSender, T> implements Comparable<
* @return Command parser
*/
@Nonnull
public ComponentParser<C, T> getParser() {
public ArgumentParser<C, T> 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<C extends CommandSender, T> 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<C extends CommandSender, T> 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<C extends CommandSender, T> 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<C extends CommandSender, T> 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<C extends CommandSender, T> implements Comparable<
}
/**
* Mutable builder for {@link CommandComponent} instances
* Mutable builder for {@link CommandArgument} instances
*
* @param <C> Command sender type
* @param <T> Component value type
* @param <T> Argument value type
*/
public static class Builder<C extends CommandSender, T> {
@ -268,7 +268,7 @@ public class CommandComponent<C extends CommandSender, T> implements Comparable<
private CommandManager<C, ?> manager;
private boolean required = true;
private ComponentParser<C, T> parser;
private ArgumentParser<C, T> parser;
private String defaultValue = "";
protected Builder(@Nonnull final Class<T> valueType,
@ -291,11 +291,11 @@ public class CommandComponent<C extends CommandSender, T> 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<C extends CommandSender, T> 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<C extends CommandSender, T> 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<C extends CommandSender, T> implements Comparable<
}
/**
* Set the component parser
* Set the argument parser
*
* @param parser Component parser
* @param parser Argument parser
* @return Builder instance
*/
@Nonnull
public Builder<C, T> withParser(@Nonnull final ComponentParser<C, T> parser) {
public Builder<C, T> withParser(@Nonnull final ArgumentParser<C, T> 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<C, T> build() {
public CommandArgument<C, T> 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<C extends CommandSender, T> implements Comparable<
}
@Nonnull
protected final ComponentParser<C, T> getParser() {
protected final ArgumentParser<C, T> getParser() {
return this.parser;
}

View file

@ -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 <C> Command sender type
*/
@FunctionalInterface
public interface CommandSyntaxFormatter<C extends CommandSender> extends Function<List<CommandComponent<C, ?>>, String> {
public interface CommandSyntaxFormatter<C extends CommandSender> extends Function<List<CommandArgument<C, ?>>, String> {
@Override
@Nonnull
String apply(@Nonnull List<CommandComponent<C, ?>> commandComponents);
String apply(@Nonnull List<CommandArgument<C, ?>> commandArguments);
}

View file

@ -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:
* <ul>
* <li>static components are serialized as their name, without a bracket</li>
* <li>required components are serialized as their name, surrounded by angle brackets</li>
* <li>optional components are serialized as their name, surrounded by square brackets</li>
* <li>static arguments are serialized as their name, without a bracket</li>
* <li>required arguments are serialized as their name, surrounded by angle brackets</li>
* <li>optional arguments are serialized as their name, surrounded by square brackets</li>
* </ul>
*
* @param <C> Command sender type
@ -43,18 +43,18 @@ public class StandardCommandSyntaxFormatter<C extends CommandSender> implements
@Nonnull
@Override
public final String apply(@Nonnull final List<CommandComponent<C, ?>> commandComponents) {
public final String apply(@Nonnull final List<CommandArgument<C, ?>> commandArguments) {
final StringBuilder stringBuilder = new StringBuilder();
final Iterator<CommandComponent<C, ?>> iterator = commandComponents.iterator();
final Iterator<CommandArgument<C, ?>> 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()) {

View file

@ -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 <C> Command sender type
*/
public final class StaticComponent<C extends CommandSender> extends CommandComponent<C, String> {
public final class StaticArgument<C extends CommandSender> extends CommandArgument<C, String> {
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 <C> Command sender type
* @return Constructed component
* @return Constructed argument
*/
@Nonnull
public static <C extends CommandSender> StaticComponent<C> required(@Nonnull final String name,
@Nonnull final String... aliases) {
return new StaticComponent<>(true, name, aliases);
public static <C extends CommandSender> StaticArgument<C> 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 <C> Command sender type
* @return Constructed component
* @return Constructed argument
*/
@Nonnull
public static <C extends CommandSender> StaticComponent<C> optional(@Nonnull final String name,
@Nonnull final String... aliases) {
return new StaticComponent<>(false, name, aliases);
public static <C extends CommandSender> StaticArgument<C> optional(@Nonnull final String name,
@Nonnull final String... aliases) {
return new StaticArgument<>(false, name, aliases);
}
/**
@ -81,26 +81,26 @@ public final class StaticComponent<C extends CommandSender> extends CommandCompo
* @param alias New alias
*/
public void registerAlias(@Nonnull final String alias) {
((StaticComponentParser<C>) this.getParser()).acceptedStrings.add(alias);
((StaticArgumentParser<C>) 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<String> getAliases() {
return Collections.unmodifiableSet(((StaticComponentParser<C>) this.getParser()).getAcceptedStrings());
return Collections.unmodifiableSet(((StaticArgumentParser<C>) this.getParser()).getAcceptedStrings());
}
private static final class StaticComponentParser<C extends CommandSender> implements ComponentParser<C, String> {
private static final class StaticArgumentParser<C extends CommandSender> implements ArgumentParser<C, String> {
private final String name;
private final Set<String> 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<C extends CommandSender> extends CommandCompo
@Nonnull
@Override
public ComponentParseResult<String> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> inputQueue) {
public ArgumentParseResult<String> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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

View file

@ -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;

View file

@ -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 <T> Parser return type
*/
public abstract class ComponentParseResult<T> {
public abstract class ArgumentParseResult<T> {
private ComponentParseResult() {
private ArgumentParseResult() {
}
/**
@ -44,7 +44,7 @@ public abstract class ComponentParseResult<T> {
* @return Failed parse result
*/
@Nonnull
public static <T> ComponentParseResult<T> failure(@Nonnull final Throwable failure) {
public static <T> ArgumentParseResult<T> failure(@Nonnull final Throwable failure) {
return new ParseFailure<>(failure);
}
@ -56,7 +56,7 @@ public abstract class ComponentParseResult<T> {
* @return Succeeded parse result
*/
@Nonnull
public static <T> ComponentParseResult<T> success(@Nonnull final T value) {
public static <T> ArgumentParseResult<T> success(@Nonnull final T value) {
return new ParseSuccess<>(value);
}
@ -77,7 +77,7 @@ public abstract class ComponentParseResult<T> {
public abstract Optional<Throwable> getFailure();
private static final class ParseSuccess<T> extends ComponentParseResult<T> {
private static final class ParseSuccess<T> extends ArgumentParseResult<T> {
/**
* Parsed value
@ -103,7 +103,7 @@ public abstract class ComponentParseResult<T> {
}
private static final class ParseFailure<T> extends ComponentParseResult<T> {
private static final class ParseFailure<T> extends ArgumentParseResult<T> {
/**
* Parse failure

View file

@ -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 <T> Value type
*/
@FunctionalInterface
public interface ComponentParser<C extends CommandSender, T> {
public interface ArgumentParser<C extends CommandSender, T> {
/**
* Parse command input into a command result
@ -48,7 +48,7 @@ public interface ComponentParser<C extends CommandSender, T> {
* @return Parsed command result
*/
@Nonnull
ComponentParseResult<T> parse(@Nonnull CommandContext<C> commandContext, @Nonnull Queue<String> inputQueue);
ArgumentParseResult<T> parse(@Nonnull CommandContext<C> commandContext, @Nonnull Queue<String> inputQueue);
/**
* Get a list of suggested arguments that would be correctly parsed by this parser
@ -63,7 +63,7 @@ public interface ComponentParser<C extends CommandSender, T> {
}
/**
* 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}

View file

@ -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;

View file

@ -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;

View file

@ -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<C extends CommandSender> {
* @param <T> Generic type specifying what is produced by the parser
*/
<T> void registerParserSupplier(@Nonnull TypeToken<T> type,
@Nonnull Function<ParserParameters, ComponentParser<C, ?>> supplier);
@Nonnull Function<ParserParameters, ArgumentParser<C, ?>> supplier);
/**
* Register a mapper that maps annotation instances to a map of parameter-object pairs
@ -77,7 +77,7 @@ public interface ParserRegistry<C extends CommandSender> {
ParserParameters parseAnnotations(@Nonnull TypeToken<?> parsingType, @Nonnull Collection<? extends Annotation> 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<C extends CommandSender> {
* @return Parser, if one can be created
*/
@Nonnull
<T> Optional<ComponentParser<C, T>> createParser(@Nonnull TypeToken<T> type,
@Nonnull ParserParameters parserParameters);
<T> Optional<ArgumentParser<C, T>> createParser(@Nonnull TypeToken<T> type,
@Nonnull ParserParameters parserParameters);
}

View file

@ -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;

View file

@ -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<C extends CommandSender> implements Pa
.put(boolean.class, Boolean.class)
.build();
private final Map<TypeToken<?>, Function<ParserParameters, ComponentParser<C, ?>>> parserSuppliers = new HashMap<>();
private final Map<TypeToken<?>, Function<ParserParameters, ArgumentParser<C, ?>>> parserSuppliers = new HashMap<>();
private final Map<Class<? extends Annotation>, BiFunction<? extends Annotation, TypeToken<?>, ParserParameters>>
annotationMappers = new HashMap<>();
@ -79,31 +79,31 @@ public final class StandardParserRegistry<C extends CommandSender> implements Pa
/* Register standard types */
this.registerParserSupplier(TypeToken.of(Byte.class), options ->
new ByteComponent.ByteParser<C>((byte) options.get(StandardParameters.RANGE_MIN, Byte.MIN_VALUE),
(byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE)));
new ByteArgument.ByteParser<C>((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<C>((short) options.get(StandardParameters.RANGE_MIN, Short.MIN_VALUE),
(short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE)));
new ShortArgument.ShortParser<C>((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<C>((int) options.get(StandardParameters.RANGE_MIN, Integer.MIN_VALUE),
(int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE)));
new IntegerArgument.IntegerParser<C>((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<C>((float) options.get(StandardParameters.RANGE_MIN, Float.MIN_VALUE),
(float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE)));
new FloatArgument.FloatParser<C>((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<C>((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<C>());
new DoubleArgument.DoubleParser<C>((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<C>());
/* Make this one less awful */
this.registerParserSupplier(TypeToken.of(String.class), options -> new StringComponent.StringParser<C>(
StringComponent.StringMode.SINGLE, (context, s) -> Collections.emptyList()));
this.registerParserSupplier(TypeToken.of(String.class), options -> new StringArgument.StringParser<C>(
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 <T> void registerParserSupplier(@Nonnull final TypeToken<T> type,
@Nonnull final Function<ParserParameters, ComponentParser<C, ?>> supplier) {
@Nonnull final Function<ParserParameters, ArgumentParser<C, ?>> supplier) {
this.parserSuppliers.put(type, supplier);
}
@ -134,27 +134,27 @@ public final class StandardParserRegistry<C extends CommandSender> implements Pa
@Nonnull
@Override
public <T> Optional<ComponentParser<C, T>> createParser(@Nonnull final TypeToken<T> type,
@Nonnull final ParserParameters parserParameters) {
public <T> Optional<ArgumentParser<C, T>> createParser(@Nonnull final TypeToken<T> type,
@Nonnull final ParserParameters parserParameters) {
final TypeToken<?> actualType;
if (type.isPrimitive()) {
actualType = TypeToken.of(PRIMITIVE_MAPPINGS.get(type.getRawType()));
} else {
actualType = type;
}
final Function<ParserParameters, ComponentParser<C, ?>> producer = this.parserSuppliers.get(actualType);
final Function<ParserParameters, ArgumentParser<C, ?>> 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<Enum>)
final EnumArgument.EnumParser enumArgument = new EnumArgument.EnumParser((Class<Enum>)
actualType.getRawType());
// noinspection all
return Optional.of(enumComponent);
return Optional.of(enumArgument);
}
return Optional.empty();
}
@SuppressWarnings("unchecked") final ComponentParser<C, T> parser = (ComponentParser<C, T>) producer.apply(
@SuppressWarnings("unchecked") final ArgumentParser<C, T> parser = (ArgumentParser<C, T>) producer.apply(
parserParameters);
return Optional.of(parser);
}

View file

@ -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;

View file

@ -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<C extends CommandSender> extends CommandComponent<C, Boolean> {
public final class BooleanArgument<C extends CommandSender> extends CommandArgument<C, Boolean> {
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<C extends CommandSender> extends CommandComp
/**
* Create a new builder
*
* @param name Name of the component
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
@ -57,45 +57,45 @@ public final class BooleanComponent<C extends CommandSender> extends CommandComp
}
/**
* Create a new required command component
* Create a new required command argument
*
* @param name Component name
* @param name Argument name
* @param <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Boolean> required(@Nonnull final String name) {
return BooleanComponent.<C>newBuilder(name).asRequired().build();
public static <C extends CommandSender> CommandArgument<C, Boolean> required(@Nonnull final String name) {
return BooleanArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Boolean> optional(@Nonnull final String name) {
return BooleanComponent.<C>newBuilder(name).asOptional().build();
public static <C extends CommandSender> CommandArgument<C, Boolean> optional(@Nonnull final String name) {
return BooleanArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Boolean> optional(@Nonnull final String name,
final String defaultNum) {
return BooleanComponent.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
public static <C extends CommandSender> CommandArgument<C, Boolean> optional(@Nonnull final String name,
final String defaultNum) {
return BooleanArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
}
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, Boolean> {
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Boolean> {
private boolean liberal = false;
@ -116,14 +116,14 @@ public final class BooleanComponent<C extends CommandSender> extends CommandComp
}
/**
* Builder a new boolean component
* Builder a new boolean argument
*
* @return Constructed component
* @return Constructed argument
*/
@Nonnull
@Override
public BooleanComponent<C> build() {
return new BooleanComponent<>(this.isRequired(), this.getName(), this.liberal, this.getDefaultValue());
public BooleanArgument<C> build() {
return new BooleanArgument<>(this.isRequired(), this.getName(), this.liberal, this.getDefaultValue());
}
}
@ -138,7 +138,7 @@ public final class BooleanComponent<C extends CommandSender> extends CommandComp
}
public static final class BooleanParser<C extends CommandSender> implements ComponentParser<C, Boolean> {
public static final class BooleanParser<C extends CommandSender> implements ArgumentParser<C, Boolean> {
private static final List<String> LIBERAL = Arrays.asList("TRUE", "YES", "ON", "FALSE", "NO", "OFF");
private static final List<String> LIBERAL_TRUE = Arrays.asList("TRUE", "YES", "ON");
@ -157,37 +157,37 @@ public final class BooleanComponent<C extends CommandSender> extends CommandComp
@Nonnull
@Override
public ComponentParseResult<Boolean> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> inputQueue) {
public ArgumentParseResult<Boolean> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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

View file

@ -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<C extends CommandSender> extends CommandComponent<C, Byte> {
public final class ByteArgument<C extends CommandSender> extends CommandArgument<C, Byte> {
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<C extends CommandSender> extends CommandCompone
/**
* Create a new builder
*
* @param name Name of the component
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
@ -59,44 +59,44 @@ public final class ByteComponent<C extends CommandSender> extends CommandCompone
}
/**
* Create a new required command component
* Create a new required command argument
*
* @param name Component name
* @param name Argument name
* @param <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Byte> required(@Nonnull final String name) {
return ByteComponent.<C>newBuilder(name).asRequired().build();
public static <C extends CommandSender> CommandArgument<C, Byte> required(@Nonnull final String name) {
return ByteArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Byte> optional(@Nonnull final String name) {
return ByteComponent.<C>newBuilder(name).asOptional().build();
public static <C extends CommandSender> CommandArgument<C, Byte> optional(@Nonnull final String name) {
return ByteArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull public static <C extends CommandSender> CommandComponent<C, Byte> optional(@Nonnull final String name,
final byte defaultNum) {
return ByteComponent.<C>newBuilder(name).asOptionalWithDefault(Byte.toString(defaultNum)).build();
@Nonnull public static <C extends CommandSender> CommandArgument<C, Byte> optional(@Nonnull final String name,
final byte defaultNum) {
return ByteArgument.<C>newBuilder(name).asOptionalWithDefault(Byte.toString(defaultNum)).build();
}
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, Byte> {
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Byte> {
private byte min = Byte.MIN_VALUE;
private byte max = Byte.MAX_VALUE;
@ -130,14 +130,14 @@ public final class ByteComponent<C extends CommandSender> extends CommandCompone
}
/**
* Builder a new byte component
* Builder a new byte argument
*
* @return Constructed component
* @return Constructed argument
*/
@Nonnull
@Override
public ByteComponent<C> build() {
return new ByteComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
public ByteArgument<C> build() {
return new ByteArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
}
}
@ -162,7 +162,7 @@ public final class ByteComponent<C extends CommandSender> extends CommandCompone
}
public static final class ByteParser<C extends CommandSender> implements ComponentParser<C, Byte> {
public static final class ByteParser<C extends CommandSender> implements ArgumentParser<C, Byte> {
private final byte min;
private final byte max;
@ -180,25 +180,25 @@ public final class ByteComponent<C extends CommandSender> extends CommandCompone
@Nonnull
@Override
public ComponentParseResult<Byte> parse(
public ArgumentParseResult<Byte> parse(
@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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));
}

View file

@ -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<C extends CommandSender> extends CommandComponent<C, Character> {
public final class CharArgument<C extends CommandSender> extends CommandArgument<C, Character> {
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 <C> Command sender type
* @return Created builder
*/
@Nonnull
public static <C extends CommandSender> CharComponent.Builder<C> newBuilder(@Nonnull final String name) {
return new CharComponent.Builder<>(name);
public static <C extends CommandSender> CharArgument.Builder<C> 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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Character> required(@Nonnull final String name) {
return CharComponent.<C>newBuilder(name).asRequired().build();
public static <C extends CommandSender> CommandArgument<C, Character> required(@Nonnull final String name) {
return CharArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Character> optional(@Nonnull final String name) {
return CharComponent.<C>newBuilder(name).asOptional().build();
public static <C extends CommandSender> CommandArgument<C, Character> optional(@Nonnull final String name) {
return CharArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Character> optional(@Nonnull final String name,
final String defaultNum) {
return CharComponent.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
public static <C extends CommandSender> CommandArgument<C, Character> optional(@Nonnull final String name,
final String defaultNum) {
return CharArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
}
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, Character> {
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Character> {
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<C> build() {
return new CharComponent<>(this.isRequired(), this.getName(), this.getDefaultValue());
public CharArgument<C> build() {
return new CharArgument<>(this.isRequired(), this.getName(), this.getDefaultValue());
}
}
public static final class CharacterParser<C extends CommandSender> implements ComponentParser<C, Character> {
public static final class CharacterParser<C extends CommandSender> implements ArgumentParser<C, Character> {
@Nonnull
@Override
public ComponentParseResult<Character> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> inputQueue) {
public ArgumentParseResult<Character> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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

View file

@ -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<C extends CommandSender> extends CommandComponent<C, Double> {
public final class DoubleArgument<C extends CommandSender> extends CommandArgument<C, Double> {
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<C extends CommandSender> extends CommandCompo
/**
* Create a new builder
*
* @param name Name of the component
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
@ -62,45 +62,45 @@ public final class DoubleComponent<C extends CommandSender> extends CommandCompo
}
/**
* Create a new required command component
* Create a new required command argument
*
* @param name Component name
* @param name Argument name
* @param <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Double> required(@Nonnull final String name) {
return DoubleComponent.<C>newBuilder(name).asRequired().build();
public static <C extends CommandSender> CommandArgument<C, Double> required(@Nonnull final String name) {
return DoubleArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Double> optional(@Nonnull final String name) {
return DoubleComponent.<C>newBuilder(name).asOptional().build();
public static <C extends CommandSender> CommandArgument<C, Double> optional(@Nonnull final String name) {
return DoubleArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Double> optional(@Nonnull final String name,
final double defaultNum) {
return DoubleComponent.<C>newBuilder(name).asOptionalWithDefault(Double.toString(defaultNum)).build();
public static <C extends CommandSender> CommandArgument<C, Double> optional(@Nonnull final String name,
final double defaultNum) {
return DoubleArgument.<C>newBuilder(name).asOptionalWithDefault(Double.toString(defaultNum)).build();
}
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, Double> {
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Double> {
private double min = Double.MIN_VALUE;
private double max = Double.MAX_VALUE;
@ -134,14 +134,14 @@ public final class DoubleComponent<C extends CommandSender> extends CommandCompo
}
/**
* Builder a new double component
* Builder a new double argument
*
* @return Constructed component
* @return Constructed argument
*/
@Nonnull
@Override
public DoubleComponent<C> build() {
return new DoubleComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
public DoubleArgument<C> build() {
return new DoubleArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
}
}
@ -166,7 +166,7 @@ public final class DoubleComponent<C extends CommandSender> extends CommandCompo
}
public static final class DoubleParser<C extends CommandSender> implements ComponentParser<C, Double> {
public static final class DoubleParser<C extends CommandSender> implements ArgumentParser<C, Double> {
private final double min;
private final double max;
@ -184,22 +184,22 @@ public final class DoubleComponent<C extends CommandSender> extends CommandCompo
@Nonnull
@Override
public ComponentParseResult<Double> parse(
public ArgumentParseResult<Double> parse(
@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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));
}
}

View file

@ -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 <C> Component sender
* @param <C> Argument sender
* @param <E> Enum type
*/
@SuppressWarnings("unused")
public class EnumComponent<C extends CommandSender, E extends Enum<E>> extends CommandComponent<C, E> {
public class EnumArgument<C extends CommandSender, E extends Enum<E>> extends CommandArgument<C, E> {
protected EnumComponent(@Nonnull final Class<E> enumClass,
final boolean required,
@Nonnull final String name,
@Nonnull final String defaultValue) {
protected EnumArgument(@Nonnull final Class<E> 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 <C> Command sender type
* @param <E> Enum type
* @return Created builder
*/
@Nonnull
public static <C extends CommandSender, E extends Enum<E>> EnumComponent.Builder<C, E> newBuilder(
public static <C extends CommandSender, E extends Enum<E>> EnumArgument.Builder<C, E> newBuilder(
@Nonnull final Class<E> 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 <C> Command sender type
* @param <E> Enum type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender, E extends Enum<E>> CommandComponent<C, E> required(
public static <C extends CommandSender, E extends Enum<E>> CommandArgument<C, E> required(
@Nonnull final Class<E> enumClass, @Nonnull final String name) {
return EnumComponent.<C, E>newBuilder(enumClass, name).asRequired().build();
return EnumArgument.<C, E>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 <C> Command sender type
* @param <E> Enum type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender, E extends Enum<E>> CommandComponent<C, E> optional(
public static <C extends CommandSender, E extends Enum<E>> CommandArgument<C, E> optional(
@Nonnull final Class<E> enumClass, @Nonnull final String name) {
return EnumComponent.<C, E>newBuilder(enumClass, name).asOptional().build();
return EnumArgument.<C, E>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 <C> Command sender type
* @param <E> Enum type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender, E extends Enum<E>> CommandComponent<C, E> optional(
public static <C extends CommandSender, E extends Enum<E>> CommandArgument<C, E> optional(
@Nonnull final Class<E> enumClass, @Nonnull final String name, @Nonnull final E defaultValue) {
return EnumComponent.<C, E>newBuilder(enumClass, name).asOptionalWithDefault(defaultValue.name().toLowerCase()).build();
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptionalWithDefault(defaultValue.name().toLowerCase()).build();
}
public static final class Builder<C extends CommandSender, E extends Enum<E>> extends CommandComponent.Builder<C, E> {
public static final class Builder<C extends CommandSender, E extends Enum<E>> extends CommandArgument.Builder<C, E> {
private final Class<E> enumClass;
@ -124,13 +124,13 @@ public class EnumComponent<C extends CommandSender, E extends Enum<E>> extends C
@Nonnull
@Override
public CommandComponent<C, E> build() {
return new EnumComponent<>(this.enumClass, this.isRequired(), this.getName(), this.getDefaultValue());
public CommandArgument<C, E> build() {
return new EnumArgument<>(this.enumClass, this.isRequired(), this.getName(), this.getDefaultValue());
}
}
public static final class EnumParser<C extends CommandSender, E extends Enum<E>> implements ComponentParser<C, E> {
public static final class EnumParser<C extends CommandSender, E extends Enum<E>> implements ArgumentParser<C, E> {
private final Class<E> enumClass;
private final EnumSet<E> allowedValues;
@ -147,21 +147,21 @@ public class EnumComponent<C extends CommandSender, E extends Enum<E>> extends C
@Nonnull
@Override
public ComponentParseResult<E> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> inputQueue) {
public ArgumentParseResult<E> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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

View file

@ -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<C extends CommandSender> extends CommandComponent<C, Float> {
public final class FloatArgument<C extends CommandSender> extends CommandArgument<C, Float> {
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<C extends CommandSender> extends CommandCompon
/**
* Create a new builder
*
* @param name Name of the component
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
@ -62,45 +62,45 @@ public final class FloatComponent<C extends CommandSender> extends CommandCompon
}
/**
* Create a new required command component
* Create a new required command argument
*
* @param name Component name
* @param name Argument name
* @param <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Float> required(@Nonnull final String name) {
return FloatComponent.<C>newBuilder(name).asRequired().build();
public static <C extends CommandSender> CommandArgument<C, Float> required(@Nonnull final String name) {
return FloatArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Float> optional(@Nonnull final String name) {
return FloatComponent.<C>newBuilder(name).asOptional().build();
public static <C extends CommandSender> CommandArgument<C, Float> optional(@Nonnull final String name) {
return FloatArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Float> optional(@Nonnull final String name,
final float defaultNum) {
return FloatComponent.<C>newBuilder(name).asOptionalWithDefault(Float.toString(defaultNum)).build();
public static <C extends CommandSender> CommandArgument<C, Float> optional(@Nonnull final String name,
final float defaultNum) {
return FloatArgument.<C>newBuilder(name).asOptionalWithDefault(Float.toString(defaultNum)).build();
}
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, Float> {
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Float> {
private float min = Float.MIN_VALUE;
private float max = Float.MAX_VALUE;
@ -134,14 +134,14 @@ public final class FloatComponent<C extends CommandSender> extends CommandCompon
}
/**
* Builder a new float component
* Builder a new float argument
*
* @return Constructed component
* @return Constructed argument
*/
@Nonnull
@Override
public FloatComponent<C> build() {
return new FloatComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
public FloatArgument<C> build() {
return new FloatArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
}
}
@ -166,7 +166,7 @@ public final class FloatComponent<C extends CommandSender> extends CommandCompon
}
public static final class FloatParser<C extends CommandSender> implements ComponentParser<C, Float> {
public static final class FloatParser<C extends CommandSender> implements ArgumentParser<C, Float> {
private final float min;
private final float max;
@ -184,22 +184,22 @@ public final class FloatComponent<C extends CommandSender> extends CommandCompon
@Nonnull
@Override
public ComponentParseResult<Float> parse(
public ArgumentParseResult<Float> parse(
@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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));
}
}

View file

@ -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<C extends CommandSender> extends CommandComponent<C, Integer> {
public final class IntegerArgument<C extends CommandSender> extends CommandArgument<C, Integer> {
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<C extends CommandSender> extends CommandComp
/**
* Create a new builder
*
* @param name Name of the component
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
@ -62,45 +62,45 @@ public final class IntegerComponent<C extends CommandSender> extends CommandComp
}
/**
* Create a new required command component
* Create a new required command argument
*
* @param name Component name
* @param name Argument name
* @param <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Integer> required(@Nonnull final String name) {
return IntegerComponent.<C>newBuilder(name).asRequired().build();
public static <C extends CommandSender> CommandArgument<C, Integer> required(@Nonnull final String name) {
return IntegerArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Integer> optional(@Nonnull final String name) {
return IntegerComponent.<C>newBuilder(name).asOptional().build();
public static <C extends CommandSender> CommandArgument<C, Integer> optional(@Nonnull final String name) {
return IntegerArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Integer> optional(@Nonnull final String name,
final int defaultNum) {
return IntegerComponent.<C>newBuilder(name).asOptionalWithDefault(Integer.toString(defaultNum)).build();
public static <C extends CommandSender> CommandArgument<C, Integer> optional(@Nonnull final String name,
final int defaultNum) {
return IntegerArgument.<C>newBuilder(name).asOptionalWithDefault(Integer.toString(defaultNum)).build();
}
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, Integer> {
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Integer> {
private int min = Integer.MIN_VALUE;
private int max = Integer.MAX_VALUE;
@ -134,14 +134,14 @@ public final class IntegerComponent<C extends CommandSender> extends CommandComp
}
/**
* Builder a new integer component
* Builder a new integer argument
*
* @return Constructed component
* @return Constructed argument
*/
@Nonnull
@Override
public IntegerComponent<C> build() {
return new IntegerComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
public IntegerArgument<C> build() {
return new IntegerArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
}
}
@ -166,7 +166,7 @@ public final class IntegerComponent<C extends CommandSender> extends CommandComp
}
public static final class IntegerParser<C extends CommandSender> implements ComponentParser<C, Integer> {
public static final class IntegerParser<C extends CommandSender> implements ArgumentParser<C, Integer> {
private final int min;
private final int max;
@ -184,22 +184,22 @@ public final class IntegerComponent<C extends CommandSender> extends CommandComp
@Nonnull
@Override
public ComponentParseResult<Integer> parse(
public ArgumentParseResult<Integer> parse(
@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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));
}
}

View file

@ -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<C extends CommandSender> extends CommandComponent<C, Long> {
public final class LongArgument<C extends CommandSender> extends CommandArgument<C, Long> {
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<C extends CommandSender> extends CommandCompone
/**
* Create a new builder
*
* @param name Name of the component
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
@Nonnull
public static <C extends CommandSender> LongComponent.Builder<C> newBuilder(@Nonnull final String name) {
public static <C extends CommandSender> LongArgument.Builder<C> 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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Long> required(@Nonnull final String name) {
return LongComponent.<C>newBuilder(name).asRequired().build();
public static <C extends CommandSender> CommandArgument<C, Long> required(@Nonnull final String name) {
return LongArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Long> optional(@Nonnull final String name) {
return LongComponent.<C>newBuilder(name).asOptional().build();
public static <C extends CommandSender> CommandArgument<C, Long> optional(@Nonnull final String name) {
return LongArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Long> optional(@Nonnull final String name,
final long defaultNum) {
return LongComponent.<C>newBuilder(name).asOptionalWithDefault(Long.toString(defaultNum)).build();
public static <C extends CommandSender> CommandArgument<C, Long> optional(@Nonnull final String name,
final long defaultNum) {
return LongArgument.<C>newBuilder(name).asOptionalWithDefault(Long.toString(defaultNum)).build();
}
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, Long> {
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Long> {
private long min = Long.MIN_VALUE;
private long max = Long.MAX_VALUE;
@ -134,14 +134,14 @@ public final class LongComponent<C extends CommandSender> extends CommandCompone
}
/**
* Builder a new long component
* Builder a new long argument
*
* @return Constructed component
* @return Constructed argument
*/
@Nonnull
@Override
public LongComponent<C> build() {
return new LongComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
public LongArgument<C> build() {
return new LongArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
}
}
@ -166,7 +166,7 @@ public final class LongComponent<C extends CommandSender> extends CommandCompone
}
private static final class LongParser<C extends CommandSender> implements ComponentParser<C, Long> {
private static final class LongParser<C extends CommandSender> implements ArgumentParser<C, Long> {
private final long min;
private final long max;
@ -178,22 +178,22 @@ public final class LongComponent<C extends CommandSender> extends CommandCompone
@Nonnull
@Override
public ComponentParseResult<Long> parse(
public ArgumentParseResult<Long> parse(
@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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));
}
}

View file

@ -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<C extends CommandSender> extends CommandComponent<C, Short> {
public final class ShortArgument<C extends CommandSender> extends CommandArgument<C, Short> {
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<C extends CommandSender> extends CommandCompon
/**
* Create a new builder
*
* @param name Name of the component
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
@Nonnull
public static <C extends CommandSender> ShortComponent.Builder<C> newBuilder(@Nonnull final String name) {
public static <C extends CommandSender> ShortArgument.Builder<C> 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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Short> required(@Nonnull final String name) {
return ShortComponent.<C>newBuilder(name).asRequired().build();
public static <C extends CommandSender> CommandArgument<C, Short> required(@Nonnull final String name) {
return ShortArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Short> optional(@Nonnull final String name) {
return ShortComponent.<C>newBuilder(name).asOptional().build();
public static <C extends CommandSender> CommandArgument<C, Short> optional(@Nonnull final String name) {
return ShortArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, Short> optional(@Nonnull final String name,
public static <C extends CommandSender> CommandArgument<C, Short> optional(@Nonnull final String name,
final short defaultNum) {
return ShortComponent.<C>newBuilder(name).asOptionalWithDefault(Short.toString(defaultNum)).build();
return ShortArgument.<C>newBuilder(name).asOptionalWithDefault(Short.toString(defaultNum)).build();
}
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, Short> {
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Short> {
private short min = Short.MIN_VALUE;
private short max = Short.MAX_VALUE;
@ -134,14 +134,14 @@ public final class ShortComponent<C extends CommandSender> extends CommandCompon
}
/**
* Builder a new short component
* Builder a new short argument
*
* @return Constructed component
* @return Constructed argument
*/
@Nonnull
@Override
public ShortComponent<C> build() {
return new ShortComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
public ShortArgument<C> build() {
return new ShortArgument<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
}
}
@ -166,7 +166,7 @@ public final class ShortComponent<C extends CommandSender> extends CommandCompon
}
public static final class ShortParser<C extends CommandSender> implements ComponentParser<C, Short> {
public static final class ShortParser<C extends CommandSender> implements ArgumentParser<C, Short> {
private final short min;
private final short max;
@ -184,22 +184,22 @@ public final class ShortComponent<C extends CommandSender> extends CommandCompon
@Nonnull
@Override
public ComponentParseResult<Short> parse(
public ArgumentParseResult<Short> parse(
@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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));
}
}

View file

@ -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<C extends CommandSender> extends CommandComponent<C, String> {
public final class StringArgument<C extends CommandSender> extends CommandArgument<C, String> {
private final StringMode stringMode;
private StringComponent(final boolean required,
@Nonnull final String name,
@Nonnull final StringMode stringMode,
@Nonnull final String defaultValue,
@Nonnull final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
private StringArgument(final boolean required,
@Nonnull final String name,
@Nonnull final StringMode stringMode,
@Nonnull final String defaultValue,
@Nonnull final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
super(required, name, new StringParser<>(stringMode, suggestionsProvider), defaultValue, String.class);
this.stringMode = stringMode;
}
@ -53,51 +53,51 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
/**
* Create a new builder
*
* @param name Name of the component
* @param name Name of the argument
* @param <C> Command sender type
* @return Created builder
*/
@Nonnull
public static <C extends CommandSender> StringComponent.Builder<C> newBuilder(@Nonnull final String name) {
return new StringComponent.Builder<>(name);
public static <C extends CommandSender> StringArgument.Builder<C> 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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, String> required(@Nonnull final String name) {
return StringComponent.<C>newBuilder(name).asRequired().build();
public static <C extends CommandSender> CommandArgument<C, String> required(@Nonnull final String name) {
return StringArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, String> optional(@Nonnull final String name) {
return StringComponent.<C>newBuilder(name).asOptional().build();
public static <C extends CommandSender> CommandArgument<C, String> optional(@Nonnull final String name) {
return StringArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, String> optional(@Nonnull final String name,
final String defaultNum) {
return StringComponent.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
public static <C extends CommandSender> CommandArgument<C, String> optional(@Nonnull final String name,
final String defaultNum) {
return StringArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
}
/**
@ -118,7 +118,7 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
}
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, String> {
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, String> {
private StringMode stringMode = StringMode.SINGLE;
private BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider = (v1, v2) -> Collections.emptyList();
@ -174,21 +174,21 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
}
/**
* Builder a new string component
* Builder a new string argument
*
* @return Constructed component
* @return Constructed argument
*/
@Nonnull
@Override
public StringComponent<C> build() {
return new StringComponent<>(this.isRequired(), this.getName(), this.stringMode,
this.getDefaultValue(), this.suggestionsProvider);
public StringArgument<C> build() {
return new StringArgument<>(this.isRequired(), this.getName(), this.stringMode,
this.getDefaultValue(), this.suggestionsProvider);
}
}
public static final class StringParser<C extends CommandSender> implements ComponentParser<C, String> {
public static final class StringParser<C extends CommandSender> implements ArgumentParser<C, String> {
private final StringMode stringMode;
private final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider;
@ -207,16 +207,16 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
@Nonnull
@Override
public ComponentParseResult<String> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> inputQueue) {
public ArgumentParseResult<String> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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<C extends CommandSender> 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<C extends CommandSender> 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

View file

@ -23,6 +23,6 @@
//
/**
* Standard command component types
* Standard command argument types
*/
package com.intellectualsites.commands.components.standard;
package com.intellectualsites.commands.arguments.standard;

View file

@ -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<CommandComponent<?, ?>> children;
private final CommandArgument<?, ?> parentNode;
private final CommandArgument<?, ?> ambiguousNode;
private final List<CommandArgument<?, ?>> 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<CommandComponent<?, ?>> children) {
public AmbiguousNodeException(@Nullable final CommandArgument<?, ?> parentNode,
@Nonnull final CommandArgument<?, ?> ambiguousNode,
@Nonnull final List<CommandArgument<?, ?>> 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<CommandComponent<?, ?>> getChildren() {
public List<CommandArgument<?, ?>> 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 ? "<root>" : parentNode.getName())
.append(" (All children: ");
final Iterator<CommandComponent<?, ?>> childIterator = this.children.iterator();
final Iterator<CommandArgument<?, ?>> childIterator = this.children.iterator();
while (childIterator.hasNext()) {
stringBuilder.append(childIterator.next().getName());
if (childIterator.hasNext()) {

View file

@ -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<CommandComponent<?, ?>> currentChain) {
public ArgumentParseException(@Nonnull final Throwable throwable,
@Nonnull final CommandSender commandSender,
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
super(commandSender, currentChain);
this.cause = throwable;
}

View file

@ -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<CommandComponent<?, ?>> currentChain;
private final List<CommandArgument<?, ?>> 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<CommandComponent<?, ?>> currentChain) {
@Nonnull final List<CommandArgument<?, ?>> 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<CommandComponent<?, ?>> getCurrentChain() {
public List<CommandArgument<?, ?>> getCurrentChain() {
return Collections.unmodifiableList(this.currentChain);
}

View file

@ -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<CommandComponent<?, ?>> currentChain) {
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
super(commandSender, currentChain);
this.requiredSender = requiredSender;
}

View file

@ -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<CommandComponent<?, ?>> currentChain) {
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
super(commandSender, currentChain);
this.correctSyntax = correctSyntax;
}

View file

@ -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;
}
}

View file

@ -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<CommandComponent<?, ?>> currentChain) {
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
super(commandSender, currentChain);
this.missingPermission = missingPermission;
}

View file

@ -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<CommandComponent<?, ?>> currentChain,
@Nonnull final List<CommandArgument<?, ?>> 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());
}

View file

@ -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.<SampleEnum>get(

View file

@ -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());
}

View file

@ -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());
}
}

View file

@ -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);

View file

@ -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<CommandSender, ?> parser = parserRegistry.createParser(parsedType,
parserParameters)
.orElseThrow(
final ArgumentParser<CommandSender, ?> 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<CommandSender> integerParser = (IntegerComponent.IntegerParser<CommandSender>) parser;
final IntegerArgument.IntegerParser<CommandSender> integerParser = (IntegerArgument.IntegerParser<CommandSender>) parser;
Assertions.assertEquals(RANGE_MIN, integerParser.getMin());
Assertions.assertEquals(RANGE_MAX, integerParser.getMax());
}

View file

@ -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<JLineCommandSender, Simp
shouldStop[0] = true)
.build())
.command(jLineCommandManager.commandBuilder("echo", SimpleCommandMeta.empty())
.component(String.class, "string", builder ->
.argument(String.class, "string", builder ->
builder.asRequired()
.withParser(((commandContext, inputQueue) -> {
final StringBuilder stringBuilder =
@ -92,7 +92,7 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender, Simp
stringBuilder.append(" ");
}
}
return ComponentParseResult.success(
return ArgumentParseResult.success(
stringBuilder.toString());
})).build())
.handler(commandContext -> commandContext.get("string")
@ -100,11 +100,11 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender, Simp
System.out::println))
.build())
.command(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty())
.component(StaticComponent.required("one"))
.argument(StaticArgument.required("one"))
.handler(commandContext -> 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...");

View file

@ -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<C extends CommandSender, S> {
private final Map<Class<?>, Function<? extends CommandComponent<C, ?>,
private final Map<Class<?>, Function<? extends CommandArgument<C, ?>,
? extends ArgumentType<?>>> mappers;
private final Map<Class<?>, Supplier<ArgumentType<?>>> defaultArgumentTypeSuppliers;
private final Supplier<com.intellectualsites.commands.context.CommandContext<C>> dummyContextProvider;
@ -101,75 +101,75 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
private void registerInternalMappings() {
/* Map byte, short and int to IntegerArgumentType */
this.registerMapping(new TypeToken<ByteComponent<C>>() {
}, component -> {
final boolean hasMin = component.getMin() != Byte.MIN_VALUE;
final boolean hasMax = component.getMax() != Byte.MAX_VALUE;
this.registerMapping(new TypeToken<ByteArgument<C>>() {
}, 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<ShortComponent<C>>() {
}, component -> {
final boolean hasMin = component.getMin() != Short.MIN_VALUE;
final boolean hasMax = component.getMax() != Short.MAX_VALUE;
this.registerMapping(new TypeToken<ShortArgument<C>>() {
}, 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<IntegerComponent<C>>() {
}, component -> {
final boolean hasMin = component.getMin() != Integer.MIN_VALUE;
final boolean hasMax = component.getMax() != Integer.MAX_VALUE;
this.registerMapping(new TypeToken<IntegerArgument<C>>() {
}, 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<FloatComponent<C>>() {
}, component -> {
final boolean hasMin = component.getMin() != Float.MIN_VALUE;
final boolean hasMax = component.getMax() != Float.MAX_VALUE;
this.registerMapping(new TypeToken<FloatArgument<C>>() {
}, 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<DoubleComponent<C>>() {
}, component -> {
final boolean hasMin = component.getMin() != Double.MIN_VALUE;
final boolean hasMax = component.getMax() != Double.MAX_VALUE;
this.registerMapping(new TypeToken<DoubleArgument<C>>() {
}, 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<BooleanComponent<C>>() {
}, component -> BoolArgumentType.bool());
this.registerMapping(new TypeToken<BooleanArgument<C>>() {
}, argument -> BoolArgumentType.bool());
/* Map String properly to StringArgumentType */
this.registerMapping(new TypeToken<StringComponent<C>>() {
}, component -> {
switch (component.getStringMode()) {
this.registerMapping(new TypeToken<StringArgument<C>>() {
}, argument -> {
switch (argument.getStringMode()) {
case QUOTED:
return StringArgumentType.string();
case GREEDY:
@ -183,16 +183,16 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
/**
* Register a cloud-Brigadier mapping
*
* @param componentType cloud component type
* @param argumentType cloud argument type
* @param mapper mapper function
* @param <T> cloud component value type
* @param <K> cloud component type
* @param <T> cloud argument value type
* @param <K> cloud argument type
* @param <O> Brigadier argument type value
*/
public <T, K extends CommandComponent<C, T>, O> void registerMapping(@Nonnull final TypeToken<K> componentType,
@Nonnull final Function<? extends K,
public <T, K extends CommandArgument<C, T>, O> void registerMapping(@Nonnull final TypeToken<K> argumentType,
@Nonnull final Function<? extends K,
? extends ArgumentType<O>> mapper) {
this.mappers.put(componentType.getRawType(), mapper);
this.mappers.put(argumentType.getRawType(), mapper);
}
/**
@ -207,36 +207,36 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
}
/**
* 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 <T> cloud component value type (generic)
* @param <K> cloud component type (generic)
* @param argumentType cloud argument type
* @param argument cloud argument
* @param <T> cloud argument value type (generic)
* @param <K> cloud argument type (generic)
* @return Brigadier argument type
*/
@Nullable
@SuppressWarnings("all")
private <T, K extends CommandComponent<?, ?>> Pair<ArgumentType<?>, Boolean> getArgument(
@Nonnull final TypeToken<T> componentType,
@Nonnull final K component) {
final CommandComponent<C, ?> commandComponent = (CommandComponent<C, ?>) component;
Function function = this.mappers.get(componentType.getRawType());
private <T, K extends CommandArgument<?, ?>> Pair<ArgumentType<?>, Boolean> getArgument(
@Nonnull final TypeToken<T> argumentType,
@Nonnull final K argument) {
final CommandArgument<C, ?> commandArgument = (CommandArgument<C, ?>) 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 <T, K extends CommandComponent<C, T>> Pair<ArgumentType<?>, Boolean> createDefaultMapper(
@Nonnull final CommandComponent<C, T>
component) {
final Supplier<ArgumentType<?>> argumentTypeSupplier = this.defaultArgumentTypeSuppliers.get(component.getValueType());
private <T, K extends CommandArgument<C, T>> Pair<ArgumentType<?>, Boolean> createDefaultMapper(
@Nonnull final CommandArgument<C, T>
argument) {
final Supplier<ArgumentType<?>> 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<C extends CommandSender, S> {
* @return Constructed literal command node
*/
@Nonnull
public LiteralCommandNode<S> createLiteralCommandNode(@Nonnull final CommandTree.Node<CommandComponent<C, ?>> cloudCommand,
public LiteralCommandNode<S> createLiteralCommandNode(@Nonnull final CommandTree.Node<CommandArgument<C, ?>> cloudCommand,
@Nonnull final LiteralCommandNode<S> root,
@Nonnull final SuggestionProvider<S> suggestionProvider,
@Nonnull final com.mojang.brigadier.Command<S> executor,
@ -262,19 +262,19 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
literalArgumentBuilder.executes(executor);
}
final LiteralCommandNode<S> constructedRoot = literalArgumentBuilder.build();
for (final CommandTree.Node<CommandComponent<C, ?>> child : cloudCommand.getChildren()) {
for (final CommandTree.Node<CommandArgument<C, ?>> child : cloudCommand.getChildren()) {
constructedRoot.addChild(this.constructCommandNode(child, permissionChecker, executor, suggestionProvider).build());
}
return constructedRoot;
}
private ArgumentBuilder<S, ?> constructCommandNode(@Nonnull final CommandTree.Node<CommandComponent<C, ?>> root,
private ArgumentBuilder<S, ?> constructCommandNode(@Nonnull final CommandTree.Node<CommandArgument<C, ?>> root,
@Nonnull final BiPredicate<S, String> permissionChecker,
@Nonnull final com.mojang.brigadier.Command<S> executor,
@Nonnull final SuggestionProvider<S> suggestionProvider) {
ArgumentBuilder<S, ?> argumentBuilder;
if (root.getValue() instanceof StaticComponent) {
if (root.getValue() instanceof StaticArgument) {
argumentBuilder = LiteralArgumentBuilder.<S>literal(root.getValue().getName())
.requires(sender -> permissionChecker.test(sender, root.getNodeMeta().getOrDefault("permission", "")))
.executes(executor);
@ -290,14 +290,14 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
if (root.isLeaf() || !root.getValue().isRequired()) {
argumentBuilder.executes(executor);
}
for (final CommandTree.Node<CommandComponent<C, ?>> node : root.getChildren()) {
for (final CommandTree.Node<CommandArgument<C, ?>> node : root.getChildren()) {
argumentBuilder.then(constructCommandNode(node, permissionChecker, executor, suggestionProvider));
}
return argumentBuilder;
}
@Nonnull
private CompletableFuture<Suggestions> buildSuggestions(@Nonnull final CommandComponent<C, ?> component,
private CompletableFuture<Suggestions> buildSuggestions(@Nonnull final CommandArgument<C, ?> argument,
@Nonnull final CommandContext<S> s,
@Nonnull final SuggestionsBuilder builder) {
final com.intellectualsites.commands.context.CommandContext<C> commandContext = this.dummyContextProvider.get();
@ -314,7 +314,7 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
command = command.substring(1);
}
final List<String> 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<C extends CommandSender, S> {
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 + ']';

View file

@ -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.<BukkitCommandSender>newBuilder("player")
.argument(EnumArgument.required(GameMode.class, "gamemode"))
.argument(StringArgument.<BukkitCommandSender>newBuilder("player")
.withSuggestionsProvider((v1, v2) -> {
final List<String> 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
.<BukkitCommandSender>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.<UUID>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) {

View file

@ -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<C extends com.intellectualsites.commands.sender.CommandSender>
extends org.bukkit.command.Command implements PluginIdentifiableCommand {
private final CommandComponent<C, ?> command;
private final CommandArgument<C, ?> command;
private final BukkitCommandManager<C> bukkitCommandManager;
private final com.intellectualsites.commands.Command<C, BukkitCommandMeta> cloudCommand;
BukkitCommand(@Nonnull final com.intellectualsites.commands.Command<C, BukkitCommandMeta> cloudCommand,
@Nonnull final CommandComponent<C, ?> command,
@Nonnull final CommandArgument<C, ?> command,
@Nonnull final BukkitCommandManager<C> bukkitCommandManager) {
super(command.getName());
this.command = command;

View file

@ -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<C extends com.intellectualsites.commands.sende
this.commandSenderMapper = commandSenderMapper;
/* Register Bukkit parsers */
this.getParserRegistry().registerParserSupplier(TypeToken.of(World.class), params -> new WorldComponent.WorldParser<>());
this.getParserRegistry().registerParserSupplier(TypeToken.of(World.class), params -> new WorldArgument.WorldParser<>());
}
/**

View file

@ -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<C extends CommandSender> implements CommandRegistrationHandler<BukkitCommandMeta> {
private final Map<CommandComponent<?, ?>, org.bukkit.command.Command> registeredCommands = new HashMap<>();
private final Map<CommandArgument<?, ?>, org.bukkit.command.Command> registeredCommands = new HashMap<>();
private Map<String, org.bukkit.command.Command> bukkitCommands;
private BukkitCommandManager<C> bukkitCommandManager;
@ -63,23 +63,23 @@ final class BukkitPluginRegistrationHandler<C extends CommandSender> implements
@Override
public boolean registerCommand(@Nonnull final Command<?, BukkitCommandMeta> 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<C> bukkitCommand = new BukkitCommand<>(
(Command<C, BukkitCommandMeta>) command,
(CommandComponent<C, ?>) commandComponent,
(CommandArgument<C, ?>) 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;
}

View file

@ -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 <C> Command sender type
*/
public class WorldComponent<C extends CommandSender> extends CommandComponent<C, World> {
public class WorldArgument<C extends CommandSender> extends CommandArgument<C, World> {
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 <C> Command sender type
* @return Created builder
*/
@Nonnull
public static <C extends CommandSender> CommandComponent.Builder<C, World> newBuilder(@Nonnull final String name) {
return new WorldComponent.Builder<>(name);
public static <C extends CommandSender> CommandArgument.Builder<C, World> 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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, World> required(@Nonnull final String name) {
return WorldComponent.<C>newBuilder(name).asRequired().build();
public static <C extends CommandSender> CommandArgument<C, World> required(@Nonnull final String name) {
return WorldArgument.<C>newBuilder(name).asRequired().build();
}
/**
* Create a new optional component
* Create a new optional argument
*
* @param name Component name
* @param name Argument name
* @param <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, World> optional(@Nonnull final String name) {
return WorldComponent.<C>newBuilder(name).asOptional().build();
public static <C extends CommandSender> CommandArgument<C, World> optional(@Nonnull final String name) {
return WorldArgument.<C>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 <C> Command sender type
* @return Created component
* @return Created argument
*/
@Nonnull
public static <C extends CommandSender> CommandComponent<C, World> optional(@Nonnull final String name,
@Nonnull final String defaultValue) {
return WorldComponent.<C>newBuilder(name).asOptionalWithDefault(defaultValue).build();
public static <C extends CommandSender> CommandArgument<C, World> optional(@Nonnull final String name,
@Nonnull final String defaultValue) {
return WorldArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue).build();
}
public static final class Builder<C extends CommandSender> extends CommandComponent.Builder<C, World> {
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, World> {
protected Builder(@Nonnull final String name) {
super(World.class, name);
@ -108,30 +108,30 @@ public class WorldComponent<C extends CommandSender> extends CommandComponent<C,
@Nonnull
@Override
public CommandComponent<C, World> build() {
return new WorldComponent<>(this.isRequired(), this.getName(), this.getDefaultValue());
public CommandArgument<C, World> build() {
return new WorldArgument<>(this.isRequired(), this.getName(), this.getDefaultValue());
}
}
public static final class WorldParser<C extends CommandSender> implements ComponentParser<C, World> {
public static final class WorldParser<C extends CommandSender> implements ArgumentParser<C, World> {
@Nonnull
@Override
public ComponentParseResult<World> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> inputQueue) {
public ArgumentParseResult<World> parse(@Nonnull final CommandContext<C> commandContext,
@Nonnull final Queue<String> 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

View file

@ -23,6 +23,6 @@
//
/**
* Bukkit specific command components
* Bukkit specific command arguments
*/
package com.intellectualsites.commands.parsers;

View file

@ -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<C extends CommandSender> implements Listener {
@EventHandler
public void onCommandRegister(@Nonnull final CommandRegisteredEvent<BukkitBrigadierCommandSource> event) {
final CommandTree<C, BukkitCommandMeta> commandTree = this.paperCommandManager.getCommandTree();
final CommandTree.Node<CommandComponent<C, ?>> node = commandTree.getNamedNode(event.getCommandLabel());
final CommandTree.Node<CommandArgument<C, ?>> node = commandTree.getNamedNode(event.getCommandLabel());
if (node == null) {
return;
}