-
-
Notifications
You must be signed in to change notification settings - Fork 294
/
CurrentLocation.java
62 lines (51 loc) · 1.53 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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.api.util.DataKey;
import net.citizensnpcs.util.NMS;
/**
* Persists the current {@link Location} of the {@link net.citizensnpcs.api.npc.NPC}. Will cache last known location if
* despawned.
*/
@TraitName("location")
public class CurrentLocation extends Trait {
@Persist
private float bodyYaw = Float.NaN;
@Persist(value = "", required = true)
private Location location = new Location(null, 0, 0, 0);
public CurrentLocation() {
super("location");
}
public float getBodyYaw() {
return bodyYaw;
}
public Location getLocation() {
return location.getWorld() == null ? null : location.clone();
}
@Override
public void load(DataKey key) {
key.removeKey("headYaw");
}
@Override
public void onSpawn() {
if (!Float.isNaN(bodyYaw)) {
NMS.setBodyYaw(npc.getEntity(), bodyYaw);
}
}
@Override
public void run() {
if (!npc.isSpawned())
return;
location = npc.getEntity().getLocation(location);
bodyYaw = NMS.getYaw(npc.getEntity());
}
public void setLocation(Location loc) {
location = loc.clone();
}
@Override
public String toString() {
return "CurrentLocation{" + location + "}";
}
}