Get rid of the command sender interface entirely
This commit is contained in:
parent
8b0a650b48
commit
4cbbee7db0
57 changed files with 192 additions and 301 deletions
|
|
@ -27,7 +27,6 @@ import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.StaticArgument;
|
import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.execution.CommandExecutionHandler;
|
import com.intellectualsites.commands.execution.CommandExecutionHandler;
|
||||||
import com.intellectualsites.commands.meta.CommandMeta;
|
import com.intellectualsites.commands.meta.CommandMeta;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
@ -45,7 +44,7 @@ import java.util.function.Consumer;
|
||||||
* @param <M> Command meta type
|
* @param <M> Command meta type
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class Command<C extends CommandSender, M extends CommandMeta> {
|
public class Command<C, M extends CommandMeta> {
|
||||||
|
|
||||||
@Nonnull private final List<CommandArgument<C, ?>> arguments;
|
@Nonnull private final List<CommandArgument<C, ?>> arguments;
|
||||||
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
|
@Nonnull private final CommandExecutionHandler<C> commandExecutionHandler;
|
||||||
|
|
@ -132,7 +131,7 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
|
||||||
* @return Command builder
|
* @return Command builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender, M extends CommandMeta> Builder<C, M> newBuilder(@Nonnull final String commandName,
|
public static <C, M extends CommandMeta> Builder<C, M> newBuilder(@Nonnull final String commandName,
|
||||||
@Nonnull final M commandMeta,
|
@Nonnull final M commandMeta,
|
||||||
@Nonnull final String... aliases) {
|
@Nonnull final String... aliases) {
|
||||||
return new Builder<>(null, commandMeta, null,
|
return new Builder<>(null, commandMeta, null,
|
||||||
|
|
@ -217,7 +216,7 @@ public class Command<C extends CommandSender, M extends CommandMeta> {
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <M> Command meta type
|
* @param <M> Command meta type
|
||||||
*/
|
*/
|
||||||
public static final class Builder<C extends CommandSender, M extends CommandMeta> {
|
public static final class Builder<C, M extends CommandMeta> {
|
||||||
|
|
||||||
@Nonnull private final M commandMeta;
|
@Nonnull private final M commandMeta;
|
||||||
@Nonnull private final List<CommandArgument<C, ?>> commandArguments;
|
@Nonnull private final List<CommandArgument<C, ?>> commandArguments;
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,6 @@ import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessin
|
||||||
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessor;
|
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessor;
|
||||||
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
||||||
import com.intellectualsites.commands.meta.CommandMeta;
|
import com.intellectualsites.commands.meta.CommandMeta;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
import com.intellectualsites.services.ServicePipeline;
|
import com.intellectualsites.services.ServicePipeline;
|
||||||
import com.intellectualsites.services.State;
|
import com.intellectualsites.services.State;
|
||||||
|
|
||||||
|
|
@ -61,7 +60,7 @@ import java.util.function.Function;
|
||||||
* @param <M> Command meta type
|
* @param <M> Command meta type
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public abstract class CommandManager<C extends CommandSender, M extends CommandMeta> {
|
public abstract class CommandManager<C, M extends CommandMeta> {
|
||||||
|
|
||||||
private final CommandContextFactory<C> commandContextFactory = new StandardCommandContextFactory<>();
|
private final CommandContextFactory<C> commandContextFactory = new StandardCommandContextFactory<>();
|
||||||
private final ServicePipeline servicePipeline = ServicePipeline.builder().build();
|
private final ServicePipeline servicePipeline = ServicePipeline.builder().build();
|
||||||
|
|
@ -194,6 +193,15 @@ public abstract class CommandManager<C extends CommandSender, M extends CommandM
|
||||||
return this.commandRegistrationHandler;
|
return this.commandRegistrationHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if the command sender has the required permission
|
||||||
|
*
|
||||||
|
* @param sender Command sender
|
||||||
|
* @param permission Permission node
|
||||||
|
* @return {@code true} if the sender has the permission, else {@code false}
|
||||||
|
*/
|
||||||
|
public abstract boolean hasPermission(@Nonnull C sender, @Nonnull String permission);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command builder
|
* Create a new command builder
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,6 @@ import com.intellectualsites.commands.exceptions.NoPermissionException;
|
||||||
import com.intellectualsites.commands.exceptions.NoSuchCommandException;
|
import com.intellectualsites.commands.exceptions.NoSuchCommandException;
|
||||||
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
||||||
import com.intellectualsites.commands.meta.CommandMeta;
|
import com.intellectualsites.commands.meta.CommandMeta;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
@ -59,7 +58,7 @@ import java.util.stream.Collectors;
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <M> Command meta type
|
* @param <M> Command meta type
|
||||||
*/
|
*/
|
||||||
public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
public final class CommandTree<C, M extends CommandMeta> {
|
||||||
|
|
||||||
private final Object commandLock = new Object();
|
private final Object commandLock = new Object();
|
||||||
|
|
||||||
|
|
@ -83,7 +82,7 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
* @return New command tree
|
* @return New command tree
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender, M extends CommandMeta> CommandTree<C, M> newTree(
|
public static <C, M extends CommandMeta> CommandTree<C, M> newTree(
|
||||||
@Nonnull final CommandManager<C, M> commandManager,
|
@Nonnull final CommandManager<C, M> commandManager,
|
||||||
@Nonnull final CommandRegistrationHandler<M> commandRegistrationHandler) {
|
@Nonnull final CommandRegistrationHandler<M> commandRegistrationHandler) {
|
||||||
return new CommandTree<>(commandManager, commandRegistrationHandler);
|
return new CommandTree<>(commandManager, commandRegistrationHandler);
|
||||||
|
|
@ -369,10 +368,10 @@ public final class CommandTree<C extends CommandSender, M extends CommandMeta> {
|
||||||
private String isPermitted(@Nonnull final C sender, @Nonnull final Node<CommandArgument<C, ?>> node) {
|
private String isPermitted(@Nonnull final C sender, @Nonnull final Node<CommandArgument<C, ?>> node) {
|
||||||
final String permission = node.nodeMeta.get("permission");
|
final String permission = node.nodeMeta.get("permission");
|
||||||
if (permission != null) {
|
if (permission != null) {
|
||||||
return sender.hasPermission(permission) ? null : permission;
|
return this.commandManager.hasPermission(sender, permission) ? null : permission;
|
||||||
}
|
}
|
||||||
if (node.isLeaf()) {
|
if (node.isLeaf()) {
|
||||||
return sender.hasPermission(
|
return this.commandManager.hasPermission(sender,
|
||||||
Objects.requireNonNull(Objects.requireNonNull(node.value, "node.value").getOwningCommand(),
|
Objects.requireNonNull(Objects.requireNonNull(node.value, "node.value").getOwningCommand(),
|
||||||
"owning command").getCommandPermission())
|
"owning command").getCommandPermission())
|
||||||
? null : Objects.requireNonNull(node.value.getOwningCommand(), "owning command").getCommandPermission();
|
? null : Objects.requireNonNull(node.value.getOwningCommand(), "owning command").getCommandPermission();
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import com.intellectualsites.commands.CommandManager;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.arguments.parser.ParserParameters;
|
import com.intellectualsites.commands.arguments.parser.ParserParameters;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
|
@ -43,7 +42,7 @@ import java.util.regex.Pattern;
|
||||||
* @param <T> The type that the argument parses into
|
* @param <T> The type that the argument parses into
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class CommandArgument<C extends CommandSender, T> implements Comparable<CommandArgument<?, ?>> {
|
public class CommandArgument<C, T> implements Comparable<CommandArgument<?, ?>> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pattern for command argument names
|
* Pattern for command argument names
|
||||||
|
|
@ -128,7 +127,7 @@ public class CommandArgument<C extends CommandSender, T> implements Comparable<C
|
||||||
* @return Argument builder
|
* @return Argument builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender, T> CommandArgument.Builder<C, 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<>(clazz, name);
|
return new Builder<>(clazz, name);
|
||||||
}
|
}
|
||||||
|
|
@ -261,7 +260,7 @@ public class CommandArgument<C extends CommandSender, T> implements Comparable<C
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <T> Argument value type
|
* @param <T> Argument value type
|
||||||
*/
|
*/
|
||||||
public static class Builder<C extends CommandSender, T> {
|
public static class Builder<C, T> {
|
||||||
|
|
||||||
private final Class<T> valueType;
|
private final Class<T> valueType;
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.arguments;
|
package com.intellectualsites.commands.arguments;
|
||||||
|
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
|
|
@ -35,7 +33,7 @@ import java.util.function.Function;
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface CommandSyntaxFormatter<C extends CommandSender> extends Function<List<CommandArgument<C, ?>>, String> {
|
public interface CommandSyntaxFormatter<C> extends Function<List<CommandArgument<C, ?>>, String> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.arguments;
|
package com.intellectualsites.commands.arguments;
|
||||||
|
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -39,7 +37,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public class StandardCommandSyntaxFormatter<C extends CommandSender> implements CommandSyntaxFormatter<C> {
|
public class StandardCommandSyntaxFormatter<C> implements CommandSyntaxFormatter<C> {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ package com.intellectualsites.commands.arguments;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -41,7 +40,7 @@ import java.util.Set;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public final class StaticArgument<C extends CommandSender> 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,7 +55,7 @@ public final class StaticArgument<C extends CommandSender> extends CommandArgume
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> 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,7 +69,7 @@ public final class StaticArgument<C extends CommandSender> extends CommandArgume
|
||||||
* @return Constructed argument
|
* @return Constructed argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> 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);
|
||||||
}
|
}
|
||||||
|
|
@ -95,7 +94,7 @@ public final class StaticArgument<C extends CommandSender> extends CommandArgume
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class StaticArgumentParser<C extends CommandSender> implements ArgumentParser<C, String> {
|
private static final class StaticArgumentParser<C> implements ArgumentParser<C, String> {
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
private final Set<String> acceptedStrings = new HashSet<>();
|
private final Set<String> acceptedStrings = new HashSet<>();
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
package com.intellectualsites.commands.arguments.parser;
|
package com.intellectualsites.commands.arguments.parser;
|
||||||
|
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -38,7 +37,7 @@ import java.util.Queue;
|
||||||
* @param <T> Value type
|
* @param <T> Value type
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ArgumentParser<C extends CommandSender, T> {
|
public interface ArgumentParser<C, T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse command input into a command result
|
* Parse command input into a command result
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
package com.intellectualsites.commands.arguments.parser;
|
package com.intellectualsites.commands.arguments.parser;
|
||||||
|
|
||||||
import com.google.common.reflect.TypeToken;
|
import com.google.common.reflect.TypeToken;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
|
|
@ -40,7 +39,7 @@ import java.util.function.Function;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public interface ParserRegistry<C extends CommandSender> {
|
public interface ParserRegistry<C> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a parser supplier
|
* Register a parser supplier
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ import com.intellectualsites.commands.arguments.standard.FloatArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.ShortArgument;
|
import com.intellectualsites.commands.arguments.standard.ShortArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
|
|
@ -52,7 +51,7 @@ import java.util.function.Function;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public final class StandardParserRegistry<C extends CommandSender> implements ParserRegistry<C> {
|
public final class StandardParserRegistry<C> implements ParserRegistry<C> {
|
||||||
|
|
||||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_MAPPINGS = ImmutableMap.<Class<?>, Class<?>>builder()
|
private static final Map<Class<?>, Class<?>> PRIMITIVE_MAPPINGS = ImmutableMap.<Class<?>, Class<?>>builder()
|
||||||
.put(char.class, Character.class)
|
.put(char.class, Character.class)
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
@ -35,7 +34,7 @@ import java.util.List;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class BooleanArgument<C extends CommandSender> extends CommandArgument<C, Boolean> {
|
public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
||||||
private final boolean liberal;
|
private final boolean liberal;
|
||||||
|
|
||||||
private BooleanArgument(final boolean required, @Nonnull final String name,
|
private BooleanArgument(final boolean required, @Nonnull final String name,
|
||||||
|
|
@ -52,7 +51,7 @@ public final class BooleanArgument<C extends CommandSender> extends CommandArgum
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> Builder<C> newBuilder(@Nonnull final String name) {
|
public static <C> Builder<C> newBuilder(@Nonnull final String name) {
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -64,7 +63,7 @@ public final class BooleanArgument<C extends CommandSender> extends CommandArgum
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Boolean> required(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Boolean> required(@Nonnull final String name) {
|
||||||
return BooleanArgument.<C>newBuilder(name).asRequired().build();
|
return BooleanArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -76,7 +75,7 @@ public final class BooleanArgument<C extends CommandSender> extends CommandArgum
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Boolean> optional(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Boolean> optional(@Nonnull final String name) {
|
||||||
return BooleanArgument.<C>newBuilder(name).asOptional().build();
|
return BooleanArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,13 +88,13 @@ public final class BooleanArgument<C extends CommandSender> extends CommandArgum
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Boolean> optional(@Nonnull final String name,
|
public static <C> CommandArgument<C, Boolean> optional(@Nonnull final String name,
|
||||||
final String defaultNum) {
|
final String defaultNum) {
|
||||||
return BooleanArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
return BooleanArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Boolean> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Boolean> {
|
||||||
|
|
||||||
private boolean liberal = false;
|
private boolean liberal = false;
|
||||||
|
|
||||||
|
|
@ -138,7 +137,7 @@ public final class BooleanArgument<C extends CommandSender> extends CommandArgum
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class BooleanParser<C extends CommandSender> implements ArgumentParser<C, Boolean> {
|
public static final class BooleanParser<C> implements ArgumentParser<C, Boolean> {
|
||||||
|
|
||||||
private static final List<String> LIBERAL = Arrays.asList("TRUE", "YES", "ON", "FALSE", "NO", "OFF");
|
private static final List<String> LIBERAL = Arrays.asList("TRUE", "YES", "ON", "FALSE", "NO", "OFF");
|
||||||
private static final List<String> LIBERAL_TRUE = Arrays.asList("TRUE", "YES", "ON");
|
private static final List<String> LIBERAL_TRUE = Arrays.asList("TRUE", "YES", "ON");
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,12 @@ import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class ByteArgument<C extends CommandSender> extends CommandArgument<C, Byte> {
|
public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
||||||
|
|
||||||
private final byte min;
|
private final byte min;
|
||||||
private final byte max;
|
private final byte max;
|
||||||
|
|
@ -54,7 +53,7 @@ public final class ByteArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> Builder<C> newBuilder(@Nonnull final String name) {
|
public static <C> Builder<C> newBuilder(@Nonnull final String name) {
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -66,7 +65,7 @@ public final class ByteArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Byte> required(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Byte> required(@Nonnull final String name) {
|
||||||
return ByteArgument.<C>newBuilder(name).asRequired().build();
|
return ByteArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,7 +77,7 @@ public final class ByteArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Byte> optional(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Byte> optional(@Nonnull final String name) {
|
||||||
return ByteArgument.<C>newBuilder(name).asOptional().build();
|
return ByteArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,13 +89,13 @@ public final class ByteArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull public static <C extends CommandSender> CommandArgument<C, Byte> optional(@Nonnull final String name,
|
@Nonnull public static <C> CommandArgument<C, Byte> optional(@Nonnull final String name,
|
||||||
final byte defaultNum) {
|
final byte defaultNum) {
|
||||||
return ByteArgument.<C>newBuilder(name).asOptionalWithDefault(Byte.toString(defaultNum)).build();
|
return ByteArgument.<C>newBuilder(name).asOptionalWithDefault(Byte.toString(defaultNum)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Byte> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Byte> {
|
||||||
|
|
||||||
private byte min = Byte.MIN_VALUE;
|
private byte min = Byte.MIN_VALUE;
|
||||||
private byte max = Byte.MAX_VALUE;
|
private byte max = Byte.MAX_VALUE;
|
||||||
|
|
@ -162,7 +161,7 @@ public final class ByteArgument<C extends CommandSender> extends CommandArgument
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class ByteParser<C extends CommandSender> implements ArgumentParser<C, Byte> {
|
public static final class ByteParser<C> implements ArgumentParser<C, Byte> {
|
||||||
|
|
||||||
private final byte min;
|
private final byte min;
|
||||||
private final byte max;
|
private final byte max;
|
||||||
|
|
|
||||||
|
|
@ -27,13 +27,12 @@ import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class CharArgument<C extends CommandSender> extends CommandArgument<C, Character> {
|
public final class CharArgument<C> extends CommandArgument<C, Character> {
|
||||||
|
|
||||||
private CharArgument(final boolean required, @Nonnull final String name,
|
private CharArgument(final boolean required, @Nonnull final String name,
|
||||||
@Nonnull final String defaultValue) {
|
@Nonnull final String defaultValue) {
|
||||||
|
|
@ -48,7 +47,7 @@ public final class CharArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CharArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
public static <C> CharArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
||||||
return new CharArgument.Builder<>(name);
|
return new CharArgument.Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,7 +59,7 @@ public final class CharArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Character> required(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Character> required(@Nonnull final String name) {
|
||||||
return CharArgument.<C>newBuilder(name).asRequired().build();
|
return CharArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,7 +71,7 @@ public final class CharArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Character> optional(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Character> optional(@Nonnull final String name) {
|
||||||
return CharArgument.<C>newBuilder(name).asOptional().build();
|
return CharArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -85,13 +84,13 @@ public final class CharArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Character> optional(@Nonnull final String name,
|
public static <C> CommandArgument<C, Character> optional(@Nonnull final String name,
|
||||||
final String defaultNum) {
|
final String defaultNum) {
|
||||||
return CharArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
return CharArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Character> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Character> {
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@Nonnull final String name) {
|
||||||
super(Character.class, name);
|
super(Character.class, name);
|
||||||
|
|
@ -111,7 +110,7 @@ public final class CharArgument<C extends CommandSender> extends CommandArgument
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class CharacterParser<C extends CommandSender> implements ArgumentParser<C, Character> {
|
public static final class CharacterParser<C> implements ArgumentParser<C, Character> {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,12 @@ import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class DoubleArgument<C extends CommandSender> extends CommandArgument<C, Double> {
|
public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
||||||
|
|
||||||
private final double min;
|
private final double min;
|
||||||
private final double max;
|
private final double max;
|
||||||
|
|
@ -57,7 +56,7 @@ public final class DoubleArgument<C extends CommandSender> extends CommandArgume
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> Builder<C> newBuilder(@Nonnull final String name) {
|
public static <C> Builder<C> newBuilder(@Nonnull final String name) {
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +68,7 @@ public final class DoubleArgument<C extends CommandSender> extends CommandArgume
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Double> required(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Double> required(@Nonnull final String name) {
|
||||||
return DoubleArgument.<C>newBuilder(name).asRequired().build();
|
return DoubleArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +80,7 @@ public final class DoubleArgument<C extends CommandSender> extends CommandArgume
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Double> optional(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Double> optional(@Nonnull final String name) {
|
||||||
return DoubleArgument.<C>newBuilder(name).asOptional().build();
|
return DoubleArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,13 +93,13 @@ public final class DoubleArgument<C extends CommandSender> extends CommandArgume
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Double> optional(@Nonnull final String name,
|
public static <C> CommandArgument<C, Double> optional(@Nonnull final String name,
|
||||||
final double defaultNum) {
|
final double defaultNum) {
|
||||||
return DoubleArgument.<C>newBuilder(name).asOptionalWithDefault(Double.toString(defaultNum)).build();
|
return DoubleArgument.<C>newBuilder(name).asOptionalWithDefault(Double.toString(defaultNum)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Double> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Double> {
|
||||||
|
|
||||||
private double min = Double.MIN_VALUE;
|
private double min = Double.MIN_VALUE;
|
||||||
private double max = Double.MAX_VALUE;
|
private double max = Double.MAX_VALUE;
|
||||||
|
|
@ -166,7 +165,7 @@ public final class DoubleArgument<C extends CommandSender> extends CommandArgume
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class DoubleParser<C extends CommandSender> implements ArgumentParser<C, Double> {
|
public static final class DoubleParser<C> implements ArgumentParser<C, Double> {
|
||||||
|
|
||||||
private final double min;
|
private final double min;
|
||||||
private final double max;
|
private final double max;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
@ -42,7 +41,7 @@ import java.util.stream.Collectors;
|
||||||
* @param <E> Enum type
|
* @param <E> Enum type
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class EnumArgument<C extends CommandSender, E extends Enum<E>> extends CommandArgument<C, E> {
|
public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
||||||
|
|
||||||
protected EnumArgument(@Nonnull final Class<E> enumClass,
|
protected EnumArgument(@Nonnull final Class<E> enumClass,
|
||||||
final boolean required,
|
final boolean required,
|
||||||
|
|
@ -61,7 +60,7 @@ public class EnumArgument<C extends CommandSender, E extends Enum<E>> extends Co
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender, E extends Enum<E>> EnumArgument.Builder<C, E> newBuilder(
|
public static <C, E extends Enum<E>> EnumArgument.Builder<C, E> newBuilder(
|
||||||
@Nonnull final Class<E> enumClass, @Nonnull final String name) {
|
@Nonnull final Class<E> enumClass, @Nonnull final String name) {
|
||||||
return new EnumArgument.Builder<>(name, enumClass);
|
return new EnumArgument.Builder<>(name, enumClass);
|
||||||
}
|
}
|
||||||
|
|
@ -76,7 +75,7 @@ public class EnumArgument<C extends CommandSender, E extends Enum<E>> extends Co
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender, E extends Enum<E>> CommandArgument<C, E> required(
|
public static <C, E extends Enum<E>> CommandArgument<C, E> required(
|
||||||
@Nonnull final Class<E> enumClass, @Nonnull final String name) {
|
@Nonnull final Class<E> enumClass, @Nonnull final String name) {
|
||||||
return EnumArgument.<C, E>newBuilder(enumClass, name).asRequired().build();
|
return EnumArgument.<C, E>newBuilder(enumClass, name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
@ -91,7 +90,7 @@ public class EnumArgument<C extends CommandSender, E extends Enum<E>> extends Co
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender, E extends Enum<E>> CommandArgument<C, E> optional(
|
public static <C, E extends Enum<E>> CommandArgument<C, E> optional(
|
||||||
@Nonnull final Class<E> enumClass, @Nonnull final String name) {
|
@Nonnull final Class<E> enumClass, @Nonnull final String name) {
|
||||||
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptional().build();
|
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
@ -107,13 +106,13 @@ public class EnumArgument<C extends CommandSender, E extends Enum<E>> extends Co
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender, E extends Enum<E>> CommandArgument<C, E> optional(
|
public static <C, E extends Enum<E>> CommandArgument<C, E> optional(
|
||||||
@Nonnull final Class<E> enumClass, @Nonnull final String name, @Nonnull final E defaultValue) {
|
@Nonnull final Class<E> enumClass, @Nonnull final String name, @Nonnull final E defaultValue) {
|
||||||
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptionalWithDefault(defaultValue.name().toLowerCase()).build();
|
return EnumArgument.<C, E>newBuilder(enumClass, name).asOptionalWithDefault(defaultValue.name().toLowerCase()).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C extends CommandSender, E extends Enum<E>> extends CommandArgument.Builder<C, E> {
|
public static final class Builder<C, E extends Enum<E>> extends CommandArgument.Builder<C, E> {
|
||||||
|
|
||||||
private final Class<E> enumClass;
|
private final Class<E> enumClass;
|
||||||
|
|
||||||
|
|
@ -130,7 +129,7 @@ public class EnumArgument<C extends CommandSender, E extends Enum<E>> extends Co
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class EnumParser<C extends CommandSender, E extends Enum<E>> implements ArgumentParser<C, E> {
|
public static final class EnumParser<C, E extends Enum<E>> implements ArgumentParser<C, E> {
|
||||||
|
|
||||||
private final Class<E> enumClass;
|
private final Class<E> enumClass;
|
||||||
private final EnumSet<E> allowedValues;
|
private final EnumSet<E> allowedValues;
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,12 @@ import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class FloatArgument<C extends CommandSender> extends CommandArgument<C, Float> {
|
public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
||||||
|
|
||||||
private final float min;
|
private final float min;
|
||||||
private final float max;
|
private final float max;
|
||||||
|
|
@ -57,7 +56,7 @@ public final class FloatArgument<C extends CommandSender> extends CommandArgumen
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> Builder<C> newBuilder(@Nonnull final String name) {
|
public static <C> Builder<C> newBuilder(@Nonnull final String name) {
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +68,7 @@ public final class FloatArgument<C extends CommandSender> extends CommandArgumen
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Float> required(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Float> required(@Nonnull final String name) {
|
||||||
return FloatArgument.<C>newBuilder(name).asRequired().build();
|
return FloatArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +80,7 @@ public final class FloatArgument<C extends CommandSender> extends CommandArgumen
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Float> optional(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Float> optional(@Nonnull final String name) {
|
||||||
return FloatArgument.<C>newBuilder(name).asOptional().build();
|
return FloatArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,13 +93,13 @@ public final class FloatArgument<C extends CommandSender> extends CommandArgumen
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Float> optional(@Nonnull final String name,
|
public static <C> CommandArgument<C, Float> optional(@Nonnull final String name,
|
||||||
final float defaultNum) {
|
final float defaultNum) {
|
||||||
return FloatArgument.<C>newBuilder(name).asOptionalWithDefault(Float.toString(defaultNum)).build();
|
return FloatArgument.<C>newBuilder(name).asOptionalWithDefault(Float.toString(defaultNum)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Float> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Float> {
|
||||||
|
|
||||||
private float min = Float.MIN_VALUE;
|
private float min = Float.MIN_VALUE;
|
||||||
private float max = Float.MAX_VALUE;
|
private float max = Float.MAX_VALUE;
|
||||||
|
|
@ -166,7 +165,7 @@ public final class FloatArgument<C extends CommandSender> extends CommandArgumen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class FloatParser<C extends CommandSender> implements ArgumentParser<C, Float> {
|
public static final class FloatParser<C> implements ArgumentParser<C, Float> {
|
||||||
|
|
||||||
private final float min;
|
private final float min;
|
||||||
private final float max;
|
private final float max;
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,12 @@ import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class IntegerArgument<C extends CommandSender> extends CommandArgument<C, Integer> {
|
public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
||||||
|
|
||||||
private final int min;
|
private final int min;
|
||||||
private final int max;
|
private final int max;
|
||||||
|
|
@ -57,7 +56,7 @@ public final class IntegerArgument<C extends CommandSender> extends CommandArgum
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> Builder<C> newBuilder(@Nonnull final String name) {
|
public static <C> Builder<C> newBuilder(@Nonnull final String name) {
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +68,7 @@ public final class IntegerArgument<C extends CommandSender> extends CommandArgum
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Integer> required(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Integer> required(@Nonnull final String name) {
|
||||||
return IntegerArgument.<C>newBuilder(name).asRequired().build();
|
return IntegerArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +80,7 @@ public final class IntegerArgument<C extends CommandSender> extends CommandArgum
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Integer> optional(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Integer> optional(@Nonnull final String name) {
|
||||||
return IntegerArgument.<C>newBuilder(name).asOptional().build();
|
return IntegerArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,13 +93,13 @@ public final class IntegerArgument<C extends CommandSender> extends CommandArgum
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Integer> optional(@Nonnull final String name,
|
public static <C> CommandArgument<C, Integer> optional(@Nonnull final String name,
|
||||||
final int defaultNum) {
|
final int defaultNum) {
|
||||||
return IntegerArgument.<C>newBuilder(name).asOptionalWithDefault(Integer.toString(defaultNum)).build();
|
return IntegerArgument.<C>newBuilder(name).asOptionalWithDefault(Integer.toString(defaultNum)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Integer> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Integer> {
|
||||||
|
|
||||||
private int min = Integer.MIN_VALUE;
|
private int min = Integer.MIN_VALUE;
|
||||||
private int max = Integer.MAX_VALUE;
|
private int max = Integer.MAX_VALUE;
|
||||||
|
|
@ -166,7 +165,7 @@ public final class IntegerArgument<C extends CommandSender> extends CommandArgum
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class IntegerParser<C extends CommandSender> implements ArgumentParser<C, Integer> {
|
public static final class IntegerParser<C> implements ArgumentParser<C, Integer> {
|
||||||
|
|
||||||
private final int min;
|
private final int min;
|
||||||
private final int max;
|
private final int max;
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,12 @@ import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class LongArgument<C extends CommandSender> extends CommandArgument<C, Long> {
|
public final class LongArgument<C> extends CommandArgument<C, Long> {
|
||||||
|
|
||||||
private final long min;
|
private final long min;
|
||||||
private final long max;
|
private final long max;
|
||||||
|
|
@ -57,7 +56,7 @@ public final class LongArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> LongArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
public static <C> LongArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
||||||
return new Builder<>(name);
|
return new Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +68,7 @@ public final class LongArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Long> required(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Long> required(@Nonnull final String name) {
|
||||||
return LongArgument.<C>newBuilder(name).asRequired().build();
|
return LongArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +80,7 @@ public final class LongArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Long> optional(@Nonnull final String name) {
|
public static <C> CommandArgument<C, Long> optional(@Nonnull final String name) {
|
||||||
return LongArgument.<C>newBuilder(name).asOptional().build();
|
return LongArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,13 +93,13 @@ public final class LongArgument<C extends CommandSender> extends CommandArgument
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, Long> optional(@Nonnull final String name,
|
public static <C> CommandArgument<C, Long> optional(@Nonnull final String name,
|
||||||
final long defaultNum) {
|
final long defaultNum) {
|
||||||
return LongArgument.<C>newBuilder(name).asOptionalWithDefault(Long.toString(defaultNum)).build();
|
return LongArgument.<C>newBuilder(name).asOptionalWithDefault(Long.toString(defaultNum)).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Long> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Long> {
|
||||||
|
|
||||||
private long min = Long.MIN_VALUE;
|
private long min = Long.MIN_VALUE;
|
||||||
private long max = Long.MAX_VALUE;
|
private long max = Long.MAX_VALUE;
|
||||||
|
|
@ -166,7 +165,7 @@ public final class LongArgument<C extends CommandSender> extends CommandArgument
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static final class LongParser<C extends CommandSender> implements ArgumentParser<C, Long> {
|
private static final class LongParser<C> implements ArgumentParser<C, Long> {
|
||||||
|
|
||||||
private final long min;
|
private final long min;
|
||||||
private final long max;
|
private final long max;
|
||||||
|
|
|
||||||
|
|
@ -28,13 +28,12 @@ import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
import com.intellectualsites.commands.exceptions.parsing.NumberParseException;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class ShortArgument<C extends CommandSender> extends CommandArgument<C, Short> {
|
public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
||||||
|
|
||||||
private final short min;
|
private final short min;
|
||||||
private final short max;
|
private final short max;
|
||||||
|
|
@ -57,7 +56,7 @@ public final class ShortArgument<C extends CommandSender> extends CommandArgumen
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> ShortArgument.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +68,7 @@ public final class ShortArgument<C extends CommandSender> extends CommandArgumen
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +80,7 @@ public final class ShortArgument<C extends CommandSender> extends CommandArgumen
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,13 +93,13 @@ public final class ShortArgument<C extends CommandSender> extends CommandArgumen
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, Short> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, Short> {
|
||||||
|
|
||||||
private short min = Short.MIN_VALUE;
|
private short min = Short.MIN_VALUE;
|
||||||
private short max = Short.MAX_VALUE;
|
private short max = Short.MAX_VALUE;
|
||||||
|
|
@ -166,7 +165,7 @@ public final class ShortArgument<C extends CommandSender> extends CommandArgumen
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class ShortParser<C extends CommandSender> implements ArgumentParser<C, Short> {
|
public static final class ShortParser<C> implements ArgumentParser<C, Short> {
|
||||||
|
|
||||||
private final short min;
|
private final short min;
|
||||||
private final short max;
|
private final short max;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -37,7 +36,7 @@ import java.util.StringJoiner;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public final class StringArgument<C extends CommandSender> extends CommandArgument<C, String> {
|
public final class StringArgument<C> extends CommandArgument<C, String> {
|
||||||
|
|
||||||
private final StringMode stringMode;
|
private final StringMode stringMode;
|
||||||
|
|
||||||
|
|
@ -58,7 +57,7 @@ public final class StringArgument<C extends CommandSender> extends CommandArgume
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> StringArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
public static <C> StringArgument.Builder<C> newBuilder(@Nonnull final String name) {
|
||||||
return new StringArgument.Builder<>(name);
|
return new StringArgument.Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -70,7 +69,7 @@ public final class StringArgument<C extends CommandSender> extends CommandArgume
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, String> required(@Nonnull final String name) {
|
public static <C> CommandArgument<C, String> required(@Nonnull final String name) {
|
||||||
return StringArgument.<C>newBuilder(name).asRequired().build();
|
return StringArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,7 +81,7 @@ public final class StringArgument<C extends CommandSender> extends CommandArgume
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, String> optional(@Nonnull final String name) {
|
public static <C> CommandArgument<C, String> optional(@Nonnull final String name) {
|
||||||
return StringArgument.<C>newBuilder(name).asOptional().build();
|
return StringArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -95,7 +94,7 @@ public final class StringArgument<C extends CommandSender> extends CommandArgume
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, String> optional(@Nonnull final String name,
|
public static <C> CommandArgument<C, String> optional(@Nonnull final String name,
|
||||||
final String defaultNum) {
|
final String defaultNum) {
|
||||||
return StringArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
return StringArgument.<C>newBuilder(name).asOptionalWithDefault(defaultNum).build();
|
||||||
}
|
}
|
||||||
|
|
@ -118,7 +117,7 @@ public final class StringArgument<C extends CommandSender> extends CommandArgume
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, String> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, String> {
|
||||||
|
|
||||||
private StringMode stringMode = StringMode.SINGLE;
|
private StringMode stringMode = StringMode.SINGLE;
|
||||||
private BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider = (v1, v2) -> Collections.emptyList();
|
private BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider = (v1, v2) -> Collections.emptyList();
|
||||||
|
|
@ -188,7 +187,7 @@ public final class StringArgument<C extends CommandSender> extends CommandArgume
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class StringParser<C extends CommandSender> implements ArgumentParser<C, String> {
|
public static final class StringParser<C> implements ArgumentParser<C, String> {
|
||||||
|
|
||||||
private final StringMode stringMode;
|
private final StringMode stringMode;
|
||||||
private final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider;
|
private final BiFunction<CommandContext<C>, String, List<String>> suggestionsProvider;
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.context;
|
package com.intellectualsites.commands.context;
|
||||||
|
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
@ -35,7 +33,7 @@ import java.util.Optional;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public final class CommandContext<C extends CommandSender> {
|
public final class CommandContext<C> {
|
||||||
|
|
||||||
private final Map<String, Object> internalStorage = new HashMap<>();
|
private final Map<String, Object> internalStorage = new HashMap<>();
|
||||||
private final C commandSender;
|
private final C commandSender;
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.context;
|
package com.intellectualsites.commands.context;
|
||||||
|
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -32,7 +30,7 @@ import javax.annotation.Nonnull;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender
|
* @param <C> Command sender
|
||||||
*/
|
*/
|
||||||
public interface CommandContextFactory<C extends CommandSender> {
|
public interface CommandContextFactory<C> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command context
|
* Create a new command context
|
||||||
|
|
|
||||||
|
|
@ -23,11 +23,9 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.context;
|
package com.intellectualsites.commands.context;
|
||||||
|
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public final class StandardCommandContextFactory<C extends CommandSender> implements CommandContextFactory<C> {
|
public final class StandardCommandContextFactory<C> implements CommandContextFactory<C> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new command context
|
* Construct a new command context
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Command context stores values for a {@link com.intellectualsites.commands.sender.CommandSender}
|
* Command context stores values for a command sender
|
||||||
* before and during command execution and parsing
|
* before and during command execution and parsing
|
||||||
*/
|
*/
|
||||||
package com.intellectualsites.commands.context;
|
package com.intellectualsites.commands.context;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -41,7 +40,7 @@ public class ArgumentParseException extends CommandParseException {
|
||||||
* @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 CommandSender commandSender,
|
@Nonnull final Object commandSender,
|
||||||
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.cause = throwable;
|
this.cause = throwable;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
@ -36,7 +35,7 @@ import java.util.List;
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class CommandParseException extends IllegalArgumentException {
|
public class CommandParseException extends IllegalArgumentException {
|
||||||
|
|
||||||
private final CommandSender commandSender;
|
private final Object commandSender;
|
||||||
private final List<CommandArgument<?, ?>> currentChain;
|
private final List<CommandArgument<?, ?>> currentChain;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -45,7 +44,7 @@ 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 CommandSender 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;
|
||||||
|
|
@ -57,7 +56,7 @@ public class CommandParseException extends IllegalArgumentException {
|
||||||
* @return Command sender
|
* @return Command sender
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public CommandSender getCommandSender() {
|
public Object getCommandSender() {
|
||||||
return this.commandSender;
|
return this.commandSender;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -43,7 +42,7 @@ 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 CommandSender commandSender,
|
public InvalidCommandSenderException(@Nonnull final Object commandSender,
|
||||||
@Nonnull final Class<?> requiredSender,
|
@Nonnull final Class<?> requiredSender,
|
||||||
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,12 @@
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception sent when a {@link CommandSender} inputs invalid command syntax
|
* Exception sent when a command sender inputs invalid command syntax
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public class InvalidSyntaxException extends CommandParseException {
|
public class InvalidSyntaxException extends CommandParseException {
|
||||||
|
|
@ -45,7 +44,7 @@ public class InvalidSyntaxException extends CommandParseException {
|
||||||
* @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 CommandSender commandSender,
|
@Nonnull final Object commandSender,
|
||||||
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.correctSyntax = correctSyntax;
|
this.correctSyntax = correctSyntax;
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,12 @@
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exception thrown when a {@link CommandSender} misses a permission required
|
* Exception thrown when a command sender misses a permission required
|
||||||
* to execute a {@link com.intellectualsites.commands.Command}
|
* to execute a {@link com.intellectualsites.commands.Command}
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
@ -46,7 +45,7 @@ public class NoPermissionException extends CommandParseException {
|
||||||
* @param currentChain Chain leading up to the exception
|
* @param currentChain Chain leading up to the exception
|
||||||
*/
|
*/
|
||||||
public NoPermissionException(@Nonnull final String missingPermission,
|
public NoPermissionException(@Nonnull final String missingPermission,
|
||||||
@Nonnull final CommandSender commandSender,
|
@Nonnull final Object commandSender,
|
||||||
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
@Nonnull final List<CommandArgument<?, ?>> currentChain) {
|
||||||
super(commandSender, currentChain);
|
super(commandSender, currentChain);
|
||||||
this.missingPermission = missingPermission;
|
this.missingPermission = missingPermission;
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
package com.intellectualsites.commands.exceptions;
|
package com.intellectualsites.commands.exceptions;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
@ -45,7 +44,7 @@ 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 CommandSender 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);
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ package com.intellectualsites.commands.execution;
|
||||||
import com.intellectualsites.commands.CommandTree;
|
import com.intellectualsites.commands.CommandTree;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.meta.CommandMeta;
|
import com.intellectualsites.commands.meta.CommandMeta;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
@ -42,7 +41,7 @@ import java.util.function.Function;
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <M> Command meta type
|
* @param <M> Command meta type
|
||||||
*/
|
*/
|
||||||
public abstract class CommandExecutionCoordinator<C extends CommandSender, M extends CommandMeta> {
|
public abstract class CommandExecutionCoordinator<C, M extends CommandMeta> {
|
||||||
|
|
||||||
private final CommandTree<C, M> commandTree;
|
private final CommandTree<C, M> commandTree;
|
||||||
|
|
||||||
|
|
@ -62,7 +61,7 @@ public abstract class CommandExecutionCoordinator<C extends CommandSender, M ext
|
||||||
* @param <M> Command meta type
|
* @param <M> Command meta type
|
||||||
* @return New coordinator instance
|
* @return New coordinator instance
|
||||||
*/
|
*/
|
||||||
public static <C extends CommandSender, M extends CommandMeta> Function<CommandTree<C, M>,
|
public static <C, M extends CommandMeta> Function<CommandTree<C, M>,
|
||||||
CommandExecutionCoordinator<C, M>> simpleCoordinator() {
|
CommandExecutionCoordinator<C, M>> simpleCoordinator() {
|
||||||
return SimpleCoordinator::new;
|
return SimpleCoordinator::new;
|
||||||
}
|
}
|
||||||
|
|
@ -94,7 +93,7 @@ public abstract class CommandExecutionCoordinator<C extends CommandSender, M ext
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <M> Command meta type
|
* @param <M> Command meta type
|
||||||
*/
|
*/
|
||||||
public static final class SimpleCoordinator<C extends CommandSender, M extends CommandMeta> extends
|
public static final class SimpleCoordinator<C, M extends CommandMeta> extends
|
||||||
CommandExecutionCoordinator<C, M> {
|
CommandExecutionCoordinator<C, M> {
|
||||||
|
|
||||||
private SimpleCoordinator(@Nonnull final CommandTree<C, M> commandTree) {
|
private SimpleCoordinator(@Nonnull final CommandTree<C, M> commandTree) {
|
||||||
|
|
|
||||||
|
|
@ -24,18 +24,17 @@
|
||||||
package com.intellectualsites.commands.execution;
|
package com.intellectualsites.commands.execution;
|
||||||
|
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler that is invoked whenever a {@link com.intellectualsites.commands.Command} is executed
|
* Handler that is invoked whenever a {@link com.intellectualsites.commands.Command} is executed
|
||||||
* by a {@link com.intellectualsites.commands.sender.CommandSender}
|
* by a command sender
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface CommandExecutionHandler<C extends CommandSender> {
|
public interface CommandExecutionHandler<C> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle command execution
|
* Handle command execution
|
||||||
|
|
@ -50,7 +49,7 @@ public interface CommandExecutionHandler<C extends CommandSender> {
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
class NullCommandExecutionHandler<C extends CommandSender> 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,7 +24,6 @@
|
||||||
package com.intellectualsites.commands.execution;
|
package com.intellectualsites.commands.execution;
|
||||||
|
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
|
@ -33,7 +32,7 @@ import javax.annotation.Nonnull;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public class CommandResult<C extends CommandSender> {
|
public class CommandResult<C> {
|
||||||
|
|
||||||
private final CommandContext<C> commandContext;
|
private final CommandContext<C> commandContext;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
package com.intellectualsites.commands.execution;
|
package com.intellectualsites.commands.execution;
|
||||||
|
|
||||||
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.BiFunction;
|
import java.util.function.BiFunction;
|
||||||
|
|
@ -34,7 +33,7 @@ import java.util.function.BiFunction;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public interface CommandSuggestionProcessor<C extends CommandSender> extends
|
public interface CommandSuggestionProcessor<C> extends
|
||||||
BiFunction<CommandPreprocessingContext<C>, List<String>, List<String>> {
|
BiFunction<CommandPreprocessingContext<C>, List<String>, List<String>> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
package com.intellectualsites.commands.execution;
|
package com.intellectualsites.commands.execution;
|
||||||
|
|
||||||
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
@ -35,7 +34,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public final class FilteringCommandSuggestionProcessor<C extends CommandSender> implements CommandSuggestionProcessor<C> {
|
public final class FilteringCommandSuggestionProcessor<C> implements CommandSuggestionProcessor<C> {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,6 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.execution.preprocessor;
|
package com.intellectualsites.commands.execution.preprocessor;
|
||||||
|
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -33,7 +31,7 @@ import javax.annotation.Nonnull;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public final class AcceptingCommandPreprocessor<C extends CommandSender> implements CommandPreprocessor<C> {
|
public final class AcceptingCommandPreprocessor<C> implements CommandPreprocessor<C> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Key used to access the context meta that indicates that the context has been fully processed
|
* Key used to access the context meta that indicates that the context has been fully processed
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
package com.intellectualsites.commands.execution.preprocessor;
|
package com.intellectualsites.commands.execution.preprocessor;
|
||||||
|
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
@ -35,7 +34,7 @@ import java.util.Objects;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public final class CommandPreprocessingContext<C extends CommandSender> {
|
public final class CommandPreprocessingContext<C> {
|
||||||
|
|
||||||
private final CommandContext<C> commandContext;
|
private final CommandContext<C> commandContext;
|
||||||
private final LinkedList<String> inputQueue;
|
private final LinkedList<String> inputQueue;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.execution.preprocessor;
|
package com.intellectualsites.commands.execution.preprocessor;
|
||||||
|
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
import com.intellectualsites.services.types.ConsumerService;
|
import com.intellectualsites.services.types.ConsumerService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -36,5 +35,5 @@ import com.intellectualsites.services.types.ConsumerService;
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public interface CommandPreprocessor<C extends CommandSender> extends ConsumerService<CommandPreprocessingContext<C>> {
|
public interface CommandPreprocessor<C> extends ConsumerService<CommandPreprocessingContext<C>> {
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
//
|
|
||||||
// MIT License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2020 Alexander Söderberg
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
|
||||||
// in the Software without restriction, including without limitation the rights
|
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
|
||||||
// furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
|
||||||
// copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
// SOFTWARE.
|
|
||||||
//
|
|
||||||
package com.intellectualsites.commands.sender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public interface CommandSender {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Check if the command sender has a given permission node
|
|
||||||
*
|
|
||||||
* @param permission Permission node
|
|
||||||
* @return {@code true} if the sender has the given permission node, else {@code false}
|
|
||||||
*/
|
|
||||||
boolean hasPermission(@Nonnull String permission);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
//
|
|
||||||
// MIT License
|
|
||||||
//
|
|
||||||
// Copyright (c) 2020 Alexander Söderberg
|
|
||||||
//
|
|
||||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
// of this software and associated documentation files (the "Software"), to deal
|
|
||||||
// in the Software without restriction, including without limitation the rights
|
|
||||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
// copies of the Software, and to permit persons to whom the Software is
|
|
||||||
// furnished to do so, subject to the following conditions:
|
|
||||||
//
|
|
||||||
// The above copyright notice and this permission notice shall be included in all
|
|
||||||
// copies or substantial portions of the Software.
|
|
||||||
//
|
|
||||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
// SOFTWARE.
|
|
||||||
//
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Command sender related classes
|
|
||||||
*/
|
|
||||||
package com.intellectualsites.commands.sender;
|
|
||||||
|
|
@ -27,7 +27,6 @@ import com.intellectualsites.commands.arguments.standard.EnumArgument;
|
||||||
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
||||||
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessor;
|
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessor;
|
||||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
import com.intellectualsites.services.types.ConsumerService;
|
import com.intellectualsites.services.types.ConsumerService;
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
|
@ -37,7 +36,7 @@ import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class CommandPreProcessorTest {
|
public class CommandPreProcessorTest {
|
||||||
|
|
||||||
private static CommandManager<CommandSender, SimpleCommandMeta> manager;
|
private static CommandManager<TestCommandSender, SimpleCommandMeta> manager;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void newTree() {
|
static void newTree() {
|
||||||
|
|
@ -70,10 +69,10 @@ public class CommandPreProcessorTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static final class SamplePreprocessor implements CommandPreprocessor<CommandSender> {
|
static final class SamplePreprocessor implements CommandPreprocessor<TestCommandSender> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(@Nonnull final CommandPreprocessingContext<CommandSender> context) {
|
public void accept(@Nonnull final CommandPreprocessingContext<TestCommandSender> context) {
|
||||||
try {
|
try {
|
||||||
final int num = Integer.parseInt(context.getInputQueue().removeFirst());
|
final int num = Integer.parseInt(context.getInputQueue().removeFirst());
|
||||||
context.getCommandContext().store("int", num);
|
context.getCommandContext().store("int", num);
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import com.intellectualsites.commands.arguments.StaticArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.EnumArgument;
|
import com.intellectualsites.commands.arguments.standard.EnumArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -38,7 +37,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class CommandSuggestionsTest {
|
public class CommandSuggestionsTest {
|
||||||
|
|
||||||
private static CommandManager<CommandSender, SimpleCommandMeta> manager;
|
private static CommandManager<TestCommandSender, SimpleCommandMeta> manager;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void setupManager() {
|
static void setupManager() {
|
||||||
|
|
@ -47,7 +46,7 @@ public class CommandSuggestionsTest {
|
||||||
manager.command(manager.commandBuilder("test").argument(StaticArgument.required("two")).build());
|
manager.command(manager.commandBuilder("test").argument(StaticArgument.required("two")).build());
|
||||||
manager.command(manager.commandBuilder("test")
|
manager.command(manager.commandBuilder("test")
|
||||||
.argument(StaticArgument.required("var"))
|
.argument(StaticArgument.required("var"))
|
||||||
.argument(StringArgument.newBuilder("str")
|
.argument(StringArgument.<TestCommandSender>newBuilder("str")
|
||||||
.withSuggestionsProvider((c, s) -> Arrays.asList("one", "two"))
|
.withSuggestionsProvider((c, s) -> Arrays.asList("one", "two"))
|
||||||
.build())
|
.build())
|
||||||
.argument(EnumArgument.required(TestEnum.class, "enum"))
|
.argument(EnumArgument.required(TestEnum.class, "enum"))
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,6 @@ import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.exceptions.NoPermissionException;
|
import com.intellectualsites.commands.exceptions.NoPermissionException;
|
||||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
@ -42,7 +41,7 @@ import java.util.concurrent.CompletionException;
|
||||||
class CommandTreeTest {
|
class CommandTreeTest {
|
||||||
|
|
||||||
private static final int EXPECTED_INPUT_NUMBER = 15;
|
private static final int EXPECTED_INPUT_NUMBER = 15;
|
||||||
private static CommandManager<CommandSender, SimpleCommandMeta> manager;
|
private static CommandManager<TestCommandSender, SimpleCommandMeta> manager;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
static void newTree() {
|
static void newTree() {
|
||||||
|
|
@ -62,7 +61,7 @@ class CommandTreeTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void parse() {
|
void parse() {
|
||||||
final Optional<Command<CommandSender, SimpleCommandMeta>> command = manager.getCommandTree()
|
final Optional<Command<TestCommandSender, SimpleCommandMeta>> command = manager.getCommandTree()
|
||||||
.parse(new CommandContext<>(
|
.parse(new CommandContext<>(
|
||||||
new TestCommandSender()),
|
new TestCommandSender()),
|
||||||
new LinkedList<>(
|
new LinkedList<>(
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,6 @@ import com.intellectualsites.commands.arguments.parser.ParserRegistry;
|
||||||
import com.intellectualsites.commands.arguments.parser.StandardParameters;
|
import com.intellectualsites.commands.arguments.parser.StandardParameters;
|
||||||
import com.intellectualsites.commands.arguments.parser.StandardParserRegistry;
|
import com.intellectualsites.commands.arguments.parser.StandardParserRegistry;
|
||||||
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
|
@ -46,7 +45,7 @@ public class ParserRegistryTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void testParserRegistry() {
|
void testParserRegistry() {
|
||||||
final ParserRegistry<CommandSender> parserRegistry = new StandardParserRegistry<>();
|
final ParserRegistry<TestCommandSender> parserRegistry = new StandardParserRegistry<>();
|
||||||
final Range range = new Range() {
|
final Range range = new Range() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -72,13 +71,14 @@ public class ParserRegistryTest {
|
||||||
final ParserParameters parserParameters = parserRegistry.parseAnnotations(parsedType, Collections.singleton(range));
|
final ParserParameters parserParameters = parserRegistry.parseAnnotations(parsedType, Collections.singleton(range));
|
||||||
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MIN));
|
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MIN));
|
||||||
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MAX));
|
Assertions.assertTrue(parserParameters.has(StandardParameters.RANGE_MAX));
|
||||||
final ArgumentParser<CommandSender, ?> parser = parserRegistry.createParser(parsedType,
|
final ArgumentParser<TestCommandSender, ?> parser = parserRegistry.createParser(parsedType,
|
||||||
parserParameters)
|
parserParameters)
|
||||||
.orElseThrow(
|
.orElseThrow(
|
||||||
() -> new NullPointerException("No parser found"));
|
() -> new NullPointerException("No parser found"));
|
||||||
Assertions.assertTrue(parser instanceof IntegerArgument.IntegerParser);
|
Assertions.assertTrue(parser instanceof IntegerArgument.IntegerParser);
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
final IntegerArgument.IntegerParser<CommandSender> integerParser = (IntegerArgument.IntegerParser<CommandSender>) parser;
|
final IntegerArgument.IntegerParser<TestCommandSender> integerParser =
|
||||||
|
(IntegerArgument.IntegerParser<TestCommandSender>) parser;
|
||||||
Assertions.assertEquals(RANGE_MIN, integerParser.getMin());
|
Assertions.assertEquals(RANGE_MIN, integerParser.getMin());
|
||||||
Assertions.assertEquals(RANGE_MAX, integerParser.getMax());
|
Assertions.assertEquals(RANGE_MAX, integerParser.getMax());
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,11 +26,10 @@ package com.intellectualsites.commands;
|
||||||
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
||||||
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
||||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class TestCommandManager extends CommandManager<CommandSender, SimpleCommandMeta> {
|
public class TestCommandManager extends CommandManager<TestCommandSender, SimpleCommandMeta> {
|
||||||
|
|
||||||
protected TestCommandManager() {
|
protected TestCommandManager() {
|
||||||
super(CommandExecutionCoordinator.simpleCoordinator(), CommandRegistrationHandler.nullCommandRegistrationHandler());
|
super(CommandExecutionCoordinator.simpleCoordinator(), CommandRegistrationHandler.nullCommandRegistrationHandler());
|
||||||
|
|
@ -42,5 +41,11 @@ public class TestCommandManager extends CommandManager<CommandSender, SimpleComm
|
||||||
return SimpleCommandMeta.empty();
|
return SimpleCommandMeta.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean hasPermission(@Nonnull final TestCommandSender sender,
|
||||||
|
@Nonnull final String permission) {
|
||||||
|
return !permission.equalsIgnoreCase("no");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,18 +23,6 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
public class TestCommandSender {
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class TestCommandSender implements CommandSender {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean hasPermission(@Nonnull final String permission) {
|
|
||||||
if (permission.equalsIgnoreCase("no")) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -155,4 +155,9 @@ public class JLineCommandManager extends CommandManager<JLineCommandSender, Simp
|
||||||
return SimpleCommandMeta.empty();
|
return SimpleCommandMeta.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean hasPermission(@Nonnull final JLineCommandSender sender, @Nonnull final String permission) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,15 +23,6 @@
|
||||||
//
|
//
|
||||||
package com.intellectualsites.commands.jline;
|
package com.intellectualsites.commands.jline;
|
||||||
|
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
public class JLineCommandSender {
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
|
|
||||||
public class JLineCommandSender implements CommandSender {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean hasPermission(@Nonnull final String permission) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,6 @@ import com.intellectualsites.commands.arguments.standard.IntegerArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.ShortArgument;
|
import com.intellectualsites.commands.arguments.standard.ShortArgument;
|
||||||
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||||
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
import com.intellectualsites.commands.execution.preprocessor.CommandPreprocessingContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
import com.mojang.brigadier.LiteralMessage;
|
import com.mojang.brigadier.LiteralMessage;
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import com.mojang.brigadier.arguments.BoolArgumentType;
|
import com.mojang.brigadier.arguments.BoolArgumentType;
|
||||||
|
|
@ -75,7 +74,7 @@ import java.util.function.Supplier;
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
* @param <S> Brigadier sender type
|
* @param <S> Brigadier sender type
|
||||||
*/
|
*/
|
||||||
public final class CloudBrigadierManager<C extends CommandSender, S> {
|
public final class CloudBrigadierManager<C, S> {
|
||||||
|
|
||||||
private final Map<Class<?>, Function<? extends CommandArgument<C, ?>,
|
private final Map<Class<?>, Function<? extends CommandArgument<C, ?>,
|
||||||
? extends ArgumentType<?>>> mappers;
|
? extends ArgumentType<?>>> mappers;
|
||||||
|
|
|
||||||
|
|
@ -55,10 +55,13 @@ public final class BukkitTest extends JavaPlugin {
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
try {
|
try {
|
||||||
final PaperCommandManager<BukkitCommandSender> mgr = new PaperCommandManager<>(this,
|
final PaperCommandManager<BukkitCommandSender> mgr = new PaperCommandManager<>(
|
||||||
CommandExecutionCoordinator
|
this,
|
||||||
.simpleCoordinator(),
|
CommandExecutionCoordinator
|
||||||
BukkitCommandSender::of);
|
.simpleCoordinator(),
|
||||||
|
BukkitCommandSender::of,
|
||||||
|
BukkitCommandSender::getInternalSender
|
||||||
|
);
|
||||||
mgr.registerBrigadier();
|
mgr.registerBrigadier();
|
||||||
mgr.command(mgr.commandBuilder("gamemode",
|
mgr.command(mgr.commandBuilder("gamemode",
|
||||||
Collections.singleton("gajmöde"),
|
Collections.singleton("gajmöde"),
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ import org.bukkit.plugin.Plugin;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
final class BukkitCommand<C extends com.intellectualsites.commands.sender.CommandSender>
|
final class BukkitCommand<C>
|
||||||
extends org.bukkit.command.Command implements PluginIdentifiableCommand {
|
extends org.bukkit.command.Command implements PluginIdentifiableCommand {
|
||||||
|
|
||||||
private final CommandArgument<C, ?> command;
|
private final CommandArgument<C, ?> command;
|
||||||
|
|
|
||||||
|
|
@ -39,29 +39,34 @@ import java.util.function.Function;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public class BukkitCommandManager<C extends com.intellectualsites.commands.sender.CommandSender>
|
public class BukkitCommandManager<C>
|
||||||
extends CommandManager<C, BukkitCommandMeta> {
|
extends CommandManager<C, BukkitCommandMeta> {
|
||||||
|
|
||||||
private final Plugin owningPlugin;
|
private final Plugin owningPlugin;
|
||||||
|
|
||||||
private final Function<CommandSender, C> commandSenderMapper;
|
private final Function<CommandSender, C> commandSenderMapper;
|
||||||
|
private final Function<C, CommandSender> backwardsCommandSenderMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new Bukkit command manager
|
* Construct a new Bukkit command manager
|
||||||
*
|
*
|
||||||
* @param owningPlugin Plugin that is constructing the manager
|
* @param owningPlugin Plugin that is constructing the manager
|
||||||
* @param commandExecutionCoordinator Coordinator provider
|
* @param commandExecutionCoordinator Coordinator provider
|
||||||
* @param commandSenderMapper Function that maps {@link CommandSender} to the command sender type
|
* @param commandSenderMapper Function that maps {@link CommandSender} to the command sender type
|
||||||
|
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
||||||
* @throws Exception If the construction of the manager fails
|
* @throws Exception If the construction of the manager fails
|
||||||
*/
|
*/
|
||||||
public BukkitCommandManager(@Nonnull final Plugin owningPlugin,
|
public BukkitCommandManager(@Nonnull final Plugin owningPlugin,
|
||||||
@Nonnull final Function<CommandTree<C, BukkitCommandMeta>,
|
@Nonnull final Function<CommandTree<C, BukkitCommandMeta>,
|
||||||
CommandExecutionCoordinator<C, BukkitCommandMeta>> commandExecutionCoordinator,
|
CommandExecutionCoordinator<C, BukkitCommandMeta>> commandExecutionCoordinator,
|
||||||
@Nonnull final Function<CommandSender, C> commandSenderMapper)
|
@Nonnull final Function<CommandSender, C> commandSenderMapper,
|
||||||
|
@Nonnull final Function<C, CommandSender> backwardsCommandSenderMapper)
|
||||||
throws Exception {
|
throws Exception {
|
||||||
super(commandExecutionCoordinator, new BukkitPluginRegistrationHandler<>());
|
super(commandExecutionCoordinator, new BukkitPluginRegistrationHandler<>());
|
||||||
((BukkitPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
((BukkitPluginRegistrationHandler<C>) this.getCommandRegistrationHandler()).initialize(this);
|
||||||
this.owningPlugin = owningPlugin;
|
this.owningPlugin = owningPlugin;
|
||||||
this.commandSenderMapper = commandSenderMapper;
|
this.commandSenderMapper = commandSenderMapper;
|
||||||
|
this.backwardsCommandSenderMapper = backwardsCommandSenderMapper;
|
||||||
|
|
||||||
/* Register Bukkit parsers */
|
/* Register Bukkit parsers */
|
||||||
this.getParserRegistry().registerParserSupplier(TypeToken.of(World.class), params -> new WorldArgument.WorldParser<>());
|
this.getParserRegistry().registerParserSupplier(TypeToken.of(World.class), params -> new WorldArgument.WorldParser<>());
|
||||||
|
|
@ -93,4 +98,9 @@ public class BukkitCommandManager<C extends com.intellectualsites.commands.sende
|
||||||
return this.commandSenderMapper;
|
return this.commandSenderMapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean hasPermission(@Nonnull final C sender, @Nonnull final String permission) {
|
||||||
|
return this.backwardsCommandSenderMapper.apply(sender).hasPermission(permission);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
package com.intellectualsites.commands;
|
package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
@ -33,12 +32,12 @@ import javax.annotation.Nonnull;
|
||||||
* Command sender that proxies {@link org.bukkit.command.CommandSender}
|
* Command sender that proxies {@link org.bukkit.command.CommandSender}
|
||||||
* {@inheritDoc}
|
* {@inheritDoc}
|
||||||
*/
|
*/
|
||||||
public abstract class BukkitCommandSender implements CommandSender {
|
public abstract class BukkitCommandSender {
|
||||||
|
|
||||||
private final org.bukkit.command.CommandSender internalSender;
|
private final org.bukkit.command.CommandSender internalSender;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new command sender from a Bukkit {@link CommandSender}
|
* Create a new command sender from a Bukkit {@link org.bukkit.command.CommandSender}
|
||||||
*
|
*
|
||||||
* @param internalSender Bukkit command sender
|
* @param internalSender Bukkit command sender
|
||||||
*/
|
*/
|
||||||
|
|
@ -68,7 +67,7 @@ public abstract class BukkitCommandSender implements CommandSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct a new {@link BukkitCommandSender} from a Bukkit {@link CommandSender}
|
* Construct a new {@link BukkitCommandSender} from a Bukkit {@link org.bukkit.command.CommandSender}
|
||||||
*
|
*
|
||||||
* @param sender Bukkit command sender
|
* @param sender Bukkit command sender
|
||||||
* @return Constructed command sender
|
* @return Constructed command sender
|
||||||
|
|
@ -124,11 +123,6 @@ public abstract class BukkitCommandSender implements CommandSender {
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public abstract Player asPlayer();
|
public abstract Player asPlayer();
|
||||||
|
|
||||||
@Override
|
|
||||||
public final boolean hasPermission(@Nonnull final String permission) {
|
|
||||||
return this.internalSender.hasPermission(permission);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the command sender
|
* Send a message to the command sender
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
import com.intellectualsites.commands.internal.CommandRegistrationHandler;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandMap;
|
import org.bukkit.command.CommandMap;
|
||||||
import org.bukkit.command.SimpleCommandMap;
|
import org.bukkit.command.SimpleCommandMap;
|
||||||
|
|
@ -37,7 +36,7 @@ import java.lang.reflect.Method;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
final class BukkitPluginRegistrationHandler<C extends CommandSender> implements CommandRegistrationHandler<BukkitCommandMeta> {
|
final class BukkitPluginRegistrationHandler<C> implements CommandRegistrationHandler<BukkitCommandMeta> {
|
||||||
|
|
||||||
private final Map<CommandArgument<?, ?>, org.bukkit.command.Command> registeredCommands = new HashMap<>();
|
private final Map<CommandArgument<?, ?>, org.bukkit.command.Command> registeredCommands = new HashMap<>();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,6 @@ import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||||
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
import com.intellectualsites.commands.arguments.parser.ArgumentParser;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
|
|
||||||
|
|
@ -41,7 +40,7 @@ import java.util.stream.Collectors;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public class WorldArgument<C extends CommandSender> extends CommandArgument<C, World> {
|
public class WorldArgument<C> extends CommandArgument<C, World> {
|
||||||
|
|
||||||
protected WorldArgument(final boolean required,
|
protected WorldArgument(final boolean required,
|
||||||
@Nonnull final String name,
|
@Nonnull final String name,
|
||||||
|
|
@ -57,7 +56,7 @@ public class WorldArgument<C extends CommandSender> extends CommandArgument<C, W
|
||||||
* @return Created builder
|
* @return Created builder
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument.Builder<C, World> newBuilder(@Nonnull final String name) {
|
public static <C> CommandArgument.Builder<C, World> newBuilder(@Nonnull final String name) {
|
||||||
return new WorldArgument.Builder<>(name);
|
return new WorldArgument.Builder<>(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -69,7 +68,7 @@ public class WorldArgument<C extends CommandSender> extends CommandArgument<C, W
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, World> required(@Nonnull final String name) {
|
public static <C> CommandArgument<C, World> required(@Nonnull final String name) {
|
||||||
return WorldArgument.<C>newBuilder(name).asRequired().build();
|
return WorldArgument.<C>newBuilder(name).asRequired().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +80,7 @@ public class WorldArgument<C extends CommandSender> extends CommandArgument<C, W
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, World> optional(@Nonnull final String name) {
|
public static <C> CommandArgument<C, World> optional(@Nonnull final String name) {
|
||||||
return WorldArgument.<C>newBuilder(name).asOptional().build();
|
return WorldArgument.<C>newBuilder(name).asOptional().build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -94,13 +93,13 @@ public class WorldArgument<C extends CommandSender> extends CommandArgument<C, W
|
||||||
* @return Created argument
|
* @return Created argument
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public static <C extends CommandSender> CommandArgument<C, World> optional(@Nonnull final String name,
|
public static <C> CommandArgument<C, World> optional(@Nonnull final String name,
|
||||||
@Nonnull final String defaultValue) {
|
@Nonnull final String defaultValue) {
|
||||||
return WorldArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue).build();
|
return WorldArgument.<C>newBuilder(name).asOptionalWithDefault(defaultValue).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class Builder<C extends CommandSender> extends CommandArgument.Builder<C, World> {
|
public static final class Builder<C> extends CommandArgument.Builder<C, World> {
|
||||||
|
|
||||||
protected Builder(@Nonnull final String name) {
|
protected Builder(@Nonnull final String name) {
|
||||||
super(World.class, name);
|
super(World.class, name);
|
||||||
|
|
@ -114,7 +113,7 @@ public class WorldArgument<C extends CommandSender> extends CommandArgument<C, W
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static final class WorldParser<C extends CommandSender> implements ArgumentParser<C, World> {
|
public static final class WorldParser<C> implements ArgumentParser<C, World> {
|
||||||
|
|
||||||
@Nonnull
|
@Nonnull
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -25,10 +25,9 @@ package com.intellectualsites.commands;
|
||||||
|
|
||||||
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
import com.destroystokyo.paper.brigadier.BukkitBrigadierCommandSource;
|
||||||
import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
|
import com.destroystokyo.paper.event.brigadier.CommandRegisteredEvent;
|
||||||
import com.intellectualsites.commands.brigadier.CloudBrigadierManager;
|
|
||||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||||
|
import com.intellectualsites.commands.brigadier.CloudBrigadierManager;
|
||||||
import com.intellectualsites.commands.context.CommandContext;
|
import com.intellectualsites.commands.context.CommandContext;
|
||||||
import com.intellectualsites.commands.sender.CommandSender;
|
|
||||||
import com.mojang.brigadier.arguments.ArgumentType;
|
import com.mojang.brigadier.arguments.ArgumentType;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
|
@ -42,7 +41,7 @@ import java.lang.reflect.Constructor;
|
||||||
import java.lang.reflect.InvocationTargetException;
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
class PaperBrigadierListener<C extends CommandSender> implements Listener {
|
class PaperBrigadierListener<C> implements Listener {
|
||||||
|
|
||||||
private final CloudBrigadierManager<C, BukkitBrigadierCommandSource> brigadierManager;
|
private final CloudBrigadierManager<C, BukkitBrigadierCommandSource> brigadierManager;
|
||||||
private final PaperCommandManager<C> paperCommandManager;
|
private final PaperCommandManager<C> paperCommandManager;
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ import java.util.function.Function;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @param <C> Command sender type
|
||||||
*/
|
*/
|
||||||
public class PaperCommandManager<C extends com.intellectualsites.commands.sender.CommandSender>
|
public class PaperCommandManager<C>
|
||||||
extends BukkitCommandManager<C> {
|
extends BukkitCommandManager<C> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -46,14 +46,16 @@ public class PaperCommandManager<C extends com.intellectualsites.commands.sender
|
||||||
* @param owningPlugin Plugin that is constructing the manager
|
* @param owningPlugin Plugin that is constructing the manager
|
||||||
* @param commandExecutionCoordinator Coordinator provider
|
* @param commandExecutionCoordinator Coordinator provider
|
||||||
* @param commandSenderMapper Function that maps {@link CommandSender} to the command sender type
|
* @param commandSenderMapper Function that maps {@link CommandSender} to the command sender type
|
||||||
|
* @param backwardsCommandSenderMapper Function that maps the command sender type to {@link CommandSender}
|
||||||
* @throws Exception If the construction of the manager fails
|
* @throws Exception If the construction of the manager fails
|
||||||
*/
|
*/
|
||||||
public PaperCommandManager(@Nonnull final Plugin owningPlugin,
|
public PaperCommandManager(@Nonnull final Plugin owningPlugin,
|
||||||
@Nonnull final Function<CommandTree<C, BukkitCommandMeta>,
|
@Nonnull final Function<CommandTree<C, BukkitCommandMeta>,
|
||||||
CommandExecutionCoordinator<C, BukkitCommandMeta>> commandExecutionCoordinator,
|
CommandExecutionCoordinator<C, BukkitCommandMeta>> commandExecutionCoordinator,
|
||||||
@Nonnull final Function<CommandSender, C> commandSenderMapper) throws
|
@Nonnull final Function<CommandSender, C> commandSenderMapper,
|
||||||
|
@Nonnull final Function<C, CommandSender> backwardsCommandSenderMapper) throws
|
||||||
Exception {
|
Exception {
|
||||||
super(owningPlugin, commandExecutionCoordinator, commandSenderMapper);
|
super(owningPlugin, commandExecutionCoordinator, commandSenderMapper, backwardsCommandSenderMapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue