forked from Maxlego08/zEssentials
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSafeLocation.java
More file actions
115 lines (92 loc) · 2.52 KB
/
Copy pathSafeLocation.java
File metadata and controls
115 lines (92 loc) · 2.52 KB
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
113
114
115
package fr.maxlego08.essentials.api.utils;
import org.bukkit.Bukkit;
import org.bukkit.Location;
public class SafeLocation {
private final String world;
private double x;
private double y;
private double z;
private float yaw;
private float pitch;
private transient Location location;
public SafeLocation(String world, double x, double y, double z, float yaw, float pitch) {
this.world = world;
this.x = x;
this.y = y;
this.z = z;
this.yaw = yaw;
this.pitch = pitch;
}
public SafeLocation(Location location) {
this(location.getWorld().getName(), location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
this.location = location;
}
public String getWorld() {
return world;
}
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
this.location = null;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
this.location = null;
}
public double getZ() {
return z;
}
public void setZ(double z) {
this.z = z;
this.location = null;
}
public float getYaw() {
return yaw;
}
public void setYaw(float yaw) {
this.yaw = yaw;
this.location = null;
}
public float getPitch() {
return pitch;
}
public void setPitch(float pitch) {
this.pitch = pitch;
this.location = null;
}
public Location getLocation() {
if (this.location == null) {
var bukkitWorld = Bukkit.getWorld(this.world);
if (bukkitWorld == null) return null;
this.location = new Location(bukkitWorld, this.x, this.y, this.z, this.yaw, this.pitch);
}
return location;
}
public boolean isValid() {
return this.world != null && Bukkit.getWorld(this.world) != null;
}
@Override
public String toString() {
return "SafeLocation{" + "world='" + world + '\'' + ", x=" + x + ", y=" + y + ", z=" + z + ", yaw=" + yaw + ", pitch=" + pitch + ", location=" + location + '}';
}
public int getBlockX() {
return (int) this.x;
}
public int getBlockY() {
return (int) this.y;
}
public int getBlockZ() {
return (int) this.z;
}
public void set(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
this.location = null;
}
}