Skip to content

Commit 74fb78e

Browse files
authored
GH-6 Allow usage of Position without some parameters. (#6)
* Allow usage of Position without some parameters. * Use record. * Fix tests. * Remove equals method.
1 parent e40ee62 commit 74fb78e

File tree

1 file changed

+21
-33
lines changed
  • eternalcode-commons-bukkit/src/main/java/com/eternalcode/commons/shared/bukkit/position

1 file changed

+21
-33
lines changed

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

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
/**
77
* Disclaimer - Bukkit {@link org.bukkit.Location} storage may cause a memory leak, because it is a wrapper for
88
* coordinates and {@link org.bukkit.World} reference. If you need to store location use {@link Position} and
9-
* {@link PositionAdapter}.
9+
* {@link PositionAdapter} to convert it to {@link org.bukkit.Location} when needed.
1010
*/
1111
public record Position(double x, double y, double z, float yaw, float pitch, String world) {
1212

@@ -15,40 +15,12 @@ public record Position(double x, double y, double z, float yaw, float pitch, Str
1515
private static final Pattern PARSE_FORMAT = Pattern.compile(
1616
"Position\\{x=(?<x>-?[\\d.]+), y=(?<y>-?[\\d.]+), z=(?<z>-?[\\d.]+), yaw=(?<yaw>-?[\\d.]+), pitch=(?<pitch>-?[\\d.]+), world='(?<world>.+)'}");
1717

18-
public boolean isNoneWorld() {
19-
return this.world.equals(NONE_WORLD);
20-
}
21-
22-
@Override
23-
public boolean equals(Object o) {
24-
if (this == o) {
25-
return true;
26-
}
27-
28-
if (o == null || getClass() != o.getClass()) {
29-
return false;
30-
}
31-
32-
Position position = (Position) o;
33-
34-
return Double.compare(position.x, this.x) == 0
35-
&& Double.compare(position.y, this.y) == 0
36-
&& Double.compare(position.z, this.z) == 0
37-
&& Float.compare(position.yaw, this.yaw) == 0
38-
&& Float.compare(position.pitch, this.pitch) == 0
39-
&& this.world.equals(position.world);
18+
public Position(double x, double y, double z, String world) {
19+
this(x, y, z, 0F, 0F, world);
4020
}
4121

42-
@Override
43-
public String toString() {
44-
return "Position{" +
45-
"x=" + this.x +
46-
", y=" + this.y +
47-
", z=" + this.z +
48-
", yaw=" + this.yaw +
49-
", pitch=" + this.pitch +
50-
", world='" + this.world + '\'' +
51-
'}';
22+
public Position(double x, double z, String world) {
23+
this(x, 0.0, z, 0F, 0F, world);
5224
}
5325

5426
public static Position parse(String parse) {
@@ -67,4 +39,20 @@ public static Position parse(String parse) {
6739
matcher.group("world")
6840
);
6941
}
42+
43+
@Override
44+
public String toString() {
45+
return "Position{" +
46+
"x=" + this.x +
47+
", y=" + this.y +
48+
", z=" + this.z +
49+
", yaw=" + this.yaw +
50+
", pitch=" + this.pitch +
51+
", world='" + this.world + '\'' +
52+
'}';
53+
}
54+
55+
public boolean isNoneWorld() {
56+
return this.world.equals(NONE_WORLD);
57+
}
7058
}

0 commit comments

Comments
 (0)