component->argument
This commit is contained in:
parent
b3d75496b5
commit
8b0a650b48
52 changed files with 1032 additions and 1024 deletions
14
README.md
14
README.md
|
|
@ -1,3 +1,4 @@
|
||||||
|
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<img src="icons/cloud.svg" width="300px"/>
|
<img src="icons/cloud.svg" width="300px"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -40,6 +41,15 @@ Once the core functionality is present, the framework will offer implementation
|
||||||
- Create a Discord implementation (JDA)
|
- Create a Discord implementation (JDA)
|
||||||
- Create a Java CLI implementation (JLine3)
|
- 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
|
## links
|
||||||
|
|
||||||
- Discord: https://discord.gg/KxkjDVg
|
- Discord: https://discord.gg/KxkjDVg
|
||||||
|
|
@ -68,9 +78,7 @@ cloud is available from [IntellectualSites](https://intellectualsites.com)' mave
|
||||||
```xml
|
```xml
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.intellectualsites</groupId>
|
<groupId>com.intellectualsites</groupId>
|
||||||
<artifactId></artifactId>
|
<artifactId></artifactId> <version></version></dependency>
|
||||||
<version></version>
|
|
||||||
</dependency>
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### attributions, links & acknowledgements
|
### attributions, links & acknowledgements
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.StaticComponent;
|
import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.execution.CommandExecutionHandler;
|
import com.intellectualsites.commands.execution.CommandExecutionHandler;
|
||||||
import com.intellectualsites.commands.meta.CommandMeta;
|
import com.intellectualsites.commands.meta.CommandMeta;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
@ -39,7 +39,7 @@ import java.util.Optional;
|
||||||
import java.util.function.Consumer;
|
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 <C> Command sender type
|
||||||
* @param <M> Command meta type
|
* @param <M> Command meta type
|
||||||
|
|
@ -47,7 +47,7 @@ import java.util.function.Consumer;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class Command<C extends CommandSender, M extends CommandMeta> {
|
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;
|
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
|
||||||
@Nullable private final Class<? extends C> senderType;
|
@Nullable private final Class<? extends C> senderType;
|
||||||
@Nonnull private final String commandPermission;
|
@Nonnull private final String commandPermission;
|
||||||
|
|
@ -56,32 +56,32 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
|
||||||
/**
|
/**
|
||||||
* Construct a new command
|
* Construct a new command
|
||||||
*
|
*
|
||||||
* @param commandComponents Command components
|
* @param commandArguments Command arguments
|
||||||
* @param commandExecutionHandler Execution handler
|
* @param commandExecutionHandler Execution handler
|
||||||
* @param senderType Required sender type. May be {@code null}
|
* @param senderType Required sender type. May be {@code null}
|
||||||
* @param commandPermission Command permission
|
* @param commandPermission Command permission
|
||||||
* @param commandMeta Command meta instance
|
* @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 CommandExecutionHandler<C> commandExecutionHandler,
|
||||||
@Nullable final Class<? extends C> senderType,
|
@Nullable final Class<? extends C> senderType,
|
||||||
@Nonnull final String commandPermission,
|
@Nonnull final String commandPermission,
|
||||||
@Nonnull final M commandMeta) {
|
@Nonnull final M commandMeta) {
|
||||||
this.components = Objects.requireNonNull(commandComponents, "Command components may not be null");
|
this.arguments = Objects.requireNonNull(commandArguments, "Command arguments may not be null");
|
||||||
if (this.components.size() == 0) {
|
if (this.arguments.size() == 0) {
|
||||||
throw new IllegalArgumentException("At least one command component is required");
|
throw new IllegalArgumentException("At least one command argument is required");
|
||||||
}
|
}
|
||||||
// Enforce ordering of command components
|
// Enforce ordering of command arguments
|
||||||
boolean foundOptional = false;
|
boolean foundOptional = false;
|
||||||
for (final CommandComponent<C, ?> component : this.components) {
|
for (final CommandArgument<C, ?> argument : this.arguments) {
|
||||||
if (component.getName().isEmpty()) {
|
if (argument.getName().isEmpty()) {
|
||||||
throw new IllegalArgumentException("Component names may not be empty");
|
throw new IllegalArgumentException("Argument names may not be empty");
|
||||||
}
|
}
|
||||||
if (foundOptional && component.isRequired()) {
|
if (foundOptional && argument.isRequired()) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
String.format("Command component '%s' cannot be placed after an optional component",
|
String.format("Command argument '%s' cannot be placed after an optional argument",
|
||||||
component.getName()));
|
argument.getName()));
|
||||||
} else if (!component.isRequired()) {
|
} else if (!argument.isRequired()) {
|
||||||
foundOptional = true;
|
foundOptional = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -94,37 +94,37 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
|
||||||
/**
|
/**
|
||||||
* Construct a new command
|
* Construct a new command
|
||||||
*
|
*
|
||||||
* @param commandComponents Command components
|
* @param commandArguments Command arguments
|
||||||
* @param commandExecutionHandler Execution handler
|
* @param commandExecutionHandler Execution handler
|
||||||
* @param senderType Required sender type. May be {@code null}
|
* @param senderType Required sender type. May be {@code null}
|
||||||
* @param commandMeta Command meta instance
|
* @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 CommandExecutionHandler<C> commandExecutionHandler,
|
||||||
@Nullable final Class<? extends C> senderType,
|
@Nullable final Class<? extends C> senderType,
|
||||||
@Nonnull final M commandMeta) {
|
@Nonnull final M commandMeta) {
|
||||||
this(commandComponents, commandExecutionHandler, senderType, "", commandMeta);
|
this(commandArguments, commandExecutionHandler, senderType, "", commandMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new command
|
* Construct a new command
|
||||||
*
|
*
|
||||||
* @param commandComponents Command components
|
* @param commandArguments Command arguments
|
||||||
* @param commandExecutionHandler Execution handler
|
* @param commandExecutionHandler Execution handler
|
||||||
* @param commandPermission Command permission
|
* @param commandPermission Command permission
|
||||||
* @param commandMeta Command meta instance
|
* @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 CommandExecutionHandler<C> commandExecutionHandler,
|
||||||
@Nonnull final String commandPermission,
|
@Nonnull final String commandPermission,
|
||||||
@Nonnull final M commandMeta) {
|
@Nonnull final M commandMeta) {
|
||||||
this(commandComponents, commandExecutionHandler, null, "", commandMeta);
|
this(commandArguments, commandExecutionHandler, null, "", commandMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command builder
|
* Create a new command builder
|
||||||
*
|
*
|
||||||
* @param commandName Base command component
|
* @param commandName Base command argument
|
||||||
* @param commandMeta Command meta instance
|
* @param commandMeta Command meta instance
|
||||||
* @param aliases Command aliases
|
* @param aliases Command aliases
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
|
|
@ -136,18 +136,18 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
|
||||||
@Nonnull final M commandMeta,
|
@Nonnull final M commandMeta,
|
||||||
@Nonnull final String... aliases) {
|
@Nonnull final String... aliases) {
|
||||||
return new Builder<>(null, commandMeta, null,
|
return new Builder<>(null, commandMeta, null,
|
||||||
Collections.singletonList(StaticComponent.required(commandName, aliases)),
|
Collections.singletonList(StaticArgument.required(commandName, aliases)),
|
||||||
new CommandExecutionHandler.NullCommandExecutionHandler<>(), "");
|
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
|
@Nonnull
|
||||||
public List<CommandComponent<C, ?>> getComponents() {
|
public List<CommandArgument<C, ?>> getArguments() {
|
||||||
return Collections.unmodifiableList(this.components);
|
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
|
* two commands
|
||||||
*
|
*
|
||||||
* @param other Command to compare to
|
* @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) {
|
public List<CommandArgument<C, ?>> getSharedArgumentChain(@Nonnull final Command<C, M> other) {
|
||||||
final List<CommandComponent<C, ?>> commandComponents = new LinkedList<>();
|
final List<CommandArgument<C, ?>> commandArguments = new LinkedList<>();
|
||||||
for (int i = 0; i < this.components.size() && i < other.components.size(); i++) {
|
for (int i = 0; i < this.arguments.size() && i < other.arguments.size(); i++) {
|
||||||
if (this.components.get(i).equals(other.components.get(i))) {
|
if (this.arguments.get(i).equals(other.arguments.get(i))) {
|
||||||
commandComponents.add(this.components.get(i));
|
commandArguments.add(this.arguments.get(i));
|
||||||
} else {
|
} else {
|
||||||
break;
|
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> {
|
public static final class Builder<C extends CommandSender, M extends CommandMeta> {
|
||||||
|
|
||||||
@Nonnull private final M 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;
|
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
|
||||||
@Nullable private final Class<? extends C> senderType;
|
@Nullable private final Class<? extends C> senderType;
|
||||||
@Nonnull private final String commandPermission;
|
@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,
|
private Builder(@Nullable final CommandManager<C, M> commandManager,
|
||||||
@Nonnull final M commandMeta,
|
@Nonnull final M commandMeta,
|
||||||
@Nullable final Class<? extends C> senderType,
|
@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 CommandExecutionHandler<C> commandExecutionHandler,
|
||||||
@Nonnull final String commandPermission) {
|
@Nonnull final String commandPermission) {
|
||||||
this.commandManager = commandManager;
|
this.commandManager = commandManager;
|
||||||
this.senderType = senderType;
|
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.commandExecutionHandler = Objects.requireNonNull(commandExecutionHandler, "Execution handler may not be null");
|
||||||
this.commandPermission = Objects.requireNonNull(commandPermission, "Permission may not be null");
|
this.commandPermission = Objects.requireNonNull(commandPermission, "Permission may not be null");
|
||||||
this.commandMeta = Objects.requireNonNull(commandMeta, "Meta 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
|
* 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
|
* is optional
|
||||||
*
|
*
|
||||||
* @param commandManager Command manager
|
* @param commandManager Command manager
|
||||||
|
|
@ -250,44 +250,44 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Builder<C, M> manager(@Nullable final CommandManager<C, M> commandManager) {
|
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);
|
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 argument Argument to add
|
||||||
* @param <T> Component type
|
* @param <T> Argument type
|
||||||
* @return New builder instance with the command component inserted into the component list
|
* @return New builder instance with the command argument inserted into the argument list
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public <T> Builder<C, M> component(@Nonnull final CommandComponent<C, T> component) {
|
public <T> Builder<C, M> argument(@Nonnull final CommandArgument<C, T> argument) {
|
||||||
final List<CommandComponent<C, ?>> commandComponents = new LinkedList<>(this.commandComponents);
|
final List<CommandArgument<C, ?>> commandArguments = new LinkedList<>(this.commandArguments);
|
||||||
commandComponents.add(component);
|
commandArguments.add(argument);
|
||||||
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, commandComponents,
|
return new Builder<>(this.commandManager, this.commandMeta, this.senderType, commandArguments,
|
||||||
this.commandExecutionHandler, this.commandPermission);
|
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 clazz Argument class
|
||||||
* @param name Component name
|
* @param name Argument name
|
||||||
* @param builderConsumer Builder consumer
|
* @param builderConsumer Builder consumer
|
||||||
* @param <T> Component type
|
* @param <T> Argument type
|
||||||
* @return New builder instance with the command component inserted into the component list
|
* @return New builder instance with the command argument inserted into the argument list
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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 String name,
|
||||||
@Nonnull final Consumer<CommandComponent.Builder<C, T>> builderConsumer) {
|
@Nonnull final Consumer<CommandArgument.Builder<C, T>> builderConsumer) {
|
||||||
final CommandComponent.Builder<C, T> builder = CommandComponent.ofType(clazz, name);
|
final CommandArgument.Builder<C, T> builder = CommandArgument.ofType(clazz, name);
|
||||||
if (this.commandManager != null) {
|
if (this.commandManager != null) {
|
||||||
builder.manager(this.commandManager);
|
builder.manager(this.commandManager);
|
||||||
}
|
}
|
||||||
builderConsumer.accept(builder);
|
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
|
@Nonnull
|
||||||
public Builder<C, M> handler(@Nonnull final CommandExecutionHandler<C> commandExecutionHandler) {
|
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);
|
commandExecutionHandler, this.commandPermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -310,7 +310,7 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Builder<C, M> withSenderType(@Nonnull final Class<? extends C> senderType) {
|
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);
|
this.commandExecutionHandler, this.commandPermission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,7 +322,7 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Builder<C, M> withPermission(@Nonnull final String permission) {
|
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);
|
this.commandExecutionHandler, permission);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -333,7 +333,7 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Command<C, M> build() {
|
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);
|
this.commandExecutionHandler, this.senderType, this.commandPermission, this.commandMeta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,11 @@
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.CommandSyntaxFormatter;
|
import com.intellectualsites.commands.arguments.CommandSyntaxFormatter;
|
||||||
import com.intellectualsites.commands.components.StandardCommandSyntaxFormatter;
|
import com.intellectualsites.commands.arguments.StandardCommandSyntaxFormatter;
|
||||||
import com.intellectualsites.commands.components.parser.ParserRegistry;
|
import com.intellectualsites.commands.arguments.parser.ParserRegistry;
|
||||||
import com.intellectualsites.commands.components.parser.StandardParserRegistry;
|
import com.intellectualsites.commands.arguments.parser.StandardParserRegistry;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.context.CommandContextFactory;
|
import com.intellectualsites.commands.context.CommandContextFactory;
|
||||||
import com.intellectualsites.commands.context.StandardCommandContextFactory;
|
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 type Argument type
|
||||||
* @param name Component name
|
* @param name Argument name
|
||||||
* @param <T> Generic component name
|
* @param <T> Generic argument name
|
||||||
* @return Component builder
|
* @return Argument builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public <T> CommandComponent.Builder<C, T> componentBuilder(@Nonnull final Class<T> type, @Nonnull final String name) {
|
public <T> CommandArgument.Builder<C, T> argumentBuilder(@Nonnull final Class<T> type, @Nonnull final String name) {
|
||||||
return CommandComponent.<C, T>ofType(type, name).manager(this);
|
return CommandArgument.<C, T>ofType(type, name).manager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -23,12 +23,12 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.StaticComponent;
|
import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.AmbiguousNodeException;
|
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.InvalidCommandSenderException;
|
||||||
import com.intellectualsites.commands.exceptions.InvalidSyntaxException;
|
import com.intellectualsites.commands.exceptions.InvalidSyntaxException;
|
||||||
import com.intellectualsites.commands.exceptions.NoCommandInLeafException;
|
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 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 CommandManager<C, M> commandManager;
|
||||||
private final CommandRegistrationHandler<M> commandRegistrationHandler;
|
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,
|
private Optional<Command<C, M>> parseCommand(@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> commandQueue,
|
@Nonnull final Queue<String> commandQueue,
|
||||||
@Nonnull final Node<CommandComponent<C, ?>> root) {
|
@Nonnull final Node<CommandArgument<C, ?>> root) {
|
||||||
String permission = this.isPermitted(commandContext.getSender(), root);
|
String permission = this.isPermitted(commandContext.getSender(), root);
|
||||||
if (permission != null) {
|
if (permission != null) {
|
||||||
throw new NoPermissionException(permission, commandContext.getSender(), this.getChain(root)
|
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;
|
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()) {
|
if (root.children.isEmpty()) {
|
||||||
/* We are at the bottom. Check if there's a command attached, in which case we're done */
|
/* 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) {
|
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()
|
throw new InvalidSyntaxException(this.commandManager.getCommandSyntaxFormatter()
|
||||||
.apply(root.getValue()
|
.apply(root.getValue()
|
||||||
.getOwningCommand()
|
.getOwningCommand()
|
||||||
.getComponents()),
|
.getArguments()),
|
||||||
commandContext.getSender(), this.getChain(root)
|
commandContext.getSender(), this.getChain(root)
|
||||||
.stream()
|
.stream()
|
||||||
.map(Node::getValue)
|
.map(Node::getValue)
|
||||||
|
|
@ -151,19 +151,19 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
.apply(Objects.requireNonNull(
|
.apply(Objects.requireNonNull(
|
||||||
Objects.requireNonNull(root.getValue())
|
Objects.requireNonNull(root.getValue())
|
||||||
.getOwningCommand())
|
.getOwningCommand())
|
||||||
.getComponents()),
|
.getArguments()),
|
||||||
commandContext.getSender(), this.getChain(root)
|
commandContext.getSender(), this.getChain(root)
|
||||||
.stream()
|
.stream()
|
||||||
.map(Node::getValue)
|
.map(Node::getValue)
|
||||||
.collect(Collectors.toList()));
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final Iterator<Node<CommandComponent<C, ?>>> childIterator = root.getChildren().iterator();
|
final Iterator<Node<CommandArgument<C, ?>>> childIterator = root.getChildren().iterator();
|
||||||
if (childIterator.hasNext()) {
|
if (childIterator.hasNext()) {
|
||||||
while (childIterator.hasNext()) {
|
while (childIterator.hasNext()) {
|
||||||
final Node<CommandComponent<C, ?>> child = childIterator.next();
|
final Node<CommandArgument<C, ?>> child = childIterator.next();
|
||||||
if (child.getValue() != null) {
|
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()) {
|
if (result.getParsedValue().isPresent()) {
|
||||||
return this.parseCommand(commandContext, commandQueue, child);
|
return this.parseCommand(commandContext, commandQueue, child);
|
||||||
} /*else if (result.getFailure().isPresent() && root.children.size() == 1) {
|
} /*else if (result.getFailure().isPresent() && root.children.size() == 1) {
|
||||||
|
|
@ -180,13 +180,13 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Optional<Command<C, M>> attemptParseUnambiguousChild(@Nonnull final CommandContext<C> commandContext,
|
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) {
|
@Nonnull final Queue<String> commandQueue) {
|
||||||
String permission;
|
String permission;
|
||||||
final List<Node<CommandComponent<C, ?>>> children = root.getChildren();
|
final List<Node<CommandArgument<C, ?>>> children = root.getChildren();
|
||||||
if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticComponent)) {
|
if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticArgument)) {
|
||||||
// The value has to be a variable
|
// 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);
|
permission = this.isPermitted(commandContext.getSender(), child);
|
||||||
if (permission != null) {
|
if (permission != null) {
|
||||||
throw new NoPermissionException(permission, commandContext.getSender(), this.getChain(child)
|
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()
|
throw new InvalidSyntaxException(this.commandManager.getCommandSyntaxFormatter()
|
||||||
.apply(Objects.requireNonNull(
|
.apply(Objects.requireNonNull(
|
||||||
child.getValue().getOwningCommand())
|
child.getValue().getOwningCommand())
|
||||||
.getComponents()),
|
.getArguments()),
|
||||||
commandContext.getSender(), this.getChain(root)
|
commandContext.getSender(), this.getChain(root)
|
||||||
.stream()
|
.stream()
|
||||||
.map(Node::getValue)
|
.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()) {
|
if (result.getParsedValue().isPresent()) {
|
||||||
commandContext.store(child.getValue().getName(), result.getParsedValue().get());
|
commandContext.store(child.getValue().getName(), result.getParsedValue().get());
|
||||||
if (child.isLeaf()) {
|
if (child.isLeaf()) {
|
||||||
|
|
@ -230,7 +230,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
throw new InvalidSyntaxException(this.commandManager.getCommandSyntaxFormatter()
|
throw new InvalidSyntaxException(this.commandManager.getCommandSyntaxFormatter()
|
||||||
.apply(Objects.requireNonNull(child.getValue()
|
.apply(Objects.requireNonNull(child.getValue()
|
||||||
.getOwningCommand())
|
.getOwningCommand())
|
||||||
.getComponents()),
|
.getArguments()),
|
||||||
commandContext.getSender(), this.getChain(root)
|
commandContext.getSender(), this.getChain(root)
|
||||||
.stream()
|
.stream()
|
||||||
.map(Node::getValue)
|
.map(Node::getValue)
|
||||||
|
|
@ -241,7 +241,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
return this.parseCommand(commandContext, commandQueue, child);
|
return this.parseCommand(commandContext, commandQueue, child);
|
||||||
}
|
}
|
||||||
} else if (result.getFailure().isPresent()) {
|
} else if (result.getFailure().isPresent()) {
|
||||||
throw new ComponentParseException(result.getFailure().get(), commandContext.getSender(),
|
throw new ArgumentParseException(result.getFailure().get(), commandContext.getSender(),
|
||||||
this.getChain(child)
|
this.getChain(child)
|
||||||
.stream()
|
.stream()
|
||||||
.map(Node::getValue)
|
.map(Node::getValue)
|
||||||
|
|
@ -268,16 +268,16 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
private List<String> getSuggestions(@Nonnull final CommandContext<C> commandContext,
|
private List<String> getSuggestions(@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> commandQueue,
|
@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 the sender isn't allowed to access the root node, no suggestions are needed */
|
||||||
if (this.isPermitted(commandContext.getSender(), root) != null) {
|
if (this.isPermitted(commandContext.getSender(), root) != null) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
final List<Node<CommandComponent<C, ?>>> children = root.getChildren();
|
final List<Node<CommandArgument<C, ?>>> children = root.getChildren();
|
||||||
if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticComponent)) {
|
if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticArgument)) {
|
||||||
// The value has to be a variable
|
// 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 (child.getValue() != null) {
|
||||||
if (commandQueue.isEmpty()) {
|
if (commandQueue.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
|
@ -287,7 +287,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
} else if (child.isLeaf()) {
|
} else if (child.isLeaf()) {
|
||||||
return Collections.emptyList();
|
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()) {
|
if (result.getParsedValue().isPresent()) {
|
||||||
commandContext.store(child.getValue().getName(), result.getParsedValue().get());
|
commandContext.store(child.getValue().getName(), result.getParsedValue().get());
|
||||||
return this.getSuggestions(commandContext, commandQueue, child);
|
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()) {
|
if (children.isEmpty() || commandQueue.isEmpty()) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
} else {
|
} else {
|
||||||
final Iterator<Node<CommandComponent<C, ?>>> childIterator = root.getChildren().iterator();
|
final Iterator<Node<CommandArgument<C, ?>>> childIterator = root.getChildren().iterator();
|
||||||
if (childIterator.hasNext()) {
|
if (childIterator.hasNext()) {
|
||||||
while (childIterator.hasNext()) {
|
while (childIterator.hasNext()) {
|
||||||
final Node<CommandComponent<C, ?>> child = childIterator.next();
|
final Node<CommandArgument<C, ?>> child = childIterator.next();
|
||||||
if (child.getValue() != null) {
|
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()) {
|
if (result.getParsedValue().isPresent()) {
|
||||||
return this.getSuggestions(commandContext, commandQueue, child);
|
return this.getSuggestions(commandContext, commandQueue, child);
|
||||||
} /* else if (result.getFailure().isPresent() && root.children.size() == 1) {
|
} /* 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<>();
|
final List<String> suggestions = new LinkedList<>();
|
||||||
for (final Node<CommandComponent<C, ?>> component : root.getChildren()) {
|
for (final Node<CommandArgument<C, ?>> argument : root.getChildren()) {
|
||||||
if (component.getValue() == null || this.isPermitted(commandContext.getSender(), component) != null) {
|
if (argument.getValue() == null || this.isPermitted(commandContext.getSender(), argument) != null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
suggestions.addAll(
|
suggestions.addAll(
|
||||||
component.getValue().getParser().suggestions(commandContext, stringOrEmpty(commandQueue.peek())));
|
argument.getValue().getParser().suggestions(commandContext, stringOrEmpty(commandQueue.peek())));
|
||||||
}
|
}
|
||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
@ -341,14 +341,14 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void insertCommand(@Nonnull final Command<C, M> command) {
|
public void insertCommand(@Nonnull final Command<C, M> command) {
|
||||||
synchronized (this.commandLock) {
|
synchronized (this.commandLock) {
|
||||||
Node<CommandComponent<C, ?>> node = this.internalTree;
|
Node<CommandArgument<C, ?>> node = this.internalTree;
|
||||||
for (final CommandComponent<C, ?> component : command.getComponents()) {
|
for (final CommandArgument<C, ?> argument : command.getArguments()) {
|
||||||
Node<CommandComponent<C, ?>> tempNode = node.getChild(component);
|
Node<CommandArgument<C, ?>> tempNode = node.getChild(argument);
|
||||||
if (tempNode == null) {
|
if (tempNode == null) {
|
||||||
tempNode = node.addChild(component);
|
tempNode = node.addChild(argument);
|
||||||
} else if (component instanceof StaticComponent && tempNode.getValue() != null) {
|
} else if (argument instanceof StaticArgument && tempNode.getValue() != null) {
|
||||||
for (final String alias : ((StaticComponent<C>) component).getAliases()) {
|
for (final String alias : ((StaticArgument<C>) argument).getAliases()) {
|
||||||
((StaticComponent<C>) tempNode.getValue()).registerAlias(alias);
|
((StaticArgument<C>) tempNode.getValue()).registerAlias(alias);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (node.children.size() > 0) {
|
if (node.children.size() > 0) {
|
||||||
|
|
@ -366,7 +366,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@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");
|
final String permission = node.nodeMeta.get("permission");
|
||||||
if (permission != null) {
|
if (permission != null) {
|
||||||
return sender.hasPermission(permission) ? null : permission;
|
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
|
chain to execute, and so we allow them to execute the root
|
||||||
*/
|
*/
|
||||||
final List<String> missingPermissions = new LinkedList<>();
|
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);
|
final String check = this.isPermitted(sender, child);
|
||||||
if (check == null) {
|
if (check == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -399,9 +399,9 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
*/
|
*/
|
||||||
public void verifyAndRegister() {
|
public void verifyAndRegister() {
|
||||||
// All top level commands are supposed to be registered in the command manager
|
// All top level commands are supposed to be registered in the command manager
|
||||||
this.internalTree.children.stream().map(Node::getValue).forEach(commandComponent -> {
|
this.internalTree.children.stream().map(Node::getValue).forEach(commandArgument -> {
|
||||||
if (!(commandComponent instanceof StaticComponent)) {
|
if (!(commandArgument instanceof StaticArgument)) {
|
||||||
throw new IllegalStateException("Top level command component cannot be a variable");
|
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
|
// noinspection all
|
||||||
node.nodeMeta.put("permission", node.getValue().getOwningCommand().getCommandPermission());
|
node.nodeMeta.put("permission", node.getValue().getOwningCommand().getCommandPermission());
|
||||||
// Get chain and order it tail->head then skip the tail (leaf node)
|
// 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);
|
Collections.reverse(chain);
|
||||||
chain = chain.subList(1, chain.size());
|
chain = chain.subList(1, chain.size());
|
||||||
// Go through all nodes from the tail upwards until a collision occurs
|
// Go through all nodes from the tail upwards until a collision occurs
|
||||||
for (final Node<CommandComponent<C, ?>> commandComponentNode : chain) {
|
for (final Node<CommandArgument<C, ?>> commandArgumentNode : chain) {
|
||||||
if (commandComponentNode.nodeMeta.containsKey("permission") && !commandComponentNode.nodeMeta.get("permission")
|
if (commandArgumentNode.nodeMeta.containsKey("permission") && !commandArgumentNode.nodeMeta.get("permission")
|
||||||
.equalsIgnoreCase(
|
.equalsIgnoreCase(
|
||||||
node.nodeMeta
|
node.nodeMeta
|
||||||
.get("permission"))) {
|
.get("permission"))) {
|
||||||
commandComponentNode.nodeMeta.put("permission", "");
|
commandArgumentNode.nodeMeta.put("permission", "");
|
||||||
} else {
|
} 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()) {
|
if (node.isLeaf()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int size = node.children.size();
|
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) {
|
if (child.getValue() != null && !child.getValue().isRequired() && size > 1) {
|
||||||
throw new AmbiguousNodeException(node.getValue(),
|
throw new AmbiguousNodeException(node.getValue(),
|
||||||
child.getValue(),
|
child.getValue(),
|
||||||
|
|
@ -456,8 +456,8 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
node.children.forEach(this::checkAmbiguity);
|
node.children.forEach(this::checkAmbiguity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Node<CommandComponent<C, ?>>> getLeavesRaw(@Nonnull final Node<CommandComponent<C, ?>> node) {
|
private List<Node<CommandArgument<C, ?>>> getLeavesRaw(@Nonnull final Node<CommandArgument<C, ?>> node) {
|
||||||
final List<Node<CommandComponent<C, ?>>> leaves = new LinkedList<>();
|
final List<Node<CommandArgument<C, ?>>> leaves = new LinkedList<>();
|
||||||
if (node.isLeaf()) {
|
if (node.isLeaf()) {
|
||||||
if (node.getValue() != null) {
|
if (node.getValue() != null) {
|
||||||
leaves.add(node);
|
leaves.add(node);
|
||||||
|
|
@ -468,8 +468,8 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
return leaves;
|
return leaves;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CommandComponent<C, ?>> getLeaves(@Nonnull final Node<CommandComponent<C, ?>> node) {
|
private List<CommandArgument<C, ?>> getLeaves(@Nonnull final Node<CommandArgument<C, ?>> node) {
|
||||||
final List<CommandComponent<C, ?>> leaves = new LinkedList<>();
|
final List<CommandArgument<C, ?>> leaves = new LinkedList<>();
|
||||||
if (node.isLeaf()) {
|
if (node.isLeaf()) {
|
||||||
if (node.getValue() != null) {
|
if (node.getValue() != null) {
|
||||||
leaves.add(node.getValue());
|
leaves.add(node.getValue());
|
||||||
|
|
@ -480,9 +480,9 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
return leaves;
|
return leaves;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Node<CommandComponent<C, ?>>> getChain(@Nullable final Node<CommandComponent<C, ?>> end) {
|
private List<Node<CommandArgument<C, ?>>> getChain(@Nullable final Node<CommandArgument<C, ?>> end) {
|
||||||
final List<Node<CommandComponent<C, ?>>> chain = new LinkedList<>();
|
final List<Node<CommandArgument<C, ?>>> chain = new LinkedList<>();
|
||||||
Node<CommandComponent<C, ?>> tail = end;
|
Node<CommandArgument<C, ?>> tail = end;
|
||||||
while (tail != null) {
|
while (tail != null) {
|
||||||
chain.add(tail);
|
chain.add(tail);
|
||||||
tail = tail.getParent();
|
tail = tail.getParent();
|
||||||
|
|
@ -507,7 +507,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
* @return Root nodes
|
* @return Root nodes
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Collection<Node<CommandComponent<C, ?>>> getRootNodes() {
|
public Collection<Node<CommandArgument<C, ?>>> getRootNodes() {
|
||||||
return this.internalTree.getChildren();
|
return this.internalTree.getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -518,7 +518,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
* @return Root node, or {@code null}
|
* @return Root node, or {@code null}
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@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
|
return this.getRootNodes().stream().filter(node -> node.getValue() != null
|
||||||
&& node.getValue().getName().equalsIgnoreCase(name)).findAny().orElse(null);
|
&& node.getValue().getName().equalsIgnoreCase(name)).findAny().orElse(null);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ import java.lang.annotation.Target;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to specify min and max values of numerical
|
* 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)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.PARAMETER)
|
@Target(ElementType.PARAMETER)
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard annotations used to match {@link com.intellectualsites.commands.components.parser.ComponentParser}
|
* Standard annotations used to match {@link com.intellectualsites.commands.arguments.parser.ArgumentParser}
|
||||||
* in {@link com.intellectualsites.commands.components.parser.ParserRegistry}
|
* in {@link com.intellectualsites.commands.arguments.parser.ParserRegistry}
|
||||||
*/
|
*/
|
||||||
package com.intellectualsites.commands.annotations.specifier;
|
package com.intellectualsites.commands.annotations.specifier;
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,14 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components;
|
package com.intellectualsites.commands.arguments;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.intellectualsites.commands.Command;
|
import com.intellectualsites.commands.Command;
|
||||||
import com.intellectualsites.commands.CommandManager;
|
import com.intellectualsites.commands.CommandManager;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.components.parser.ParserParameters;
|
import com.intellectualsites.commands.arguments.parser.ParserParameters;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
@ -37,29 +37,29 @@ import java.util.Objects;
|
||||||
import java.util.regex.Pattern;
|
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 <C> Command sender type
|
||||||
* @param <T> The type that the component parses into
|
* @param <T> The type that the argument parses into
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@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]+");
|
private static final Pattern NAME_PATTERN = Pattern.compile("[A-Za-z0-9]+");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates whether or not the component is required
|
* Indicates whether or not the argument is required
|
||||||
* or not. All components prior to any other required
|
* or not. All arguments prior to any other required
|
||||||
* component must also be required, such that the predicate
|
* argument must also be required, such that the predicate
|
||||||
* (∀ c_i ∈ required)({c_0, ..., c_i-1} ⊂ required) holds true,
|
* (∀ 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;
|
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.
|
* to command senders and so should be chosen carefully.
|
||||||
*/
|
*/
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
@ -67,30 +67,30 @@ public class CommandComponent<C extends CommandSender, T> implements Comparable<
|
||||||
* The parser that is used to parse the command input
|
* The parser that is used to parse the command input
|
||||||
* into the corresponding command type
|
* 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
|
* Default value, will be empty if none was supplied
|
||||||
*/
|
*/
|
||||||
private final String defaultValue;
|
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 final Class<T> valueType;
|
||||||
|
|
||||||
private Command<C, ?> owningCommand;
|
private Command<C, ?> owningCommand;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new command component
|
* Construct a new command argument
|
||||||
*
|
*
|
||||||
* @param required Whether or not the component is required
|
* @param required Whether or not the argument is required
|
||||||
* @param name The component name
|
* @param name The argument name
|
||||||
* @param parser The component parser
|
* @param parser The argument parser
|
||||||
* @param defaultValue Default value used when no value is provided by the command sender
|
* @param defaultValue Default value used when no value is provided by the command sender
|
||||||
* @param valueType Type produced by the parser
|
* @param valueType Type produced by the parser
|
||||||
*/
|
*/
|
||||||
public CommandComponent(final boolean required,
|
public CommandArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@Nonnull final String name,
|
||||||
@Nonnull final ComponentParser<C, T> parser,
|
@Nonnull final ArgumentParser<C, T> parser,
|
||||||
@Nonnull final String defaultValue,
|
@Nonnull final String defaultValue,
|
||||||
@Nonnull final Class<T> valueType) {
|
@Nonnull final Class<T> valueType) {
|
||||||
this.required = required;
|
this.required = required;
|
||||||
|
|
@ -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 required Whether or not the argument is required
|
||||||
* @param name The component name
|
* @param name The argument name
|
||||||
* @param parser The component parser
|
* @param parser The argument parser
|
||||||
* @param valueType Type produced by the parser
|
* @param valueType Type produced by the parser
|
||||||
*/
|
*/
|
||||||
public CommandComponent(final boolean required,
|
public CommandArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@Nonnull final String name,
|
||||||
@Nonnull final ComponentParser<C, T> parser,
|
@Nonnull final ArgumentParser<C, T> parser,
|
||||||
@Nonnull final Class<T> valueType) {
|
@Nonnull final Class<T> valueType) {
|
||||||
this(required, name, parser, "", valueType);
|
this(required, name, parser, "", valueType);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command component
|
* Create a new command argument
|
||||||
*
|
*
|
||||||
* @param clazz Argument class
|
* @param clazz Argument class
|
||||||
* @param name Component name
|
* @param name Argument name
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <T> Argument Type. Used to make the compiler happy.
|
* @param <T> Argument Type. Used to make the compiler happy.
|
||||||
* @return Component builder
|
* @return Argument builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender, T> CommandComponent.Builder<C, T> ofType(@Nonnull final Class<T> clazz,
|
public static <C extends CommandSender, T> CommandArgument.Builder<C, T> ofType(@Nonnull final Class<T> clazz,
|
||||||
@Nonnull final String name) {
|
@Nonnull final String name) {
|
||||||
return new Builder<>(clazz, 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() {
|
public boolean isRequired() {
|
||||||
return this.required;
|
return this.required;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the command component name;
|
* Get the command argument name;
|
||||||
*
|
*
|
||||||
* @return Component name
|
* @return Argument name
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public String getName() {
|
public String getName() {
|
||||||
|
|
@ -159,14 +159,14 @@ public class CommandComponent<C extends CommandSender, T> implements Comparable<
|
||||||
* @return Command parser
|
* @return Command parser
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public ComponentParser<C, T> getParser() {
|
public ArgumentParser<C, T> getParser() {
|
||||||
return this.parser;
|
return this.parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public final String toString() {
|
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()) {
|
if (o == null || getClass() != o.getClass()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final CommandComponent<?, ?> that = (CommandComponent<?, ?>) o;
|
final CommandArgument<?, ?> that = (CommandArgument<?, ?>) o;
|
||||||
return isRequired() == that.isRequired() && Objects.equals(getName(), that.getName());
|
return isRequired() == that.isRequired() && Objects.equals(getName(), that.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -209,15 +209,15 @@ public class CommandComponent<C extends CommandSender, T> implements Comparable<
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int compareTo(@Nonnull final CommandComponent<?, ?> o) {
|
public final int compareTo(@Nonnull final CommandArgument<?, ?> o) {
|
||||||
if (this instanceof StaticComponent) {
|
if (this instanceof StaticArgument) {
|
||||||
if (o instanceof StaticComponent) {
|
if (o instanceof StaticArgument) {
|
||||||
return (this.getName().compareTo(o.getName()));
|
return (this.getName().compareTo(o.getName()));
|
||||||
} else {
|
} else {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (o instanceof StaticComponent) {
|
if (o instanceof StaticArgument) {
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
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() {
|
public boolean hasDefaultValue() {
|
||||||
return !this.isRequired()
|
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
|
* @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 <C> Command sender type
|
||||||
* @param <T> Component value type
|
* @param <T> Argument value type
|
||||||
*/
|
*/
|
||||||
public static class Builder<C extends CommandSender, T> {
|
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 CommandManager<C, ?> manager;
|
||||||
private boolean required = true;
|
private boolean required = true;
|
||||||
private ComponentParser<C, T> parser;
|
private ArgumentParser<C, T> parser;
|
||||||
private String defaultValue = "";
|
private String defaultValue = "";
|
||||||
|
|
||||||
protected Builder(@Nonnull final Class<T> valueType,
|
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.
|
* Indicates that the argument is required.
|
||||||
* All components prior to any other required
|
* All arguments prior to any other required
|
||||||
* component must also be required, such that the predicate
|
* argument must also be required, such that the predicate
|
||||||
* (∀ c_i ∈ required)({c_0, ..., c_i-1} ⊂ required) holds true,
|
* (∀ 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
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
|
|
@ -306,11 +306,11 @@ public class CommandComponent<C extends CommandSender, T> implements Comparable<
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that the component is optional.
|
* Indicates that the argument is optional.
|
||||||
* All components prior to any other required
|
* All arguments prior to any other required
|
||||||
* component must also be required, such that the predicate
|
* argument must also be required, such that the predicate
|
||||||
* (∀ c_i ∈ required)({c_0, ..., c_i-1} ⊂ required) holds true,
|
* (∀ 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
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
|
|
@ -321,11 +321,11 @@ public class CommandComponent<C extends CommandSender, T> implements Comparable<
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Indicates that the component is optional.
|
* Indicates that the argument is optional.
|
||||||
* All components prior to any other required
|
* All arguments prior to any other required
|
||||||
* component must also be required, such that the predicate
|
* argument must also be required, such that the predicate
|
||||||
* (∀ c_i ∈ required)({c_0, ..., c_i-1} ⊂ required) holds true,
|
* (∀ 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
|
* @param defaultValue Default value that will be used if none was supplied
|
||||||
* @return Builder instance
|
* @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
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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");
|
this.parser = Objects.requireNonNull(parser, "Parser may not be null");
|
||||||
return this;
|
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
|
@Nonnull
|
||||||
public CommandComponent<C, T> build() {
|
public CommandArgument<C, T> build() {
|
||||||
if (this.parser == null && this.manager != null) {
|
if (this.parser == null && this.manager != null) {
|
||||||
this.parser = this.manager.getParserRegistry().createParser(TypeToken.of(valueType), ParserParameters.empty())
|
this.parser = this.manager.getParserRegistry().createParser(TypeToken.of(valueType), ParserParameters.empty())
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
}
|
}
|
||||||
if (this.parser == null) {
|
if (this.parser == null) {
|
||||||
this.parser = (c, i) -> ComponentParseResult
|
this.parser = (c, i) -> ArgumentParseResult
|
||||||
.failure(new UnsupportedOperationException("No parser was specified"));
|
.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
|
@Nonnull
|
||||||
|
|
@ -377,7 +377,7 @@ public class CommandComponent<C extends CommandSender, T> implements Comparable<
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
protected final ComponentParser<C, T> getParser() {
|
protected final ArgumentParser<C, T> getParser() {
|
||||||
return this.parser;
|
return this.parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components;
|
package com.intellectualsites.commands.arguments;
|
||||||
|
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
|
|
@ -30,15 +30,15 @@ import java.util.List;
|
||||||
import java.util.function.Function;
|
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
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@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
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
String apply(@Nonnull List<CommandComponent<C, ?>> commandComponents);
|
String apply(@Nonnull List<CommandArgument<C, ?>> commandArguments);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components;
|
package com.intellectualsites.commands.arguments;
|
||||||
|
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
|
|
@ -32,9 +32,9 @@ import java.util.List;
|
||||||
/**
|
/**
|
||||||
* {@link CommandSyntaxFormatter} implementation that uses the following rules:
|
* {@link CommandSyntaxFormatter} implementation that uses the following rules:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>static components are serialized as their name, without a bracket</li>
|
* <li>static arguments are serialized as their name, without a bracket</li>
|
||||||
* <li>required components are serialized as their name, surrounded by angle brackets</li>
|
* <li>required arguments are serialized as their name, surrounded by angle brackets</li>
|
||||||
* <li>optional components are serialized as their name, surrounded by square brackets</li>
|
* <li>optional arguments are serialized as their name, surrounded by square brackets</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
|
|
@ -43,18 +43,18 @@ public class StandardCommandSyntaxFormatter<C extends CommandSender> implements
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@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 StringBuilder stringBuilder = new StringBuilder();
|
||||||
final Iterator<CommandComponent<C, ?>> iterator = commandComponents.iterator();
|
final Iterator<CommandArgument<C, ?>> iterator = commandArguments.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
final CommandComponent<?, ?> commandComponent = iterator.next();
|
final CommandArgument<?, ?> commandArgument = iterator.next();
|
||||||
if (commandComponent instanceof StaticComponent) {
|
if (commandArgument instanceof StaticArgument) {
|
||||||
stringBuilder.append(commandComponent.getName());
|
stringBuilder.append(commandArgument.getName());
|
||||||
} else {
|
} else {
|
||||||
if (commandComponent.isRequired()) {
|
if (commandArgument.isRequired()) {
|
||||||
stringBuilder.append("<").append(commandComponent.getName()).append(">");
|
stringBuilder.append("<").append(commandArgument.getName()).append(">");
|
||||||
} else {
|
} else {
|
||||||
stringBuilder.append("[").append(commandComponent.getName()).append("]");
|
stringBuilder.append("[").append(commandArgument.getName()).append("]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
|
|
@ -21,10 +21,10 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components;
|
package com.intellectualsites.commands.arguments;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
|
|
@ -37,42 +37,42 @@ import java.util.Queue;
|
||||||
import java.util.Set;
|
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
|
* @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) {
|
private StaticArgument(final boolean required, @Nonnull final String name, @Nonnull final String... aliases) {
|
||||||
super(required, name, new StaticComponentParser<>(name, aliases), String.class);
|
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 name Argument name
|
||||||
* @param aliases Component aliases
|
* @param aliases Argument aliases
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Constructed component
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> StaticComponent<C> required(@Nonnull final String name,
|
public static <C extends CommandSender> StaticArgument<C> required(@Nonnull final String name,
|
||||||
@Nonnull final String... aliases) {
|
@Nonnull final String... aliases) {
|
||||||
return new StaticComponent<>(true, name, 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 name Argument name
|
||||||
* @param aliases Component aliases
|
* @param aliases Argument aliases
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Constructed component
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> StaticComponent<C> optional(@Nonnull final String name,
|
public static <C extends CommandSender> StaticArgument<C> optional(@Nonnull final String name,
|
||||||
@Nonnull final String... aliases) {
|
@Nonnull final String... aliases) {
|
||||||
return new StaticComponent<>(false, name, aliases);
|
return new StaticArgument<>(false, name, aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -81,26 +81,26 @@ public final class StaticComponent<C extends CommandSender> extends CommandCompo
|
||||||
* @param alias New alias
|
* @param alias New alias
|
||||||
*/
|
*/
|
||||||
public void registerAlias(@Nonnull final String 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
|
* Get an immutable view of the aliases
|
||||||
*
|
*
|
||||||
* @return Immutable view of the component aliases
|
* @return Immutable view of the argument aliases
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public Set<String> getAliases() {
|
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 String name;
|
||||||
private final Set<String> acceptedStrings = new HashSet<>();
|
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.name = name;
|
||||||
this.acceptedStrings.add(this.name);
|
this.acceptedStrings.add(this.name);
|
||||||
this.acceptedStrings.addAll(Arrays.asList(aliases));
|
this.acceptedStrings.addAll(Arrays.asList(aliases));
|
||||||
|
|
@ -108,20 +108,20 @@ public final class StaticComponent<C extends CommandSender> extends CommandCompo
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<String> parse(@Nonnull final CommandContext<C> commandContext,
|
public ArgumentParseResult<String> parse(@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String string = inputQueue.peek();
|
final String string = inputQueue.peek();
|
||||||
if (string == null) {
|
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) {
|
for (final String acceptedString : this.acceptedStrings) {
|
||||||
if (string.equalsIgnoreCase(acceptedString)) {
|
if (string.equalsIgnoreCase(acceptedString)) {
|
||||||
// Remove the head of the queue
|
// Remove the head of the queue
|
||||||
inputQueue.remove();
|
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
|
@Nonnull
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -21,19 +21,19 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.parser;
|
package com.intellectualsites.commands.arguments.parser;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Optional;
|
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
|
* @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
|
* @return Failed parse result
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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);
|
return new ParseFailure<>(failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,7 +56,7 @@ public abstract class ComponentParseResult<T> {
|
||||||
* @return Succeeded parse result
|
* @return Succeeded parse result
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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);
|
return new ParseSuccess<>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -77,7 +77,7 @@ public abstract class ComponentParseResult<T> {
|
||||||
public abstract Optional<Throwable> getFailure();
|
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
|
* 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
|
* Parse failure
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.parser;
|
package com.intellectualsites.commands.arguments.parser;
|
||||||
|
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
@ -38,7 +38,7 @@ import java.util.Queue;
|
||||||
* @param <T> Value type
|
* @param <T> Value type
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ComponentParser<C extends CommandSender, T> {
|
public interface ArgumentParser<C extends CommandSender, T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse command input into a command result
|
* Parse command input into a command result
|
||||||
|
|
@ -48,7 +48,7 @@ public interface ComponentParser<C extends CommandSender, T> {
|
||||||
* @return Parsed command result
|
* @return Parsed command result
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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
|
* 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
|
* 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}
|
* @return {@code true} if the parser is context free, else {@code false}
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.parser;
|
package com.intellectualsites.commands.arguments.parser;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.parser;
|
package com.intellectualsites.commands.arguments.parser;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.parser;
|
package com.intellectualsites.commands.arguments.parser;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
@ -34,7 +34,7 @@ import java.util.function.BiFunction;
|
||||||
import java.util.function.Function;
|
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})
|
* referenced by a {@link Class} (or really, a {@link com.google.common.reflect.TypeToken})
|
||||||
* or a {@link String} key
|
* 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
|
* @param <T> Generic type specifying what is produced by the parser
|
||||||
*/
|
*/
|
||||||
<T> void registerParserSupplier(@Nonnull TypeToken<T> type,
|
<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
|
* 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);
|
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
|
* an instance of {@link ParserParameter} to configure the parser settings
|
||||||
*
|
*
|
||||||
* @param type Type that should be produced by the parser
|
* @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
|
* @return Parser, if one can be created
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
<T> Optional<ComponentParser<C, T>> createParser(@Nonnull TypeToken<T> type,
|
<T> Optional<ArgumentParser<C, T>> createParser(@Nonnull TypeToken<T> type,
|
||||||
@Nonnull ParserParameters parserParameters);
|
@Nonnull ParserParameters parserParameters);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.parser;
|
package com.intellectualsites.commands.arguments.parser;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
|
|
||||||
|
|
@ -21,20 +21,20 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.parser;
|
package com.intellectualsites.commands.arguments.parser;
|
||||||
|
|
||||||
import com.google.common.collect.ImmutableMap;
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.intellectualsites.commands.annotations.specifier.Range;
|
import com.intellectualsites.commands.annotations.specifier.Range;
|
||||||
import com.intellectualsites.commands.components.standard.BooleanComponent;
|
import com.intellectualsites.commands.arguments.standard.BooleanArgument;
|
||||||
import com.intellectualsites.commands.components.standard.ByteComponent;
|
import com.intellectualsites.commands.arguments.standard.ByteArgument;
|
||||||
import com.intellectualsites.commands.components.standard.CharComponent;
|
import com.intellectualsites.commands.arguments.standard.CharArgument;
|
||||||
import com.intellectualsites.commands.components.standard.DoubleComponent;
|
import com.intellectualsites.commands.arguments.standard.DoubleArgument;
|
||||||
import com.intellectualsites.commands.components.standard.EnumComponent;
|
import com.intellectualsites.commands.arguments.standard.EnumArgument;
|
||||||
import com.intellectualsites.commands.components.standard.FloatComponent;
|
import com.intellectualsites.commands.arguments.standard.FloatArgument;
|
||||||
import com.intellectualsites.commands.components.standard.IntegerComponent;
|
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||||
import com.intellectualsites.commands.components.standard.ShortComponent;
|
import com.intellectualsites.commands.arguments.standard.ShortArgument;
|
||||||
import com.intellectualsites.commands.components.standard.StringComponent;
|
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
@ -65,7 +65,7 @@ public final class StandardParserRegistry<C extends CommandSender> implements Pa
|
||||||
.put(boolean.class, Boolean.class)
|
.put(boolean.class, Boolean.class)
|
||||||
.build();
|
.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>>
|
private final Map<Class<? extends Annotation>, BiFunction<? extends Annotation, TypeToken<?>, ParserParameters>>
|
||||||
annotationMappers = new HashMap<>();
|
annotationMappers = new HashMap<>();
|
||||||
|
|
||||||
|
|
@ -79,31 +79,31 @@ public final class StandardParserRegistry<C extends CommandSender> implements Pa
|
||||||
|
|
||||||
/* Register standard types */
|
/* Register standard types */
|
||||||
this.registerParserSupplier(TypeToken.of(Byte.class), options ->
|
this.registerParserSupplier(TypeToken.of(Byte.class), options ->
|
||||||
new ByteComponent.ByteParser<C>((byte) options.get(StandardParameters.RANGE_MIN, Byte.MIN_VALUE),
|
new ByteArgument.ByteParser<C>((byte) options.get(StandardParameters.RANGE_MIN, Byte.MIN_VALUE),
|
||||||
(byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE)));
|
(byte) options.get(StandardParameters.RANGE_MAX, Byte.MAX_VALUE)));
|
||||||
this.registerParserSupplier(TypeToken.of(Short.class), options ->
|
this.registerParserSupplier(TypeToken.of(Short.class), options ->
|
||||||
new ShortComponent.ShortParser<C>((short) options.get(StandardParameters.RANGE_MIN, Short.MIN_VALUE),
|
new ShortArgument.ShortParser<C>((short) options.get(StandardParameters.RANGE_MIN, Short.MIN_VALUE),
|
||||||
(short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE)));
|
(short) options.get(StandardParameters.RANGE_MAX, Short.MAX_VALUE)));
|
||||||
this.registerParserSupplier(TypeToken.of(Integer.class), options ->
|
this.registerParserSupplier(TypeToken.of(Integer.class), options ->
|
||||||
new IntegerComponent.IntegerParser<C>((int) options.get(StandardParameters.RANGE_MIN, Integer.MIN_VALUE),
|
new IntegerArgument.IntegerParser<C>((int) options.get(StandardParameters.RANGE_MIN, Integer.MIN_VALUE),
|
||||||
(int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE)));
|
(int) options.get(StandardParameters.RANGE_MAX, Integer.MAX_VALUE)));
|
||||||
this.registerParserSupplier(TypeToken.of(Float.class), options ->
|
this.registerParserSupplier(TypeToken.of(Float.class), options ->
|
||||||
new FloatComponent.FloatParser<C>((float) options.get(StandardParameters.RANGE_MIN, Float.MIN_VALUE),
|
new FloatArgument.FloatParser<C>((float) options.get(StandardParameters.RANGE_MIN, Float.MIN_VALUE),
|
||||||
(float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE)));
|
(float) options.get(StandardParameters.RANGE_MAX, Float.MAX_VALUE)));
|
||||||
this.registerParserSupplier(TypeToken.of(Double.class), options ->
|
this.registerParserSupplier(TypeToken.of(Double.class), options ->
|
||||||
new DoubleComponent.DoubleParser<C>((double) options.get(StandardParameters.RANGE_MIN, Double.MIN_VALUE),
|
new DoubleArgument.DoubleParser<C>((double) options.get(StandardParameters.RANGE_MIN, Double.MIN_VALUE),
|
||||||
(double) options.get(StandardParameters.RANGE_MAX, Double.MAX_VALUE)));
|
(double) options.get(StandardParameters.RANGE_MAX, Double.MAX_VALUE)));
|
||||||
this.registerParserSupplier(TypeToken.of(Character.class), options -> new CharComponent.CharacterParser<C>());
|
this.registerParserSupplier(TypeToken.of(Character.class), options -> new CharArgument.CharacterParser<C>());
|
||||||
/* Make this one less awful */
|
/* Make this one less awful */
|
||||||
this.registerParserSupplier(TypeToken.of(String.class), options -> new StringComponent.StringParser<C>(
|
this.registerParserSupplier(TypeToken.of(String.class), options -> new StringArgument.StringParser<C>(
|
||||||
StringComponent.StringMode.SINGLE, (context, s) -> Collections.emptyList()));
|
StringArgument.StringMode.SINGLE, (context, s) -> Collections.emptyList()));
|
||||||
/* Add options to this */
|
/* 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
|
@Override
|
||||||
public <T> void registerParserSupplier(@Nonnull final TypeToken<T> type,
|
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);
|
this.parserSuppliers.put(type, supplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -134,7 +134,7 @@ public final class StandardParserRegistry<C extends CommandSender> implements Pa
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<ComponentParser<C, T>> createParser(@Nonnull final TypeToken<T> type,
|
public <T> Optional<ArgumentParser<C, T>> createParser(@Nonnull final TypeToken<T> type,
|
||||||
@Nonnull final ParserParameters parserParameters) {
|
@Nonnull final ParserParameters parserParameters) {
|
||||||
final TypeToken<?> actualType;
|
final TypeToken<?> actualType;
|
||||||
if (type.isPrimitive()) {
|
if (type.isPrimitive()) {
|
||||||
|
|
@ -142,19 +142,19 @@ public final class StandardParserRegistry<C extends CommandSender> implements Pa
|
||||||
} else {
|
} else {
|
||||||
actualType = type;
|
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) {
|
if (producer == null) {
|
||||||
/* Give enums special treatment */
|
/* Give enums special treatment */
|
||||||
if (actualType.isSubtypeOf(Enum.class)) {
|
if (actualType.isSubtypeOf(Enum.class)) {
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
final EnumComponent.EnumParser enumComponent = new EnumComponent.EnumParser((Class<Enum>)
|
final EnumArgument.EnumParser enumArgument = new EnumArgument.EnumParser((Class<Enum>)
|
||||||
actualType.getRawType());
|
actualType.getRawType());
|
||||||
// noinspection all
|
// noinspection all
|
||||||
return Optional.of(enumComponent);
|
return Optional.of(enumArgument);
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
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);
|
parserParameters);
|
||||||
return Optional.of(parser);
|
return Optional.of(parser);
|
||||||
}
|
}
|
||||||
|
|
@ -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;
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.standard;
|
package com.intellectualsites.commands.arguments.standard;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
|
|
@ -35,10 +35,10 @@ import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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 final boolean liberal;
|
||||||
|
|
||||||
private BooleanComponent(final boolean required, @Nonnull final String name,
|
private BooleanArgument(final boolean required, @Nonnull final String name,
|
||||||
final boolean liberal, @Nonnull final String defaultValue) {
|
final boolean liberal, @Nonnull final String defaultValue) {
|
||||||
super(required, name, new BooleanParser<>(liberal), defaultValue, Boolean.class);
|
super(required, name, new BooleanParser<>(liberal), defaultValue, Boolean.class);
|
||||||
this.liberal = liberal;
|
this.liberal = liberal;
|
||||||
|
|
@ -47,7 +47,7 @@ public final class BooleanComponent<C extends CommandSender> extends CommandComp
|
||||||
/**
|
/**
|
||||||
* Create a new builder
|
* Create a new builder
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Boolean> required(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Boolean> required(@Nonnull final String name) {
|
||||||
return BooleanComponent.<C>newBuilder(name).asRequired().build();
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Boolean> optional(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Boolean> optional(@Nonnull final String name) {
|
||||||
return BooleanComponent.<C>newBuilder(name).asOptional().build();
|
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 defaultNum Default num
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Boolean> optional(@Nonnull final String name,
|
public static <C extends CommandSender> CommandArgument<C, Boolean> optional(@Nonnull final String name,
|
||||||
final String defaultNum) {
|
final String defaultNum) {
|
||||||
return BooleanComponent.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
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;
|
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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public BooleanComponent<C> build() {
|
public BooleanArgument<C> build() {
|
||||||
return new BooleanComponent<>(this.isRequired(), this.getName(), this.liberal, this.getDefaultValue());
|
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 = Arrays.asList("TRUE", "YES", "ON", "FALSE", "NO", "OFF");
|
||||||
private static final List<String> LIBERAL_TRUE = Arrays.asList("TRUE", "YES", "ON");
|
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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<Boolean> parse(@Nonnull final CommandContext<C> commandContext,
|
public ArgumentParseResult<Boolean> parse(@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ComponentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
}
|
}
|
||||||
inputQueue.remove();
|
inputQueue.remove();
|
||||||
|
|
||||||
if (!liberal) {
|
if (!liberal) {
|
||||||
if (input.equalsIgnoreCase("true")) {
|
if (input.equalsIgnoreCase("true")) {
|
||||||
return ComponentParseResult.success(true);
|
return ArgumentParseResult.success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (input.equalsIgnoreCase("false")) {
|
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();
|
final String uppercaseInput = input.toUpperCase();
|
||||||
|
|
||||||
if (LIBERAL_TRUE.contains(uppercaseInput)) {
|
if (LIBERAL_TRUE.contains(uppercaseInput)) {
|
||||||
return ComponentParseResult.success(true);
|
return ArgumentParseResult.success(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LIBERAL_FALSE.contains(uppercaseInput)) {
|
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
|
@Nonnull
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.standard;
|
package com.intellectualsites.commands.arguments.standard;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
@ -34,12 +34,12 @@ import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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 min;
|
||||||
private final byte max;
|
private final byte max;
|
||||||
|
|
||||||
private ByteComponent(final boolean required, @Nonnull final String name, final byte min,
|
private ByteArgument(final boolean required, @Nonnull final String name, final byte min,
|
||||||
final byte max, final String defaultValue) {
|
final byte max, final String defaultValue) {
|
||||||
super(required, name, new ByteParser<>(min, max), defaultValue, Byte.class);
|
super(required, name, new ByteParser<>(min, max), defaultValue, Byte.class);
|
||||||
this.min = min;
|
this.min = min;
|
||||||
|
|
@ -49,7 +49,7 @@ public final class ByteComponent<C extends CommandSender> extends CommandCompone
|
||||||
/**
|
/**
|
||||||
* Create a new builder
|
* Create a new builder
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Byte> required(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Byte> required(@Nonnull final String name) {
|
||||||
return ByteComponent.<C>newBuilder(name).asRequired().build();
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Byte> optional(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Byte> optional(@Nonnull final String name) {
|
||||||
return ByteComponent.<C>newBuilder(name).asOptional().build();
|
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 defaultNum Default num
|
||||||
* @param <C> Command sender type
|
* @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,
|
@Nonnull public static <C extends CommandSender> CommandArgument<C, Byte> optional(@Nonnull final String name,
|
||||||
final byte defaultNum) {
|
final byte defaultNum) {
|
||||||
return ByteComponent.<C>newBuilder(name).asOptionalWithDefault(Byte.toString(defaultNum)).build();
|
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 min = Byte.MIN_VALUE;
|
||||||
private byte max = Byte.MAX_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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ByteComponent<C> build() {
|
public ByteArgument<C> build() {
|
||||||
return new ByteComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
|
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 min;
|
||||||
private final byte max;
|
private final byte max;
|
||||||
|
|
@ -180,25 +180,25 @@ public final class ByteComponent<C extends CommandSender> extends CommandCompone
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<Byte> parse(
|
public ArgumentParseResult<Byte> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ComponentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final byte value = Byte.parseByte(input);
|
final byte value = Byte.parseByte(input);
|
||||||
if (value < this.min || value > this.max) {
|
if (value < this.min || value > this.max) {
|
||||||
return ComponentParseResult.failure(
|
return ArgumentParseResult.failure(
|
||||||
new ByteParseException(input,
|
new ByteParseException(input,
|
||||||
this.min,
|
this.min,
|
||||||
this.max));
|
this.max));
|
||||||
}
|
}
|
||||||
inputQueue.remove();
|
inputQueue.remove();
|
||||||
return ComponentParseResult.success(value);
|
return ArgumentParseResult.success(value);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return ComponentParseResult.failure(
|
return ArgumentParseResult.failure(
|
||||||
new ByteParseException(input, this.min,
|
new ByteParseException(input, this.min,
|
||||||
this.max));
|
this.max));
|
||||||
}
|
}
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.standard;
|
package com.intellectualsites.commands.arguments.standard;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
|
|
@ -33,9 +33,9 @@ import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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,
|
private CharArgument(final boolean required, @Nonnull final String name,
|
||||||
@Nonnull final String defaultValue) {
|
@Nonnull final String defaultValue) {
|
||||||
super(required, name, new CharacterParser<>(), defaultValue, Character.class);
|
super(required, name, new CharacterParser<>(), defaultValue, Character.class);
|
||||||
}
|
}
|
||||||
|
|
@ -43,90 +43,90 @@ public final class CharComponent<C extends CommandSender> extends CommandCompone
|
||||||
/**
|
/**
|
||||||
* Create a new builder
|
* Create a new builder
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CharComponent.Builder<C> newBuilder(@Nonnull final String name) {
|
public static <C extends CommandSender> CharArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
||||||
return new CharComponent.Builder<>(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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Character> required(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Character> required(@Nonnull final String name) {
|
||||||
return CharComponent.<C>newBuilder(name).asRequired().build();
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Character> optional(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Character> optional(@Nonnull final String name) {
|
||||||
return CharComponent.<C>newBuilder(name).asOptional().build();
|
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 defaultNum Default num
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Character> optional(@Nonnull final String name,
|
public static <C extends CommandSender> CommandArgument<C, Character> optional(@Nonnull final String name,
|
||||||
final String defaultNum) {
|
final String defaultNum) {
|
||||||
return CharComponent.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
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) {
|
protected Builder(@Nonnull final String name) {
|
||||||
super(Character.class, name);
|
super(Character.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builder a new char component
|
* Builder a new char argument
|
||||||
*
|
*
|
||||||
* @return Constructed component
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CharComponent<C> build() {
|
public CharArgument<C> build() {
|
||||||
return new CharComponent<>(this.isRequired(), this.getName(), this.getDefaultValue());
|
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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<Character> parse(@Nonnull final CommandContext<C> commandContext,
|
public ArgumentParseResult<Character> parse(@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
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) {
|
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
|
@Override
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.standard;
|
package com.intellectualsites.commands.arguments.standard;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
@ -34,12 +34,12 @@ import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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 min;
|
||||||
private final double max;
|
private final double max;
|
||||||
|
|
||||||
private DoubleComponent(final boolean required,
|
private DoubleArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@Nonnull final String name,
|
||||||
final double min,
|
final double min,
|
||||||
final double max,
|
final double max,
|
||||||
|
|
@ -52,7 +52,7 @@ public final class DoubleComponent<C extends CommandSender> extends CommandCompo
|
||||||
/**
|
/**
|
||||||
* Create a new builder
|
* Create a new builder
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Double> required(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Double> required(@Nonnull final String name) {
|
||||||
return DoubleComponent.<C>newBuilder(name).asRequired().build();
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Double> optional(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Double> optional(@Nonnull final String name) {
|
||||||
return DoubleComponent.<C>newBuilder(name).asOptional().build();
|
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 defaultNum Default num
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Double> optional(@Nonnull final String name,
|
public static <C extends CommandSender> CommandArgument<C, Double> optional(@Nonnull final String name,
|
||||||
final double defaultNum) {
|
final double defaultNum) {
|
||||||
return DoubleComponent.<C>newBuilder(name).asOptionalWithDefault(Double.toString(defaultNum)).build();
|
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 min = Double.MIN_VALUE;
|
||||||
private double max = Double.MAX_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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public DoubleComponent<C> build() {
|
public DoubleArgument<C> build() {
|
||||||
return new DoubleComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
|
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 min;
|
||||||
private final double max;
|
private final double max;
|
||||||
|
|
@ -184,22 +184,22 @@ public final class DoubleComponent<C extends CommandSender> extends CommandCompo
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<Double> parse(
|
public ArgumentParseResult<Double> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ComponentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final double value = Double.parseDouble(input);
|
final double value = Double.parseDouble(input);
|
||||||
if (value < this.min || value > this.max) {
|
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();
|
inputQueue.remove();
|
||||||
return ComponentParseResult.success(value);
|
return ArgumentParseResult.success(value);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return ComponentParseResult.failure(new DoubleParseException(input, this.min, this.max));
|
return ArgumentParseResult.failure(new DoubleParseException(input, this.min, this.max));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.standard;
|
package com.intellectualsites.commands.arguments.standard;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
|
|
@ -36,15 +36,15 @@ import java.util.Queue;
|
||||||
import java.util.stream.Collectors;
|
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
|
* @param <E> Enum type
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@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,
|
protected EnumArgument(@Nonnull final Class<E> enumClass,
|
||||||
final boolean required,
|
final boolean required,
|
||||||
@Nonnull final String name,
|
@Nonnull final String name,
|
||||||
@Nonnull final String defaultValue) {
|
@Nonnull final String defaultValue) {
|
||||||
|
|
@ -54,66 +54,66 @@ public class EnumComponent<C extends CommandSender, E extends Enum<E>> extends C
|
||||||
/**
|
/**
|
||||||
* Create a new builder
|
* Create a new builder
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param enumClass Enum class
|
* @param enumClass Enum class
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <E> Enum type
|
* @param <E> Enum type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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) {
|
@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 enumClass Enum class
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <E> Enum type
|
* @param <E> Enum type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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) {
|
@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 enumClass Enum class
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <E> Enum type
|
* @param <E> Enum type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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 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 enumClass Enum class
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param defaultValue Default value
|
* @param defaultValue Default value
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <E> Enum type
|
* @param <E> Enum type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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) {
|
@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;
|
private final Class<E> enumClass;
|
||||||
|
|
||||||
|
|
@ -124,13 +124,13 @@ public class EnumComponent<C extends CommandSender, E extends Enum<E>> extends C
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CommandComponent<C, E> build() {
|
public CommandArgument<C, E> build() {
|
||||||
return new EnumComponent<>(this.enumClass, this.isRequired(), this.getName(), this.getDefaultValue());
|
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 Class<E> enumClass;
|
||||||
private final EnumSet<E> allowedValues;
|
private final EnumSet<E> allowedValues;
|
||||||
|
|
@ -147,21 +147,21 @@ public class EnumComponent<C extends CommandSender, E extends Enum<E>> extends C
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<E> parse(@Nonnull final CommandContext<C> commandContext,
|
public ArgumentParseResult<E> parse(@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
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) {
|
for (final E value : this.allowedValues) {
|
||||||
if (value.name().equalsIgnoreCase(input)) {
|
if (value.name().equalsIgnoreCase(input)) {
|
||||||
inputQueue.remove();
|
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
|
@Nonnull
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.standard;
|
package com.intellectualsites.commands.arguments.standard;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
@ -34,12 +34,12 @@ import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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 min;
|
||||||
private final float max;
|
private final float max;
|
||||||
|
|
||||||
private FloatComponent(final boolean required,
|
private FloatArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@Nonnull final String name,
|
||||||
final float min,
|
final float min,
|
||||||
final float max,
|
final float max,
|
||||||
|
|
@ -52,7 +52,7 @@ public final class FloatComponent<C extends CommandSender> extends CommandCompon
|
||||||
/**
|
/**
|
||||||
* Create a new builder
|
* Create a new builder
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Float> required(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Float> required(@Nonnull final String name) {
|
||||||
return FloatComponent.<C>newBuilder(name).asRequired().build();
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Float> optional(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Float> optional(@Nonnull final String name) {
|
||||||
return FloatComponent.<C>newBuilder(name).asOptional().build();
|
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 defaultNum Default num
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Float> optional(@Nonnull final String name,
|
public static <C extends CommandSender> CommandArgument<C, Float> optional(@Nonnull final String name,
|
||||||
final float defaultNum) {
|
final float defaultNum) {
|
||||||
return FloatComponent.<C>newBuilder(name).asOptionalWithDefault(Float.toString(defaultNum)).build();
|
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 min = Float.MIN_VALUE;
|
||||||
private float max = Float.MAX_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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public FloatComponent<C> build() {
|
public FloatArgument<C> build() {
|
||||||
return new FloatComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
|
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 min;
|
||||||
private final float max;
|
private final float max;
|
||||||
|
|
@ -184,22 +184,22 @@ public final class FloatComponent<C extends CommandSender> extends CommandCompon
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<Float> parse(
|
public ArgumentParseResult<Float> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ComponentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final float value = Float.parseFloat(input);
|
final float value = Float.parseFloat(input);
|
||||||
if (value < this.min || value > this.max) {
|
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();
|
inputQueue.remove();
|
||||||
return ComponentParseResult.success(value);
|
return ArgumentParseResult.success(value);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return ComponentParseResult.failure(new FloatParseException(input, this.min, this.max));
|
return ArgumentParseResult.failure(new FloatParseException(input, this.min, this.max));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.standard;
|
package com.intellectualsites.commands.arguments.standard;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
@ -34,12 +34,12 @@ import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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 min;
|
||||||
private final int max;
|
private final int max;
|
||||||
|
|
||||||
private IntegerComponent(final boolean required,
|
private IntegerArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@Nonnull final String name,
|
||||||
final int min,
|
final int min,
|
||||||
final int max,
|
final int max,
|
||||||
|
|
@ -52,7 +52,7 @@ public final class IntegerComponent<C extends CommandSender> extends CommandComp
|
||||||
/**
|
/**
|
||||||
* Create a new builder
|
* Create a new builder
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Integer> required(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Integer> required(@Nonnull final String name) {
|
||||||
return IntegerComponent.<C>newBuilder(name).asRequired().build();
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Integer> optional(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Integer> optional(@Nonnull final String name) {
|
||||||
return IntegerComponent.<C>newBuilder(name).asOptional().build();
|
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 defaultNum Default num
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Integer> optional(@Nonnull final String name,
|
public static <C extends CommandSender> CommandArgument<C, Integer> optional(@Nonnull final String name,
|
||||||
final int defaultNum) {
|
final int defaultNum) {
|
||||||
return IntegerComponent.<C>newBuilder(name).asOptionalWithDefault(Integer.toString(defaultNum)).build();
|
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 min = Integer.MIN_VALUE;
|
||||||
private int max = Integer.MAX_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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public IntegerComponent<C> build() {
|
public IntegerArgument<C> build() {
|
||||||
return new IntegerComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
|
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 min;
|
||||||
private final int max;
|
private final int max;
|
||||||
|
|
@ -184,22 +184,22 @@ public final class IntegerComponent<C extends CommandSender> extends CommandComp
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<Integer> parse(
|
public ArgumentParseResult<Integer> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ComponentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final int value = Integer.parseInt(input);
|
final int value = Integer.parseInt(input);
|
||||||
if (value < this.min || value > this.max) {
|
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();
|
inputQueue.remove();
|
||||||
return ComponentParseResult.success(value);
|
return ArgumentParseResult.success(value);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return ComponentParseResult.failure(new IntegerParseException(input, this.min, this.max));
|
return ArgumentParseResult.failure(new IntegerParseException(input, this.min, this.max));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.standard;
|
package com.intellectualsites.commands.arguments.standard;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
@ -34,12 +34,12 @@ import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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 min;
|
||||||
private final long max;
|
private final long max;
|
||||||
|
|
||||||
private LongComponent(final boolean required,
|
private LongArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@Nonnull final String name,
|
||||||
final long min,
|
final long min,
|
||||||
final long max,
|
final long max,
|
||||||
|
|
@ -52,55 +52,55 @@ public final class LongComponent<C extends CommandSender> extends CommandCompone
|
||||||
/**
|
/**
|
||||||
* Create a new builder
|
* Create a new builder
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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);
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Long> required(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Long> required(@Nonnull final String name) {
|
||||||
return LongComponent.<C>newBuilder(name).asRequired().build();
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Long> optional(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Long> optional(@Nonnull final String name) {
|
||||||
return LongComponent.<C>newBuilder(name).asOptional().build();
|
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 defaultNum Default num
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Long> optional(@Nonnull final String name,
|
public static <C extends CommandSender> CommandArgument<C, Long> optional(@Nonnull final String name,
|
||||||
final long defaultNum) {
|
final long defaultNum) {
|
||||||
return LongComponent.<C>newBuilder(name).asOptionalWithDefault(Long.toString(defaultNum)).build();
|
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 min = Long.MIN_VALUE;
|
||||||
private long max = Long.MAX_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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public LongComponent<C> build() {
|
public LongArgument<C> build() {
|
||||||
return new LongComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
|
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 min;
|
||||||
private final long max;
|
private final long max;
|
||||||
|
|
@ -178,22 +178,22 @@ public final class LongComponent<C extends CommandSender> extends CommandCompone
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<Long> parse(
|
public ArgumentParseResult<Long> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ComponentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final long value = Long.parseLong(input);
|
final long value = Long.parseLong(input);
|
||||||
if (value < this.min || value > this.max) {
|
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();
|
inputQueue.remove();
|
||||||
return ComponentParseResult.success(value);
|
return ArgumentParseResult.success(value);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return ComponentParseResult.failure(new LongParseException(input, this.min, this.max));
|
return ArgumentParseResult.failure(new LongParseException(input, this.min, this.max));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.standard;
|
package com.intellectualsites.commands.arguments.standard;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
@ -34,12 +34,12 @@ import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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 min;
|
||||||
private final short max;
|
private final short max;
|
||||||
|
|
||||||
private ShortComponent(final boolean required,
|
private ShortArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@Nonnull final String name,
|
||||||
final short min,
|
final short min,
|
||||||
final short max,
|
final short max,
|
||||||
|
|
@ -52,55 +52,55 @@ public final class ShortComponent<C extends CommandSender> extends CommandCompon
|
||||||
/**
|
/**
|
||||||
* Create a new builder
|
* Create a new builder
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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);
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, Short> required(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, Short> required(@Nonnull final String name) {
|
||||||
return ShortComponent.<C>newBuilder(name).asRequired().build();
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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) {
|
||||||
return ShortComponent.<C>newBuilder(name).asOptional().build();
|
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 defaultNum Default num
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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) {
|
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 min = Short.MIN_VALUE;
|
||||||
private short max = Short.MAX_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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ShortComponent<C> build() {
|
public ShortArgument<C> build() {
|
||||||
return new ShortComponent<>(this.isRequired(), this.getName(), this.min, this.max, this.getDefaultValue());
|
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 min;
|
||||||
private final short max;
|
private final short max;
|
||||||
|
|
@ -184,22 +184,22 @@ public final class ShortComponent<C extends CommandSender> extends CommandCompon
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<Short> parse(
|
public ArgumentParseResult<Short> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ComponentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
final short value = Short.parseShort(input);
|
final short value = Short.parseShort(input);
|
||||||
if (value < this.min || value > this.max) {
|
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();
|
inputQueue.remove();
|
||||||
return ComponentParseResult.success(value);
|
return ArgumentParseResult.success(value);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return ComponentParseResult.failure(new ShortParseException(input, this.min, this.max));
|
return ArgumentParseResult.failure(new ShortParseException(input, this.min, this.max));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.components.standard;
|
package com.intellectualsites.commands.arguments.standard;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
|
|
@ -37,11 +37,11 @@ import java.util.StringJoiner;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@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 final StringMode stringMode;
|
||||||
|
|
||||||
private StringComponent(final boolean required,
|
private StringArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@Nonnull final String name,
|
||||||
@Nonnull final StringMode stringMode,
|
@Nonnull final StringMode stringMode,
|
||||||
@Nonnull final String defaultValue,
|
@Nonnull final String defaultValue,
|
||||||
|
|
@ -53,51 +53,51 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
|
||||||
/**
|
/**
|
||||||
* Create a new builder
|
* Create a new builder
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> StringComponent.Builder<C> newBuilder(@Nonnull final String name) {
|
public static <C extends CommandSender> StringArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
||||||
return new StringComponent.Builder<>(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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, String> required(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, String> required(@Nonnull final String name) {
|
||||||
return StringComponent.<C>newBuilder(name).asRequired().build();
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, String> optional(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, String> optional(@Nonnull final String name) {
|
||||||
return StringComponent.<C>newBuilder(name).asOptional().build();
|
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 defaultNum Default num
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, String> optional(@Nonnull final String name,
|
public static <C extends CommandSender> CommandArgument<C, String> optional(@Nonnull final String name,
|
||||||
final String defaultNum) {
|
final String defaultNum) {
|
||||||
return StringComponent.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
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 StringMode stringMode = StringMode.SINGLE;
|
||||||
private BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider = (v1, v2) -> Collections.emptyList();
|
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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public StringComponent<C> build() {
|
public StringArgument<C> build() {
|
||||||
return new StringComponent<>(this.isRequired(), this.getName(), this.stringMode,
|
return new StringArgument<>(this.isRequired(), this.getName(), this.stringMode,
|
||||||
this.getDefaultValue(), this.suggestionsProvider);
|
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 StringMode stringMode;
|
||||||
private final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider;
|
private final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider;
|
||||||
|
|
@ -207,16 +207,16 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<String> parse(@Nonnull final CommandContext<C> commandContext,
|
public ArgumentParseResult<String> parse(@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
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) {
|
if (this.stringMode == StringMode.SINGLE) {
|
||||||
inputQueue.remove();
|
inputQueue.remove();
|
||||||
return ComponentParseResult.success(input);
|
return ArgumentParseResult.success(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringJoiner sj = new StringJoiner(" ");
|
final StringJoiner sj = new StringJoiner(" ");
|
||||||
|
|
@ -239,7 +239,7 @@ public final class StringComponent<C extends CommandSender> extends CommandCompo
|
||||||
sj.add(string.substring(1));
|
sj.add(string.substring(1));
|
||||||
started = true;
|
started = true;
|
||||||
} else {
|
} else {
|
||||||
return ComponentParseResult.failure(new StringParseException(string, StringMode.QUOTED));
|
return ArgumentParseResult.failure(new StringParseException(string, StringMode.QUOTED));
|
||||||
}
|
}
|
||||||
} else if (string.endsWith("\"")) {
|
} else if (string.endsWith("\"")) {
|
||||||
sj.add(string.substring(0, string.length() - 1));
|
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)) {
|
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
|
@Nonnull
|
||||||
|
|
@ -23,6 +23,6 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Standard command component types
|
* Standard command argument types
|
||||||
*/
|
*/
|
||||||
package com.intellectualsites.commands.components.standard;
|
package com.intellectualsites.commands.arguments.standard;
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
@ -38,9 +38,9 @@ import java.util.List;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class AmbiguousNodeException extends IllegalStateException {
|
public final class AmbiguousNodeException extends IllegalStateException {
|
||||||
|
|
||||||
private final CommandComponent<?, ?> parentNode;
|
private final CommandArgument<?, ?> parentNode;
|
||||||
private final CommandComponent<?, ?> ambiguousNode;
|
private final CommandArgument<?, ?> ambiguousNode;
|
||||||
private final List<CommandComponent<?, ?>> children;
|
private final List<CommandArgument<?, ?>> children;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new ambiguous node exception
|
* Construct a new ambiguous node exception
|
||||||
|
|
@ -49,9 +49,9 @@ public final class AmbiguousNodeException extends IllegalStateException {
|
||||||
* @param ambiguousNode Node that caused exception
|
* @param ambiguousNode Node that caused exception
|
||||||
* @param children All children of the parent
|
* @param children All children of the parent
|
||||||
*/
|
*/
|
||||||
public AmbiguousNodeException(@Nullable final CommandComponent<?, ?> parentNode,
|
public AmbiguousNodeException(@Nullable final CommandArgument<?, ?> parentNode,
|
||||||
@Nonnull final CommandComponent<?, ?> ambiguousNode,
|
@Nonnull final CommandArgument<?, ?> ambiguousNode,
|
||||||
@Nonnull final List<CommandComponent<?, ?>> children) {
|
@Nonnull final List<CommandArgument<?, ?>> children) {
|
||||||
this.parentNode = parentNode;
|
this.parentNode = parentNode;
|
||||||
this.ambiguousNode = ambiguousNode;
|
this.ambiguousNode = ambiguousNode;
|
||||||
this.children = children;
|
this.children = children;
|
||||||
|
|
@ -63,7 +63,7 @@ public final class AmbiguousNodeException extends IllegalStateException {
|
||||||
* @return Parent node
|
* @return Parent node
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public CommandComponent<?, ?> getParentNode() {
|
public CommandArgument<?, ?> getParentNode() {
|
||||||
return this.parentNode;
|
return this.parentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,7 +73,7 @@ public final class AmbiguousNodeException extends IllegalStateException {
|
||||||
* @return Ambiguous node
|
* @return Ambiguous node
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public CommandComponent<?, ?> getAmbiguousNode() {
|
public CommandArgument<?, ?> getAmbiguousNode() {
|
||||||
return this.ambiguousNode;
|
return this.ambiguousNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,7 +83,7 @@ public final class AmbiguousNodeException extends IllegalStateException {
|
||||||
* @return Child nodes
|
* @return Child nodes
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public List<CommandComponent<?, ?>> getChildren() {
|
public List<CommandArgument<?, ?>> getChildren() {
|
||||||
return this.children;
|
return this.children;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,7 +94,7 @@ public final class AmbiguousNodeException extends IllegalStateException {
|
||||||
.append(" cannot be added as a child to ")
|
.append(" cannot be added as a child to ")
|
||||||
.append(parentNode == null ? "<root>" : parentNode.getName())
|
.append(parentNode == null ? "<root>" : parentNode.getName())
|
||||||
.append(" (All children: ");
|
.append(" (All children: ");
|
||||||
final Iterator<CommandComponent<?, ?>> childIterator = this.children.iterator();
|
final Iterator<CommandArgument<?, ?>> childIterator = this.children.iterator();
|
||||||
while (childIterator.hasNext()) {
|
while (childIterator.hasNext()) {
|
||||||
stringBuilder.append(childIterator.next().getName());
|
stringBuilder.append(childIterator.next().getName());
|
||||||
if (childIterator.hasNext()) {
|
if (childIterator.hasNext()) {
|
||||||
|
|
|
||||||
|
|
@ -23,13 +23,13 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ComponentParseException extends CommandParseException {
|
public class ArgumentParseException extends CommandParseException {
|
||||||
|
|
||||||
private final Throwable cause;
|
private final Throwable cause;
|
||||||
|
|
||||||
|
|
@ -40,9 +40,9 @@ public class ComponentParseException extends CommandParseException {
|
||||||
* @param commandSender Command sender
|
* @param commandSender Command sender
|
||||||
* @param currentChain Chain leading up to the exception
|
* @param currentChain Chain leading up to the exception
|
||||||
*/
|
*/
|
||||||
public ComponentParseException(@Nonnull final Throwable throwable,
|
public ArgumentParseException(@Nonnull final Throwable throwable,
|
||||||
@Nonnull final CommandSender commandSender,
|
@Nonnull final CommandSender commandSender,
|
||||||
@Nonnull final List<CommandComponent<?, ?>> currentChain) {
|
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.cause = throwable;
|
this.cause = throwable;
|
||||||
}
|
}
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
@ -37,7 +37,7 @@ import java.util.List;
|
||||||
public class CommandParseException extends IllegalArgumentException {
|
public class CommandParseException extends IllegalArgumentException {
|
||||||
|
|
||||||
private final CommandSender commandSender;
|
private final CommandSender commandSender;
|
||||||
private final List<CommandComponent<?, ?>> currentChain;
|
private final List<CommandArgument<?, ?>> currentChain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new command parse exception
|
* Construct a new command parse exception
|
||||||
|
|
@ -46,7 +46,7 @@ public class CommandParseException extends IllegalArgumentException {
|
||||||
* @param currentChain Chain leading up to the exception
|
* @param currentChain Chain leading up to the exception
|
||||||
*/
|
*/
|
||||||
protected CommandParseException(@Nonnull final CommandSender commandSender,
|
protected CommandParseException(@Nonnull final CommandSender commandSender,
|
||||||
@Nonnull final List<CommandComponent<?, ?>> currentChain) {
|
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
||||||
this.commandSender = commandSender;
|
this.commandSender = commandSender;
|
||||||
this.currentChain = currentChain;
|
this.currentChain = currentChain;
|
||||||
}
|
}
|
||||||
|
|
@ -64,10 +64,10 @@ public class CommandParseException extends IllegalArgumentException {
|
||||||
/**
|
/**
|
||||||
* Get the command chain leading up to the exception
|
* Get the command chain leading up to the exception
|
||||||
*
|
*
|
||||||
* @return Unmodifiable list of command components
|
* @return Unmodifiable list of command arguments
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public List<CommandComponent<?, ?>> getCurrentChain() {
|
public List<CommandArgument<?, ?>> getCurrentChain() {
|
||||||
return Collections.unmodifiableList(this.currentChain);
|
return Collections.unmodifiableList(this.currentChain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
@ -45,7 +45,7 @@ public final class InvalidCommandSenderException extends CommandParseException {
|
||||||
*/
|
*/
|
||||||
public InvalidCommandSenderException(@Nonnull final CommandSender commandSender,
|
public InvalidCommandSenderException(@Nonnull final CommandSender commandSender,
|
||||||
@Nonnull final Class<?> requiredSender,
|
@Nonnull final Class<?> requiredSender,
|
||||||
@Nonnull final List<CommandComponent<?, ?>> currentChain) {
|
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.requiredSender = requiredSender;
|
this.requiredSender = requiredSender;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
@ -46,7 +46,7 @@ public class InvalidSyntaxException extends CommandParseException {
|
||||||
*/
|
*/
|
||||||
public InvalidSyntaxException(@Nonnull final String correctSyntax,
|
public InvalidSyntaxException(@Nonnull final String correctSyntax,
|
||||||
@Nonnull final CommandSender commandSender,
|
@Nonnull final CommandSender commandSender,
|
||||||
@Nonnull final List<CommandComponent<?, ?>> currentChain) {
|
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.correctSyntax = correctSyntax;
|
this.correctSyntax = correctSyntax;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,37 +23,37 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
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}
|
* that is registered as a leaf node, does not contain an owning {@link com.intellectualsites.commands.Command}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class NoCommandInLeafException extends IllegalStateException {
|
public final class NoCommandInLeafException extends IllegalStateException {
|
||||||
|
|
||||||
private final CommandComponent<?, ?> commandComponent;
|
private final CommandArgument<?, ?> commandArgument;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new no command in leaf exception instance
|
* 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) {
|
public NoCommandInLeafException(@Nonnull final CommandArgument<?, ?> commandArgument) {
|
||||||
super(String.format("Leaf node '%s' does not have associated owning command", commandComponent.getName()));
|
super(String.format("Leaf node '%s' does not have associated owning command", commandArgument.getName()));
|
||||||
this.commandComponent = commandComponent;
|
this.commandArgument = commandArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the command component
|
* Get the command argument
|
||||||
*
|
*
|
||||||
* @return Command component
|
* @return Command argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public CommandComponent<?, ?> getCommandComponent() {
|
public CommandArgument<?, ?> getCommandArgument() {
|
||||||
return this.commandComponent;
|
return this.commandArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
@ -47,7 +47,7 @@ public class NoPermissionException extends CommandParseException {
|
||||||
*/
|
*/
|
||||||
public NoPermissionException(@Nonnull final String missingPermission,
|
public NoPermissionException(@Nonnull final String missingPermission,
|
||||||
@Nonnull final CommandSender commandSender,
|
@Nonnull final CommandSender commandSender,
|
||||||
@Nonnull final List<CommandComponent<?, ?>> currentChain) {
|
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.missingPermission = missingPermission;
|
this.missingPermission = missingPermission;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
@ -46,7 +46,7 @@ public final class NoSuchCommandException extends CommandParseException {
|
||||||
* @param command Entered command (following the command chain)
|
* @param command Entered command (following the command chain)
|
||||||
*/
|
*/
|
||||||
public NoSuchCommandException(@Nonnull final CommandSender commandSender,
|
public NoSuchCommandException(@Nonnull final CommandSender commandSender,
|
||||||
@Nonnull final List<CommandComponent<?, ?>> currentChain,
|
@Nonnull final List<CommandArgument<?, ?>> currentChain,
|
||||||
@Nonnull final String command) {
|
@Nonnull final String command) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.suppliedCommand = command;
|
this.suppliedCommand = command;
|
||||||
|
|
@ -56,11 +56,11 @@ public final class NoSuchCommandException extends CommandParseException {
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
final StringBuilder builder = new StringBuilder();
|
final StringBuilder builder = new StringBuilder();
|
||||||
for (final CommandComponent<?, ?> commandComponent : this.getCurrentChain()) {
|
for (final CommandArgument<?, ?> commandArgument : this.getCurrentChain()) {
|
||||||
if (commandComponent == null) {
|
if (commandArgument == null) {
|
||||||
continue;
|
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());
|
return String.format("Unrecognized command input '%s' following chain%s", this.suppliedCommand, builder.toString());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
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.CommandPreprocessingContext;
|
||||||
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessor;
|
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessor;
|
||||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||||
|
|
@ -43,7 +43,7 @@ public class CommandPreProcessorTest {
|
||||||
static void newTree() {
|
static void newTree() {
|
||||||
manager = new TestCommandManager();
|
manager = new TestCommandManager();
|
||||||
manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
|
manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
|
||||||
.component(EnumComponent.required(SampleEnum.class, "enum"))
|
.argument(EnumArgument.required(SampleEnum.class, "enum"))
|
||||||
.handler(
|
.handler(
|
||||||
commandContext -> System.out.printf("enum = %s | integer = %d\n",
|
commandContext -> System.out.printf("enum = %s | integer = %d\n",
|
||||||
commandContext.<SampleEnum>get(
|
commandContext.<SampleEnum>get(
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,9 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.StaticComponent;
|
import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.components.standard.EnumComponent;
|
import com.intellectualsites.commands.arguments.standard.EnumArgument;
|
||||||
import com.intellectualsites.commands.components.standard.StringComponent;
|
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
@ -43,14 +43,14 @@ public class CommandSuggestionsTest {
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void setupManager() {
|
static void setupManager() {
|
||||||
manager = new TestCommandManager();
|
manager = new TestCommandManager();
|
||||||
manager.command(manager.commandBuilder("test").component(StaticComponent.required("one")).build());
|
manager.command(manager.commandBuilder("test").argument(StaticArgument.required("one")).build());
|
||||||
manager.command(manager.commandBuilder("test").component(StaticComponent.required("two")).build());
|
manager.command(manager.commandBuilder("test").argument(StaticArgument.required("two")).build());
|
||||||
manager.command(manager.commandBuilder("test")
|
manager.command(manager.commandBuilder("test")
|
||||||
.component(StaticComponent.required("var"))
|
.argument(StaticArgument.required("var"))
|
||||||
.component(StringComponent.newBuilder("str")
|
.argument(StringArgument.newBuilder("str")
|
||||||
.withSuggestionsProvider((c, s) -> Arrays.asList("one", "two"))
|
.withSuggestionsProvider((c, s) -> Arrays.asList("one", "two"))
|
||||||
.build())
|
.build())
|
||||||
.component(EnumComponent.required(TestEnum.class, "enum"))
|
.argument(EnumArgument.required(TestEnum.class, "enum"))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.StaticComponent;
|
import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -31,15 +31,15 @@ import org.junit.jupiter.api.Test;
|
||||||
class CommandTest {
|
class CommandTest {
|
||||||
|
|
||||||
@Test()
|
@Test()
|
||||||
void noComponents() {
|
void noArguments() {
|
||||||
Assertions.assertEquals(1, Command.newBuilder("test", SimpleCommandMeta.empty()).build().getComponents().size());
|
Assertions.assertEquals(1, Command.newBuilder("test", SimpleCommandMeta.empty()).build().getArguments().size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void ensureOrdering() {
|
void ensureOrdering() {
|
||||||
Assertions.assertThrows(IllegalArgumentException.class, () ->
|
Assertions.assertThrows(IllegalArgumentException.class, () ->
|
||||||
Command.newBuilder("test", SimpleCommandMeta.empty()).component(StaticComponent.optional("something"))
|
Command.newBuilder("test", SimpleCommandMeta.empty()).argument(StaticArgument.optional("something"))
|
||||||
.component(StaticComponent.required("somethingelse")).build());
|
.argument(StaticArgument.required("somethingelse")).build());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,8 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.StaticComponent;
|
import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.components.standard.IntegerComponent;
|
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.NoPermissionException;
|
import com.intellectualsites.commands.exceptions.NoPermissionException;
|
||||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||||
|
|
@ -48,13 +48,13 @@ class CommandTreeTest {
|
||||||
static void newTree() {
|
static void newTree() {
|
||||||
manager = new TestCommandManager();
|
manager = new TestCommandManager();
|
||||||
manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
|
manager.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
|
||||||
.component(StaticComponent.required("one")).build())
|
.argument(StaticArgument.required("one")).build())
|
||||||
.command(manager.commandBuilder("test", SimpleCommandMeta.empty())
|
.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"),
|
.command(manager.commandBuilder("test", Collections.singleton("other"),
|
||||||
SimpleCommandMeta.empty())
|
SimpleCommandMeta.empty())
|
||||||
.component(StaticComponent.required("opt", "öpt"))
|
.argument(StaticArgument.required("opt", "öpt"))
|
||||||
.component(IntegerComponent
|
.argument(IntegerArgument
|
||||||
.optional("num", EXPECTED_INPUT_NUMBER))
|
.optional("num", EXPECTED_INPUT_NUMBER))
|
||||||
.build())
|
.build())
|
||||||
.command(manager.commandBuilder("req").withSenderType(SpecificCommandSender.class).build());
|
.command(manager.commandBuilder("req").withSenderType(SpecificCommandSender.class).build());
|
||||||
|
|
@ -106,7 +106,7 @@ class CommandTreeTest {
|
||||||
void testDefaultParser() {
|
void testDefaultParser() {
|
||||||
manager.command(
|
manager.command(
|
||||||
manager.commandBuilder("default")
|
manager.commandBuilder("default")
|
||||||
.component(manager.componentBuilder(Integer.class, "int").build())
|
.argument(manager.argumentBuilder(Integer.class, "int").build())
|
||||||
.handler(context -> {
|
.handler(context -> {
|
||||||
final int number = context.getRequired("int");
|
final int number = context.getRequired("int");
|
||||||
System.out.printf("Supplied number is: %d\n", number);
|
System.out.printf("Supplied number is: %d\n", number);
|
||||||
|
|
|
||||||
|
|
@ -25,12 +25,12 @@ package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.intellectualsites.commands.annotations.specifier.Range;
|
import com.intellectualsites.commands.annotations.specifier.Range;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.components.parser.ParserParameters;
|
import com.intellectualsites.commands.arguments.parser.ParserParameters;
|
||||||
import com.intellectualsites.commands.components.parser.ParserRegistry;
|
import com.intellectualsites.commands.arguments.parser.ParserRegistry;
|
||||||
import com.intellectualsites.commands.components.parser.StandardParameters;
|
import com.intellectualsites.commands.arguments.parser.StandardParameters;
|
||||||
import com.intellectualsites.commands.components.parser.StandardParserRegistry;
|
import com.intellectualsites.commands.arguments.parser.StandardParserRegistry;
|
||||||
import com.intellectualsites.commands.components.standard.IntegerComponent;
|
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -72,13 +72,13 @@ public class ParserRegistryTest {
|
||||||
final ParserParameters parserParameters = parserRegistry.parseAnnotations(parsedType, Collections.singleton(range));
|
final ParserParameters parserParameters = parserRegistry.parseAnnotations(parsedType, Collections.singleton(range));
|
||||||
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MIN));
|
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MIN));
|
||||||
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MAX));
|
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MAX));
|
||||||
final ComponentParser<CommandSender, ?> parser = parserRegistry.createParser(parsedType,
|
final ArgumentParser<CommandSender, ?> parser = parserRegistry.createParser(parsedType,
|
||||||
parserParameters)
|
parserParameters)
|
||||||
.orElseThrow(
|
.orElseThrow(
|
||||||
() -> new NullPointerException("No parser found"));
|
() -> new NullPointerException("No parser found"));
|
||||||
Assertions.assertTrue(parser instanceof IntegerComponent.IntegerParser);
|
Assertions.assertTrue(parser instanceof IntegerArgument.IntegerParser);
|
||||||
@SuppressWarnings("unchecked")
|
@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_MIN, integerParser.getMin());
|
||||||
Assertions.assertEquals(RANGE_MAX, integerParser.getMax());
|
Assertions.assertEquals(RANGE_MAX, integerParser.getMax());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,8 @@ package com.intellectualsites.commands.jline;
|
||||||
|
|
||||||
import com.intellectualsites.commands.CommandManager;
|
import com.intellectualsites.commands.CommandManager;
|
||||||
import com.intellectualsites.commands.CommandTree;
|
import com.intellectualsites.commands.CommandTree;
|
||||||
import com.intellectualsites.commands.components.StaticComponent;
|
import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.exceptions.InvalidSyntaxException;
|
import com.intellectualsites.commands.exceptions.InvalidSyntaxException;
|
||||||
import com.intellectualsites.commands.exceptions.NoSuchCommandException;
|
import com.intellectualsites.commands.exceptions.NoSuchCommandException;
|
||||||
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
||||||
|
|
@ -81,7 +81,7 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender, Simp
|
||||||
shouldStop[0] = true)
|
shouldStop[0] = true)
|
||||||
.build())
|
.build())
|
||||||
.command(jLineCommandManager.commandBuilder("echo", SimpleCommandMeta.empty())
|
.command(jLineCommandManager.commandBuilder("echo", SimpleCommandMeta.empty())
|
||||||
.component(String.class, "string", builder ->
|
.argument(String.class, "string", builder ->
|
||||||
builder.asRequired()
|
builder.asRequired()
|
||||||
.withParser(((commandContext, inputQueue) -> {
|
.withParser(((commandContext, inputQueue) -> {
|
||||||
final StringBuilder stringBuilder =
|
final StringBuilder stringBuilder =
|
||||||
|
|
@ -92,7 +92,7 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender, Simp
|
||||||
stringBuilder.append(" ");
|
stringBuilder.append(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ComponentParseResult.success(
|
return ArgumentParseResult.success(
|
||||||
stringBuilder.toString());
|
stringBuilder.toString());
|
||||||
})).build())
|
})).build())
|
||||||
.handler(commandContext -> commandContext.get("string")
|
.handler(commandContext -> commandContext.get("string")
|
||||||
|
|
@ -100,11 +100,11 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender, Simp
|
||||||
System.out::println))
|
System.out::println))
|
||||||
.build())
|
.build())
|
||||||
.command(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty())
|
.command(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty())
|
||||||
.component(StaticComponent.required("one"))
|
.argument(StaticArgument.required("one"))
|
||||||
.handler(commandContext -> System.out.println("Test (1)"))
|
.handler(commandContext -> System.out.println("Test (1)"))
|
||||||
.build())
|
.build())
|
||||||
.command(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty())
|
.command(jLineCommandManager.commandBuilder("test", SimpleCommandMeta.empty())
|
||||||
.component(StaticComponent.required("two"))
|
.argument(StaticArgument.required("two"))
|
||||||
.handler(commandContext -> System.out.println("Test (2)"))
|
.handler(commandContext -> System.out.println("Test (2)"))
|
||||||
.build());
|
.build());
|
||||||
System.out.println("Ready...");
|
System.out.println("Ready...");
|
||||||
|
|
|
||||||
|
|
@ -27,15 +27,15 @@ import com.google.common.collect.Maps;
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.intellectualsites.commands.CommandManager;
|
import com.intellectualsites.commands.CommandManager;
|
||||||
import com.intellectualsites.commands.CommandTree;
|
import com.intellectualsites.commands.CommandTree;
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.StaticComponent;
|
import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.components.standard.BooleanComponent;
|
import com.intellectualsites.commands.arguments.standard.BooleanArgument;
|
||||||
import com.intellectualsites.commands.components.standard.ByteComponent;
|
import com.intellectualsites.commands.arguments.standard.ByteArgument;
|
||||||
import com.intellectualsites.commands.components.standard.DoubleComponent;
|
import com.intellectualsites.commands.arguments.standard.DoubleArgument;
|
||||||
import com.intellectualsites.commands.components.standard.FloatComponent;
|
import com.intellectualsites.commands.arguments.standard.FloatArgument;
|
||||||
import com.intellectualsites.commands.components.standard.IntegerComponent;
|
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||||
import com.intellectualsites.commands.components.standard.ShortComponent;
|
import com.intellectualsites.commands.arguments.standard.ShortArgument;
|
||||||
import com.intellectualsites.commands.components.standard.StringComponent;
|
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||||
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
import com.mojang.brigadier.LiteralMessage;
|
import com.mojang.brigadier.LiteralMessage;
|
||||||
|
|
@ -77,7 +77,7 @@ import java.util.function.Supplier;
|
||||||
*/
|
*/
|
||||||
public final class CloudBrigadierManager<C extends CommandSender, S> {
|
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;
|
? extends ArgumentType<?>>> mappers;
|
||||||
private final Map<Class<?>, Supplier<ArgumentType<?>>> defaultArgumentTypeSuppliers;
|
private final Map<Class<?>, Supplier<ArgumentType<?>>> defaultArgumentTypeSuppliers;
|
||||||
private final Supplier<com.intellectualsites.commands.context.CommandContext<C>> dummyContextProvider;
|
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() {
|
private void registerInternalMappings() {
|
||||||
/* Map byte, short and int to IntegerArgumentType */
|
/* Map byte, short and int to IntegerArgumentType */
|
||||||
this.registerMapping(new TypeToken<ByteComponent<C>>() {
|
this.registerMapping(new TypeToken<ByteArgument<C>>() {
|
||||||
}, component -> {
|
}, argument -> {
|
||||||
final boolean hasMin = component.getMin() != Byte.MIN_VALUE;
|
final boolean hasMin = argument.getMin() != Byte.MIN_VALUE;
|
||||||
final boolean hasMax = component.getMax() != Byte.MAX_VALUE;
|
final boolean hasMax = argument.getMax() != Byte.MAX_VALUE;
|
||||||
if (hasMin) {
|
if (hasMin) {
|
||||||
return IntegerArgumentType.integer(component.getMin(), component.getMax());
|
return IntegerArgumentType.integer(argument.getMin(), argument.getMax());
|
||||||
} else if (hasMax) {
|
} else if (hasMax) {
|
||||||
return IntegerArgumentType.integer(Byte.MIN_VALUE, component.getMax());
|
return IntegerArgumentType.integer(Byte.MIN_VALUE, argument.getMax());
|
||||||
} else {
|
} else {
|
||||||
return IntegerArgumentType.integer();
|
return IntegerArgumentType.integer();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.registerMapping(new TypeToken<ShortComponent<C>>() {
|
this.registerMapping(new TypeToken<ShortArgument<C>>() {
|
||||||
}, component -> {
|
}, argument -> {
|
||||||
final boolean hasMin = component.getMin() != Short.MIN_VALUE;
|
final boolean hasMin = argument.getMin() != Short.MIN_VALUE;
|
||||||
final boolean hasMax = component.getMax() != Short.MAX_VALUE;
|
final boolean hasMax = argument.getMax() != Short.MAX_VALUE;
|
||||||
if (hasMin) {
|
if (hasMin) {
|
||||||
return IntegerArgumentType.integer(component.getMin(), component.getMax());
|
return IntegerArgumentType.integer(argument.getMin(), argument.getMax());
|
||||||
} else if (hasMax) {
|
} else if (hasMax) {
|
||||||
return IntegerArgumentType.integer(Short.MIN_VALUE, component.getMax());
|
return IntegerArgumentType.integer(Short.MIN_VALUE, argument.getMax());
|
||||||
} else {
|
} else {
|
||||||
return IntegerArgumentType.integer();
|
return IntegerArgumentType.integer();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.registerMapping(new TypeToken<IntegerComponent<C>>() {
|
this.registerMapping(new TypeToken<IntegerArgument<C>>() {
|
||||||
}, component -> {
|
}, argument -> {
|
||||||
final boolean hasMin = component.getMin() != Integer.MIN_VALUE;
|
final boolean hasMin = argument.getMin() != Integer.MIN_VALUE;
|
||||||
final boolean hasMax = component.getMax() != Integer.MAX_VALUE;
|
final boolean hasMax = argument.getMax() != Integer.MAX_VALUE;
|
||||||
if (hasMin) {
|
if (hasMin) {
|
||||||
return IntegerArgumentType.integer(component.getMin(), component.getMax());
|
return IntegerArgumentType.integer(argument.getMin(), argument.getMax());
|
||||||
} else if (hasMax) {
|
} else if (hasMax) {
|
||||||
return IntegerArgumentType.integer(Integer.MIN_VALUE, component.getMax());
|
return IntegerArgumentType.integer(Integer.MIN_VALUE, argument.getMax());
|
||||||
} else {
|
} else {
|
||||||
return IntegerArgumentType.integer();
|
return IntegerArgumentType.integer();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/* Map float to FloatArgumentType */
|
/* Map float to FloatArgumentType */
|
||||||
this.registerMapping(new TypeToken<FloatComponent<C>>() {
|
this.registerMapping(new TypeToken<FloatArgument<C>>() {
|
||||||
}, component -> {
|
}, argument -> {
|
||||||
final boolean hasMin = component.getMin() != Float.MIN_VALUE;
|
final boolean hasMin = argument.getMin() != Float.MIN_VALUE;
|
||||||
final boolean hasMax = component.getMax() != Float.MAX_VALUE;
|
final boolean hasMax = argument.getMax() != Float.MAX_VALUE;
|
||||||
if (hasMin) {
|
if (hasMin) {
|
||||||
return FloatArgumentType.floatArg(component.getMin(), component.getMax());
|
return FloatArgumentType.floatArg(argument.getMin(), argument.getMax());
|
||||||
} else if (hasMax) {
|
} else if (hasMax) {
|
||||||
return FloatArgumentType.floatArg(Float.MIN_VALUE, component.getMax());
|
return FloatArgumentType.floatArg(Float.MIN_VALUE, argument.getMax());
|
||||||
} else {
|
} else {
|
||||||
return FloatArgumentType.floatArg();
|
return FloatArgumentType.floatArg();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/* Map double to DoubleArgumentType */
|
/* Map double to DoubleArgumentType */
|
||||||
this.registerMapping(new TypeToken<DoubleComponent<C>>() {
|
this.registerMapping(new TypeToken<DoubleArgument<C>>() {
|
||||||
}, component -> {
|
}, argument -> {
|
||||||
final boolean hasMin = component.getMin() != Double.MIN_VALUE;
|
final boolean hasMin = argument.getMin() != Double.MIN_VALUE;
|
||||||
final boolean hasMax = component.getMax() != Double.MAX_VALUE;
|
final boolean hasMax = argument.getMax() != Double.MAX_VALUE;
|
||||||
if (hasMin) {
|
if (hasMin) {
|
||||||
return DoubleArgumentType.doubleArg(component.getMin(), component.getMax());
|
return DoubleArgumentType.doubleArg(argument.getMin(), argument.getMax());
|
||||||
} else if (hasMax) {
|
} else if (hasMax) {
|
||||||
return DoubleArgumentType.doubleArg(Double.MIN_VALUE, component.getMax());
|
return DoubleArgumentType.doubleArg(Double.MIN_VALUE, argument.getMax());
|
||||||
} else {
|
} else {
|
||||||
return DoubleArgumentType.doubleArg();
|
return DoubleArgumentType.doubleArg();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/* Map boolean to BoolArgumentType */
|
/* Map boolean to BoolArgumentType */
|
||||||
this.registerMapping(new TypeToken<BooleanComponent<C>>() {
|
this.registerMapping(new TypeToken<BooleanArgument<C>>() {
|
||||||
}, component -> BoolArgumentType.bool());
|
}, argument -> BoolArgumentType.bool());
|
||||||
/* Map String properly to StringArgumentType */
|
/* Map String properly to StringArgumentType */
|
||||||
this.registerMapping(new TypeToken<StringComponent<C>>() {
|
this.registerMapping(new TypeToken<StringArgument<C>>() {
|
||||||
}, component -> {
|
}, argument -> {
|
||||||
switch (component.getStringMode()) {
|
switch (argument.getStringMode()) {
|
||||||
case QUOTED:
|
case QUOTED:
|
||||||
return StringArgumentType.string();
|
return StringArgumentType.string();
|
||||||
case GREEDY:
|
case GREEDY:
|
||||||
|
|
@ -183,16 +183,16 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
|
||||||
/**
|
/**
|
||||||
* Register a cloud-Brigadier mapping
|
* Register a cloud-Brigadier mapping
|
||||||
*
|
*
|
||||||
* @param componentType cloud component type
|
* @param argumentType cloud argument type
|
||||||
* @param mapper mapper function
|
* @param mapper mapper function
|
||||||
* @param <T> cloud component value type
|
* @param <T> cloud argument value type
|
||||||
* @param <K> cloud component type
|
* @param <K> cloud argument type
|
||||||
* @param <O> Brigadier argument type value
|
* @param <O> Brigadier argument type value
|
||||||
*/
|
*/
|
||||||
public <T, K extends CommandComponent<C, T>, O> void registerMapping(@Nonnull final TypeToken<K> componentType,
|
public <T, K extends CommandArgument<C, T>, O> void registerMapping(@Nonnull final TypeToken<K> argumentType,
|
||||||
@Nonnull final Function<? extends K,
|
@Nonnull final Function<? extends K,
|
||||||
? extends ArgumentType<O>> mapper) {
|
? 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 argumentType cloud argument type
|
||||||
* @param component cloud component
|
* @param argument cloud argument
|
||||||
* @param <T> cloud component value type (generic)
|
* @param <T> cloud argument value type (generic)
|
||||||
* @param <K> cloud component type (generic)
|
* @param <K> cloud argument type (generic)
|
||||||
* @return Brigadier argument type
|
* @return Brigadier argument type
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
private <T, K extends CommandComponent<?, ?>> Pair<ArgumentType<?>, Boolean> getArgument(
|
private <T, K extends CommandArgument<?, ?>> Pair<ArgumentType<?>, Boolean> getArgument(
|
||||||
@Nonnull final TypeToken<T> componentType,
|
@Nonnull final TypeToken<T> argumentType,
|
||||||
@Nonnull final K component) {
|
@Nonnull final K argument) {
|
||||||
final CommandComponent<C, ?> commandComponent = (CommandComponent<C, ?>) component;
|
final CommandArgument<C, ?> commandArgument = (CommandArgument<C, ?>) argument;
|
||||||
Function function = this.mappers.get(componentType.getRawType());
|
Function function = this.mappers.get(argumentType.getRawType());
|
||||||
if (function == null) {
|
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
|
@Nonnull
|
||||||
private <T, K extends CommandComponent<C, T>> Pair<ArgumentType<?>, Boolean> createDefaultMapper(
|
private <T, K extends CommandArgument<C, T>> Pair<ArgumentType<?>, Boolean> createDefaultMapper(
|
||||||
@Nonnull final CommandComponent<C, T>
|
@Nonnull final CommandArgument<C, T>
|
||||||
component) {
|
argument) {
|
||||||
final Supplier<ArgumentType<?>> argumentTypeSupplier = this.defaultArgumentTypeSuppliers.get(component.getValueType());
|
final Supplier<ArgumentType<?>> argumentTypeSupplier = this.defaultArgumentTypeSuppliers.get(argument.getValueType());
|
||||||
if (argumentTypeSupplier != null) {
|
if (argumentTypeSupplier != null) {
|
||||||
return new Pair<>(argumentTypeSupplier.get(), true);
|
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);
|
return new Pair<>(StringArgumentType.string(), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -251,7 +251,7 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
|
||||||
* @return Constructed literal command node
|
* @return Constructed literal command node
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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 LiteralCommandNode<S> root,
|
||||||
@Nonnull final SuggestionProvider<S> suggestionProvider,
|
@Nonnull final SuggestionProvider<S> suggestionProvider,
|
||||||
@Nonnull final com.mojang.brigadier.Command<S> executor,
|
@Nonnull final com.mojang.brigadier.Command<S> executor,
|
||||||
|
|
@ -262,19 +262,19 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
|
||||||
literalArgumentBuilder.executes(executor);
|
literalArgumentBuilder.executes(executor);
|
||||||
}
|
}
|
||||||
final LiteralCommandNode<S> constructedRoot = literalArgumentBuilder.build();
|
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());
|
constructedRoot.addChild(this.constructCommandNode(child, permissionChecker, executor, suggestionProvider).build());
|
||||||
}
|
}
|
||||||
return constructedRoot;
|
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 BiPredicate<S, String> permissionChecker,
|
||||||
@Nonnull final com.mojang.brigadier.Command<S> executor,
|
@Nonnull final com.mojang.brigadier.Command<S> executor,
|
||||||
@Nonnull final SuggestionProvider<S> suggestionProvider) {
|
@Nonnull final SuggestionProvider<S> suggestionProvider) {
|
||||||
|
|
||||||
ArgumentBuilder<S, ?> argumentBuilder;
|
ArgumentBuilder<S, ?> argumentBuilder;
|
||||||
if (root.getValue() instanceof StaticComponent) {
|
if (root.getValue() instanceof StaticArgument) {
|
||||||
argumentBuilder = LiteralArgumentBuilder.<S>literal(root.getValue().getName())
|
argumentBuilder = LiteralArgumentBuilder.<S>literal(root.getValue().getName())
|
||||||
.requires(sender -> permissionChecker.test(sender, root.getNodeMeta().getOrDefault("permission", "")))
|
.requires(sender -> permissionChecker.test(sender, root.getNodeMeta().getOrDefault("permission", "")))
|
||||||
.executes(executor);
|
.executes(executor);
|
||||||
|
|
@ -290,14 +290,14 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
|
||||||
if (root.isLeaf() || !root.getValue().isRequired()) {
|
if (root.isLeaf() || !root.getValue().isRequired()) {
|
||||||
argumentBuilder.executes(executor);
|
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));
|
argumentBuilder.then(constructCommandNode(node, permissionChecker, executor, suggestionProvider));
|
||||||
}
|
}
|
||||||
return argumentBuilder;
|
return argumentBuilder;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@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 CommandContext<S> s,
|
||||||
@Nonnull final SuggestionsBuilder builder) {
|
@Nonnull final SuggestionsBuilder builder) {
|
||||||
final com.intellectualsites.commands.context.CommandContext<C> commandContext = this.dummyContextProvider.get();
|
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);
|
command = command.substring(1);
|
||||||
}
|
}
|
||||||
final List<String> suggestions = this.commandManager.suggest(commandContext.getSender(), command);
|
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) {
|
for (final String suggestion : suggestions) {
|
||||||
System.out.printf("- %s\n", suggestion);
|
System.out.printf("- %s\n", suggestion);
|
||||||
}
|
}
|
||||||
|
|
@ -327,9 +327,9 @@ public final class CloudBrigadierManager<C extends CommandSender, S> {
|
||||||
System.out.printf("- %s\n", suggestion);
|
System.out.printf("- %s\n", suggestion);
|
||||||
}*/
|
}*/
|
||||||
for (final String suggestion : suggestions) {
|
for (final String suggestion : suggestions) {
|
||||||
String tooltip = component.getName();
|
String tooltip = argument.getName();
|
||||||
if (!(component instanceof StaticComponent)) {
|
if (!(argument instanceof StaticArgument)) {
|
||||||
if (component.isRequired()) {
|
if (argument.isRequired()) {
|
||||||
tooltip = '<' + tooltip + '>';
|
tooltip = '<' + tooltip + '>';
|
||||||
} else {
|
} else {
|
||||||
tooltip = '[' + tooltip + ']';
|
tooltip = '[' + tooltip + ']';
|
||||||
|
|
|
||||||
|
|
@ -23,16 +23,16 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.StaticComponent;
|
import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.standard.BooleanComponent;
|
import com.intellectualsites.commands.arguments.standard.BooleanArgument;
|
||||||
import com.intellectualsites.commands.components.standard.DoubleComponent;
|
import com.intellectualsites.commands.arguments.standard.DoubleArgument;
|
||||||
import com.intellectualsites.commands.components.standard.EnumComponent;
|
import com.intellectualsites.commands.arguments.standard.EnumArgument;
|
||||||
import com.intellectualsites.commands.components.standard.FloatComponent;
|
import com.intellectualsites.commands.arguments.standard.FloatArgument;
|
||||||
import com.intellectualsites.commands.components.standard.IntegerComponent;
|
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||||
import com.intellectualsites.commands.components.standard.StringComponent;
|
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||||
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
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.Bukkit;
|
||||||
import org.bukkit.GameMode;
|
import org.bukkit.GameMode;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
@ -65,8 +65,8 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
BukkitCommandMetaBuilder.builder()
|
BukkitCommandMetaBuilder.builder()
|
||||||
.withDescription("Your ugli")
|
.withDescription("Your ugli")
|
||||||
.build())
|
.build())
|
||||||
.component(EnumComponent.required(GameMode.class, "gamemode"))
|
.argument(EnumArgument.required(GameMode.class, "gamemode"))
|
||||||
.component(StringComponent.<BukkitCommandSender>newBuilder("player")
|
.argument(StringArgument.<BukkitCommandSender>newBuilder("player")
|
||||||
.withSuggestionsProvider((v1, v2) -> {
|
.withSuggestionsProvider((v1, v2) -> {
|
||||||
final List<String> suggestions =
|
final List<String> suggestions =
|
||||||
new ArrayList<>(
|
new ArrayList<>(
|
||||||
|
|
@ -84,8 +84,8 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
.orElse(GameMode.SURVIVAL)))
|
.orElse(GameMode.SURVIVAL)))
|
||||||
.build())
|
.build())
|
||||||
.command(mgr.commandBuilder("kenny")
|
.command(mgr.commandBuilder("kenny")
|
||||||
.component(StaticComponent.required("sux"))
|
.argument(StaticArgument.required("sux"))
|
||||||
.component(IntegerComponent
|
.argument(IntegerArgument
|
||||||
.<BukkitCommandSender>newBuilder("perc")
|
.<BukkitCommandSender>newBuilder("perc")
|
||||||
.withMin(PERC_MIN).withMax(PERC_MAX).build())
|
.withMin(PERC_MIN).withMax(PERC_MAX).build())
|
||||||
.handler(context -> {
|
.handler(context -> {
|
||||||
|
|
@ -96,32 +96,32 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
})
|
})
|
||||||
.build())
|
.build())
|
||||||
.command(mgr.commandBuilder("test")
|
.command(mgr.commandBuilder("test")
|
||||||
.component(StaticComponent.required("one"))
|
.argument(StaticArgument.required("one"))
|
||||||
.handler(c -> c.getSender().sendMessage("One!"))
|
.handler(c -> c.getSender().sendMessage("One!"))
|
||||||
.build())
|
.build())
|
||||||
.command(mgr.commandBuilder("test")
|
.command(mgr.commandBuilder("test")
|
||||||
.component(StaticComponent.required("two"))
|
.argument(StaticArgument.required("two"))
|
||||||
.handler(c -> c.getSender().sendMessage("Two!"))
|
.handler(c -> c.getSender().sendMessage("Two!"))
|
||||||
.build())
|
.build())
|
||||||
.command(mgr.commandBuilder("uuidtest")
|
.command(mgr.commandBuilder("uuidtest")
|
||||||
.component(UUID.class, "uuid", builder -> builder
|
.argument(UUID.class, "uuid", builder -> builder
|
||||||
.asRequired()
|
.asRequired()
|
||||||
.withParser((c, i) -> {
|
.withParser((c, i) -> {
|
||||||
final String string = i.peek();
|
final String string = i.peek();
|
||||||
try {
|
try {
|
||||||
final UUID uuid = UUID.fromString(string);
|
final UUID uuid = UUID.fromString(string);
|
||||||
i.remove();
|
i.remove();
|
||||||
return ComponentParseResult.success(uuid);
|
return ArgumentParseResult.success(uuid);
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return ComponentParseResult.failure(e);
|
return ArgumentParseResult.failure(e);
|
||||||
}
|
}
|
||||||
}).build())
|
}).build())
|
||||||
.handler(c -> c.getSender()
|
.handler(c -> c.getSender()
|
||||||
.sendMessage(String.format("UUID: %s\n", c.<UUID>get("uuid").orElse(null))))
|
.sendMessage(String.format("UUID: %s\n", c.<UUID>get("uuid").orElse(null))))
|
||||||
.build())
|
.build())
|
||||||
.command(mgr.commandBuilder("give")
|
.command(mgr.commandBuilder("give")
|
||||||
.component(EnumComponent.required(Material.class, "material"))
|
.argument(EnumArgument.required(Material.class, "material"))
|
||||||
.component(IntegerComponent.required("amount"))
|
.argument(IntegerArgument.required("amount"))
|
||||||
.handler(c -> {
|
.handler(c -> {
|
||||||
final Material material = c.getRequired("material");
|
final Material material = c.getRequired("material");
|
||||||
final int amount = c.getRequired("amount");
|
final int amount = c.getRequired("amount");
|
||||||
|
|
@ -133,7 +133,7 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
.command(mgr.commandBuilder("worldtp", BukkitCommandMetaBuilder.builder()
|
.command(mgr.commandBuilder("worldtp", BukkitCommandMetaBuilder.builder()
|
||||||
.withDescription("Teleport to a world")
|
.withDescription("Teleport to a world")
|
||||||
.build())
|
.build())
|
||||||
.component(WorldComponent.required("world"))
|
.argument(WorldArgument.required("world"))
|
||||||
.handler(c -> {
|
.handler(c -> {
|
||||||
final World world = c.getRequired("world");
|
final World world = c.getRequired("world");
|
||||||
c.getSender().asPlayer().teleport(world.getSpawnLocation());
|
c.getSender().asPlayer().teleport(world.getSpawnLocation());
|
||||||
|
|
@ -141,11 +141,11 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
})
|
})
|
||||||
.build())
|
.build())
|
||||||
.command(mgr.commandBuilder("brigadier")
|
.command(mgr.commandBuilder("brigadier")
|
||||||
.component(FloatComponent.required("float"))
|
.argument(FloatArgument.required("float"))
|
||||||
.component(DoubleComponent.required("double"))
|
.argument(DoubleArgument.required("double"))
|
||||||
.component(IntegerComponent.required("int"))
|
.argument(IntegerArgument.required("int"))
|
||||||
.component(BooleanComponent.required("bool"))
|
.argument(BooleanArgument.required("bool"))
|
||||||
.component(StringComponent.required("string"))
|
.argument(StringArgument.required("string"))
|
||||||
.handler(c -> c.getSender().sendMessage("Executed the command"))
|
.handler(c -> c.getSender().sendMessage("Executed the command"))
|
||||||
.build());
|
.build());
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.PluginIdentifiableCommand;
|
import org.bukkit.command.PluginIdentifiableCommand;
|
||||||
|
|
@ -35,12 +35,12 @@ import java.util.List;
|
||||||
final class BukkitCommand<C extends com.intellectualsites.commands.sender.CommandSender>
|
final class BukkitCommand<C extends com.intellectualsites.commands.sender.CommandSender>
|
||||||
extends org.bukkit.command.Command implements PluginIdentifiableCommand {
|
extends org.bukkit.command.Command implements PluginIdentifiableCommand {
|
||||||
|
|
||||||
private final CommandComponent<C, ?> command;
|
private final CommandArgument<C, ?> command;
|
||||||
private final BukkitCommandManager<C> bukkitCommandManager;
|
private final BukkitCommandManager<C> bukkitCommandManager;
|
||||||
private final com.intellectualsites.commands.Command<C, BukkitCommandMeta> cloudCommand;
|
private final com.intellectualsites.commands.Command<C, BukkitCommandMeta> cloudCommand;
|
||||||
|
|
||||||
BukkitCommand(@Nonnull 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) {
|
@Nonnull final BukkitCommandManager<C> bukkitCommandManager) {
|
||||||
super(command.getName());
|
super(command.getName());
|
||||||
this.command = command;
|
this.command = command;
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
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.World;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
@ -64,7 +64,7 @@ public class BukkitCommandManager<C extends com.intellectualsites.commands.sende
|
||||||
this.commandSenderMapper = commandSenderMapper;
|
this.commandSenderMapper = commandSenderMapper;
|
||||||
|
|
||||||
/* Register Bukkit parsers */
|
/* 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<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
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.internal.CommandRegistrationHandler;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -39,7 +39,7 @@ import java.util.Map;
|
||||||
|
|
||||||
final class BukkitPluginRegistrationHandler<C extends CommandSender> implements CommandRegistrationHandler<BukkitCommandMeta> {
|
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 Map<String, org.bukkit.command.Command> bukkitCommands;
|
||||||
private BukkitCommandManager<C> bukkitCommandManager;
|
private BukkitCommandManager<C> bukkitCommandManager;
|
||||||
|
|
@ -63,23 +63,23 @@ final class BukkitPluginRegistrationHandler<C extends CommandSender> implements
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean registerCommand(@Nonnull final Command<?, BukkitCommandMeta> command) {
|
public boolean registerCommand(@Nonnull final Command<?, BukkitCommandMeta> command) {
|
||||||
/* We only care about the root command component */
|
/* We only care about the root command argument */
|
||||||
final CommandComponent<?, ?> commandComponent = command.getComponents().get(0);
|
final CommandArgument<?, ?> commandArgument = command.getArguments().get(0);
|
||||||
if (this.registeredCommands.containsKey(commandComponent)) {
|
if (this.registeredCommands.containsKey(commandArgument)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final String label;
|
final String label;
|
||||||
if (bukkitCommands.containsKey(commandComponent.getName())) {
|
if (bukkitCommands.containsKey(commandArgument.getName())) {
|
||||||
label = String.format("%s:%s", this.bukkitCommandManager.getOwningPlugin().getName(), commandComponent.getName());
|
label = String.format("%s:%s", this.bukkitCommandManager.getOwningPlugin().getName(), commandArgument.getName());
|
||||||
} else {
|
} else {
|
||||||
label = commandComponent.getName();
|
label = commandArgument.getName();
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked") final BukkitCommand<C> bukkitCommand = new BukkitCommand<>(
|
@SuppressWarnings("unchecked") final BukkitCommand<C> bukkitCommand = new BukkitCommand<>(
|
||||||
(Command<C, BukkitCommandMeta>) command,
|
(Command<C, BukkitCommandMeta>) command,
|
||||||
(CommandComponent<C, ?>) commandComponent,
|
(CommandArgument<C, ?>) commandArgument,
|
||||||
this.bukkitCommandManager);
|
this.bukkitCommandManager);
|
||||||
this.registeredCommands.put(commandComponent, bukkitCommand);
|
this.registeredCommands.put(commandArgument, bukkitCommand);
|
||||||
this.commandMap.register(commandComponent.getName(), this.bukkitCommandManager.getOwningPlugin().getName().toLowerCase(),
|
this.commandMap.register(commandArgument.getName(), this.bukkitCommandManager.getOwningPlugin().getName().toLowerCase(),
|
||||||
bukkitCommand);
|
bukkitCommand);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,9 +23,9 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.parsers;
|
package com.intellectualsites.commands.parsers;
|
||||||
|
|
||||||
import com.intellectualsites.commands.components.CommandComponent;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.components.parser.ComponentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
|
@ -37,13 +37,13 @@ import java.util.Queue;
|
||||||
import java.util.stream.Collectors;
|
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
|
* @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,
|
protected WorldArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@Nonnull final String name,
|
||||||
@Nonnull final String defaultValue) {
|
@Nonnull final String defaultValue) {
|
||||||
super(required, name, new WorldParser<>(), defaultValue, World.class);
|
super(required, name, new WorldParser<>(), defaultValue, World.class);
|
||||||
|
|
@ -52,55 +52,55 @@ public class WorldComponent<C extends CommandSender> extends CommandComponent<C,
|
||||||
/**
|
/**
|
||||||
* Create a new builder
|
* Create a new builder
|
||||||
*
|
*
|
||||||
* @param name Name of the component
|
* @param name Name of the argument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent.Builder<C, World> newBuilder(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument.Builder<C, World> newBuilder(@Nonnull final String name) {
|
||||||
return new WorldComponent.Builder<>(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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, World> required(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, World> required(@Nonnull final String name) {
|
||||||
return WorldComponent.<C>newBuilder(name).asRequired().build();
|
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
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, World> optional(@Nonnull final String name) {
|
public static <C extends CommandSender> CommandArgument<C, World> optional(@Nonnull final String name) {
|
||||||
return WorldComponent.<C>newBuilder(name).asOptional().build();
|
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 defaultValue Default value
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created component
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandComponent<C, World> optional(@Nonnull final String name,
|
public static <C extends CommandSender> CommandArgument<C, World> optional(@Nonnull final String name,
|
||||||
@Nonnull final String defaultValue) {
|
@Nonnull final String defaultValue) {
|
||||||
return WorldComponent.<C>newBuilder(name).asOptionalWithDefault(defaultValue).build();
|
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) {
|
protected Builder(@Nonnull final String name) {
|
||||||
super(World.class, name);
|
super(World.class, name);
|
||||||
|
|
@ -108,30 +108,30 @@ public class WorldComponent<C extends CommandSender> extends CommandComponent<C,
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public CommandComponent<C, World> build() {
|
public CommandArgument<C, World> build() {
|
||||||
return new WorldComponent<>(this.isRequired(), this.getName(), this.getDefaultValue());
|
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
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
public ComponentParseResult<World> parse(@Nonnull final CommandContext<C> commandContext,
|
public ArgumentParseResult<World> parse(@Nonnull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@Nonnull final Queue<String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
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);
|
final World world = Bukkit.getWorld(input);
|
||||||
if (world == null) {
|
if (world == null) {
|
||||||
return ComponentParseResult.failure(new WorldParseException(input));
|
return ArgumentParseResult.failure(new WorldParseException(input));
|
||||||
}
|
}
|
||||||
|
|
||||||
inputQueue.remove();
|
inputQueue.remove();
|
||||||
return ComponentParseResult.success(world);
|
return ArgumentParseResult.success(world);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
@ -23,6 +23,6 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bukkit specific command components
|
* Bukkit specific command arguments
|
||||||
*/
|
*/
|
||||||
package com.intellectualsites.commands.parsers;
|
package com.intellectualsites.commands.parsers;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ package com.intellectualsites.commands;
|
||||||
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
||||||
import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
|
import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
|
||||||
import com.intellectualsites.commands.brigadier.CloudBrigadierManager;
|
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.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
import com.intellectualsites.commands.sender.CommandSender;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
|
|
@ -112,7 +112,7 @@ class PaperBrigadierListener<C extends CommandSender> implements Listener {
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onCommandRegister(@Nonnull final CommandRegisteredEvent<BukkitBrigadierCommandSource> event) {
|
public void onCommandRegister(@Nonnull final CommandRegisteredEvent<BukkitBrigadierCommandSource> event) {
|
||||||
final CommandTree<C, BukkitCommandMeta> commandTree = this.paperCommandManager.getCommandTree();
|
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) {
|
if (node == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue