Removed concept of argument suffix

This commit is contained in:
Nathan Adams
2017-11-06 16:17:21 +01:00
parent c746232ffc
commit e342380600
7 changed files with 9 additions and 158 deletions
@@ -11,9 +11,4 @@ public interface ArgumentType<T> {
default <S> void listSuggestions(final String command, final Set<String> output, final CommandContextBuilder<S> contextBuilder) {
}
default String getUsageSuffix() {
return null;
}
}
@@ -6,21 +6,16 @@ import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType;
import java.util.Objects;
public class FloatArgumentType implements ArgumentType<Float> {
public static final ParameterizedCommandExceptionType ERROR_WRONG_SUFFIX = new ParameterizedCommandExceptionType("argument.float.wrongsuffix", "Expected suffix '${suffix}'", "suffix");
public static final ParameterizedCommandExceptionType ERROR_TOO_SMALL = new ParameterizedCommandExceptionType("argument.float.low", "Float must not be less than ${minimum}, found ${found}", "found", "minimum");
public static final ParameterizedCommandExceptionType ERROR_TOO_BIG = new ParameterizedCommandExceptionType("argument.float.big", "Float must not be more than ${maximum}, found ${found}", "found", "maximum");
private final float minimum;
private final float maximum;
private final String suffix;
private FloatArgumentType(final float minimum, final float maximum, final String suffix) {
private FloatArgumentType(final float minimum, final float maximum) {
this.minimum = minimum;
this.maximum = maximum;
this.suffix = suffix;
}
public static FloatArgumentType floatArg() {
@@ -32,11 +27,7 @@ public class FloatArgumentType implements ArgumentType<Float> {
}
public static FloatArgumentType floatArg(final float min, final float max) {
return floatArg(min, max, "");
}
public static FloatArgumentType floatArg(final float min, final float max, final String suffix) {
return new FloatArgumentType(min, max, suffix);
return new FloatArgumentType(min, max);
}
public static float getFloat(final CommandContext<?> context, final String name) {
@@ -47,14 +38,6 @@ public class FloatArgumentType implements ArgumentType<Float> {
public <S> Float parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
final int start = reader.getCursor();
final float result = (float) reader.readDouble();
for (int i = 0; i < suffix.length(); i++) {
if (reader.canRead() && reader.peek() == suffix.charAt(i)) {
reader.skip();
} else {
reader.setCursor(start);
throw ERROR_WRONG_SUFFIX.createWithContext(reader, suffix);
}
}
if (result < minimum) {
reader.setCursor(start);
throw ERROR_TOO_SMALL.createWithContext(reader, result, minimum);
@@ -72,7 +55,7 @@ public class FloatArgumentType implements ArgumentType<Float> {
if (!(o instanceof FloatArgumentType)) return false;
final FloatArgumentType that = (FloatArgumentType) o;
return maximum == that.maximum && minimum == that.minimum && Objects.equals(suffix, that.suffix);
return maximum == that.maximum && minimum == that.minimum;
}
@Override
@@ -90,9 +73,4 @@ public class FloatArgumentType implements ArgumentType<Float> {
return "float(" + minimum + ", " + maximum + ")";
}
}
@Override
public String getUsageSuffix() {
return suffix.length() == 0 ? null : suffix;
}
}
@@ -6,21 +6,16 @@ import com.mojang.brigadier.context.CommandContextBuilder;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.exceptions.ParameterizedCommandExceptionType;
import java.util.Objects;
public class IntegerArgumentType implements ArgumentType<Integer> {
public static final ParameterizedCommandExceptionType ERROR_WRONG_SUFFIX = new ParameterizedCommandExceptionType("argument.integer.wrongsuffix", "Expected suffix '${suffix}'", "suffix");
public static final ParameterizedCommandExceptionType ERROR_TOO_SMALL = new ParameterizedCommandExceptionType("argument.integer.low", "Integer must not be less than ${minimum}, found ${found}", "found", "minimum");
public static final ParameterizedCommandExceptionType ERROR_TOO_BIG = new ParameterizedCommandExceptionType("argument.integer.big", "Integer must not be more than ${maximum}, found ${found}", "found", "maximum");
private final int minimum;
private final int maximum;
private final String suffix;
private IntegerArgumentType(final int minimum, final int maximum, final String suffix) {
private IntegerArgumentType(final int minimum, final int maximum) {
this.minimum = minimum;
this.maximum = maximum;
this.suffix = suffix;
}
public static IntegerArgumentType integer() {
@@ -32,11 +27,7 @@ public class IntegerArgumentType implements ArgumentType<Integer> {
}
public static IntegerArgumentType integer(final int min, final int max) {
return integer(min, max, "");
}
public static IntegerArgumentType integer(final int min, final int max, final String suffix) {
return new IntegerArgumentType(min, max, suffix);
return new IntegerArgumentType(min, max);
}
public static int getInteger(final CommandContext<?> context, final String name) {
@@ -47,14 +38,6 @@ public class IntegerArgumentType implements ArgumentType<Integer> {
public <S> Integer parse(final StringReader reader, final CommandContextBuilder<S> contextBuilder) throws CommandSyntaxException {
final int start = reader.getCursor();
final int result = reader.readInt();
for (int i = 0; i < suffix.length(); i++) {
if (reader.canRead() && reader.peek() == suffix.charAt(i)) {
reader.skip();
} else {
reader.setCursor(start);
throw ERROR_WRONG_SUFFIX.createWithContext(reader, suffix);
}
}
if (result < minimum) {
reader.setCursor(start);
throw ERROR_TOO_SMALL.createWithContext(reader, result, minimum);
@@ -72,7 +55,7 @@ public class IntegerArgumentType implements ArgumentType<Integer> {
if (!(o instanceof IntegerArgumentType)) return false;
final IntegerArgumentType that = (IntegerArgumentType) o;
return maximum == that.maximum && minimum == that.minimum && Objects.equals(suffix, that.suffix);
return maximum == that.maximum && minimum == that.minimum;
}
@Override
@@ -90,9 +73,4 @@ public class IntegerArgumentType implements ArgumentType<Integer> {
return "integer(" + minimum + ", " + maximum + ")";
}
}
@Override
public String getUsageSuffix() {
return suffix.length() == 0 ? null : suffix;
}
}
@@ -43,11 +43,7 @@ public class ArgumentCommandNode<S, T> extends CommandNode<S> {
@Override
public String getUsageText() {
String usage = USAGE_ARGUMENT_OPEN + name + USAGE_ARGUMENT_CLOSE;
if (type.getUsageSuffix() != null) {
usage += type.getUsageSuffix();
}
return usage;
return USAGE_ARGUMENT_OPEN + name + USAGE_ARGUMENT_CLOSE;
}
@Override