Trait fix for proper UUID serialization and functionality when NPCs appear in different order

This commit is contained in:
liec0dez 2016-12-03 22:08:16 +01:00
parent 2442e24255
commit aabc85f177

View File

@ -2,6 +2,7 @@ package net.citizensnpcs.trait;
import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import net.citizensnpcs.api.CitizensAPI;
@ -14,8 +15,9 @@ import net.citizensnpcs.util.NMS;
@TraitName("mounttrait")
public class MountTrait extends Trait {
@Persist("mountedon")
@Persist("mountedon") private String uuid;
private UUID mountedOn;
private boolean triggered = false;
public MountTrait() {
super("mounttrait");
@ -26,6 +28,7 @@ public class MountTrait extends Trait {
NPC other = CitizensAPI.getNPCRegistry().getByUniqueId(mountedOn);
if (other != null && other.isSpawned()) {
NMS.mount(other.getEntity(), npc.getEntity());
triggered = true;
}
}
}
@ -47,11 +50,16 @@ public class MountTrait extends Trait {
public void run() {
if (!npc.isSpawned())
return;
if(!triggered && uuid != null) {
mountedOn = UUID.fromString(uuid);
checkMount(null);
}
Entity e = NMS.getVehicle(npc.getEntity());
if (e == null) {
if (e == null && !triggered) {
mountedOn = null;
} else if (e instanceof NPCHolder) {
mountedOn = ((NPCHolder) e).getNPC().getUniqueId();
uuid = mountedOn.toString();
}
checkMount(e);
}