mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-06 16:37:38 +01:00
Fix parsing
This commit is contained in:
parent
dff8bc61f6
commit
cfad7a4145
@ -35,7 +35,12 @@ public class ArgumentRelativeBlockPosition extends ArgumentRelativeVec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Function<String, ? extends Number> getNumberParser() {
|
Function<String, ? extends Number> getRelativeNumberParser() {
|
||||||
|
return Double::parseDouble;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Function<String, ? extends Number> getAbsoluteNumberParser() {
|
||||||
return Integer::parseInt;
|
return Integer::parseInt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,8 @@ public abstract class ArgumentRelativeVec extends Argument<RelativeVec> {
|
|||||||
this.numberCount = numberCount;
|
this.numberCount = numberCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract Function<String, ? extends Number> getNumberParser();
|
abstract Function<String, ? extends Number> getRelativeNumberParser();
|
||||||
|
abstract Function<String, ? extends Number> getAbsoluteNumberParser();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
@ -34,7 +35,7 @@ public abstract class ArgumentRelativeVec extends Argument<RelativeVec> {
|
|||||||
if (split.length != getNumberCount()) {
|
if (split.length != getNumberCount()) {
|
||||||
throw new ArgumentSyntaxException("Invalid number of values", input, INVALID_NUMBER_COUNT_ERROR);
|
throw new ArgumentSyntaxException("Invalid number of values", input, INVALID_NUMBER_COUNT_ERROR);
|
||||||
}
|
}
|
||||||
return RelativeVec.parse(split, getNumberParser());
|
return RelativeVec.parse(split, getRelativeNumberParser());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +32,12 @@ public class ArgumentRelativeVec2 extends ArgumentRelativeVec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Function<String, ? extends Number> getNumberParser() {
|
Function<String, ? extends Number> getRelativeNumberParser() {
|
||||||
return Float::parseFloat;
|
return Double::parseDouble;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Function<String, ? extends Number> getAbsoluteNumberParser() {
|
||||||
|
return Double::parseDouble;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,12 @@ public class ArgumentRelativeVec3 extends ArgumentRelativeVec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Function<String, ? extends Number> getNumberParser() {
|
Function<String, ? extends Number> getRelativeNumberParser() {
|
||||||
return Float::parseFloat;
|
return Double::parseDouble;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
Function<String, ? extends Number> getAbsoluteNumberParser() {
|
||||||
|
return Double::parseDouble;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +109,7 @@ public final class RelativeVec {
|
|||||||
return relativeZ;
|
return relativeZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RelativeVec parse(String[] input, Function<String, ? extends Number> numberParser) throws ArgumentSyntaxException {
|
public static RelativeVec parse(String[] input, Function<String, ? extends Number> relativeNumberParser, Function<String, ? extends Number> absoluteNumberParser) throws ArgumentSyntaxException {
|
||||||
// Check if the value has enough element to be correct
|
// Check if the value has enough element to be correct
|
||||||
if (input.length != 3 && input.length != 2) {
|
if (input.length != 3 && input.length != 2) {
|
||||||
throw new ArgumentSyntaxException("Invalid number of values", String.join(StringUtils.SPACE, input), INVALID_NUMBER_COUNT_ERROR);
|
throw new ArgumentSyntaxException("Invalid number of values", String.join(StringUtils.SPACE, input), INVALID_NUMBER_COUNT_ERROR);
|
||||||
@ -125,10 +125,10 @@ public final class RelativeVec {
|
|||||||
|
|
||||||
if (element.length() != RELATIVE_CHAR.length()) {
|
if (element.length() != RELATIVE_CHAR.length()) {
|
||||||
final String potentialNumber = element.substring(1);
|
final String potentialNumber = element.substring(1);
|
||||||
coordinates[i] = numberParser.apply(potentialNumber).doubleValue();
|
coordinates[i] = relativeNumberParser.apply(potentialNumber).doubleValue();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
coordinates[i] = numberParser.apply(element).doubleValue();
|
coordinates[i] = absoluteNumberParser.apply(element).doubleValue();
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new ArgumentSyntaxException("Invalid number", String.join(StringUtils.SPACE, input), INVALID_NUMBER_ERROR);
|
throw new ArgumentSyntaxException("Invalid number", String.join(StringUtils.SPACE, input), INVALID_NUMBER_ERROR);
|
||||||
|
Loading…
Reference in New Issue
Block a user