Fix load bug in body yaw

This commit is contained in:
fullwall 2020-04-30 23:11:45 +08:00
parent 521c1d3fda
commit 8336fe1b7c
3 changed files with 14 additions and 7 deletions

View File

@ -157,11 +157,11 @@ public class CitizensNPC extends AbstractNPC {
// 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"));

View File

@ -106,7 +106,7 @@ public class CommandTrait extends Trait {
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);

View File

@ -14,7 +14,7 @@ import net.citizensnpcs.util.NMS;
@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);
@ -35,6 +35,13 @@ public class CurrentLocation extends Trait {
key.removeKey("headYaw");
}
@Override
public void onSpawn() {
if (!Float.isNaN(bodyYaw)) {
NMS.setBodyYaw(npc.getEntity(), bodyYaw);
}
}
@Override
public void run() {
if (!npc.isSpawned())