Skip to content

Commit 37d4325

Browse files
committed
Move command - fix floats in difference values (Ex.: ~0.1)
1 parent b15fda0 commit 37d4325

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/main/java/eu/decentsoftware/holograms/plugin/Validator.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.bukkit.command.CommandSender;
1616
import org.bukkit.entity.Player;
1717
import org.bukkit.inventory.ItemStack;
18+
import org.jetbrains.annotations.NotNull;
1819

1920
import java.util.Arrays;
2021

@@ -292,14 +293,18 @@ public static double getDouble(String string) {
292293
return 0;
293294
}
294295

295-
public static double getLocationValue(String string, double initialValue) {
296-
if (isDouble(string)) {
297-
return getDouble(string);
298-
} else if (string.matches("~-?[0-9]+")) {
299-
double diff = getDouble(string.substring(1));
300-
return initialValue + diff;
296+
public static double getLocationValue(@NotNull String string, double initialValue) {
297+
boolean isDiff = false;
298+
if (string.startsWith("~")) {
299+
isDiff = true;
300+
string = string.substring(1);
301301
}
302-
return initialValue;
302+
303+
double number = getDouble(string);
304+
if (isDiff) {
305+
return initialValue + number;
306+
}
307+
return number;
303308
}
304309

305310
}

0 commit comments

Comments
 (0)