-
-
Notifications
You must be signed in to change notification settings - Fork 307
/
CurrentLocation.java
48 lines (39 loc) · 1.21 KB
/
CurrentLocation.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
package net.citizensnpcs.trait;
import org.bukkit.Location;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.util.NMS;
/**
* Persists the current {@link Location} of the {@link NPC}. Will cache last known location if despawned.
*/
@TraitName("location")
public class CurrentLocation extends Trait {
@Persist
private float headYaw;
@Persist(value = "", required = true)
private Location location = new Location(null, 0, 0, 0);
public CurrentLocation() {
super("location");
}
public float getHeadYaw() {
return headYaw;
}
public Location getLocation() {
return location.getWorld() == null ? null : location;
}
@Override
public void run() {
if (!npc.isSpawned())
return;
location = npc.getEntity().getLocation(location);
headYaw = NMS.getHeadYaw(npc.getEntity());
}
public void setLocation(Location loc) {
this.location = loc.clone();
}
@Override
public String toString() {
return "CurrentLocation{" + location + "}";
}
}