mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-17 04:41:31 +01:00
Merge pull request #1001 from liec0dez/mounttrait-persistent-uuid
MountTrait serialization fix
This commit is contained in:
commit
ad00d4049c
@ -14,8 +14,9 @@ import net.citizensnpcs.util.NMS;
|
|||||||
|
|
||||||
@TraitName("mounttrait")
|
@TraitName("mounttrait")
|
||||||
public class MountTrait extends Trait {
|
public class MountTrait extends Trait {
|
||||||
@Persist("mountedon")
|
@Persist("mountedon") private String uuid;
|
||||||
private UUID mountedOn;
|
private UUID mountedOn;
|
||||||
|
private boolean triggered = false;
|
||||||
|
|
||||||
public MountTrait() {
|
public MountTrait() {
|
||||||
super("mounttrait");
|
super("mounttrait");
|
||||||
@ -26,6 +27,7 @@ public class MountTrait extends Trait {
|
|||||||
NPC other = CitizensAPI.getNPCRegistry().getByUniqueId(mountedOn);
|
NPC other = CitizensAPI.getNPCRegistry().getByUniqueId(mountedOn);
|
||||||
if (other != null && other.isSpawned()) {
|
if (other != null && other.isSpawned()) {
|
||||||
NMS.mount(other.getEntity(), npc.getEntity());
|
NMS.mount(other.getEntity(), npc.getEntity());
|
||||||
|
triggered = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -47,11 +49,16 @@ public class MountTrait extends Trait {
|
|||||||
public void run() {
|
public void run() {
|
||||||
if (!npc.isSpawned())
|
if (!npc.isSpawned())
|
||||||
return;
|
return;
|
||||||
|
if(!triggered && uuid != null) {
|
||||||
|
mountedOn = UUID.fromString(uuid);
|
||||||
|
checkMount(null);
|
||||||
|
}
|
||||||
Entity e = NMS.getVehicle(npc.getEntity());
|
Entity e = NMS.getVehicle(npc.getEntity());
|
||||||
if (e == null) {
|
if (e == null && !triggered) {
|
||||||
mountedOn = null;
|
mountedOn = null;
|
||||||
} else if (e instanceof NPCHolder) {
|
} else if (e instanceof NPCHolder) {
|
||||||
mountedOn = ((NPCHolder) e).getNPC().getUniqueId();
|
mountedOn = ((NPCHolder) e).getNPC().getUniqueId();
|
||||||
|
uuid = mountedOn.toString();
|
||||||
}
|
}
|
||||||
checkMount(e);
|
checkMount(e);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user