mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-20 07:02:32 +01:00
Fix checks
This commit is contained in:
parent
86be5ad9c5
commit
0f569d85f0
@ -22,7 +22,11 @@ public class ArgumentRelativeVec2 extends ArgumentRelative<RelativeVec> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public RelativeVec parse(@NotNull String input) throws ArgumentSyntaxException {
|
public RelativeVec parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||||
return RelativeVec.parse(input);
|
final String[] split = input.split(StringUtils.SPACE);
|
||||||
|
if (split.length != 2) {
|
||||||
|
throw new ArgumentSyntaxException("Invalid number of values", input, INVALID_NUMBER_COUNT_ERROR);
|
||||||
|
}
|
||||||
|
return RelativeVec.parse(split);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,7 +22,11 @@ public class ArgumentRelativeVec3 extends ArgumentRelative<RelativeVec> {
|
|||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public RelativeVec parse(@NotNull String input) throws ArgumentSyntaxException {
|
public RelativeVec parse(@NotNull String input) throws ArgumentSyntaxException {
|
||||||
return RelativeVec.parse(input);
|
final String[] split = input.split(StringUtils.SPACE);
|
||||||
|
if (split.length != 3) {
|
||||||
|
throw new ArgumentSyntaxException("Invalid number of values", input, INVALID_NUMBER_COUNT_ERROR);
|
||||||
|
}
|
||||||
|
return RelativeVec.parse(split);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -108,17 +108,16 @@ public final class RelativeVec {
|
|||||||
return relativeZ;
|
return relativeZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static RelativeVec parse(String input) throws ArgumentSyntaxException {
|
public static RelativeVec parse(String[] input) throws ArgumentSyntaxException {
|
||||||
final String[] split = input.split(StringUtils.SPACE);
|
|
||||||
// Check if the value has enough element to be correct
|
// Check if the value has enough element to be correct
|
||||||
if (split.length != 3 && split.length != 2) {
|
if (input.length != 3 && input.length != 2) {
|
||||||
throw new ArgumentSyntaxException("Invalid number of values", input, INVALID_NUMBER_COUNT_ERROR);
|
throw new ArgumentSyntaxException("Invalid number of values", String.join(StringUtils.SPACE, input), INVALID_NUMBER_COUNT_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
double[] coordinates = new double[split.length];
|
double[] coordinates = new double[input.length];
|
||||||
boolean[] isRelative = new boolean[split.length];
|
boolean[] isRelative = new boolean[input.length];
|
||||||
for (int i = 0; i < split.length; i++) {
|
for (int i = 0; i < input.length; i++) {
|
||||||
final String element = split[i];
|
final String element = input[i];
|
||||||
try {
|
try {
|
||||||
if (element.startsWith(RELATIVE_CHAR)) {
|
if (element.startsWith(RELATIVE_CHAR)) {
|
||||||
isRelative[i] = true;
|
isRelative[i] = true;
|
||||||
@ -131,11 +130,11 @@ public final class RelativeVec {
|
|||||||
coordinates[i] = Float.parseFloat(element);
|
coordinates[i] = Float.parseFloat(element);
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new ArgumentSyntaxException("Invalid number", input, INVALID_NUMBER_ERROR);
|
throw new ArgumentSyntaxException("Invalid number", String.join(StringUtils.SPACE, input), INVALID_NUMBER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new RelativeVec(split.length == 3 ? new Vec(coordinates[0], coordinates[1], coordinates[2]) : new Vec(coordinates[0], coordinates[1]),
|
return new RelativeVec(input.length == 3 ? new Vec(coordinates[0], coordinates[1], coordinates[2]) : new Vec(coordinates[0], coordinates[1]),
|
||||||
isRelative[0], split.length == 3 && isRelative[1], isRelative[split.length == 3 ? 2 : 1]);
|
isRelative[0], input.length == 3 && isRelative[1], isRelative[input.length == 3 ? 2 : 1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user