mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-26 20:55:44 +01:00
Trait fix for proper UUID serialization and functionality when NPCs appear in different order
This commit is contained in:
parent
2442e24255
commit
aabc85f177
@ -2,6 +2,7 @@ package net.citizensnpcs.trait;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
|
|
||||||
import net.citizensnpcs.api.CitizensAPI;
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
@ -14,8 +15,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 +28,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 +50,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