Skip to content

Commit

Permalink
Fix load bug in body yaw
Browse files Browse the repository at this point in the history
  • Loading branch information
fullwall committed Apr 30, 2020
1 parent 521c1d3 commit 8336fe1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
10 changes: 5 additions & 5 deletions main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ public void load(final DataKey root) {
// Spawn the NPC
CurrentLocation spawnLocation = getTrait(CurrentLocation.class);
if (getTrait(Spawned.class).shouldSpawn() && spawnLocation.getLocation() != null) {
spawn(spawnLocation.getLocation(), SpawnReason.RESPAWN);
NMS.setBodyYaw(getEntity(), spawnLocation.getBodyYaw());
}
if (getTrait(Spawned.class).shouldSpawn() && spawnLocation.getLocation() == null) {
Messaging.debug("Tried to spawn", getId(), "on load but world was null");
if (spawnLocation.getLocation() != null) {
spawn(spawnLocation.getLocation(), SpawnReason.RESPAWN);
} else {
Messaging.debug("Tried to spawn", getId(), "on load but world was null");
}
}

navigator.load(root.getRelative("navigator"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void run() {
Runnable runnable = new Runnable() {
@Override
public void run() {
PermissionAttachment attachment = new PermissionAttachment(CitizensAPI.getPlugin(), player);
PermissionAttachment attachment = player.addAttachment(CitizensAPI.getPlugin());
if (temporaryPermissions.size() > 0) {
for (String permission : temporaryPermissions) {
attachment.setPermission(permission, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@TraitName("location")
public class CurrentLocation extends Trait {
@Persist
private float bodyYaw;
private float bodyYaw = Float.NaN;
@Persist(value = "", required = true)
private Location location = new Location(null, 0, 0, 0);

Expand All @@ -35,6 +35,13 @@ 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())
Expand Down

0 comments on commit 8336fe1

Please sign in to comment.