-
Notifications
You must be signed in to change notification settings - Fork 5
/
Warp.java
112 lines (92 loc) · 2.93 KB
/
Warp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package com.blocklaunch.blwarps;
import com.blocklaunch.blwarps.data.WarpDataQueries;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.flowpowered.math.vector.Vector3d;
import org.spongepowered.api.data.DataContainer;
import org.spongepowered.api.data.DataSerializable;
import org.spongepowered.api.data.MemoryDataContainer;
/**
* Bean for representing a warp with name and location. Meant for easy
* (de)serialization with Jackson
*
*/
@JsonInclude(Include.NON_EMPTY)
public class Warp extends WarpBase implements DataSerializable {
private Vector3d position; // serialize the double x,y,z rather than the
// Vector3d
private double x;
private double y;
private double z;
// Empty constructor for Jackson
public Warp() {
}
public Warp(String owner, String name, String world, Vector3d position) {
super(owner, name, world);
this.position = position;
this.x = formatDouble(position.getX());
this.y = formatDouble(position.getY());
this.z = formatDouble(position.getZ());
}
/**
* Checks if the location of two warps are the same.
*
* @param warp Warp to compare to
* @return true if the two warps have the same location (x,y,z), false
* otherwise
*/
public boolean locationIsSame(Warp warp) {
if (this.world.equals(warp.getWorld()) && this.x == warp.getX() && this.y == warp.getY() && this.z == warp.getZ()) {
return true;
}
return false;
}
/**
* @return The Vector3d containing the warp's x, y, and z coordinates
*/
@JsonIgnore
public Vector3d getPosition() {
if (this.position == null) {
this.position = new Vector3d(this.x, this.y, this.z);
}
return this.position;
}
public double getX() {
return this.x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return this.y;
}
public void setY(double y) {
this.y = y;
}
public double getZ() {
return this.z;
}
public void setZ(double z) {
this.z = z;
}
@Override
public String toString() {
return "Warp [position=" + this.position + ", name=" + this.name + ", world=" + this.world + ", x=" + this.x + ", y=" + this.y + ", z="
+ this.z + "]";
}
@JsonIgnore
@Override
public int getContentVersion() {
return 1;
}
@JsonIgnore
@Override
public DataContainer toContainer() {
return new MemoryDataContainer().set(WarpDataQueries.NAME, getName())
.set(WarpDataQueries.WORLD, getWorld())
.set(WarpDataQueries.X, getX())
.set(WarpDataQueries.Y, getY())
.set(WarpDataQueries.Z, getZ());
}
}