🎨 Add caption for string "No input was provided"
This commit is contained in:
parent
c67cc35cf6
commit
fba29041e6
29 changed files with 191 additions and 31 deletions
|
|
@ -26,6 +26,7 @@ package cloud.commandframework.arguments;
|
|||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
|
@ -112,7 +113,10 @@ public final class StaticArgument<C> extends CommandArgument<C, String> {
|
|||
) {
|
||||
final String string = inputQueue.peek();
|
||||
if (string == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
StaticArgumentParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
if (this.allAcceptedAliases.contains(string)) {
|
||||
inputQueue.remove();
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import cloud.commandframework.captions.Caption;
|
|||
import cloud.commandframework.captions.CaptionVariable;
|
||||
import cloud.commandframework.captions.StandardCaptionKeys;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Queue;
|
||||
|
|
@ -89,7 +90,10 @@ public final class RegexPreprocessor<C> implements BiFunction<@NonNull CommandCo
|
|||
) {
|
||||
final String head = strings.peek();
|
||||
if (head == null) {
|
||||
throw new NullPointerException("No input");
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
RegexPreprocessor.class,
|
||||
context
|
||||
));
|
||||
}
|
||||
if (predicate.test(head)) {
|
||||
return ArgumentParseResult.success(true);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import cloud.commandframework.arguments.parser.ArgumentParser;
|
|||
import cloud.commandframework.captions.CaptionVariable;
|
||||
import cloud.commandframework.captions.StandardCaptionKeys;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.ParserException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -173,7 +174,10 @@ public final class BooleanArgument<C> extends CommandArgument<C, Boolean> {
|
|||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
BooleanParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
inputQueue.remove();
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import cloud.commandframework.arguments.CommandArgument;
|
|||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -189,7 +190,10 @@ public final class ByteArgument<C> extends CommandArgument<C, Byte> {
|
|||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
ByteParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
try {
|
||||
final byte value = Byte.parseByte(input);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import cloud.commandframework.arguments.parser.ArgumentParser;
|
|||
import cloud.commandframework.captions.CaptionVariable;
|
||||
import cloud.commandframework.captions.StandardCaptionKeys;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.ParserException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -129,7 +130,10 @@ public final class CharArgument<C> extends CommandArgument<C, Character> {
|
|||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
CharacterParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
|
||||
if (input.length() != 1) {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import cloud.commandframework.arguments.CommandArgument;
|
|||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -189,7 +190,10 @@ public final class DoubleArgument<C> extends CommandArgument<C, Double> {
|
|||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
DoubleParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
try {
|
||||
final double value = Double.parseDouble(input);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import cloud.commandframework.arguments.parser.ArgumentParser;
|
|||
import cloud.commandframework.captions.CaptionVariable;
|
||||
import cloud.commandframework.captions.StandardCaptionKeys;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.ParserException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -167,7 +168,10 @@ public class EnumArgument<C, E extends Enum<E>> extends CommandArgument<C, E> {
|
|||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
EnumParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
|
||||
for (final E value : this.allowedValues) {
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import cloud.commandframework.arguments.CommandArgument;
|
|||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -189,7 +190,10 @@ public final class FloatArgument<C> extends CommandArgument<C, Float> {
|
|||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
FloatParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
try {
|
||||
final float value = Float.parseFloat(input);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import cloud.commandframework.arguments.CommandArgument;
|
|||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -226,7 +227,10 @@ public final class IntegerArgument<C> extends CommandArgument<C, Integer> {
|
|||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
IntegerParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
try {
|
||||
final int value = Integer.parseInt(input);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import cloud.commandframework.arguments.CommandArgument;
|
|||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -183,7 +184,10 @@ public final class LongArgument<C> extends CommandArgument<C, Long> {
|
|||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
LongParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
try {
|
||||
final long value = Long.parseLong(input);
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import cloud.commandframework.arguments.CommandArgument;
|
|||
import cloud.commandframework.arguments.parser.ArgumentParseResult;
|
||||
import cloud.commandframework.arguments.parser.ArgumentParser;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.NumberParseException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -189,7 +190,10 @@ public final class ShortArgument<C> extends CommandArgument<C, Short> {
|
|||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
ShortParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
try {
|
||||
final short value = Short.parseShort(input);
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import cloud.commandframework.arguments.parser.ArgumentParser;
|
|||
import cloud.commandframework.captions.CaptionVariable;
|
||||
import cloud.commandframework.captions.StandardCaptionKeys;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.ParserException;
|
||||
import cloud.commandframework.util.StringUtils;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
|
@ -297,7 +298,10 @@ public final class StringArgument<C> extends CommandArgument<C, String> {
|
|||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
StringParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
|
||||
if (this.stringMode == StringMode.SINGLE) {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import cloud.commandframework.arguments.parser.ArgumentParser;
|
|||
import cloud.commandframework.captions.CaptionVariable;
|
||||
import cloud.commandframework.captions.StandardCaptionKeys;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import cloud.commandframework.exceptions.parsing.NoInputProvidedException;
|
||||
import cloud.commandframework.exceptions.parsing.ParserException;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
|
@ -128,7 +129,10 @@ public final class UUIDArgument<C> extends CommandArgument<C, UUID> {
|
|||
) {
|
||||
final String input = inputQueue.peek();
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new NullPointerException("No input was provided"));
|
||||
return ArgumentParseResult.failure(new NoInputProvidedException(
|
||||
UUIDParser.class,
|
||||
commandContext
|
||||
));
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ import java.util.function.BiFunction;
|
|||
*/
|
||||
public class SimpleCaptionRegistry<C> implements FactoryDelegatingCaptionRegistry<C> {
|
||||
|
||||
/**
|
||||
* Default caption for {@link StandardCaptionKeys#ARGUMENT_PARSE_FAILURE_NO_INPUT_PROVIDED}.
|
||||
*/
|
||||
public static final String ARGUMENT_PARSE_FAILURE_NO_INPUT_PROVIDED = "No input was provided";
|
||||
/**
|
||||
* Default caption for {@link StandardCaptionKeys#ARGUMENT_PARSE_FAILURE_BOOLEAN}.
|
||||
*/
|
||||
|
|
@ -84,6 +88,10 @@ public class SimpleCaptionRegistry<C> implements FactoryDelegatingCaptionRegistr
|
|||
private final Map<Caption, BiFunction<Caption, C, String>> messageFactories = new HashMap<>();
|
||||
|
||||
protected SimpleCaptionRegistry() {
|
||||
this.registerMessageFactory(
|
||||
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_NO_INPUT_PROVIDED,
|
||||
(caption, sender) -> ARGUMENT_PARSE_FAILURE_NO_INPUT_PROVIDED
|
||||
);
|
||||
this.registerMessageFactory(
|
||||
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_BOOLEAN,
|
||||
(caption, sender) -> ARGUMENT_PARSE_FAILURE_BOOLEAN
|
||||
|
|
|
|||
|
|
@ -36,6 +36,10 @@ public final class StandardCaptionKeys {
|
|||
|
||||
private static final Collection<Caption> RECOGNIZED_CAPTIONS = new LinkedList<>();
|
||||
|
||||
/**
|
||||
* Variables: None
|
||||
*/
|
||||
public static final Caption ARGUMENT_PARSE_FAILURE_NO_INPUT_PROVIDED = of("argument.parse.failure.no_input_was_provided");
|
||||
/**
|
||||
* Variables: {input}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2020 Alexander Söderberg & Contributors
|
||||
//
|
||||
// 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 cloud.commandframework.exceptions.parsing;
|
||||
|
||||
import cloud.commandframework.captions.StandardCaptionKeys;
|
||||
import cloud.commandframework.context.CommandContext;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
/**
|
||||
* An exception which is thrown when an argument's input is unexpectedly null or empty
|
||||
*/
|
||||
public class NoInputProvidedException extends ParserException {
|
||||
|
||||
/**
|
||||
* Construct a new NoInputProvidedException
|
||||
*
|
||||
* @param argumentParser Argument parser class
|
||||
* @param context Command context
|
||||
*/
|
||||
public NoInputProvidedException(
|
||||
final Class<?> argumentParser,
|
||||
final @NonNull CommandContext<?> context
|
||||
) {
|
||||
super(
|
||||
argumentParser,
|
||||
context,
|
||||
StandardCaptionKeys.ARGUMENT_PARSE_FAILURE_NO_INPUT_PROVIDED
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue