Skip to content

Commit 37c1fc8

Browse files
authored
GH-44 Fix position E identification. (#44)
1 parent 5963e2e commit 37c1fc8

File tree

2 files changed

+15
-10
lines changed
  • eternalcode-commons-bukkit

2 files changed

+15
-10
lines changed

eternalcode-commons-bukkit/src/main/java/com/eternalcode/commons/bukkit/position/Position.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@ public record Position(double x, double y, double z, float yaw, float pitch, Str
1313
public static final String NONE_WORLD = "__NONE__";
1414

1515
private static final Pattern PARSE_FORMAT = Pattern.compile(
16-
"Position\\{x=(?<x>-?[\\d.]+), y=(?<y>-?[\\d.]+), z=(?<z>-?[\\d.]+), yaw=(?<yaw>-?[\\d.]+), pitch=(?<pitch>-?[\\d.]+), world='(?<world>.+)'}");
17-
16+
"Position\\{x=(?<x>-?[\\d.]+(?:[eE][-+]?\\d+)?), " +
17+
"y=(?<y>-?[\\d.]+(?:[eE][-+]?\\d+)?), " +
18+
"z=(?<z>-?[\\d.]+(?:[eE][-+]?\\d+)?), " +
19+
"yaw=(?<yaw>-?[\\d.]+(?:[eE][-+]?\\d+)?), " +
20+
"pitch=(?<pitch>-?[\\d.]+(?:[eE][-+]?\\d+)?), " +
21+
"world='(?<world>.+)'}");
22+
1823
public Position(double x, double y, double z, String world) {
1924
this(x, y, z, 0F, 0F, world);
2025
}

eternalcode-commons-bukkit/test/com/eternalcode/commons/bukkit/position/PositionTest.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class PositionTest {
1111

1212
@BeforeEach
1313
void setUp() {
14-
position = new Position(1.0d, 2.0d, 3.0d, 4.0f, 5.0f, "world");
14+
position = new Position(1.0d, 2.0d, 3.0d, 90.49303f, -6.020069E-6f, "world");
1515
}
1616

1717
@Test
@@ -36,12 +36,12 @@ void getZ() {
3636

3737
@Test
3838
void getYaw() {
39-
assertEquals(4.0f, position.yaw());
39+
assertEquals(90.49303f, position.yaw());
4040
}
4141

4242
@Test
4343
void getPitch() {
44-
assertEquals(5.0f, position.pitch());
44+
assertEquals(-6.020069E-6f, position.pitch());
4545
}
4646

4747
@Test
@@ -51,8 +51,8 @@ void isNoneWorld() {
5151

5252
@Test
5353
void testEqualsAndHashCode() {
54-
Position position2 = new Position(1.0d, 2.0d, 3.0d, 4.0f, 5.0f, "world");
55-
Position position3 = new Position(1.0d, 2.0d, 3.1d, 4.0f, 5.0f, "world");
54+
Position position2 = new Position(1.0d, 2.0d, 3.0d, 90.49303f, -6.020069E-6f, "world");
55+
Position position3 = new Position(1.0d, 2.0d, 3.1d, 90.49303f, -6.020069E-6f, "world");
5656

5757
// Reflexive test
5858
assertEquals(position, position);
@@ -71,18 +71,18 @@ void testEqualsAndHashCode() {
7171

7272
@Test
7373
void testToString() {
74-
String expectedString = "Position{x=1.0, y=2.0, z=3.0, yaw=4.0, pitch=5.0, world='world'}";
74+
String expectedString = "Position{x=1.0, y=2.0, z=3.0, yaw=90.49303, pitch=-6.020069E-6, world='world'}";
7575
assertEquals(expectedString, position.toString());
7676
}
7777

7878
@Test
7979
void parse() {
80-
Position parsed = Position.parse("Position{x=1.0, y=2.0, z=3.0, yaw=4.0, pitch=5.0, world='world'}");
80+
Position parsed = Position.parse("Position{x=1.0, y=2.0, z=3.0, yaw=90.49303, pitch=-6.020069E-6, world='world'}");
8181
assertEquals(position, parsed);
8282
}
8383

8484
@Test
8585
void parseInvalid() {
86-
assertThrows(IllegalArgumentException.class, () -> Position.parse("Invalid{x=1.0, y=2.0, z=3.0, yaw=4.0, pitch=5.0, world='world'}"));
86+
assertThrows(IllegalArgumentException.class, () -> Position.parse("Invalid{x=1.0, y=2.0, z=3.0, yaw=90.49303, pitch=-6.020069E-6, world='world'}"));
8787
}
8888
}

0 commit comments

Comments
 (0)