🚚 More removal of javax annotations
This commit is contained in:
parent
9f0c846050
commit
4556b392b0
42 changed files with 436 additions and 574 deletions
|
|
@ -25,8 +25,8 @@ package cloud.commandframework;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.arguments.StaticArgument;
|
import cloud.commandframework.arguments.StaticArgument;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
|
|
@ -40,7 +40,7 @@ public final class CommandHelpHandler<C> {
|
||||||
|
|
||||||
private final CommandManager<C> commandManager;
|
private final CommandManager<C> commandManager;
|
||||||
|
|
||||||
CommandHelpHandler(@Nonnull final CommandManager<C> commandManager) {
|
CommandHelpHandler(@NonNull final CommandManager<C> commandManager) {
|
||||||
this.commandManager = commandManager;
|
this.commandManager = commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -49,8 +49,7 @@ public final class CommandHelpHandler<C> {
|
||||||
*
|
*
|
||||||
* @return Syntax hints for all registered commands, order in lexicographical order
|
* @return Syntax hints for all registered commands, order in lexicographical order
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull List<@NonNull VerboseHelpEntry<C>> getAllCommands() {
|
||||||
public List<VerboseHelpEntry<C>> getAllCommands() {
|
|
||||||
final List<VerboseHelpEntry<C>> syntaxHints = new ArrayList<>();
|
final List<VerboseHelpEntry<C>> syntaxHints = new ArrayList<>();
|
||||||
for (final Command<C> command : this.commandManager.getCommands()) {
|
for (final Command<C> command : this.commandManager.getCommands()) {
|
||||||
final List<CommandArgument<C, ?>> arguments = command.getArguments();
|
final List<CommandArgument<C, ?>> arguments = command.getArguments();
|
||||||
|
|
@ -71,8 +70,7 @@ public final class CommandHelpHandler<C> {
|
||||||
*
|
*
|
||||||
* @return Longest shared command chains
|
* @return Longest shared command chains
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull List<@NonNull String> getLongestSharedChains() {
|
||||||
public List<String> getLongestSharedChains() {
|
|
||||||
final List<String> chains = new ArrayList<>();
|
final List<String> chains = new ArrayList<>();
|
||||||
this.commandManager.getCommandTree().getRootNodes().forEach(node ->
|
this.commandManager.getCommandTree().getRootNodes().forEach(node ->
|
||||||
chains.add(node.getValue()
|
chains.add(node.getValue()
|
||||||
|
|
@ -91,9 +89,9 @@ public final class CommandHelpHandler<C> {
|
||||||
private final String syntaxString;
|
private final String syntaxString;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
private VerboseHelpEntry(@Nonnull final Command<C> command,
|
private VerboseHelpEntry(@NonNull final Command<C> command,
|
||||||
@Nonnull final String syntaxString,
|
@NonNull final String syntaxString,
|
||||||
@Nonnull final String description) {
|
@NonNull final String description) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
this.syntaxString = syntaxString;
|
this.syntaxString = syntaxString;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
|
@ -104,8 +102,7 @@ public final class CommandHelpHandler<C> {
|
||||||
*
|
*
|
||||||
* @return Command
|
* @return Command
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Command<C> getCommand() {
|
||||||
public Command<C> getCommand() {
|
|
||||||
return this.command;
|
return this.command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,8 +111,7 @@ public final class CommandHelpHandler<C> {
|
||||||
*
|
*
|
||||||
* @return Syntax string
|
* @return Syntax string
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getSyntaxString() {
|
||||||
public String getSyntaxString() {
|
|
||||||
return this.syntaxString;
|
return this.syntaxString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +120,7 @@ public final class CommandHelpHandler<C> {
|
||||||
*
|
*
|
||||||
* @return Command description
|
* @return Command description
|
||||||
*/
|
*/
|
||||||
public String getDescription() {
|
public @NonNull String getDescription() {
|
||||||
return this.description;
|
return this.description;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -135,7 +131,7 @@ public final class CommandHelpHandler<C> {
|
||||||
* @param query Query string
|
* @param query Query string
|
||||||
* @return Help topic, will return an empty {@link IndexHelpTopic} if no results were found
|
* @return Help topic, will return an empty {@link IndexHelpTopic} if no results were found
|
||||||
*/
|
*/
|
||||||
public HelpTopic<C> queryHelp(@Nonnull final String query) {
|
public @NonNull HelpTopic<C> queryHelp(@NonNull final String query) {
|
||||||
if (query.replace(" ", "").isEmpty()) {
|
if (query.replace(" ", "").isEmpty()) {
|
||||||
return new IndexHelpTopic<>(this.getAllCommands());
|
return new IndexHelpTopic<>(this.getAllCommands());
|
||||||
}
|
}
|
||||||
|
|
@ -265,7 +261,7 @@ public final class CommandHelpHandler<C> {
|
||||||
|
|
||||||
private final List<VerboseHelpEntry<C>> entries;
|
private final List<VerboseHelpEntry<C>> entries;
|
||||||
|
|
||||||
private IndexHelpTopic(@Nonnull final List<VerboseHelpEntry<C>> entries) {
|
private IndexHelpTopic(@NonNull final List<@NonNull VerboseHelpEntry<C>> entries) {
|
||||||
this.entries = entries;
|
this.entries = entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -274,8 +270,7 @@ public final class CommandHelpHandler<C> {
|
||||||
*
|
*
|
||||||
* @return Entries
|
* @return Entries
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull List<@NonNull VerboseHelpEntry<C>> getEntries() {
|
||||||
public List<VerboseHelpEntry<C>> getEntries() {
|
|
||||||
return this.entries;
|
return this.entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -301,7 +296,7 @@ public final class CommandHelpHandler<C> {
|
||||||
private final Command<C> command;
|
private final Command<C> command;
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
private VerboseHelpTopic(@Nonnull final Command<C> command) {
|
private VerboseHelpTopic(@NonNull final Command<C> command) {
|
||||||
this.command = command;
|
this.command = command;
|
||||||
final String shortDescription = command.getCommandMeta().getOrDefault("description", "No description");
|
final String shortDescription = command.getCommandMeta().getOrDefault("description", "No description");
|
||||||
this.description = command.getCommandMeta().getOrDefault("long-description", shortDescription);
|
this.description = command.getCommandMeta().getOrDefault("long-description", shortDescription);
|
||||||
|
|
@ -312,8 +307,7 @@ public final class CommandHelpHandler<C> {
|
||||||
*
|
*
|
||||||
* @return Command
|
* @return Command
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Command<C> getCommand() {
|
||||||
public Command<C> getCommand() {
|
|
||||||
return this.command;
|
return this.command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -322,8 +316,7 @@ public final class CommandHelpHandler<C> {
|
||||||
*
|
*
|
||||||
* @return Command description
|
* @return Command description
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getDescription() {
|
||||||
public String getDescription() {
|
|
||||||
return this.description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -340,7 +333,8 @@ public final class CommandHelpHandler<C> {
|
||||||
private final String longestPath;
|
private final String longestPath;
|
||||||
private final List<String> childSuggestions;
|
private final List<String> childSuggestions;
|
||||||
|
|
||||||
private MultiHelpTopic(@Nonnull final String longestPath, @Nonnull final List<String> childSuggestions) {
|
private MultiHelpTopic(@NonNull final String longestPath,
|
||||||
|
@NonNull final List<@NonNull String> childSuggestions) {
|
||||||
this.longestPath = longestPath;
|
this.longestPath = longestPath;
|
||||||
this.childSuggestions = childSuggestions;
|
this.childSuggestions = childSuggestions;
|
||||||
}
|
}
|
||||||
|
|
@ -350,8 +344,7 @@ public final class CommandHelpHandler<C> {
|
||||||
*
|
*
|
||||||
* @return Longest path
|
* @return Longest path
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getLongestPath() {
|
||||||
public String getLongestPath() {
|
|
||||||
return this.longestPath;
|
return this.longestPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -360,8 +353,7 @@ public final class CommandHelpHandler<C> {
|
||||||
*
|
*
|
||||||
* @return Child suggestions
|
* @return Child suggestions
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull List<@NonNull String> getChildSuggestions() {
|
||||||
public List<String> getChildSuggestions() {
|
|
||||||
return this.childSuggestions;
|
return this.childSuggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -51,9 +51,9 @@ import cloud.commandframework.permission.OrPermission;
|
||||||
import cloud.commandframework.permission.Permission;
|
import cloud.commandframework.permission.Permission;
|
||||||
import cloud.commandframework.services.ServicePipeline;
|
import cloud.commandframework.services.ServicePipeline;
|
||||||
import cloud.commandframework.services.State;
|
import cloud.commandframework.services.State;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
@ -96,8 +96,8 @@ public abstract class CommandManager<C> {
|
||||||
* @param commandRegistrationHandler Command registration handler
|
* @param commandRegistrationHandler Command registration handler
|
||||||
*/
|
*/
|
||||||
public CommandManager(
|
public CommandManager(
|
||||||
@Nonnull final Function<CommandTree<C>, CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
@NonNull final Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> commandExecutionCoordinator,
|
||||||
@Nonnull final CommandRegistrationHandler commandRegistrationHandler) {
|
@NonNull final CommandRegistrationHandler commandRegistrationHandler) {
|
||||||
this.commandTree = CommandTree.newTree(this);
|
this.commandTree = CommandTree.newTree(this);
|
||||||
this.commandExecutionCoordinator = commandExecutionCoordinator.apply(commandTree);
|
this.commandExecutionCoordinator = commandExecutionCoordinator.apply(commandTree);
|
||||||
this.commandRegistrationHandler = commandRegistrationHandler;
|
this.commandRegistrationHandler = commandRegistrationHandler;
|
||||||
|
|
@ -113,8 +113,7 @@ public abstract class CommandManager<C> {
|
||||||
* @param input Input string
|
* @param input Input string
|
||||||
* @return List of tokens
|
* @return List of tokens
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static @NonNull LinkedList<@NonNull String> tokenize(@NonNull final String input) {
|
||||||
public static LinkedList<String> tokenize(@Nonnull final String input) {
|
|
||||||
final StringTokenizer stringTokenizer = new StringTokenizer(input, " ");
|
final StringTokenizer stringTokenizer = new StringTokenizer(input, " ");
|
||||||
final LinkedList<String> tokens = new LinkedList<>();
|
final LinkedList<String> tokens = new LinkedList<>();
|
||||||
while (stringTokenizer.hasMoreElements()) {
|
while (stringTokenizer.hasMoreElements()) {
|
||||||
|
|
@ -133,8 +132,8 @@ public abstract class CommandManager<C> {
|
||||||
* @param input Input provided by the sender
|
* @param input Input provided by the sender
|
||||||
* @return Command result
|
* @return Command result
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CompletableFuture<CommandResult<C>> executeCommand(@NonNull final C commandSender,
|
||||||
public CompletableFuture<CommandResult<C>> executeCommand(@Nonnull final C commandSender, @Nonnull final String input) {
|
@NonNull final String input) {
|
||||||
final CommandContext<C> context = this.commandContextFactory.create(false, commandSender);
|
final CommandContext<C> context = this.commandContextFactory.create(false, commandSender);
|
||||||
final LinkedList<String> inputQueue = tokenize(input);
|
final LinkedList<String> inputQueue = tokenize(input);
|
||||||
try {
|
try {
|
||||||
|
|
@ -158,8 +157,8 @@ public abstract class CommandManager<C> {
|
||||||
* @param input Input provided by the sender
|
* @param input Input provided by the sender
|
||||||
* @return List of suggestions
|
* @return List of suggestions
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull List<@NonNull String> suggest(@NonNull final C commandSender,
|
||||||
public List<String> suggest(@Nonnull final C commandSender, @Nonnull final String input) {
|
@NonNull final String input) {
|
||||||
final CommandContext<C> context = this.commandContextFactory.create(true, commandSender);
|
final CommandContext<C> context = this.commandContextFactory.create(true, commandSender);
|
||||||
final LinkedList<String> inputQueue = tokenize(input);
|
final LinkedList<String> inputQueue = tokenize(input);
|
||||||
if (this.preprocessContext(context, inputQueue) == State.ACCEPTED) {
|
if (this.preprocessContext(context, inputQueue) == State.ACCEPTED) {
|
||||||
|
|
@ -177,7 +176,7 @@ public abstract class CommandManager<C> {
|
||||||
* @param command Command to register
|
* @param command Command to register
|
||||||
* @return The command manager instance
|
* @return The command manager instance
|
||||||
*/
|
*/
|
||||||
public CommandManager<C> command(@Nonnull final Command<C> command) {
|
public @NonNull CommandManager<C> command(@NonNull final Command<C> command) {
|
||||||
this.commandTree.insertCommand(command);
|
this.commandTree.insertCommand(command);
|
||||||
this.commands.add(command);
|
this.commands.add(command);
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -188,8 +187,7 @@ public abstract class CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Command syntax formatter
|
* @return Command syntax formatter
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandSyntaxFormatter<C> getCommandSyntaxFormatter() {
|
||||||
public CommandSyntaxFormatter<C> getCommandSyntaxFormatter() {
|
|
||||||
return this.commandSyntaxFormatter;
|
return this.commandSyntaxFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -198,7 +196,7 @@ public abstract class CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @param commandSyntaxFormatter New formatter
|
* @param commandSyntaxFormatter New formatter
|
||||||
*/
|
*/
|
||||||
public void setCommandSyntaxFormatter(@Nonnull final CommandSyntaxFormatter<C> commandSyntaxFormatter) {
|
public void setCommandSyntaxFormatter(@NonNull final CommandSyntaxFormatter<C> commandSyntaxFormatter) {
|
||||||
this.commandSyntaxFormatter = commandSyntaxFormatter;
|
this.commandSyntaxFormatter = commandSyntaxFormatter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,12 +205,11 @@ public abstract class CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Command registration handler
|
* @return Command registration handler
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
protected @NonNull CommandRegistrationHandler getCommandRegistrationHandler() {
|
||||||
protected CommandRegistrationHandler getCommandRegistrationHandler() {
|
|
||||||
return this.commandRegistrationHandler;
|
return this.commandRegistrationHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected final void setCommandRegistrationHandler(@Nonnull final CommandRegistrationHandler commandRegistrationHandler) {
|
protected final void setCommandRegistrationHandler(@NonNull final CommandRegistrationHandler commandRegistrationHandler) {
|
||||||
this.commandRegistrationHandler = commandRegistrationHandler;
|
this.commandRegistrationHandler = commandRegistrationHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,7 +221,8 @@ public abstract class CommandManager<C> {
|
||||||
* @param permission Permission node
|
* @param permission Permission node
|
||||||
* @return {@code true} if the sender has the permission, else {@code false}
|
* @return {@code true} if the sender has the permission, else {@code false}
|
||||||
*/
|
*/
|
||||||
public boolean hasPermission(@Nonnull final C sender, @Nonnull final CommandPermission permission) {
|
public boolean hasPermission(@NonNull final C sender,
|
||||||
|
@NonNull final CommandPermission permission) {
|
||||||
if (permission.toString().isEmpty()) {
|
if (permission.toString().isEmpty()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -250,7 +248,7 @@ public abstract class CommandManager<C> {
|
||||||
* @param permission Permission node
|
* @param permission Permission node
|
||||||
* @return {@code true} if the sender has the permission, else {@code false}
|
* @return {@code true} if the sender has the permission, else {@code false}
|
||||||
*/
|
*/
|
||||||
public abstract boolean hasPermission(@Nonnull C sender, @Nonnull String permission);
|
public abstract boolean hasPermission(@NonNull C sender, @NonNull String permission);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command builder
|
* Create a new command builder
|
||||||
|
|
@ -261,11 +259,10 @@ public abstract class CommandManager<C> {
|
||||||
* @param meta Command meta
|
* @param meta Command meta
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public Command.@NonNull Builder<C> commandBuilder(@NonNull final String name,
|
||||||
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
@NonNull final Collection<String> aliases,
|
||||||
@Nonnull final Collection<String> aliases,
|
@NonNull final Description description,
|
||||||
@Nonnull final Description description,
|
@NonNull final CommandMeta meta) {
|
||||||
@Nonnull final CommandMeta meta) {
|
|
||||||
return Command.newBuilder(name, meta, description, aliases.toArray(new String[0]));
|
return Command.newBuilder(name, meta, description, aliases.toArray(new String[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -277,10 +274,9 @@ public abstract class CommandManager<C> {
|
||||||
* @param meta Command meta
|
* @param meta Command meta
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public Command.@NonNull Builder<C> commandBuilder(@NonNull final String name,
|
||||||
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
@NonNull final Collection<String> aliases,
|
||||||
@Nonnull final Collection<String> aliases,
|
@NonNull final CommandMeta meta) {
|
||||||
@Nonnull final CommandMeta meta) {
|
|
||||||
return Command.newBuilder(name, meta, Description.empty(), aliases.toArray(new String[0]));
|
return Command.newBuilder(name, meta, Description.empty(), aliases.toArray(new String[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -293,11 +289,10 @@ public abstract class CommandManager<C> {
|
||||||
* @param aliases Command aliases
|
* @param aliases Command aliases
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public Command.@NonNull Builder<C> commandBuilder(@NonNull final String name,
|
||||||
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
@NonNull final CommandMeta meta,
|
||||||
@Nonnull final CommandMeta meta,
|
@NonNull final Description description,
|
||||||
@Nonnull final Description description,
|
@NonNull final String... aliases) {
|
||||||
@Nonnull final String... aliases) {
|
|
||||||
return Command.newBuilder(name, meta, description, aliases);
|
return Command.newBuilder(name, meta, description, aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -309,10 +304,9 @@ public abstract class CommandManager<C> {
|
||||||
* @param aliases Command aliases
|
* @param aliases Command aliases
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public Command.@NonNull Builder<C> commandBuilder(@NonNull final String name,
|
||||||
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
@NonNull final CommandMeta meta,
|
||||||
@Nonnull final CommandMeta meta,
|
@NonNull final String... aliases) {
|
||||||
@Nonnull final String... aliases) {
|
|
||||||
return Command.newBuilder(name, meta, Description.empty(), aliases);
|
return Command.newBuilder(name, meta, Description.empty(), aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -326,10 +320,9 @@ public abstract class CommandManager<C> {
|
||||||
* @throws UnsupportedOperationException If the command manager does not support default command meta creation
|
* @throws UnsupportedOperationException If the command manager does not support default command meta creation
|
||||||
* @see #createDefaultCommandMeta() Default command meta creation
|
* @see #createDefaultCommandMeta() Default command meta creation
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public Command.@NonNull Builder<C> commandBuilder(@NonNull final String name,
|
||||||
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
@NonNull final Description description,
|
||||||
@Nonnull final Description description,
|
@NonNull final String... aliases) {
|
||||||
@Nonnull final String... aliases) {
|
|
||||||
return Command.<C>newBuilder(name, this.createDefaultCommandMeta(), description, aliases).manager(this);
|
return Command.<C>newBuilder(name, this.createDefaultCommandMeta(), description, aliases).manager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -342,9 +335,8 @@ public abstract class CommandManager<C> {
|
||||||
* @throws UnsupportedOperationException If the command manager does not support default command meta creation
|
* @throws UnsupportedOperationException If the command manager does not support default command meta creation
|
||||||
* @see #createDefaultCommandMeta() Default command meta creation
|
* @see #createDefaultCommandMeta() Default command meta creation
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public Command.@NonNull Builder<C> commandBuilder(@NonNull final String name,
|
||||||
public Command.Builder<C> commandBuilder(@Nonnull final String name,
|
@NonNull final String... aliases) {
|
||||||
@Nonnull final String... aliases) {
|
|
||||||
return Command.<C>newBuilder(name, this.createDefaultCommandMeta(), Description.empty(), aliases).manager(this);
|
return Command.<C>newBuilder(name, this.createDefaultCommandMeta(), Description.empty(), aliases).manager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -356,8 +348,8 @@ public abstract class CommandManager<C> {
|
||||||
* @param <T> Generic argument name
|
* @param <T> Generic argument name
|
||||||
* @return Argument builder
|
* @return Argument builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <T> CommandArgument.@NonNull Builder<C, T> argumentBuilder(@NonNull final Class<T> type,
|
||||||
public <T> CommandArgument.Builder<C, T> argumentBuilder(@Nonnull final Class<T> type, @Nonnull final String name) {
|
@NonNull final String name) {
|
||||||
return CommandArgument.<C, T>ofType(type, name).manager(this);
|
return CommandArgument.<C, T>ofType(type, name).manager(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -367,8 +359,7 @@ public abstract class CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Command tree
|
* @return Command tree
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandTree<C> getCommandTree() {
|
||||||
public CommandTree<C> getCommandTree() {
|
|
||||||
return this.commandTree;
|
return this.commandTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -378,8 +369,7 @@ public abstract class CommandManager<C> {
|
||||||
* @return Default command meta
|
* @return Default command meta
|
||||||
* @throws UnsupportedOperationException If the command manager does not support this operation
|
* @throws UnsupportedOperationException If the command manager does not support this operation
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public abstract @NonNull CommandMeta createDefaultCommandMeta();
|
||||||
public abstract CommandMeta createDefaultCommandMeta();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a new command preprocessor. The order they are registered in is respected, and they
|
* Register a new command preprocessor. The order they are registered in is respected, and they
|
||||||
|
|
@ -388,7 +378,7 @@ public abstract class CommandManager<C> {
|
||||||
* @param processor Processor to register
|
* @param processor Processor to register
|
||||||
* @see #preprocessContext(CommandContext, LinkedList) Preprocess a context
|
* @see #preprocessContext(CommandContext, LinkedList) Preprocess a context
|
||||||
*/
|
*/
|
||||||
public void registerCommandPreProcessor(@Nonnull final CommandPreprocessor<C> processor) {
|
public void registerCommandPreProcessor(@NonNull final CommandPreprocessor<C> processor) {
|
||||||
this.servicePipeline.registerServiceImplementation(new TypeToken<CommandPreprocessor<C>>() {
|
this.servicePipeline.registerServiceImplementation(new TypeToken<CommandPreprocessor<C>>() {
|
||||||
}, processor,
|
}, processor,
|
||||||
Collections.emptyList());
|
Collections.emptyList());
|
||||||
|
|
@ -401,7 +391,7 @@ public abstract class CommandManager<C> {
|
||||||
* @param processor Processor to register
|
* @param processor Processor to register
|
||||||
* @see #preprocessContext(CommandContext, LinkedList) Preprocess a context
|
* @see #preprocessContext(CommandContext, LinkedList) Preprocess a context
|
||||||
*/
|
*/
|
||||||
public void registerCommandPostProcessor(@Nonnull final CommandPostprocessor<C> processor) {
|
public void registerCommandPostProcessor(@NonNull final CommandPostprocessor<C> processor) {
|
||||||
this.servicePipeline.registerServiceImplementation(new TypeToken<CommandPostprocessor<C>>() {
|
this.servicePipeline.registerServiceImplementation(new TypeToken<CommandPostprocessor<C>>() {
|
||||||
}, processor,
|
}, processor,
|
||||||
Collections.emptyList());
|
Collections.emptyList());
|
||||||
|
|
@ -415,7 +405,8 @@ public abstract class CommandManager<C> {
|
||||||
* @return {@link State#ACCEPTED} if the command should be parsed and executed, else {@link State#REJECTED}
|
* @return {@link State#ACCEPTED} if the command should be parsed and executed, else {@link State#REJECTED}
|
||||||
* @see #registerCommandPreProcessor(CommandPreprocessor) Register a command preprocessor
|
* @see #registerCommandPreProcessor(CommandPreprocessor) Register a command preprocessor
|
||||||
*/
|
*/
|
||||||
public State preprocessContext(@Nonnull final CommandContext<C> context, @Nonnull final LinkedList<String> inputQueue) {
|
public State preprocessContext(@NonNull final CommandContext<C> context,
|
||||||
|
@NonNull final LinkedList<@NonNull String> inputQueue) {
|
||||||
this.servicePipeline.pump(new CommandPreprocessingContext<>(context, inputQueue))
|
this.servicePipeline.pump(new CommandPreprocessingContext<>(context, inputQueue))
|
||||||
.through(new TypeToken<CommandPreprocessor<C>>() {
|
.through(new TypeToken<CommandPreprocessor<C>>() {
|
||||||
})
|
})
|
||||||
|
|
@ -433,7 +424,8 @@ public abstract class CommandManager<C> {
|
||||||
* @return {@link State#ACCEPTED} if the command should be parsed and executed, else {@link State#REJECTED}
|
* @return {@link State#ACCEPTED} if the command should be parsed and executed, else {@link State#REJECTED}
|
||||||
* @see #registerCommandPostProcessor(CommandPostprocessor) Register a command postprocessor
|
* @see #registerCommandPostProcessor(CommandPostprocessor) Register a command postprocessor
|
||||||
*/
|
*/
|
||||||
public State postprocessContext(@Nonnull final CommandContext<C> context, @Nonnull final Command<C> command) {
|
public State postprocessContext(@NonNull final CommandContext<C> context,
|
||||||
|
@NonNull final Command<C> command) {
|
||||||
this.servicePipeline.pump(new CommandPostprocessingContext<>(context, command))
|
this.servicePipeline.pump(new CommandPostprocessingContext<>(context, command))
|
||||||
.through(new TypeToken<CommandPostprocessor<C>>() {
|
.through(new TypeToken<CommandPostprocessor<C>>() {
|
||||||
})
|
})
|
||||||
|
|
@ -449,8 +441,7 @@ public abstract class CommandManager<C> {
|
||||||
* @return Command suggestions processor
|
* @return Command suggestions processor
|
||||||
* @see #setCommandSuggestionProcessor(CommandSuggestionProcessor) Setting the suggestion processor
|
* @see #setCommandSuggestionProcessor(CommandSuggestionProcessor) Setting the suggestion processor
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandSuggestionProcessor<C> getCommandSuggestionProcessor() {
|
||||||
public CommandSuggestionProcessor<C> getCommandSuggestionProcessor() {
|
|
||||||
return this.commandSuggestionProcessor;
|
return this.commandSuggestionProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -461,7 +452,7 @@ public abstract class CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @param commandSuggestionProcessor New command suggestions processor
|
* @param commandSuggestionProcessor New command suggestions processor
|
||||||
*/
|
*/
|
||||||
public void setCommandSuggestionProcessor(@Nonnull final CommandSuggestionProcessor<C> commandSuggestionProcessor) {
|
public void setCommandSuggestionProcessor(@NonNull final CommandSuggestionProcessor<C> commandSuggestionProcessor) {
|
||||||
this.commandSuggestionProcessor = commandSuggestionProcessor;
|
this.commandSuggestionProcessor = commandSuggestionProcessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -478,7 +469,6 @@ public abstract class CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Parser registry instance
|
* @return Parser registry instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
public ParserRegistry<C> getParserRegistry() {
|
public ParserRegistry<C> getParserRegistry() {
|
||||||
return this.parserRegistry;
|
return this.parserRegistry;
|
||||||
}
|
}
|
||||||
|
|
@ -491,8 +481,8 @@ public abstract class CommandManager<C> {
|
||||||
* @return Exception handler, or {@code null}
|
* @return Exception handler, or {@code null}
|
||||||
* @see #registerCommandPreProcessor(CommandPreprocessor) Registering an exception handler
|
* @see #registerCommandPreProcessor(CommandPreprocessor) Registering an exception handler
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public final <E extends Exception> @Nullable BiConsumer<@NonNull C, @NonNull E>
|
||||||
public final <E extends Exception> BiConsumer<C, E> getExceptionHandler(@Nullable final Class<E> clazz) {
|
getExceptionHandler(@NonNull final Class<E> clazz) {
|
||||||
final BiConsumer<C, ? extends Exception> consumer = this.exceptionHandlers.get(clazz);
|
final BiConsumer<C, ? extends Exception> consumer = this.exceptionHandlers.get(clazz);
|
||||||
if (consumer == null) {
|
if (consumer == null) {
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -510,8 +500,8 @@ public abstract class CommandManager<C> {
|
||||||
* @param handler Exception handler
|
* @param handler Exception handler
|
||||||
* @param <E> Exception type
|
* @param <E> Exception type
|
||||||
*/
|
*/
|
||||||
public final <E extends Exception> void registerExceptionHandler(@Nonnull final Class<E> clazz,
|
public final <E extends Exception> void registerExceptionHandler(@NonNull final Class<E> clazz,
|
||||||
@Nonnull final BiConsumer<C, E> handler) {
|
@NonNull final BiConsumer<@NonNull C, @NonNull E> handler) {
|
||||||
this.exceptionHandlers.put(clazz, handler);
|
this.exceptionHandlers.put(clazz, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -526,10 +516,10 @@ public abstract class CommandManager<C> {
|
||||||
* handler stored for the exception type
|
* handler stored for the exception type
|
||||||
* @param <E> Exception type
|
* @param <E> Exception type
|
||||||
*/
|
*/
|
||||||
public final <E extends Exception> void handleException(@Nonnull final C sender,
|
public final <E extends Exception> void handleException(@NonNull final C sender,
|
||||||
@Nonnull final Class<E> clazz,
|
@NonNull final Class<E> clazz,
|
||||||
@Nonnull final E exception,
|
@NonNull final E exception,
|
||||||
@Nonnull final BiConsumer<C, E> defaultHandler) {
|
@NonNull final BiConsumer<C, E> defaultHandler) {
|
||||||
Optional.ofNullable(this.getExceptionHandler(clazz)).orElse(defaultHandler).accept(sender, exception);
|
Optional.ofNullable(this.getExceptionHandler(clazz)).orElse(defaultHandler).accept(sender, exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -538,8 +528,7 @@ public abstract class CommandManager<C> {
|
||||||
*
|
*
|
||||||
* @return Unmodifiable view of all registered commands
|
* @return Unmodifiable view of all registered commands
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public final @NonNull Collection<@NonNull Command<C>> getCommands() {
|
||||||
public final Collection<Command<C>> getCommands() {
|
|
||||||
return Collections.unmodifiableCollection(this.commands);
|
return Collections.unmodifiableCollection(this.commands);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -550,8 +539,7 @@ public abstract class CommandManager<C> {
|
||||||
* @return Command help handler. A new instance will be created
|
* @return Command help handler. A new instance will be created
|
||||||
* each time this method is called.
|
* each time this method is called.
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public final @NonNull CommandHelpHandler<C> getCommandHelpHandler() {
|
||||||
public final CommandHelpHandler<C> getCommandHelpHandler() {
|
|
||||||
return new CommandHelpHandler<>(this);
|
return new CommandHelpHandler<>(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -561,7 +549,7 @@ public abstract class CommandManager<C> {
|
||||||
* @param setting Setting
|
* @param setting Setting
|
||||||
* @return {@code true} if the setting is activated or {@code false} if it's not
|
* @return {@code true} if the setting is activated or {@code false} if it's not
|
||||||
*/
|
*/
|
||||||
public boolean getSetting(@Nonnull final ManagerSettings setting) {
|
public boolean getSetting(@NonNull final ManagerSettings setting) {
|
||||||
return this.managerSettings.contains(setting);
|
return this.managerSettings.contains(setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -571,7 +559,7 @@ public abstract class CommandManager<C> {
|
||||||
* @param setting Setting to set
|
* @param setting Setting to set
|
||||||
* @param value Value
|
* @param value Value
|
||||||
*/
|
*/
|
||||||
public void setSetting(@Nonnull final ManagerSettings setting,
|
public void setSetting(@NonNull final ManagerSettings setting,
|
||||||
final boolean value) {
|
final boolean value) {
|
||||||
if (value) {
|
if (value) {
|
||||||
this.managerSettings.add(setting);
|
this.managerSettings.add(setting);
|
||||||
|
|
|
||||||
|
|
@ -28,31 +28,13 @@ import cloud.commandframework.arguments.StaticArgument;
|
||||||
import cloud.commandframework.arguments.compound.CompoundArgument;
|
import cloud.commandframework.arguments.compound.CompoundArgument;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.exceptions.AmbiguousNodeException;
|
import cloud.commandframework.exceptions.*;
|
||||||
import cloud.commandframework.exceptions.ArgumentParseException;
|
|
||||||
import cloud.commandframework.exceptions.InvalidCommandSenderException;
|
|
||||||
import cloud.commandframework.exceptions.InvalidSyntaxException;
|
|
||||||
import cloud.commandframework.exceptions.NoCommandInLeafException;
|
|
||||||
import cloud.commandframework.exceptions.NoPermissionException;
|
|
||||||
import cloud.commandframework.exceptions.NoSuchCommandException;
|
|
||||||
import cloud.commandframework.permission.CommandPermission;
|
import cloud.commandframework.permission.CommandPermission;
|
||||||
import cloud.commandframework.permission.OrPermission;
|
import cloud.commandframework.permission.OrPermission;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import java.util.*;
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
import java.util.Queue;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -89,7 +71,7 @@ public final class CommandTree<C> {
|
||||||
private final Node<CommandArgument<C, ?>> internalTree = new Node<>(null);
|
private final Node<CommandArgument<C, ?>> internalTree = new Node<>(null);
|
||||||
private final CommandManager<C> commandManager;
|
private final CommandManager<C> commandManager;
|
||||||
|
|
||||||
private CommandTree(@Nonnull final CommandManager<C> commandManager) {
|
private CommandTree(@NonNull final CommandManager<C> commandManager) {
|
||||||
this.commandManager = commandManager;
|
this.commandManager = commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,8 +82,7 @@ public final class CommandTree<C> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return New command tree
|
* @return New command tree
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandTree<C> newTree(@NonNull final CommandManager<C> commandManager) {
|
||||||
public static <C> CommandTree<C> newTree(@Nonnull final CommandManager<C> commandManager) {
|
|
||||||
return new CommandTree<>(commandManager);
|
return new CommandTree<>(commandManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -115,8 +96,8 @@ public final class CommandTree<C> {
|
||||||
* @throws NoPermissionException If the sender lacks permission to execute the command
|
* @throws NoPermissionException If the sender lacks permission to execute the command
|
||||||
* @throws InvalidSyntaxException If the command syntax is invalid
|
* @throws InvalidSyntaxException If the command syntax is invalid
|
||||||
*/
|
*/
|
||||||
public Optional<Command<C>> parse(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull Optional<Command<C>> parse(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> args) throws
|
@NonNull final Queue<@NonNull String> args) throws
|
||||||
NoSuchCommandException, NoPermissionException, InvalidSyntaxException {
|
NoSuchCommandException, NoPermissionException, InvalidSyntaxException {
|
||||||
final Optional<Command<C>> commandOptional = parseCommand(new ArrayList<>(),
|
final Optional<Command<C>> commandOptional = parseCommand(new ArrayList<>(),
|
||||||
commandContext,
|
commandContext,
|
||||||
|
|
@ -130,10 +111,10 @@ public final class CommandTree<C> {
|
||||||
return commandOptional;
|
return commandOptional;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Optional<Command<C>> parseCommand(@Nonnull final List<CommandArgument<C, ?>> parsedArguments,
|
private Optional<Command<C>> parseCommand(@NonNull final List<@NonNull CommandArgument<C, ?>> parsedArguments,
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> commandQueue,
|
@NonNull final Queue<@NonNull String> commandQueue,
|
||||||
@Nonnull final Node<CommandArgument<C, ?>> root) {
|
@NonNull final Node<@Nullable CommandArgument<C, ?>> root) {
|
||||||
CommandPermission permission = this.isPermitted(commandContext.getSender(), root);
|
CommandPermission 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)
|
||||||
|
|
@ -225,11 +206,11 @@ public final class CommandTree<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private @Nullable Optional<Command<C>>
|
||||||
private Optional<Command<C>> attemptParseUnambiguousChild(@Nonnull final List<CommandArgument<C, ?>> parsedArguments,
|
attemptParseUnambiguousChild(@NonNull final List<@NonNull CommandArgument<C, ?>> parsedArguments,
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Node<CommandArgument<C, ?>> root,
|
@NonNull final Node<@Nullable CommandArgument<C, ?>> root,
|
||||||
@Nonnull final Queue<String> commandQueue) {
|
@NonNull final Queue<String> commandQueue) {
|
||||||
CommandPermission permission;
|
CommandPermission permission;
|
||||||
final List<Node<CommandArgument<C, ?>>> children = root.getChildren();
|
final List<Node<CommandArgument<C, ?>>> children = root.getChildren();
|
||||||
if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticArgument)) {
|
if (children.size() == 1 && !(children.get(0).getValue() instanceof StaticArgument)) {
|
||||||
|
|
@ -343,15 +324,14 @@ public final class CommandTree<C> {
|
||||||
* @param commandQueue Input queue
|
* @param commandQueue Input queue
|
||||||
* @return String suggestions. These should be filtered based on {@link String#startsWith(String)}
|
* @return String suggestions. These should be filtered based on {@link String#startsWith(String)}
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull List<@NonNull String> getSuggestions(@NonNull final CommandContext<C> context,
|
||||||
public List<String> getSuggestions(@Nonnull final CommandContext<C> context, @Nonnull final Queue<String> commandQueue) {
|
@NonNull final Queue<@NonNull String> commandQueue) {
|
||||||
return getSuggestions(context, commandQueue, this.internalTree);
|
return getSuggestions(context, commandQueue, this.internalTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private @NonNull List<@NonNull String> getSuggestions(@NonNull final CommandContext<C> commandContext,
|
||||||
private List<String> getSuggestions(@Nonnull final CommandContext<C> commandContext,
|
@NonNull final Queue<@NonNull String> commandQueue,
|
||||||
@Nonnull final Queue<String> commandQueue,
|
@NonNull final Node<@Nullable CommandArgument<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) {
|
||||||
|
|
@ -432,8 +412,7 @@ public final class CommandTree<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private @NonNull String stringOrEmpty(@Nullable final String string) {
|
||||||
private String stringOrEmpty(@Nullable final String string) {
|
|
||||||
if (string == null) {
|
if (string == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
@ -446,7 +425,7 @@ public final class CommandTree<C> {
|
||||||
* @param command Command to insert
|
* @param command Command to insert
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public void insertCommand(@Nonnull final Command<C> command) {
|
public void insertCommand(@NonNull final Command<C> command) {
|
||||||
synchronized (this.commandLock) {
|
synchronized (this.commandLock) {
|
||||||
Node<CommandArgument<C, ?>> node = this.internalTree;
|
Node<CommandArgument<C, ?>> node = this.internalTree;
|
||||||
for (final CommandArgument<C, ?> argument : command.getArguments()) {
|
for (final CommandArgument<C, ?> argument : command.getArguments()) {
|
||||||
|
|
@ -478,8 +457,8 @@ public final class CommandTree<C> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private @Nullable CommandPermission isPermitted(@NonNull final C sender,
|
||||||
private CommandPermission isPermitted(@Nonnull final C sender, @Nonnull final Node<CommandArgument<C, ?>> node) {
|
@NonNull final Node<@Nullable CommandArgument<C, ?>> node) {
|
||||||
final CommandPermission permission = (CommandPermission) node.nodeMeta.get("permission");
|
final CommandPermission permission = (CommandPermission) node.nodeMeta.get("permission");
|
||||||
if (permission != null) {
|
if (permission != null) {
|
||||||
return this.commandManager.hasPermission(sender, permission) ? null : permission;
|
return this.commandManager.hasPermission(sender, permission) ? null : permission;
|
||||||
|
|
@ -569,7 +548,7 @@ public final class CommandTree<C> {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAmbiguity(@Nonnull final Node<CommandArgument<C, ?>> node) throws AmbiguousNodeException {
|
private void checkAmbiguity(@NonNull final Node<@Nullable CommandArgument<C, ?>> node) throws AmbiguousNodeException {
|
||||||
if (node.isLeaf()) {
|
if (node.isLeaf()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -584,7 +563,8 @@ public final class CommandTree<C> {
|
||||||
node.children.forEach(this::checkAmbiguity);
|
node.children.forEach(this::checkAmbiguity);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Node<CommandArgument<C, ?>>> getLeavesRaw(@Nonnull final Node<CommandArgument<C, ?>> node) {
|
private @NonNull List<@NonNull Node<@Nullable CommandArgument<C, ?>>>
|
||||||
|
getLeavesRaw(@NonNull final Node<@Nullable CommandArgument<C, ?>> node) {
|
||||||
final List<Node<CommandArgument<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) {
|
||||||
|
|
@ -596,7 +576,7 @@ public final class CommandTree<C> {
|
||||||
return leaves;
|
return leaves;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<CommandArgument<C, ?>> getLeaves(@Nonnull final Node<CommandArgument<C, ?>> node) {
|
private @NonNull List<@NonNull CommandArgument<C, ?>> getLeaves(@NonNull final Node<@NonNull CommandArgument<C, ?>> node) {
|
||||||
final List<CommandArgument<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) {
|
||||||
|
|
@ -608,7 +588,8 @@ public final class CommandTree<C> {
|
||||||
return leaves;
|
return leaves;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Node<CommandArgument<C, ?>>> getChain(@Nullable final Node<CommandArgument<C, ?>> end) {
|
private @NonNull List<@NonNull Node<@Nullable CommandArgument<C, ?>>>
|
||||||
|
getChain(@Nullable final Node<@Nullable CommandArgument<C, ?>> end) {
|
||||||
final List<Node<CommandArgument<C, ?>>> chain = new LinkedList<>();
|
final List<Node<CommandArgument<C, ?>>> chain = new LinkedList<>();
|
||||||
Node<CommandArgument<C, ?>> tail = end;
|
Node<CommandArgument<C, ?>> tail = end;
|
||||||
while (tail != null) {
|
while (tail != null) {
|
||||||
|
|
@ -619,8 +600,7 @@ public final class CommandTree<C> {
|
||||||
return chain;
|
return chain;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private @Nullable Command<C> cast(@Nullable final Command<C> command) {
|
||||||
private Command<C> cast(@Nullable final Command<C> command) {
|
|
||||||
return command;
|
return command;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -630,8 +610,7 @@ public final class CommandTree<C> {
|
||||||
*
|
*
|
||||||
* @return Root nodes
|
* @return Root nodes
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Collection<@NonNull Node<@Nullable CommandArgument<C, ?>>> getRootNodes() {
|
||||||
public Collection<Node<CommandArgument<C, ?>>> getRootNodes() {
|
|
||||||
return this.internalTree.getChildren();
|
return this.internalTree.getChildren();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -641,8 +620,7 @@ public final class CommandTree<C> {
|
||||||
* @param name Root node name
|
* @param name Root node name
|
||||||
* @return Root node, or {@code null}
|
* @return Root node, or {@code null}
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public @Nullable Node<@Nullable CommandArgument<C, ?>> getNamedNode(@Nullable final String name) {
|
||||||
public Node<CommandArgument<C, ?>> getNamedNode(@Nullable final String name) {
|
|
||||||
for (final Node<CommandArgument<C, ?>> node : this.getRootNodes()) {
|
for (final Node<CommandArgument<C, ?>> node : this.getRootNodes()) {
|
||||||
if (node.getValue() != null && node.getValue() instanceof StaticArgument) {
|
if (node.getValue() != null && node.getValue() instanceof StaticArgument) {
|
||||||
@SuppressWarnings("unchecked") final StaticArgument<C> staticArgument = (StaticArgument<C>) node.getValue();
|
@SuppressWarnings("unchecked") final StaticArgument<C> staticArgument = (StaticArgument<C>) node.getValue();
|
||||||
|
|
@ -661,8 +639,7 @@ public final class CommandTree<C> {
|
||||||
*
|
*
|
||||||
* @return Command manager
|
* @return Command manager
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandManager<C> getCommandManager() {
|
||||||
public CommandManager<C> getCommandManager() {
|
|
||||||
return this.commandManager;
|
return this.commandManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -687,20 +664,17 @@ public final class CommandTree<C> {
|
||||||
*
|
*
|
||||||
* @return Children
|
* @return Children
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull List<@NonNull Node<@Nullable T>> getChildren() {
|
||||||
public List<Node<T>> getChildren() {
|
|
||||||
return Collections.unmodifiableList(this.children);
|
return Collections.unmodifiableList(this.children);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
private @NonNull Node<@Nullable T> addChild(@NonNull final T child) {
|
||||||
private Node<T> addChild(@Nonnull final T child) {
|
|
||||||
final Node<T> node = new Node<>(child);
|
final Node<T> node = new Node<>(child);
|
||||||
this.children.add(node);
|
this.children.add(node);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
private @Nullable Node<@Nullable T> getChild(@NonNull final T type) {
|
||||||
private Node<T> getChild(@Nonnull final T type) {
|
|
||||||
for (final Node<T> child : this.children) {
|
for (final Node<T> child : this.children) {
|
||||||
if (type.equals(child.getValue())) {
|
if (type.equals(child.getValue())) {
|
||||||
return child;
|
return child;
|
||||||
|
|
@ -723,8 +697,7 @@ public final class CommandTree<C> {
|
||||||
*
|
*
|
||||||
* @return Node meta
|
* @return Node meta
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Map<@NonNull String, @NonNull Object> getNodeMeta() {
|
||||||
public Map<String, Object> getNodeMeta() {
|
|
||||||
return this.nodeMeta;
|
return this.nodeMeta;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -733,8 +706,7 @@ public final class CommandTree<C> {
|
||||||
*
|
*
|
||||||
* @return Node value
|
* @return Node value
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public @Nullable T getValue() {
|
||||||
public T getValue() {
|
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -760,8 +732,7 @@ public final class CommandTree<C> {
|
||||||
*
|
*
|
||||||
* @return Parent node
|
* @return Parent node
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public @Nullable Node<@Nullable T> getParent() {
|
||||||
public Node<T> getParent() {
|
|
||||||
return this.parent;
|
return this.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -770,7 +741,7 @@ public final class CommandTree<C> {
|
||||||
*
|
*
|
||||||
* @param parent new parent node
|
* @param parent new parent node
|
||||||
*/
|
*/
|
||||||
public void setParent(@Nullable final Node<T> parent) {
|
public void setParent(@Nullable final Node<@Nullable T> parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,7 @@
|
||||||
package cloud.commandframework;
|
package cloud.commandframework;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link CommandArgument} description
|
* {@link CommandArgument} description
|
||||||
|
|
@ -39,7 +38,7 @@ public final class Description {
|
||||||
|
|
||||||
private final String description;
|
private final String description;
|
||||||
|
|
||||||
private Description(@Nonnull final String description) {
|
private Description(@NonNull final String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -48,8 +47,7 @@ public final class Description {
|
||||||
*
|
*
|
||||||
* @return Command description
|
* @return Command description
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static @NonNull Description empty() {
|
||||||
public static Description empty() {
|
|
||||||
return EMPTY;
|
return EMPTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,8 +57,7 @@ public final class Description {
|
||||||
* @param string Command description
|
* @param string Command description
|
||||||
* @return Created command description
|
* @return Created command description
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static @NonNull Description of(@NonNull final String string) {
|
||||||
public static Description of(@Nonnull final String string) {
|
|
||||||
return new Description(string);
|
return new Description(string);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,8 +66,7 @@ public final class Description {
|
||||||
*
|
*
|
||||||
* @return Command description
|
* @return Command description
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getDescription() {
|
||||||
public String getDescription() {
|
|
||||||
return this.description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -79,9 +75,8 @@ public final class Description {
|
||||||
*
|
*
|
||||||
* @return Command description
|
* @return Command description
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public @NonNull String toString() {
|
||||||
return this.description;
|
return this.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.annotations.specifier;
|
package cloud.commandframework.annotations.specifier;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.lang.annotation.ElementType;
|
import java.lang.annotation.ElementType;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
@ -44,13 +44,13 @@ public @interface Range {
|
||||||
*
|
*
|
||||||
* @return String serialized number
|
* @return String serialized number
|
||||||
*/
|
*/
|
||||||
@Nonnull String min() default "";
|
@NonNull String min() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum value accepted by the parser
|
* Maximum value accepted by the parser
|
||||||
*
|
*
|
||||||
* @return String serialized number
|
* @return String serialized number
|
||||||
*/
|
*/
|
||||||
@Nonnull String max() default "";
|
@NonNull String max() default "";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,8 @@ import cloud.commandframework.CommandManager;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ParserParameters;
|
import cloud.commandframework.arguments.parser.ParserParameters;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
@ -94,10 +96,10 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
* @param suggestionsProvider Suggestions provider
|
* @param suggestionsProvider Suggestions provider
|
||||||
*/
|
*/
|
||||||
public CommandArgument(final boolean required,
|
public CommandArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
@Nonnull final ArgumentParser<C, T> parser,
|
@NonNull final ArgumentParser<C, T> parser,
|
||||||
@Nonnull final String defaultValue,
|
@NonNull final String defaultValue,
|
||||||
@Nonnull final TypeToken<T> valueType,
|
@NonNull final TypeToken<T> valueType,
|
||||||
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
||||||
this.required = required;
|
this.required = required;
|
||||||
this.name = Objects.requireNonNull(name, "Name may not be null");
|
this.name = Objects.requireNonNull(name, "Name may not be null");
|
||||||
|
|
@ -140,14 +142,14 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
* @param valueType Type produced by the parser
|
* @param valueType Type produced by the parser
|
||||||
*/
|
*/
|
||||||
public CommandArgument(final boolean required,
|
public CommandArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@NonNull final String name,
|
||||||
@Nonnull final ArgumentParser<C, T> parser,
|
@NonNull final ArgumentParser<C, T> parser,
|
||||||
@Nonnull final Class<T> valueType) {
|
@NonNull final Class<T> valueType) {
|
||||||
this(required, name, parser, "", valueType, null);
|
this(required, name, parser, "", valueType, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <C> BiFunction<CommandContext<C>, String, List<String>> buildDefaultSuggestionsProvider(
|
private static <C> @NonNull BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||||
@Nonnull final CommandArgument<C, ?> argument) {
|
@NonNull List<String>> buildDefaultSuggestionsProvider(@NonNull final CommandArgument<C, ?> argument) {
|
||||||
return new DelegatingSuggestionsProvider<>(argument.getName(), argument.getParser());
|
return new DelegatingSuggestionsProvider<>(argument.getName(), argument.getParser());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,9 +177,8 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
* @param <T> Argument Type. Used to make the compiler happy.
|
* @param <T> Argument Type. Used to make the compiler happy.
|
||||||
* @return Argument builder
|
* @return Argument builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C, T> CommandArgument.@NonNull Builder<@NonNull C, @NonNull T> ofType(@NonNull final Class<T> clazz,
|
||||||
public static <C, T> CommandArgument.Builder<C, T> ofType(@Nonnull final Class<T> clazz,
|
@NonNull final String name) {
|
||||||
@Nonnull final String name) {
|
|
||||||
return new Builder<>(TypeToken.get(clazz), name);
|
return new Builder<>(TypeToken.get(clazz), name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -195,8 +196,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
*
|
*
|
||||||
* @return Argument name
|
* @return Argument name
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getName() {
|
||||||
public String getName() {
|
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -206,14 +206,12 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
*
|
*
|
||||||
* @return Command parser
|
* @return Command parser
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull ArgumentParser<C, T> getParser() {
|
||||||
public ArgumentParser<C, T> getParser() {
|
|
||||||
return this.parser;
|
return this.parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final String toString() {
|
public final @NonNull String toString() {
|
||||||
return String.format("%s{name=%s}", this.getClass().getSimpleName(), this.name);
|
return String.format("%s{name=%s}", this.getClass().getSimpleName(), this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -232,7 +230,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
*
|
*
|
||||||
* @param owningCommand Owning command
|
* @param owningCommand Owning command
|
||||||
*/
|
*/
|
||||||
public void setOwningCommand(@Nonnull final Command<C> owningCommand) {
|
public void setOwningCommand(@NonNull final Command<C> owningCommand) {
|
||||||
if (this.owningCommand != null) {
|
if (this.owningCommand != null) {
|
||||||
throw new IllegalStateException("Cannot replace owning command");
|
throw new IllegalStateException("Cannot replace owning command");
|
||||||
}
|
}
|
||||||
|
|
@ -244,8 +242,8 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
*
|
*
|
||||||
* @return Suggestions provider
|
* @return Suggestions provider
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public final @NonNull BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||||
public final BiFunction<CommandContext<C>, String, List<String>> getSuggestionsProvider() {
|
@NonNull List<String>> getSuggestionsProvider() {
|
||||||
return this.suggestionsProvider;
|
return this.suggestionsProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -267,7 +265,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final int compareTo(@Nonnull final CommandArgument<?, ?> o) {
|
public final int compareTo(@NonNull CommandArgument<?, ?> o) {
|
||||||
if (this instanceof StaticArgument) {
|
if (this instanceof StaticArgument) {
|
||||||
if (o instanceof StaticArgument) {
|
if (o instanceof StaticArgument) {
|
||||||
return (this.getName().compareTo(o.getName()));
|
return (this.getName().compareTo(o.getName()));
|
||||||
|
|
@ -288,8 +286,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
*
|
*
|
||||||
* @return Default value
|
* @return Default value
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getDefaultValue() {
|
||||||
public String getDefaultValue() {
|
|
||||||
return this.defaultValue;
|
return this.defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -308,8 +305,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
*
|
*
|
||||||
* @return Value type
|
* @return Value type
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull TypeToken<T> getValueType() {
|
||||||
public TypeToken<T> getValueType() {
|
|
||||||
return this.valueType;
|
return this.valueType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -318,8 +314,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
*
|
*
|
||||||
* @return Copied argument
|
* @return Copied argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandArgument<C, T> copy() {
|
||||||
public CommandArgument<C, T> copy() {
|
|
||||||
CommandArgument.Builder<C, T> builder = ofType(this.valueType, this.name);
|
CommandArgument.Builder<C, T> builder = ofType(this.valueType, this.name);
|
||||||
builder = builder.withSuggestionsProvider(this.suggestionsProvider);
|
builder = builder.withSuggestionsProvider(this.suggestionsProvider);
|
||||||
builder = builder.withParser(this.parser);
|
builder = builder.withParser(this.parser);
|
||||||
|
|
@ -349,10 +344,10 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
private boolean required = true;
|
private boolean required = true;
|
||||||
private ArgumentParser<C, T> parser;
|
private ArgumentParser<C, T> parser;
|
||||||
private String defaultValue = "";
|
private String defaultValue = "";
|
||||||
private BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider;
|
private BiFunction<@NonNull CommandContext<C>, @NonNull String, @NonNull List<String>> suggestionsProvider;
|
||||||
|
|
||||||
protected Builder(@Nonnull final TypeToken<T> valueType,
|
protected Builder(@NonNull final TypeToken<T> valueType,
|
||||||
@Nonnull final String name) {
|
@NonNull final String name) {
|
||||||
this.valueType = valueType;
|
this.valueType = valueType;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
@ -369,8 +364,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
* @param manager Command manager
|
* @param manager Command manager
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<@NonNull C, @NonNull T> manager(@NonNull final CommandManager<C> manager) {
|
||||||
public Builder<C, T> manager(@Nonnull final CommandManager<C> manager) {
|
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -384,8 +378,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
*
|
*
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<@NonNull C, @NonNull T> asRequired() {
|
||||||
public Builder<C, T> asRequired() {
|
|
||||||
this.required = true;
|
this.required = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -399,8 +392,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
*
|
*
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<@NonNull C, @NonNull T> asOptional() {
|
||||||
public Builder<C, T> asOptional() {
|
|
||||||
this.required = false;
|
this.required = false;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -415,8 +407,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
* @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
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<@NonNull C, @NonNull T> asOptionalWithDefault(@NonNull final String defaultValue) {
|
||||||
public Builder<C, T> asOptionalWithDefault(@Nonnull final String defaultValue) {
|
|
||||||
this.defaultValue = defaultValue;
|
this.defaultValue = defaultValue;
|
||||||
this.required = false;
|
this.required = false;
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -428,8 +419,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
* @param parser Argument parser
|
* @param parser Argument parser
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<@NonNull C, @NonNull T> withParser(@NonNull final ArgumentParser<@NonNull C, @NonNull 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;
|
||||||
}
|
}
|
||||||
|
|
@ -440,9 +430,9 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
* @param suggestionsProvider Suggestions provider
|
* @param suggestionsProvider Suggestions provider
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<@NonNull C, @NonNull T> withSuggestionsProvider(
|
||||||
public Builder<C, T> withSuggestionsProvider(
|
@NonNull final BiFunction<@NonNull CommandContext<C>,
|
||||||
@Nonnull final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@NonNull String, @NonNull List<String>> suggestionsProvider) {
|
||||||
this.suggestionsProvider = suggestionsProvider;
|
this.suggestionsProvider = suggestionsProvider;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -452,8 +442,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandArgument<@NonNull C, @NonNull 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(valueType, ParserParameters.empty())
|
this.parser = this.manager.getParserRegistry().createParser(valueType, ParserParameters.empty())
|
||||||
.orElse(null);
|
.orElse(null);
|
||||||
|
|
@ -469,8 +458,7 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
this.defaultValue, this.valueType, this.suggestionsProvider);
|
this.defaultValue, this.valueType, this.suggestionsProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
protected final @NonNull String getName() {
|
||||||
protected final String getName() {
|
|
||||||
return this.name;
|
return this.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -478,18 +466,16 @@ public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>>
|
||||||
return this.required;
|
return this.required;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
protected final @NonNull ArgumentParser<@NonNull C, @NonNull T> getParser() {
|
||||||
protected final ArgumentParser<C, T> getParser() {
|
|
||||||
return this.parser;
|
return this.parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
protected final @NonNull String getDefaultValue() {
|
||||||
protected final String getDefaultValue() {
|
|
||||||
return this.defaultValue;
|
return this.defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
protected final @NonNull BiFunction<@NonNull CommandContext<C>,@NonNull String, @NonNull List<String>>
|
||||||
protected final BiFunction<CommandContext<C>, String, List<String>> getSuggestionsProvider() {
|
getSuggestionsProvider() {
|
||||||
return this.suggestionsProvider;
|
return this.suggestionsProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,9 @@
|
||||||
package cloud.commandframework.arguments;
|
package cloud.commandframework.arguments;
|
||||||
|
|
||||||
import cloud.commandframework.CommandTree;
|
import cloud.commandframework.CommandTree;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -44,8 +44,7 @@ public interface CommandSyntaxFormatter<C> {
|
||||||
* @param node Trailing node
|
* @param node Trailing node
|
||||||
* @return Syntax string
|
* @return Syntax string
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@NonNull String apply(@NonNull List<@NonNull CommandArgument<C, ?>> commandArguments,
|
||||||
String apply(@Nonnull List<CommandArgument<C, ?>> commandArguments,
|
CommandTree.@Nullable Node<@Nullable CommandArgument<C, ?>> node);
|
||||||
@Nullable CommandTree.Node<CommandArgument<C, ?>> node);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,24 +25,25 @@ package cloud.commandframework.arguments;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
final class DelegatingSuggestionsProvider<C> implements BiFunction<CommandContext<C>, String, List<String>> {
|
final class DelegatingSuggestionsProvider<C> implements BiFunction<@NonNull CommandContext<C>,
|
||||||
|
@NonNull String, @NonNull List<String>> {
|
||||||
|
|
||||||
private final String argumentName;
|
private final String argumentName;
|
||||||
private final ArgumentParser<C, ?> parser;
|
private final ArgumentParser<C, ?> parser;
|
||||||
|
|
||||||
DelegatingSuggestionsProvider(@Nonnull final String argumentName, @Nonnull final ArgumentParser<C, ?> parser) {
|
DelegatingSuggestionsProvider(@NonNull final String argumentName, @NonNull final ArgumentParser<C, ?> parser) {
|
||||||
this.argumentName = argumentName;
|
this.argumentName = argumentName;
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> apply(final CommandContext<C> context, final String string) {
|
public @NonNull List<@NonNull String> apply(@NonNull final CommandContext<C> context, @NonNull final String s) {
|
||||||
return this.parser.suggestions(context, string);
|
return this.parser.suggestions(context, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -25,9 +25,9 @@ package cloud.commandframework.arguments;
|
||||||
|
|
||||||
import cloud.commandframework.CommandTree;
|
import cloud.commandframework.CommandTree;
|
||||||
import cloud.commandframework.arguments.compound.CompoundArgument;
|
import cloud.commandframework.arguments.compound.CompoundArgument;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -43,10 +43,9 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class StandardCommandSyntaxFormatter<C> implements CommandSyntaxFormatter<C> {
|
public class StandardCommandSyntaxFormatter<C> implements CommandSyntaxFormatter<C> {
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final String apply(@Nonnull final List<CommandArgument<C, ?>> commandArguments,
|
public final @NonNull String apply(@NonNull final List<@NonNull CommandArgument<C, ?>> commandArguments,
|
||||||
@Nullable final CommandTree.Node<CommandArgument<C, ?>> node) {
|
final CommandTree.@Nullable Node<@Nullable CommandArgument<C, ?>> node) {
|
||||||
final StringBuilder stringBuilder = new StringBuilder();
|
final StringBuilder stringBuilder = new StringBuilder();
|
||||||
final Iterator<CommandArgument<C, ?>> iterator = commandArguments.iterator();
|
final Iterator<CommandArgument<C, ?>> iterator = commandArguments.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ package cloud.commandframework.arguments;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -44,7 +44,7 @@ import java.util.TreeSet;
|
||||||
*/
|
*/
|
||||||
public final class StaticArgument<C> extends CommandArgument<C, String> {
|
public final class StaticArgument<C> extends CommandArgument<C, String> {
|
||||||
|
|
||||||
private StaticArgument(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 StaticArgumentParser<>(name, aliases), String.class);
|
super(required, name, new StaticArgumentParser<>(name, aliases), String.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -56,9 +56,8 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull StaticArgument<C> required(@NonNull final String name,
|
||||||
public static <C> StaticArgument<C> required(@Nonnull final String name,
|
@NonNull final String... aliases) {
|
||||||
@Nonnull final String... aliases) {
|
|
||||||
return new StaticArgument<>(true, name, aliases);
|
return new StaticArgument<>(true, name, aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,9 +69,8 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull StaticArgument<C> optional(@NonNull final String name,
|
||||||
public static <C> StaticArgument<C> optional(@Nonnull final String name,
|
@NonNull final String... aliases) {
|
||||||
@Nonnull final String... aliases) {
|
|
||||||
return new StaticArgument<>(false, name, aliases);
|
return new StaticArgument<>(false, name, aliases);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +79,7 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @param alias New alias
|
* @param alias New alias
|
||||||
*/
|
*/
|
||||||
public void registerAlias(@Nonnull final String alias) {
|
public void registerAlias(@NonNull final String alias) {
|
||||||
((StaticArgumentParser<C>) this.getParser()).insertAlias(alias);
|
((StaticArgumentParser<C>) this.getParser()).insertAlias(alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,8 +88,7 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @return Immutable view of the argument aliases
|
* @return Immutable view of the argument aliases
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Set<@NonNull String> getAliases() {
|
||||||
public Set<String> getAliases() {
|
|
||||||
return Collections.unmodifiableSet(((StaticArgumentParser<C>) this.getParser()).getAcceptedStrings());
|
return Collections.unmodifiableSet(((StaticArgumentParser<C>) this.getParser()).getAcceptedStrings());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,8 +97,7 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @return Immutable view of the optional argument aliases
|
* @return Immutable view of the optional argument aliases
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull List<@NonNull String> getAlternativeAliases() {
|
||||||
public List<String> getAlternativeAliases() {
|
|
||||||
return Collections.unmodifiableList(new ArrayList<>(((StaticArgumentParser<C>) this.getParser()).alternativeAliases));
|
return Collections.unmodifiableList(new ArrayList<>(((StaticArgumentParser<C>) this.getParser()).alternativeAliases));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,17 +109,16 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private StaticArgumentParser(@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.allAcceptedAliases.add(this.name);
|
this.allAcceptedAliases.add(this.name);
|
||||||
this.allAcceptedAliases.addAll(Arrays.asList(aliases));
|
this.allAcceptedAliases.addAll(Arrays.asList(aliases));
|
||||||
this.alternativeAliases.addAll(Arrays.asList(aliases));
|
this.alternativeAliases.addAll(Arrays.asList(aliases));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<String> parse(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull ArgumentParseResult<String> parse(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final String string = inputQueue.peek();
|
final String string = inputQueue.peek();
|
||||||
if (string == null) {
|
if (string == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input provided"));
|
||||||
|
|
@ -135,9 +130,9 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
|
||||||
return ArgumentParseResult.failure(new IllegalArgumentException(string));
|
return ArgumentParseResult.failure(new IllegalArgumentException(string));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggestions(@Nonnull final CommandContext<C> commandContext, @Nonnull final String input) {
|
public @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||||
|
@NonNull final String input) {
|
||||||
return Collections.singletonList(this.name);
|
return Collections.singletonList(this.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -146,8 +141,7 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @return Accepted strings
|
* @return Accepted strings
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Set<@NonNull String> getAcceptedStrings() {
|
||||||
public Set<String> getAcceptedStrings() {
|
|
||||||
return this.allAcceptedAliases;
|
return this.allAcceptedAliases;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -156,7 +150,7 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
|
||||||
*
|
*
|
||||||
* @param alias New alias
|
* @param alias New alias
|
||||||
*/
|
*/
|
||||||
public void insertAlias(@Nonnull final String alias) {
|
public void insertAlias(@NonNull final String alias) {
|
||||||
this.allAcceptedAliases.add(alias);
|
this.allAcceptedAliases.add(alias);
|
||||||
this.alternativeAliases.add(alias);
|
this.alternativeAliases.add(alias);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.arguments.parser;
|
package cloud.commandframework.arguments.parser;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,8 +44,7 @@ public abstract class ArgumentParseResult<T> {
|
||||||
* @param <T> Parser return type
|
* @param <T> Parser return type
|
||||||
* @return Failed parse result
|
* @return Failed parse result
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <T> @NonNull ArgumentParseResult<T> failure(@NonNull final Throwable failure) {
|
||||||
public static <T> ArgumentParseResult<T> failure(@Nonnull final Throwable failure) {
|
|
||||||
return new ParseFailure<>(failure);
|
return new ParseFailure<>(failure);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -55,8 +55,7 @@ public abstract class ArgumentParseResult<T> {
|
||||||
* @param <T> Parser return type
|
* @param <T> Parser return type
|
||||||
* @return Succeeded parse result
|
* @return Succeeded parse result
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <T> @NonNull ArgumentParseResult<T> success(@NonNull final T value) {
|
||||||
public static <T> ArgumentParseResult<T> success(@Nonnull final T value) {
|
|
||||||
return new ParseSuccess<>(value);
|
return new ParseSuccess<>(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,16 +64,14 @@ public abstract class ArgumentParseResult<T> {
|
||||||
*
|
*
|
||||||
* @return Optional containing the parsed value
|
* @return Optional containing the parsed value
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public abstract @NonNull Optional<T> getParsedValue();
|
||||||
public abstract Optional<T> getParsedValue();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the failure reason, if it exists
|
* Get the failure reason, if it exists
|
||||||
*
|
*
|
||||||
* @return Optional containing the failure reason
|
* @return Optional containing the failure reason
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public abstract @NonNull Optional<Throwable> getFailure();
|
||||||
public abstract Optional<Throwable> getFailure();
|
|
||||||
|
|
||||||
|
|
||||||
private static final class ParseSuccess<T> extends ArgumentParseResult<T> {
|
private static final class ParseSuccess<T> extends ArgumentParseResult<T> {
|
||||||
|
|
@ -84,19 +81,17 @@ public abstract class ArgumentParseResult<T> {
|
||||||
*/
|
*/
|
||||||
private final T value;
|
private final T value;
|
||||||
|
|
||||||
private ParseSuccess(@Nonnull final T value) {
|
private ParseSuccess(@NonNull final T value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<T> getParsedValue() {
|
public @NonNull Optional<T> getParsedValue() {
|
||||||
return Optional.of(this.value);
|
return Optional.of(this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Throwable> getFailure() {
|
public @NonNull Optional<Throwable> getFailure() {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,19 +105,17 @@ public abstract class ArgumentParseResult<T> {
|
||||||
*/
|
*/
|
||||||
private final Throwable failure;
|
private final Throwable failure;
|
||||||
|
|
||||||
private ParseFailure(@Nonnull final Throwable failure) {
|
private ParseFailure(@NonNull final Throwable failure) {
|
||||||
this.failure = failure;
|
this.failure = failure;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<T> getParsedValue() {
|
public @NonNull Optional<T> getParsedValue() {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<Throwable> getFailure() {
|
public @NonNull Optional<Throwable> getFailure() {
|
||||||
return Optional.of(this.failure);
|
return Optional.of(this.failure);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.arguments.parser;
|
package cloud.commandframework.arguments.parser;
|
||||||
|
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
@ -46,8 +46,8 @@ public interface ArgumentParser<C, T> {
|
||||||
* @param inputQueue The queue of arguments
|
* @param inputQueue The queue of arguments
|
||||||
* @return Parsed command result
|
* @return Parsed command result
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@NonNull ArgumentParseResult<@NonNull T> parse(@NonNull CommandContext<@NonNull C> commandContext,
|
||||||
ArgumentParseResult<T> parse(@Nonnull CommandContext<C> commandContext, @Nonnull Queue<String> inputQueue);
|
@NonNull Queue<@NonNull 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
|
||||||
|
|
@ -56,8 +56,8 @@ public interface ArgumentParser<C, T> {
|
||||||
* @param input Input string
|
* @param input Input string
|
||||||
* @return List of suggestions
|
* @return List of suggestions
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
default @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||||
default List<String> suggestions(@Nonnull final CommandContext<C> commandContext, @Nonnull final String input) {
|
@NonNull final String input) {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.arguments.parser;
|
package cloud.commandframework.arguments.parser;
|
||||||
|
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -44,7 +44,8 @@ public class ParserParameter<T> {
|
||||||
* @param key Parameter key
|
* @param key Parameter key
|
||||||
* @param expectedType Type that is expected to be mapped to this parameter
|
* @param expectedType Type that is expected to be mapped to this parameter
|
||||||
*/
|
*/
|
||||||
public ParserParameter(@Nonnull final String key, @Nonnull final TypeToken<T> expectedType) {
|
public ParserParameter(@NonNull final String key,
|
||||||
|
@NonNull final TypeToken<T> expectedType) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.expectedType = expectedType;
|
this.expectedType = expectedType;
|
||||||
}
|
}
|
||||||
|
|
@ -54,8 +55,7 @@ public class ParserParameter<T> {
|
||||||
*
|
*
|
||||||
* @return Parameter key
|
* @return Parameter key
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getKey() {
|
||||||
public String getKey() {
|
|
||||||
return this.key;
|
return this.key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,8 +64,7 @@ public class ParserParameter<T> {
|
||||||
*
|
*
|
||||||
* @return Expected type
|
* @return Expected type
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull TypeToken<T> getExpectedType() {
|
||||||
public TypeToken<T> getExpectedType() {
|
|
||||||
return this.expectedType;
|
return this.expectedType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.arguments.parser;
|
package cloud.commandframework.arguments.parser;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -40,8 +41,7 @@ public final class ParserParameters {
|
||||||
*
|
*
|
||||||
* @return Empty instance
|
* @return Empty instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static @NonNull ParserParameters empty() {
|
||||||
public static ParserParameters empty() {
|
|
||||||
return new ParserParameters();
|
return new ParserParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -53,8 +53,8 @@ public final class ParserParameters {
|
||||||
* @param <T> Value type
|
* @param <T> Value type
|
||||||
* @return Constructed instance
|
* @return Constructed instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <T> @NonNull ParserParameters single(@NonNull final ParserParameter<T> parameter,
|
||||||
public static <T> ParserParameters single(@Nonnull final ParserParameter<T> parameter, @Nonnull final T value) {
|
@NonNull final T value) {
|
||||||
final ParserParameters parameters = new ParserParameters();
|
final ParserParameters parameters = new ParserParameters();
|
||||||
parameters.store(parameter, value);
|
parameters.store(parameter, value);
|
||||||
return parameters;
|
return parameters;
|
||||||
|
|
@ -67,7 +67,7 @@ public final class ParserParameters {
|
||||||
* @param <T> Parameter type
|
* @param <T> Parameter type
|
||||||
* @return {@code true} if such a pair is stored, else {@code false}
|
* @return {@code true} if such a pair is stored, else {@code false}
|
||||||
*/
|
*/
|
||||||
public <T> boolean has(@Nonnull final ParserParameter<T> parameter) {
|
public <T> boolean has(@NonNull final ParserParameter<T> parameter) {
|
||||||
return this.internalMap.containsKey(parameter);
|
return this.internalMap.containsKey(parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +78,8 @@ public final class ParserParameters {
|
||||||
* @param value Object
|
* @param value Object
|
||||||
* @param <T> Parameter type
|
* @param <T> Parameter type
|
||||||
*/
|
*/
|
||||||
public <T> void store(@Nonnull final ParserParameter<T> parameter, @Nonnull final T value) {
|
public <T> void store(@NonNull final ParserParameter<T> parameter,
|
||||||
|
@NonNull final T value) {
|
||||||
this.internalMap.put(parameter, value);
|
this.internalMap.put(parameter, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,9 +91,9 @@ public final class ParserParameters {
|
||||||
* @param <T> Parameter type
|
* @param <T> Parameter type
|
||||||
* @return Parameter value
|
* @return Parameter value
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T get(@Nonnull final ParserParameter<T> parameter, @Nonnull final T defaultValue) {
|
public <T> @NonNull T get(@NonNull final ParserParameter<T> parameter,
|
||||||
|
@NonNull final T defaultValue) {
|
||||||
return (T) this.internalMap.getOrDefault(parameter, defaultValue);
|
return (T) this.internalMap.getOrDefault(parameter, defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -102,7 +103,7 @@ public final class ParserParameters {
|
||||||
*
|
*
|
||||||
* @param other Other instance
|
* @param other Other instance
|
||||||
*/
|
*/
|
||||||
public void merge(@Nonnull final ParserParameters other) {
|
public void merge(@NonNull final ParserParameters other) {
|
||||||
this.internalMap.putAll(other.internalMap);
|
this.internalMap.putAll(other.internalMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -111,8 +112,7 @@ public final class ParserParameters {
|
||||||
*
|
*
|
||||||
* @return Immutable map
|
* @return Immutable map
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Map<@NonNull ParserParameter<?>, @NonNull Object> getAll() {
|
||||||
public Map<ParserParameter<?>, Object> getAll() {
|
|
||||||
return Collections.unmodifiableMap(this.internalMap);
|
return Collections.unmodifiableMap(this.internalMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.arguments.parser;
|
package cloud.commandframework.arguments.parser;
|
||||||
|
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -49,8 +49,8 @@ public interface ParserRegistry<C> {
|
||||||
* to configure the parser, many of which are documented in {@link StandardParameters}
|
* to configure the parser, many of which are documented in {@link StandardParameters}
|
||||||
* @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, ArgumentParser<C, ?>> supplier);
|
@NonNull Function<@NonNull ParserParameters, @NonNull ArgumentParser<C, ?>> supplier);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a named parser supplier
|
* Register a named parser supplier
|
||||||
|
|
@ -59,8 +59,8 @@ public interface ParserRegistry<C> {
|
||||||
* @param supplier The function that generates the parser. The map supplied my contain parameters used
|
* @param supplier The function that generates the parser. The map supplied my contain parameters used
|
||||||
* to configure the parser, many of which are documented in {@link StandardParameters}
|
* to configure the parser, many of which are documented in {@link StandardParameters}
|
||||||
*/
|
*/
|
||||||
void registerNamedParserSupplier(@Nonnull String name,
|
void registerNamedParserSupplier(@NonNull String name,
|
||||||
@Nonnull Function<ParserParameters, ArgumentParser<C, ?>> supplier);
|
@NonNull Function<@NonNull ParserParameters, @NonNull 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
|
||||||
|
|
@ -71,9 +71,9 @@ public interface ParserRegistry<C> {
|
||||||
* @param <A> Annotation type
|
* @param <A> Annotation type
|
||||||
* @param <T> Type of the object that the parser is retrieved for
|
* @param <T> Type of the object that the parser is retrieved for
|
||||||
*/
|
*/
|
||||||
<A extends Annotation, T> void registerAnnotationMapper(@Nonnull Class<A> annotation,
|
<A extends Annotation, T> void registerAnnotationMapper(@NonNull Class<A> annotation,
|
||||||
@Nonnull BiFunction<A, TypeToken<?>,
|
@NonNull BiFunction<@NonNull A, @NonNull TypeToken<?>,
|
||||||
ParserParameters> mapper);
|
@NonNull ParserParameters> mapper);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse annotations into {@link ParserParameters}
|
* Parse annotations into {@link ParserParameters}
|
||||||
|
|
@ -82,8 +82,8 @@ public interface ParserRegistry<C> {
|
||||||
* @param annotations The annotations to be parsed
|
* @param annotations The annotations to be parsed
|
||||||
* @return Parsed parameters
|
* @return Parsed parameters
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@NonNull ParserParameters parseAnnotations(@NonNull TypeToken<?> parsingType,
|
||||||
ParserParameters parseAnnotations(@Nonnull TypeToken<?> parsingType, @Nonnull Collection<? extends Annotation> annotations);
|
@NonNull Collection<? extends Annotation> annotations);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to create a {@link ArgumentParser} for a specified type, using
|
* Attempt to create a {@link ArgumentParser} for a specified type, using
|
||||||
|
|
@ -94,9 +94,8 @@ public interface ParserRegistry<C> {
|
||||||
* @param <T> Generic type
|
* @param <T> Generic type
|
||||||
* @return Parser, if one can be created
|
* @return Parser, if one can be created
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
<T> @NonNull Optional<ArgumentParser<C, T>> createParser(@NonNull TypeToken<T> type,
|
||||||
<T> Optional<ArgumentParser<C, T>> createParser(@Nonnull TypeToken<T> type,
|
@NonNull ParserParameters parserParameters);
|
||||||
@Nonnull ParserParameters parserParameters);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to create a {@link ArgumentParser} for a specified type, using
|
* Attempt to create a {@link ArgumentParser} for a specified type, using
|
||||||
|
|
@ -107,8 +106,7 @@ public interface ParserRegistry<C> {
|
||||||
* @param <T> Generic type
|
* @param <T> Generic type
|
||||||
* @return Parser, if one can be created
|
* @return Parser, if one can be created
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
<T> @NonNull Optional<ArgumentParser<C, T>> createParser(@NonNull String name,
|
||||||
<T> Optional<ArgumentParser<C, T>> createParser(@Nonnull String name,
|
@NonNull ParserParameters parserParameters);
|
||||||
@Nonnull ParserParameters parserParameters);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,7 @@
|
||||||
package cloud.commandframework.arguments.parser;
|
package cloud.commandframework.arguments.parser;
|
||||||
|
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common parser parameters used when resolving types in the {@link ParserRegistry}
|
* Common parser parameters used when resolving types in the {@link ParserRegistry}
|
||||||
|
|
@ -60,7 +59,8 @@ public final class StandardParameters {
|
||||||
private StandardParameters() {
|
private StandardParameters() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static <T> ParserParameter<T> create(@Nonnull final String key, @Nonnull final TypeToken<T> expectedType) {
|
private static <T> @NonNull ParserParameter<T> create(@NonNull final String key,
|
||||||
|
@NonNull final TypeToken<T> expectedType) {
|
||||||
return new ParserParameter<>(key, expectedType);
|
return new ParserParameter<>(key, expectedType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,8 +36,8 @@ import cloud.commandframework.arguments.standard.ShortArgument;
|
||||||
import cloud.commandframework.arguments.standard.StringArgument;
|
import cloud.commandframework.arguments.standard.StringArgument;
|
||||||
import io.leangen.geantyref.GenericTypeReflector;
|
import io.leangen.geantyref.GenericTypeReflector;
|
||||||
import io.leangen.geantyref.TypeToken;
|
import io.leangen.geantyref.TypeToken;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
@ -56,14 +56,14 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
|
|
||||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_MAPPINGS = new HashMap<Class<?>, Class<?>>() {
|
private static final Map<Class<?>, Class<?>> PRIMITIVE_MAPPINGS = new HashMap<Class<?>, Class<?>>() {
|
||||||
{
|
{
|
||||||
put(char.class, Character .class);
|
put(char.class, Character.class);
|
||||||
put(int.class, Integer .class);
|
put(int.class, Integer.class);
|
||||||
put(short.class, Short .class);
|
put(short.class, Short.class);
|
||||||
put(byte.class, Byte .class);
|
put(byte.class, Byte.class);
|
||||||
put(float.class, Float .class);
|
put(float.class, Float.class);
|
||||||
put(double.class, Double .class);
|
put(double.class, Double.class);
|
||||||
put(long.class, Long .class);
|
put(long.class, Long.class);
|
||||||
put(boolean.class, Boolean .class);
|
put(boolean.class, Boolean.class);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -107,28 +107,29 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> void registerParserSupplier(@Nonnull final TypeToken<T> type,
|
public <T> void registerParserSupplier(@NonNull final TypeToken<T> type,
|
||||||
@Nonnull final Function<ParserParameters, ArgumentParser<C, ?>> supplier) {
|
@NonNull final Function<@NonNull ParserParameters,
|
||||||
|
@NonNull ArgumentParser<C, ?>> supplier) {
|
||||||
this.parserSuppliers.put(type, supplier);
|
this.parserSuppliers.put(type, supplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void registerNamedParserSupplier(@Nonnull final String name,
|
public void registerNamedParserSupplier(@NonNull final String name,
|
||||||
@Nonnull final Function<ParserParameters, ArgumentParser<C, ?>> supplier) {
|
@NonNull final Function<@NonNull ParserParameters,
|
||||||
|
@NonNull ArgumentParser<C, ?>> supplier) {
|
||||||
this.namedParsers.put(name, supplier);
|
this.namedParsers.put(name, supplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <A extends Annotation, T> void registerAnnotationMapper(@Nonnull final Class<A> annotation,
|
public <A extends Annotation, T> void registerAnnotationMapper(@NonNull final Class<A> annotation,
|
||||||
@Nonnull final BiFunction<A, TypeToken<?>,
|
@NonNull final BiFunction<@NonNull A, @NonNull TypeToken<?>,
|
||||||
ParserParameters> mapper) {
|
@NonNull ParserParameters> mapper) {
|
||||||
this.annotationMappers.put(annotation, mapper);
|
this.annotationMappers.put(annotation, mapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ParserParameters parseAnnotations(@Nonnull final TypeToken<?> parsingType,
|
public @NonNull ParserParameters parseAnnotations(@NonNull final TypeToken<?> parsingType,
|
||||||
@Nonnull final Collection<? extends Annotation> annotations) {
|
@NonNull final Collection<@NonNull ? extends Annotation> annotations) {
|
||||||
final ParserParameters parserParameters = new ParserParameters();
|
final ParserParameters parserParameters = new ParserParameters();
|
||||||
annotations.forEach(annotation -> {
|
annotations.forEach(annotation -> {
|
||||||
// noinspection all
|
// noinspection all
|
||||||
|
|
@ -143,10 +144,9 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
return parserParameters;
|
return parserParameters;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<ArgumentParser<C, T>> createParser(@Nonnull final TypeToken<T> type,
|
public <T> @NonNull 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 (GenericTypeReflector.erase(type.getType()).isPrimitive()) {
|
if (GenericTypeReflector.erase(type.getType()).isPrimitive()) {
|
||||||
actualType = TypeToken.get(PRIMITIVE_MAPPINGS.get(GenericTypeReflector.erase(type.getType())));
|
actualType = TypeToken.get(PRIMITIVE_MAPPINGS.get(GenericTypeReflector.erase(type.getType())));
|
||||||
|
|
@ -169,10 +169,9 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
return Optional.of(parser);
|
return Optional.of(parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public <T> Optional<ArgumentParser<C, T>> createParser(@Nonnull final String name,
|
public <T> @NonNull Optional<ArgumentParser<C, T>> createParser(@NonNull final String name,
|
||||||
@Nonnull final ParserParameters parserParameters) {
|
@NonNull final ParserParameters parserParameters) {
|
||||||
final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.namedParsers.get(name);
|
final Function<ParserParameters, ArgumentParser<C, ?>> producer = this.namedParsers.get(name);
|
||||||
if (producer == null) {
|
if (producer == null) {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
@ -183,15 +182,16 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static boolean isPrimitive(@Nonnull final TypeToken<?> type) {
|
private static boolean isPrimitive(@NonNull final TypeToken<?> type) {
|
||||||
return GenericTypeReflector.erase(type.getType()).isPrimitive();
|
return GenericTypeReflector.erase(type.getType()).isPrimitive();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class RangeMapper<T> implements BiFunction<Range, TypeToken<?>, ParserParameters> {
|
private static final class RangeMapper<T> implements BiFunction<@NonNull Range, @NonNull TypeToken<?>,
|
||||||
|
@NonNull ParserParameters> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParserParameters apply(final Range range, final TypeToken<?> type) {
|
public @NonNull ParserParameters apply(@NonNull final Range range, @NonNull final TypeToken<?> type) {
|
||||||
final Class<?> clazz;
|
final Class<?> clazz;
|
||||||
if (isPrimitive(type)) {
|
if (isPrimitive(type)) {
|
||||||
clazz = PRIMITIVE_MAPPINGS.get(GenericTypeReflector.erase(type.getType()));
|
clazz = PRIMITIVE_MAPPINGS.get(GenericTypeReflector.erase(type.getType()));
|
||||||
|
|
@ -259,10 +259,11 @@ public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class CompletionsMapper implements BiFunction<Completions, TypeToken<?>, ParserParameters> {
|
private static final class CompletionsMapper implements BiFunction<@NonNull Completions, @NonNull TypeToken<?>,
|
||||||
|
@NonNull ParserParameters> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ParserParameters apply(final Completions completions, final TypeToken<?> token) {
|
public @NonNull ParserParameters apply(@NonNull final Completions completions, @NonNull final TypeToken<?> token) {
|
||||||
if (GenericTypeReflector.erase(token.getType()).equals(String.class)) {
|
if (GenericTypeReflector.erase(token.getType()).equals(String.class)) {
|
||||||
final String[] splitCompletions = completions.value().replace(" ", "").split(",");
|
final String[] splitCompletions = completions.value().replace(" ", "").split(",");
|
||||||
return ParserParameters.single(StandardParameters.COMPLETIONS, splitCompletions);
|
return ParserParameters.single(StandardParameters.COMPLETIONS, splitCompletions);
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
@ -42,11 +42,12 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
private final short max;
|
private final short max;
|
||||||
|
|
||||||
private ShortArgument(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,
|
||||||
final String defaultValue,
|
final String defaultValue,
|
||||||
@Nullable final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider) {
|
@Nullable final BiFunction<@NonNull CommandContext<C>, @NonNull String,
|
||||||
|
@NonNull List<String>> suggestionsProvider) {
|
||||||
super(required, name, new ShortParser<>(min, max), defaultValue, Short.class, suggestionsProvider);
|
super(required, name, new ShortParser<>(min, max), defaultValue, Short.class, suggestionsProvider);
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
|
|
@ -59,8 +60,7 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> ShortArgument.@NonNull Builder<C> newBuilder(@NonNull final String name) {
|
||||||
public static <C> ShortArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,8 +71,7 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Short> required(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Short> required(@Nonnull final String name) {
|
|
||||||
return ShortArgument.<C>newBuilder(name).asRequired().build();
|
return ShortArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,8 +82,7 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Short> optional(@NonNull final String name) {
|
||||||
public static <C> CommandArgument<C, Short> optional(@Nonnull final String name) {
|
|
||||||
return ShortArgument.<C>newBuilder(name).asOptional().build();
|
return ShortArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,9 +94,8 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull CommandArgument<C, Short> optional(@NonNull final String name,
|
||||||
public static <C> CommandArgument<C, Short> optional(@Nonnull final String name,
|
final short defaultNum) {
|
||||||
final short defaultNum) {
|
|
||||||
return ShortArgument.<C>newBuilder(name).asOptionalWithDefault(Short.toString(defaultNum)).build();
|
return ShortArgument.<C>newBuilder(name).asOptionalWithDefault(Short.toString(defaultNum)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -125,7 +122,7 @@ public final class ShortArgument<C> extends CommandArgument<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;
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@NonNull final String name) {
|
||||||
super(Short.class, name);
|
super(Short.class, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -135,8 +132,7 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMin(final short min) {
|
||||||
public Builder<C> withMin(final short min) {
|
|
||||||
this.min = min;
|
this.min = min;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -147,8 +143,7 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withMax(final short max) {
|
||||||
public Builder<C> withMax(final short max) {
|
|
||||||
this.max = max;
|
this.max = max;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -158,9 +153,8 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
*
|
*
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ShortArgument<C> build() {
|
public @NonNull ShortArgument<C> build() {
|
||||||
return new ShortArgument<>(this.isRequired(), this.getName(), this.min, this.max,
|
return new ShortArgument<>(this.isRequired(), this.getName(), this.min, this.max,
|
||||||
this.getDefaultValue(), this.getSuggestionsProvider());
|
this.getDefaultValue(), this.getSuggestionsProvider());
|
||||||
}
|
}
|
||||||
|
|
@ -183,11 +177,10 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
this.max = max;
|
this.max = max;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public ArgumentParseResult<Short> parse(
|
public @NonNull ArgumentParseResult<Short> parse(
|
||||||
@Nonnull final CommandContext<C> commandContext,
|
@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> inputQueue) {
|
@NonNull final Queue<@NonNull String> inputQueue) {
|
||||||
final String input = inputQueue.peek();
|
final String input = inputQueue.peek();
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||||
|
|
@ -209,10 +202,9 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> suggestions(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull List<@NonNull String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final String input) {
|
@NonNull final String input) {
|
||||||
return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input);
|
return IntegerArgument.IntegerParser.getSuggestions(this.min, this.max, input);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -246,7 +238,7 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
* @param min Minimum value
|
* @param min Minimum value
|
||||||
* @param max Maximum value
|
* @param max Maximum value
|
||||||
*/
|
*/
|
||||||
public ShortParseException(@Nonnull final String input, final short min, final short max) {
|
public ShortParseException(@NonNull final String input, final short min, final short max) {
|
||||||
super(input, min, max);
|
super(input, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -261,8 +253,7 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
public @NonNull String getNumberType() {
|
||||||
public String getNumberType() {
|
|
||||||
return "short";
|
return "short";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.context;
|
package cloud.commandframework.context;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -48,7 +48,7 @@ public final class CommandContext<C> {
|
||||||
*
|
*
|
||||||
* @param commandSender Sender of the command
|
* @param commandSender Sender of the command
|
||||||
*/
|
*/
|
||||||
public CommandContext(@Nonnull final C commandSender) {
|
public CommandContext(@NonNull final C commandSender) {
|
||||||
this(false, commandSender);
|
this(false, commandSender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,7 +58,8 @@ public final class CommandContext<C> {
|
||||||
* @param suggestions Whether or not the context is created for command suggestions
|
* @param suggestions Whether or not the context is created for command suggestions
|
||||||
* @param commandSender Sender of the command
|
* @param commandSender Sender of the command
|
||||||
*/
|
*/
|
||||||
public CommandContext(final boolean suggestions, @Nonnull final C commandSender) {
|
public CommandContext(final boolean suggestions,
|
||||||
|
@NonNull final C commandSender) {
|
||||||
this.commandSender = commandSender;
|
this.commandSender = commandSender;
|
||||||
this.suggestions = suggestions;
|
this.suggestions = suggestions;
|
||||||
}
|
}
|
||||||
|
|
@ -68,8 +69,7 @@ public final class CommandContext<C> {
|
||||||
*
|
*
|
||||||
* @return Command sender
|
* @return Command sender
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull C getSender() {
|
||||||
public C getSender() {
|
|
||||||
return this.commandSender;
|
return this.commandSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +89,7 @@ public final class CommandContext<C> {
|
||||||
* @param value Value
|
* @param value Value
|
||||||
* @param <T> Value type
|
* @param <T> Value type
|
||||||
*/
|
*/
|
||||||
public <T> void store(@Nonnull final String key, @Nonnull final T value) {
|
public <T> void store(@NonNull final String key, @NonNull final T value) {
|
||||||
this.internalStorage.put(key, value);
|
this.internalStorage.put(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -100,8 +100,7 @@ public final class CommandContext<C> {
|
||||||
* @param <T> Value type
|
* @param <T> Value type
|
||||||
* @return Value
|
* @return Value
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <T> @NonNull Optional<T> get(@NonNull final String key) {
|
||||||
public <T> Optional<T> get(@Nonnull final String key) {
|
|
||||||
final Object value = this.internalStorage.get(key);
|
final Object value = this.internalStorage.get(key);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
@SuppressWarnings("ALL") final T castedValue = (T) value;
|
@SuppressWarnings("ALL") final T castedValue = (T) value;
|
||||||
|
|
@ -119,9 +118,8 @@ public final class CommandContext<C> {
|
||||||
* @return Argument
|
* @return Argument
|
||||||
* @throws NullPointerException If no such argument is stored
|
* @throws NullPointerException If no such argument is stored
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public <T> T getRequired(@Nonnull final String key) {
|
public <T> @NonNull T getRequired(@NonNull final String key) {
|
||||||
final Object value = this.internalStorage.get(key);
|
final Object value = this.internalStorage.get(key);
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new NullPointerException("No such object stored in the context: " + key);
|
throw new NullPointerException("No such object stored in the context: " + key);
|
||||||
|
|
@ -137,8 +135,8 @@ public final class CommandContext<C> {
|
||||||
* @param <T> Argument type
|
* @param <T> Argument type
|
||||||
* @return Argument, or supplied default value
|
* @return Argument, or supplied default value
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public <T> @NonNull T getOrDefault(@NonNull final String key,
|
||||||
public <T> T getOrDefault(@Nonnull final String key, @Nonnull final T defaultValue) {
|
@NonNull final T defaultValue) {
|
||||||
return this.<T>get(key).orElse(defaultValue);
|
return this.<T>get(key).orElse(defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,8 +146,7 @@ public final class CommandContext<C> {
|
||||||
* @param argument Argument
|
* @param argument Argument
|
||||||
* @return Created timing instance
|
* @return Created timing instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull ArgumentTiming createTiming(@NonNull final CommandArgument<C, ?> argument) {
|
||||||
public ArgumentTiming createTiming(@Nonnull final CommandArgument<C, ?> argument) {
|
|
||||||
final ArgumentTiming argumentTiming = new ArgumentTiming();
|
final ArgumentTiming argumentTiming = new ArgumentTiming();
|
||||||
this.argumentTimings.put(argument, argumentTiming);
|
this.argumentTimings.put(argument, argumentTiming);
|
||||||
return argumentTiming;
|
return argumentTiming;
|
||||||
|
|
@ -160,8 +157,7 @@ public final class CommandContext<C> {
|
||||||
*
|
*
|
||||||
* @return Argument timings
|
* @return Argument timings
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Map<CommandArgument<@NonNull C, @NonNull ?>, ArgumentTiming> getArgumentTimings() {
|
||||||
public Map<CommandArgument<C, ?>, ArgumentTiming> getArgumentTimings() {
|
|
||||||
return Collections.unmodifiableMap(this.argumentTimings);
|
return Collections.unmodifiableMap(this.argumentTimings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.context;
|
package cloud.commandframework.context;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Factory for {@link CommandContext} instances
|
* Factory for {@link CommandContext} instances
|
||||||
|
|
@ -39,7 +39,6 @@ public interface CommandContextFactory<C> {
|
||||||
* @param sender Command sender
|
* @param sender Command sender
|
||||||
* @return Command context
|
* @return Command context
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@NonNull CommandContext<C> create(boolean suggestions, @NonNull C sender);
|
||||||
CommandContext<C> create(boolean suggestions, @Nonnull C sender);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.context;
|
package cloud.commandframework.context;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public final class StandardCommandContextFactory<C> implements CommandContextFactory<C> {
|
public final class StandardCommandContextFactory<C> implements CommandContextFactory<C> {
|
||||||
|
|
||||||
|
|
@ -34,9 +34,8 @@ public final class StandardCommandContextFactory<C> implements CommandContextFac
|
||||||
* @param sender Command sender
|
* @param sender Command sender
|
||||||
* @return Created context
|
* @return Created context
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public CommandContext<C> create(final boolean suggestions, @Nonnull final C sender) {
|
public CommandContext<C> create(final boolean suggestions, @NonNull final C sender) {
|
||||||
return new CommandContext<>(suggestions, sender);
|
return new CommandContext<>(suggestions, sender);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ package cloud.commandframework.exceptions;
|
||||||
import cloud.commandframework.CommandTree;
|
import cloud.commandframework.CommandTree;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -52,8 +52,8 @@ public final class AmbiguousNodeException extends IllegalStateException {
|
||||||
* @param children All children of the parent
|
* @param children All children of the parent
|
||||||
*/
|
*/
|
||||||
public AmbiguousNodeException(@Nullable final CommandArgument<?, ?> parentNode,
|
public AmbiguousNodeException(@Nullable final CommandArgument<?, ?> parentNode,
|
||||||
@Nonnull final CommandArgument<?, ?> ambiguousNode,
|
@NonNull final CommandArgument<?, ?> ambiguousNode,
|
||||||
@Nonnull final List<CommandArgument<?, ?>> children) {
|
@NonNull final List<@NonNull CommandArgument<?, ?>> children) {
|
||||||
this.parentNode = parentNode;
|
this.parentNode = parentNode;
|
||||||
this.ambiguousNode = ambiguousNode;
|
this.ambiguousNode = ambiguousNode;
|
||||||
this.children = children;
|
this.children = children;
|
||||||
|
|
@ -64,8 +64,7 @@ public final class AmbiguousNodeException extends IllegalStateException {
|
||||||
*
|
*
|
||||||
* @return Parent node
|
* @return Parent node
|
||||||
*/
|
*/
|
||||||
@Nullable
|
public @Nullable CommandArgument<?, ?> getParentNode() {
|
||||||
public CommandArgument<?, ?> getParentNode() {
|
|
||||||
return this.parentNode;
|
return this.parentNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,8 +73,7 @@ public final class AmbiguousNodeException extends IllegalStateException {
|
||||||
*
|
*
|
||||||
* @return Ambiguous node
|
* @return Ambiguous node
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandArgument<?, ?> getAmbiguousNode() {
|
||||||
public CommandArgument<?, ?> getAmbiguousNode() {
|
|
||||||
return this.ambiguousNode;
|
return this.ambiguousNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -84,8 +82,7 @@ public final class AmbiguousNodeException extends IllegalStateException {
|
||||||
*
|
*
|
||||||
* @return Child nodes
|
* @return Child nodes
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull List<@NonNull CommandArgument<?, ?>> getChildren() {
|
||||||
public List<CommandArgument<?, ?>> getChildren() {
|
|
||||||
return this.children;
|
return this.children;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.exceptions;
|
package cloud.commandframework.exceptions;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ArgumentParseException extends CommandParseException {
|
public class ArgumentParseException extends CommandParseException {
|
||||||
|
|
@ -39,9 +39,9 @@ public class ArgumentParseException 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 ArgumentParseException(@Nonnull final Throwable throwable,
|
public ArgumentParseException(@NonNull final Throwable throwable,
|
||||||
@Nonnull final Object commandSender,
|
@NonNull final Object commandSender,
|
||||||
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
@NonNull final List<@NonNull CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.cause = throwable;
|
this.cause = throwable;
|
||||||
}
|
}
|
||||||
|
|
@ -51,8 +51,7 @@ public class ArgumentParseException extends CommandParseException {
|
||||||
*
|
*
|
||||||
* @return Cause
|
* @return Cause
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Throwable getCause() {
|
||||||
public Throwable getCause() {
|
|
||||||
return this.cause;
|
return this.cause;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.exceptions;
|
package cloud.commandframework.exceptions;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -44,8 +44,8 @@ public class CommandParseException extends IllegalArgumentException {
|
||||||
* @param commandSender Sender who executed the command
|
* @param commandSender Sender who executed the command
|
||||||
* @param currentChain Chain leading up to the exception
|
* @param currentChain Chain leading up to the exception
|
||||||
*/
|
*/
|
||||||
protected CommandParseException(@Nonnull final Object commandSender,
|
protected CommandParseException(@NonNull final Object commandSender,
|
||||||
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
@NonNull final List<CommandArgument<?, ?>> currentChain) {
|
||||||
this.commandSender = commandSender;
|
this.commandSender = commandSender;
|
||||||
this.currentChain = currentChain;
|
this.currentChain = currentChain;
|
||||||
}
|
}
|
||||||
|
|
@ -55,8 +55,7 @@ public class CommandParseException extends IllegalArgumentException {
|
||||||
*
|
*
|
||||||
* @return Command sender
|
* @return Command sender
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Object getCommandSender() {
|
||||||
public Object getCommandSender() {
|
|
||||||
return this.commandSender;
|
return this.commandSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -65,8 +64,7 @@ public class CommandParseException extends IllegalArgumentException {
|
||||||
*
|
*
|
||||||
* @return Unmodifiable list of command arguments
|
* @return Unmodifiable list of command arguments
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull List<@NonNull CommandArgument<?, ?>> getCurrentChain() {
|
||||||
public List<CommandArgument<?, ?>> getCurrentChain() {
|
|
||||||
return Collections.unmodifiableList(this.currentChain);
|
return Collections.unmodifiableList(this.currentChain);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.exceptions;
|
package cloud.commandframework.exceptions;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -42,9 +42,9 @@ public final class InvalidCommandSenderException extends CommandParseException {
|
||||||
* @param requiredSender The sender type that is required
|
* @param requiredSender The sender type that is required
|
||||||
* @param currentChain Chain leading up to the exception
|
* @param currentChain Chain leading up to the exception
|
||||||
*/
|
*/
|
||||||
public InvalidCommandSenderException(@Nonnull final Object commandSender,
|
public InvalidCommandSenderException(@NonNull final Object commandSender,
|
||||||
@Nonnull final Class<?> requiredSender,
|
@NonNull final Class<?> requiredSender,
|
||||||
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
@NonNull final List<@NonNull CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.requiredSender = requiredSender;
|
this.requiredSender = requiredSender;
|
||||||
}
|
}
|
||||||
|
|
@ -54,8 +54,7 @@ public final class InvalidCommandSenderException extends CommandParseException {
|
||||||
*
|
*
|
||||||
* @return Required sender type
|
* @return Required sender type
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Class<?> getRequiredSender() {
|
||||||
public Class<?> getRequiredSender() {
|
|
||||||
return this.requiredSender;
|
return this.requiredSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.exceptions;
|
package cloud.commandframework.exceptions;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -43,9 +43,9 @@ public class InvalidSyntaxException extends CommandParseException {
|
||||||
* @param commandSender Sender that sent the command
|
* @param commandSender Sender that sent the command
|
||||||
* @param currentChain Chain leading up to issue
|
* @param currentChain Chain leading up to issue
|
||||||
*/
|
*/
|
||||||
public InvalidSyntaxException(@Nonnull final String correctSyntax,
|
public InvalidSyntaxException(@NonNull final String correctSyntax,
|
||||||
@Nonnull final Object commandSender,
|
@NonNull final Object commandSender,
|
||||||
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
@NonNull final List<@NonNull CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.correctSyntax = correctSyntax;
|
this.correctSyntax = correctSyntax;
|
||||||
}
|
}
|
||||||
|
|
@ -55,8 +55,7 @@ public class InvalidSyntaxException extends CommandParseException {
|
||||||
*
|
*
|
||||||
* @return Correct command syntax
|
* @return Correct command syntax
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getCorrectSyntax() {
|
||||||
public String getCorrectSyntax() {
|
|
||||||
return this.correctSyntax;
|
return this.correctSyntax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ package cloud.commandframework.exceptions;
|
||||||
|
|
||||||
import cloud.commandframework.Command;
|
import cloud.commandframework.Command;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Thrown when a {@link CommandArgument}
|
* Thrown when a {@link CommandArgument}
|
||||||
|
|
@ -42,7 +41,7 @@ public final class NoCommandInLeafException extends IllegalStateException {
|
||||||
*
|
*
|
||||||
* @param commandArgument Command argument that caused the exception
|
* @param commandArgument Command argument that caused the exception
|
||||||
*/
|
*/
|
||||||
public NoCommandInLeafException(@Nonnull final CommandArgument<?, ?> commandArgument) {
|
public NoCommandInLeafException(@NonNull final CommandArgument<?, ?> commandArgument) {
|
||||||
super(String.format("Leaf node '%s' does not have associated owning command", commandArgument.getName()));
|
super(String.format("Leaf node '%s' does not have associated owning command", commandArgument.getName()));
|
||||||
this.commandArgument = commandArgument;
|
this.commandArgument = commandArgument;
|
||||||
}
|
}
|
||||||
|
|
@ -52,8 +51,7 @@ public final class NoCommandInLeafException extends IllegalStateException {
|
||||||
*
|
*
|
||||||
* @return Command argument
|
* @return Command argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandArgument<?, ?> getCommandArgument() {
|
||||||
public CommandArgument<?, ?> getCommandArgument() {
|
|
||||||
return this.commandArgument;
|
return this.commandArgument;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ package cloud.commandframework.exceptions;
|
||||||
import cloud.commandframework.Command;
|
import cloud.commandframework.Command;
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
import cloud.commandframework.permission.CommandPermission;
|
import cloud.commandframework.permission.CommandPermission;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,9 +46,9 @@ public class NoPermissionException 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 NoPermissionException(@Nonnull final CommandPermission missingPermission,
|
public NoPermissionException(@NonNull final CommandPermission missingPermission,
|
||||||
@Nonnull final Object commandSender,
|
@NonNull final Object commandSender,
|
||||||
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
@NonNull final List<@NonNull CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.missingPermission = missingPermission;
|
this.missingPermission = missingPermission;
|
||||||
}
|
}
|
||||||
|
|
@ -63,8 +63,7 @@ public class NoPermissionException extends CommandParseException {
|
||||||
*
|
*
|
||||||
* @return Get the missing permission node
|
* @return Get the missing permission node
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getMissingPermission() {
|
||||||
public String getMissingPermission() {
|
|
||||||
return this.missingPermission.toString();
|
return this.missingPermission.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.exceptions;
|
package cloud.commandframework.exceptions;
|
||||||
|
|
||||||
import cloud.commandframework.arguments.CommandArgument;
|
import cloud.commandframework.arguments.CommandArgument;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -44,9 +44,9 @@ public final class NoSuchCommandException extends CommandParseException {
|
||||||
* @param currentChain Chain leading up to the exception
|
* @param currentChain Chain leading up to the exception
|
||||||
* @param command Entered command (following the command chain)
|
* @param command Entered command (following the command chain)
|
||||||
*/
|
*/
|
||||||
public NoSuchCommandException(@Nonnull final Object commandSender,
|
public NoSuchCommandException(@NonNull final Object commandSender,
|
||||||
@Nonnull final List<CommandArgument<?, ?>> 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;
|
||||||
}
|
}
|
||||||
|
|
@ -69,8 +69,7 @@ public final class NoSuchCommandException extends CommandParseException {
|
||||||
*
|
*
|
||||||
* @return Supplied command
|
* @return Supplied command
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getSuppliedCommand() {
|
||||||
public String getSuppliedCommand() {
|
|
||||||
return this.suppliedCommand;
|
return this.suppliedCommand;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.exceptions.parsing;
|
package cloud.commandframework.exceptions.parsing;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
public abstract class NumberParseException extends IllegalArgumentException {
|
public abstract class NumberParseException extends IllegalArgumentException {
|
||||||
|
|
||||||
|
|
@ -38,7 +38,9 @@ public abstract class NumberParseException extends IllegalArgumentException {
|
||||||
* @param min Maximum value
|
* @param min Maximum value
|
||||||
* @param max Minimum value
|
* @param max Minimum value
|
||||||
*/
|
*/
|
||||||
public NumberParseException(@Nonnull final String input, @Nonnull final Number min, @Nonnull final Number max) {
|
public NumberParseException(@NonNull final String input,
|
||||||
|
@NonNull final Number min,
|
||||||
|
@NonNull final Number max) {
|
||||||
this.input = input;
|
this.input = input;
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
|
|
@ -63,8 +65,7 @@ public abstract class NumberParseException extends IllegalArgumentException {
|
||||||
*
|
*
|
||||||
* @return Number type
|
* @return Number type
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public abstract @NonNull String getNumberType();
|
||||||
public abstract String getNumberType();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the parser had a maximum value
|
* If the parser had a maximum value
|
||||||
|
|
@ -85,8 +86,7 @@ public abstract class NumberParseException extends IllegalArgumentException {
|
||||||
*
|
*
|
||||||
* @return Input
|
* @return Input
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull String getInput() {
|
||||||
public String getInput() {
|
|
||||||
return this.input;
|
return this.input;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,9 +28,9 @@ import cloud.commandframework.CommandManager;
|
||||||
import cloud.commandframework.CommandTree;
|
import cloud.commandframework.CommandTree;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.services.State;
|
import cloud.commandframework.services.State;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
@ -52,7 +52,7 @@ public final class AsynchronousCommandExecutionCoordinator<C> extends CommandExe
|
||||||
|
|
||||||
private AsynchronousCommandExecutionCoordinator(@Nullable final Executor executor,
|
private AsynchronousCommandExecutionCoordinator(@Nullable final Executor executor,
|
||||||
final boolean synchronizeParsing,
|
final boolean synchronizeParsing,
|
||||||
@Nonnull final CommandTree<C> commandTree) {
|
@NonNull final CommandTree<C> commandTree) {
|
||||||
super(commandTree);
|
super(commandTree);
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
this.synchronizeParsing = synchronizeParsing;
|
this.synchronizeParsing = synchronizeParsing;
|
||||||
|
|
@ -65,14 +65,13 @@ public final class AsynchronousCommandExecutionCoordinator<C> extends CommandExe
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Builder
|
* @return Builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static <C> @NonNull Builder<C> newBuilder() {
|
||||||
public static <C> Builder<C> newBuilder() {
|
|
||||||
return new Builder<>();
|
return new Builder<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult<C>> coordinateExecution(@Nonnull final CommandContext<C> commandContext,
|
public @NonNull CompletableFuture<CommandResult<C>> coordinateExecution(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> input) {
|
@NonNull final Queue<@NonNull String> input) {
|
||||||
|
|
||||||
final Consumer<Command<C>> commandConsumer = command -> {
|
final Consumer<Command<C>> commandConsumer = command -> {
|
||||||
if (this.commandManager.postprocessContext(commandContext, command) == State.ACCEPTED) {
|
if (this.commandManager.postprocessContext(commandContext, command) == State.ACCEPTED) {
|
||||||
|
|
@ -119,8 +118,7 @@ public final class AsynchronousCommandExecutionCoordinator<C> extends CommandExe
|
||||||
*
|
*
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withSynchronousParsing() {
|
||||||
public Builder<C> withSynchronousParsing() {
|
|
||||||
this.synchronizeParsing = true;
|
this.synchronizeParsing = true;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -130,8 +128,7 @@ public final class AsynchronousCommandExecutionCoordinator<C> extends CommandExe
|
||||||
*
|
*
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withAsynchronousParsing() {
|
||||||
public Builder<C> withAsynchronousParsing() {
|
|
||||||
this.synchronizeParsing = false;
|
this.synchronizeParsing = false;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -143,8 +140,7 @@ public final class AsynchronousCommandExecutionCoordinator<C> extends CommandExe
|
||||||
* @param executor Executor to use
|
* @param executor Executor to use
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder<C> withExecutor(@NonNull final Executor executor) {
|
||||||
public Builder<C> withExecutor(@Nonnull final Executor executor) {
|
|
||||||
this.executor = executor;
|
this.executor = executor;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -155,8 +151,7 @@ public final class AsynchronousCommandExecutionCoordinator<C> extends CommandExe
|
||||||
*
|
*
|
||||||
* @return Function that builds the coordinator
|
* @return Function that builds the coordinator
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Function<@NonNull CommandTree<C>, @NonNull CommandExecutionCoordinator<C>> build() {
|
||||||
public Function<CommandTree<C>, CommandExecutionCoordinator<C>> build() {
|
|
||||||
return tree -> new AsynchronousCommandExecutionCoordinator<>(this.executor, this.synchronizeParsing, tree);
|
return tree -> new AsynchronousCommandExecutionCoordinator<>(this.executor, this.synchronizeParsing, tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,8 @@ package cloud.commandframework.execution;
|
||||||
import cloud.commandframework.CommandTree;
|
import cloud.commandframework.CommandTree;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
import cloud.commandframework.services.State;
|
import cloud.commandframework.services.State;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
@ -49,7 +49,7 @@ public abstract class CommandExecutionCoordinator<C> {
|
||||||
*
|
*
|
||||||
* @param commandTree Command tree
|
* @param commandTree Command tree
|
||||||
*/
|
*/
|
||||||
public CommandExecutionCoordinator(@Nonnull final CommandTree<C> commandTree) {
|
public CommandExecutionCoordinator(@NonNull final CommandTree<C> commandTree) {
|
||||||
this.commandTree = commandTree;
|
this.commandTree = commandTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,8 +59,8 @@ public abstract class CommandExecutionCoordinator<C> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return New coordinator instance
|
* @return New coordinator instance
|
||||||
*/
|
*/
|
||||||
public static <C> Function<CommandTree<C>,
|
public static <C> @NonNull Function<@NonNull CommandTree<C>,
|
||||||
CommandExecutionCoordinator<C>> simpleCoordinator() {
|
@NonNull CommandExecutionCoordinator<C>> simpleCoordinator() {
|
||||||
return SimpleCoordinator::new;
|
return SimpleCoordinator::new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,16 +71,15 @@ public abstract class CommandExecutionCoordinator<C> {
|
||||||
* @param input Command input
|
* @param input Command input
|
||||||
* @return Future that completes with the result
|
* @return Future that completes with the result
|
||||||
*/
|
*/
|
||||||
public abstract CompletableFuture<CommandResult<C>> coordinateExecution(@Nonnull CommandContext<C> commandContext,
|
public abstract @NonNull CompletableFuture<CommandResult<C>> coordinateExecution(@NonNull CommandContext<C> commandContext,
|
||||||
@Nonnull Queue<String> input);
|
@NonNull Queue<@NonNull String> input);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the command tree
|
* Get the command tree
|
||||||
*
|
*
|
||||||
* @return Command tree
|
* @return Command tree
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
protected @NonNull CommandTree<C> getCommandTree() {
|
||||||
protected CommandTree<C> getCommandTree() {
|
|
||||||
return this.commandTree;
|
return this.commandTree;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,13 +92,13 @@ public abstract class CommandExecutionCoordinator<C> {
|
||||||
public static final class SimpleCoordinator<C> extends
|
public static final class SimpleCoordinator<C> extends
|
||||||
CommandExecutionCoordinator<C> {
|
CommandExecutionCoordinator<C> {
|
||||||
|
|
||||||
private SimpleCoordinator(@Nonnull final CommandTree<C> commandTree) {
|
private SimpleCoordinator(@NonNull final CommandTree<C> commandTree) {
|
||||||
super(commandTree);
|
super(commandTree);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompletableFuture<CommandResult<C>> coordinateExecution(@Nonnull final CommandContext<C> commandContext,
|
public CompletableFuture<CommandResult<C>> coordinateExecution(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final Queue<String> input) {
|
@NonNull final Queue<@NonNull String> input) {
|
||||||
final CompletableFuture<CommandResult<C>> completableFuture = new CompletableFuture<>();
|
final CompletableFuture<CommandResult<C>> completableFuture = new CompletableFuture<>();
|
||||||
try {
|
try {
|
||||||
this.getCommandTree().parse(commandContext, input).ifPresent(command -> {
|
this.getCommandTree().parse(commandContext, input).ifPresent(command -> {
|
||||||
|
|
|
||||||
|
|
@ -25,8 +25,7 @@ package cloud.commandframework.execution;
|
||||||
|
|
||||||
import cloud.commandframework.Command;
|
import cloud.commandframework.Command;
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler that is invoked whenever a {@link Command} is executed
|
* Handler that is invoked whenever a {@link Command} is executed
|
||||||
|
|
@ -42,7 +41,7 @@ public interface CommandExecutionHandler<C> {
|
||||||
*
|
*
|
||||||
* @param commandContext Command context
|
* @param commandContext Command context
|
||||||
*/
|
*/
|
||||||
void execute(@Nonnull CommandContext<C> commandContext);
|
void execute(@NonNull CommandContext<C> commandContext);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -53,7 +52,7 @@ public interface CommandExecutionHandler<C> {
|
||||||
class NullCommandExecutionHandler<C> implements CommandExecutionHandler<C> {
|
class NullCommandExecutionHandler<C> implements CommandExecutionHandler<C> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(@Nonnull final CommandContext<C> commandContext) {
|
public void execute(@NonNull final CommandContext<C> commandContext) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,7 @@
|
||||||
package cloud.commandframework.execution;
|
package cloud.commandframework.execution;
|
||||||
|
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The result of a command execution
|
* The result of a command execution
|
||||||
|
|
@ -41,7 +40,7 @@ public class CommandResult<C> {
|
||||||
*
|
*
|
||||||
* @param context Command context
|
* @param context Command context
|
||||||
*/
|
*/
|
||||||
public CommandResult(@Nonnull final CommandContext<C> context) {
|
public CommandResult(@NonNull final CommandContext<C> context) {
|
||||||
this.commandContext = context;
|
this.commandContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -50,8 +49,7 @@ public class CommandResult<C> {
|
||||||
*
|
*
|
||||||
* @return Command context
|
* @return Command context
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandContext<C> getCommandContext() {
|
||||||
public CommandContext<C> getCommandContext() {
|
|
||||||
return this.commandContext;
|
return this.commandContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
package cloud.commandframework.execution;
|
package cloud.commandframework.execution;
|
||||||
|
|
||||||
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
|
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
@ -34,6 +35,6 @@ import java.util.function.BiFunction;
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public interface CommandSuggestionProcessor<C> extends
|
public interface CommandSuggestionProcessor<C> extends
|
||||||
BiFunction<CommandPreprocessingContext<C>, List<String>, List<String>> {
|
BiFunction<@NonNull CommandPreprocessingContext<C>, @NonNull List<String>, @NonNull List<String>> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.execution;
|
package cloud.commandframework.execution;
|
||||||
|
|
||||||
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
|
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|
@ -36,9 +36,9 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public final class FilteringCommandSuggestionProcessor<C> implements CommandSuggestionProcessor<C> {
|
public final class FilteringCommandSuggestionProcessor<C> implements CommandSuggestionProcessor<C> {
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public List<String> apply(@Nonnull final CommandPreprocessingContext<C> context, @Nonnull final List<String> strings) {
|
public @NonNull List<@NonNull String> apply(@NonNull final CommandPreprocessingContext<C> context,
|
||||||
|
@NonNull final List<@NonNull String> strings) {
|
||||||
final String input;
|
final String input;
|
||||||
if (context.getInputQueue().isEmpty()) {
|
if (context.getInputQueue().isEmpty()) {
|
||||||
input = "";
|
input = "";
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.execution.preprocessor;
|
package cloud.commandframework.execution.preprocessor;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link CommandPreprocessor} that does nothing besides indicating that the context
|
* {@link CommandPreprocessor} that does nothing besides indicating that the context
|
||||||
|
|
@ -39,7 +39,7 @@ public final class AcceptingCommandPreprocessor<C> implements CommandPreprocesso
|
||||||
public static final String PROCESSED_INDICATOR_KEY = "__COMMAND_PRE_PROCESSED__";
|
public static final String PROCESSED_INDICATOR_KEY = "__COMMAND_PRE_PROCESSED__";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(@Nonnull final CommandPreprocessingContext<C> context) {
|
public void accept(@NonNull final CommandPreprocessingContext<C> context) {
|
||||||
context.getCommandContext().store(PROCESSED_INDICATOR_KEY, "true");
|
context.getCommandContext().store(PROCESSED_INDICATOR_KEY, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.execution.preprocessor;
|
package cloud.commandframework.execution.preprocessor;
|
||||||
|
|
||||||
import cloud.commandframework.context.CommandContext;
|
import cloud.commandframework.context.CommandContext;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
|
@ -45,8 +45,8 @@ public final class CommandPreprocessingContext<C> {
|
||||||
* @param commandContext Command context
|
* @param commandContext Command context
|
||||||
* @param inputQueue Command input as supplied by sender
|
* @param inputQueue Command input as supplied by sender
|
||||||
*/
|
*/
|
||||||
public CommandPreprocessingContext(@Nonnull final CommandContext<C> commandContext,
|
public CommandPreprocessingContext(@NonNull final CommandContext<C> commandContext,
|
||||||
@Nonnull final LinkedList<String> inputQueue) {
|
@NonNull final LinkedList<@NonNull String> inputQueue) {
|
||||||
this.commandContext = commandContext;
|
this.commandContext = commandContext;
|
||||||
this.inputQueue = inputQueue;
|
this.inputQueue = inputQueue;
|
||||||
}
|
}
|
||||||
|
|
@ -56,8 +56,7 @@ public final class CommandPreprocessingContext<C> {
|
||||||
*
|
*
|
||||||
* @return Command context
|
* @return Command context
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandContext<C> getCommandContext() {
|
||||||
public CommandContext<C> getCommandContext() {
|
|
||||||
return this.commandContext;
|
return this.commandContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,8 +66,7 @@ public final class CommandPreprocessingContext<C> {
|
||||||
*
|
*
|
||||||
* @return Input queue
|
* @return Input queue
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull LinkedList<@NonNull String> getInputQueue() {
|
||||||
public LinkedList<String> getInputQueue() {
|
|
||||||
return this.inputQueue;
|
return this.inputQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,8 @@ import cloud.commandframework.execution.postprocessor.CommandPostprocessor;
|
||||||
import cloud.commandframework.meta.SimpleCommandMeta;
|
import cloud.commandframework.meta.SimpleCommandMeta;
|
||||||
import cloud.commandframework.services.types.ConsumerService;
|
import cloud.commandframework.services.types.ConsumerService;
|
||||||
import cloud.commandframework.types.tuples.Pair;
|
import cloud.commandframework.types.tuples.Pair;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
@ -73,9 +73,9 @@ public class CommandConfirmationManager<C> {
|
||||||
* @param errorNotifier Notifier that gets called when someone tries to confirm a command with nothing in the queue
|
* @param errorNotifier Notifier that gets called when someone tries to confirm a command with nothing in the queue
|
||||||
*/
|
*/
|
||||||
public CommandConfirmationManager(final long timeout,
|
public CommandConfirmationManager(final long timeout,
|
||||||
@Nonnull final TimeUnit timeoutTimeUnit,
|
@NonNull final TimeUnit timeoutTimeUnit,
|
||||||
@Nonnull final Consumer<CommandPostprocessingContext<C>> notifier,
|
@NonNull final Consumer<@NonNull CommandPostprocessingContext<C>> notifier,
|
||||||
@Nonnull final Consumer<C> errorNotifier) {
|
@NonNull final Consumer<@NonNull C> errorNotifier) {
|
||||||
this.notifier = notifier;
|
this.notifier = notifier;
|
||||||
this.errorNotifier = errorNotifier;
|
this.errorNotifier = errorNotifier;
|
||||||
this.pendingCommands = new LinkedHashMap<C, Pair<CommandPostprocessingContext<C>, Long>>() {
|
this.pendingCommands = new LinkedHashMap<C, Pair<CommandPostprocessingContext<C>, Long>>() {
|
||||||
|
|
@ -87,11 +87,11 @@ public class CommandConfirmationManager<C> {
|
||||||
this.timeoutMillis = timeoutTimeUnit.toMillis(timeout);
|
this.timeoutMillis = timeoutTimeUnit.toMillis(timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void notifyConsumer(@Nonnull final CommandPostprocessingContext<C> context) {
|
private void notifyConsumer(@NonNull final CommandPostprocessingContext<C> context) {
|
||||||
this.notifier.accept(context);
|
this.notifier.accept(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addPending(@Nonnull final CommandPostprocessingContext<C> context) {
|
private void addPending(@NonNull final CommandPostprocessingContext<C> context) {
|
||||||
this.pendingCommands.put(context.getCommandContext().getSender(), Pair.of(context, System.currentTimeMillis()));
|
this.pendingCommands.put(context.getCommandContext().getSender(), Pair.of(context, System.currentTimeMillis()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -101,8 +101,7 @@ public class CommandConfirmationManager<C> {
|
||||||
* @param sender Sender
|
* @param sender Sender
|
||||||
* @return Optional containing the post processing context if one has been stored, else {@link Optional#empty()}
|
* @return Optional containing the post processing context if one has been stored, else {@link Optional#empty()}
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Optional<CommandPostprocessingContext<C>> getPending(@NonNull final C sender) {
|
||||||
public Optional<CommandPostprocessingContext<C>> getPending(@Nonnull final C sender) {
|
|
||||||
final Pair<CommandPostprocessingContext<C>, Long> pair = this.pendingCommands.remove(sender);
|
final Pair<CommandPostprocessingContext<C>, Long> pair = this.pendingCommands.remove(sender);
|
||||||
if (pair != null) {
|
if (pair != null) {
|
||||||
if (System.currentTimeMillis() < pair.getSecond() + this.timeoutMillis) {
|
if (System.currentTimeMillis() < pair.getSecond() + this.timeoutMillis) {
|
||||||
|
|
@ -118,8 +117,7 @@ public class CommandConfirmationManager<C> {
|
||||||
* @param builder Command meta builder
|
* @param builder Command meta builder
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public SimpleCommandMeta.@NonNull Builder decorate(final SimpleCommandMeta.@NonNull Builder builder) {
|
||||||
public SimpleCommandMeta.Builder decorate(@Nonnull final SimpleCommandMeta.Builder builder) {
|
|
||||||
return builder.with(CONFIRMATION_REQUIRED_META, "true");
|
return builder.with(CONFIRMATION_REQUIRED_META, "true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -128,7 +126,7 @@ public class CommandConfirmationManager<C> {
|
||||||
*
|
*
|
||||||
* @param manager Command manager
|
* @param manager Command manager
|
||||||
*/
|
*/
|
||||||
public void registerConfirmationProcessor(@Nonnull final CommandManager<C> manager) {
|
public void registerConfirmationProcessor(@NonNull final CommandManager<C> manager) {
|
||||||
manager.registerCommandPostProcessor(new CommandConfirmationPostProcessor());
|
manager.registerCommandPostProcessor(new CommandConfirmationPostProcessor());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -137,8 +135,7 @@ public class CommandConfirmationManager<C> {
|
||||||
*
|
*
|
||||||
* @return Handler for a confirmation command
|
* @return Handler for a confirmation command
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull CommandExecutionHandler<C> createConfirmationExecutionHandler() {
|
||||||
public CommandExecutionHandler<C> createConfirmationExecutionHandler() {
|
|
||||||
return context -> {
|
return context -> {
|
||||||
final Optional<CommandPostprocessingContext<C>> pending = this.getPending(context.getSender());
|
final Optional<CommandPostprocessingContext<C>> pending = this.getPending(context.getSender());
|
||||||
if (pending.isPresent()) {
|
if (pending.isPresent()) {
|
||||||
|
|
@ -156,7 +153,7 @@ public class CommandConfirmationManager<C> {
|
||||||
private final class CommandConfirmationPostProcessor implements CommandPostprocessor<C> {
|
private final class CommandConfirmationPostProcessor implements CommandPostprocessor<C> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(@Nonnull final CommandPostprocessingContext<C> context) {
|
public void accept(@NonNull final CommandPostprocessingContext<C> context) {
|
||||||
if (!context.getCommand()
|
if (!context.getCommand()
|
||||||
.getCommandMeta()
|
.getCommandMeta()
|
||||||
.getOrDefault(CONFIRMATION_REQUIRED_META, "false")
|
.getOrDefault(CONFIRMATION_REQUIRED_META, "false")
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,8 @@
|
||||||
package cloud.commandframework.meta;
|
package cloud.commandframework.meta;
|
||||||
|
|
||||||
import cloud.commandframework.Command;
|
import cloud.commandframework.Command;
|
||||||
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
|
@ -42,14 +42,12 @@ public abstract class CommandMeta {
|
||||||
*
|
*
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static SimpleCommandMeta.@NonNull Builder simple() {
|
||||||
public static SimpleCommandMeta.Builder simple() {
|
|
||||||
return SimpleCommandMeta.builder();
|
return SimpleCommandMeta.builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public final String toString() {
|
public final @NonNull String toString() {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -59,8 +57,7 @@ public abstract class CommandMeta {
|
||||||
* @param key Key
|
* @param key Key
|
||||||
* @return Optional that may contain the associated value
|
* @return Optional that may contain the associated value
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public abstract @NonNull Optional<String> getValue(@NonNull String key);
|
||||||
public abstract Optional<String> getValue(@Nonnull String key);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the value if it exists, else return the default value
|
* Get the value if it exists, else return the default value
|
||||||
|
|
@ -69,15 +66,13 @@ public abstract class CommandMeta {
|
||||||
* @param defaultValue Default value
|
* @param defaultValue Default value
|
||||||
* @return Value, or default value
|
* @return Value, or default value
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public abstract @NonNull String getOrDefault(@NonNull String key, @NonNull String defaultValue);
|
||||||
public abstract String getOrDefault(@Nonnull String key, @Nonnull String defaultValue);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a copy of the meta map
|
* Get a copy of the meta map
|
||||||
*
|
*
|
||||||
* @return Copy of meta map
|
* @return Copy of meta map
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public abstract @NonNull Map<@NonNull String, @NonNull String> getAll();
|
||||||
public abstract Map<String, String> getAll();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
//
|
//
|
||||||
package cloud.commandframework.meta;
|
package cloud.commandframework.meta;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -38,7 +39,7 @@ public class SimpleCommandMeta extends CommandMeta {
|
||||||
|
|
||||||
private final Map<String, String> metaMap;
|
private final Map<String, String> metaMap;
|
||||||
|
|
||||||
protected SimpleCommandMeta(@Nonnull final Map<String, String> metaMap) {
|
protected SimpleCommandMeta(@NonNull final Map<@NonNull String, @NonNull String> metaMap) {
|
||||||
this.metaMap = Collections.unmodifiableMap(metaMap);
|
this.metaMap = Collections.unmodifiableMap(metaMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -47,8 +48,7 @@ public class SimpleCommandMeta extends CommandMeta {
|
||||||
*
|
*
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static SimpleCommandMeta.@NonNull Builder builder() {
|
||||||
public static SimpleCommandMeta.Builder builder() {
|
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,26 +57,22 @@ public class SimpleCommandMeta extends CommandMeta {
|
||||||
*
|
*
|
||||||
* @return Empty instance
|
* @return Empty instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public static @NonNull SimpleCommandMeta empty() {
|
||||||
public static SimpleCommandMeta empty() {
|
|
||||||
return SimpleCommandMeta.builder().build();
|
return SimpleCommandMeta.builder().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
public final @NonNull Optional<String> getValue(@NonNull final String key) {
|
||||||
public final Optional<String> getValue(@Nonnull final String key) {
|
|
||||||
return Optional.ofNullable(this.metaMap.get(key));
|
return Optional.ofNullable(this.metaMap.get(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
public final @NonNull String getOrDefault(@NonNull final String key, @NonNull final String defaultValue) {
|
||||||
public final String getOrDefault(@Nonnull final String key, @Nonnull final String defaultValue) {
|
|
||||||
return this.getValue(key).orElse(defaultValue);
|
return this.getValue(key).orElse(defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
public final @NonNull Map<@NonNull String, @NonNull String> getAll() {
|
||||||
public final Map<String, String> getAll() {
|
|
||||||
return new HashMap<>(this.metaMap);
|
return new HashMap<>(this.metaMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -113,8 +109,7 @@ public class SimpleCommandMeta extends CommandMeta {
|
||||||
* @param commandMeta Existing instance
|
* @param commandMeta Existing instance
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder with(@NonNull final CommandMeta commandMeta) {
|
||||||
public Builder with(@Nonnull final CommandMeta commandMeta) {
|
|
||||||
commandMeta.getAll().forEach(this::with);
|
commandMeta.getAll().forEach(this::with);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -126,8 +121,8 @@ public class SimpleCommandMeta extends CommandMeta {
|
||||||
* @param value Value
|
* @param value Value
|
||||||
* @return Builder instance
|
* @return Builder instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull Builder with(@NonNull final String key,
|
||||||
public Builder with(@Nonnull final String key, @Nonnull final String value) {
|
@NonNull final String value) {
|
||||||
this.map.put(key, value);
|
this.map.put(key, value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
@ -137,8 +132,7 @@ public class SimpleCommandMeta extends CommandMeta {
|
||||||
*
|
*
|
||||||
* @return Meta instance
|
* @return Meta instance
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
public @NonNull SimpleCommandMeta build() {
|
||||||
public SimpleCommandMeta build() {
|
|
||||||
return new SimpleCommandMeta(this.map);
|
return new SimpleCommandMeta(this.map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,17 +24,16 @@
|
||||||
package cloud.commandframework;
|
package cloud.commandframework;
|
||||||
|
|
||||||
import cloud.commandframework.annotations.specifier.Range;
|
import cloud.commandframework.annotations.specifier.Range;
|
||||||
import cloud.commandframework.arguments.standard.IntegerArgument;
|
|
||||||
import io.leangen.geantyref.TypeToken;
|
|
||||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||||
import cloud.commandframework.arguments.parser.ParserParameters;
|
import cloud.commandframework.arguments.parser.ParserParameters;
|
||||||
import cloud.commandframework.arguments.parser.ParserRegistry;
|
import cloud.commandframework.arguments.parser.ParserRegistry;
|
||||||
import cloud.commandframework.arguments.parser.StandardParameters;
|
import cloud.commandframework.arguments.parser.StandardParameters;
|
||||||
import cloud.commandframework.arguments.parser.StandardParserRegistry;
|
import cloud.commandframework.arguments.parser.StandardParserRegistry;
|
||||||
|
import cloud.commandframework.arguments.standard.IntegerArgument;
|
||||||
|
import io.leangen.geantyref.TypeToken;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
|
@ -53,13 +52,11 @@ public class ParserRegistryTest {
|
||||||
return Range.class;
|
return Range.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public String min() {
|
public String min() {
|
||||||
return Integer.toString(RANGE_MIN);
|
return Integer.toString(RANGE_MIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nonnull
|
|
||||||
@Override
|
@Override
|
||||||
public String max() {
|
public String max() {
|
||||||
return Integer.toString(RANGE_MAX);
|
return Integer.toString(RANGE_MAX);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue