Various fixes for /tp

This commit is contained in:
William committed 2022-08-18 16:44:49 +01:00
1 parent cf6d9a6079
commit 9332371c71
3 files changed
+35 -8

No files matched your search

@@ -32,8 +32,11 @@ public class Position extends Location {
* @return The position if it could be parsed, otherwise an empty optional
*/
public static Optional<Position> parse(@NotNull Position currentPosition, @NotNull String... values) {
System.out.println(String.join(" ", values));
// Validate argument length
if (values.length < 3 || values.length > 5) {
System.out.println("Invalid syntax");
return Optional.empty();
}
@@ -59,8 +62,13 @@ public class Position extends Location {
* @throws NumberFormatException If the string could not be parsed
*/
private static double parseCoordinate(@NotNull String value, double currentValue) throws NumberFormatException {
// Future: Consider supporting ^ ^ ^ (position-relative-to-facing)
if (value.startsWith("~")) {
return currentValue + Double.parseDouble(value.substring(1));
if (value.length() == 1) {
return currentValue;
} else {
return currentValue + Double.parseDouble(value.substring(1));
}
} else {
return Double.parseDouble(value);
}