Clone spawn location more, minor cleanup

This commit is contained in:
fullwall 2020-11-17 10:15:52 +08:00
parent da5a611014
commit 3c2d0625b4
2 changed files with 14 additions and 17 deletions

View File

@ -1,11 +1,11 @@
package net.citizensnpcs;
import net.citizensnpcs.api.event.NPCEvent;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.Location;
import org.bukkit.event.HandlerList;
import net.citizensnpcs.api.event.NPCEvent;
import net.citizensnpcs.api.npc.NPC;
public class NPCNeedsRespawnEvent extends NPCEvent {
private final Location spawn;
@ -20,12 +20,12 @@ public class NPCNeedsRespawnEvent extends NPCEvent {
}
public Location getSpawnLocation() {
return spawn;
return spawn.clone();
}
private static final HandlerList handlers = new HandlerList();
public static HandlerList getHandlerList() {
return handlers;
}
private static final HandlerList handlers = new HandlerList();
}

View File

@ -238,7 +238,6 @@ public class CitizensNPC extends AbstractNPC {
Messaging.debug("Tried to spawn", getId(), "but the world was null. SpawnReason." + reason);
return false;
}
data().get(NPC.DEFAULT_PROTECTED_METADATA, true);
at = at.clone();
if (reason == SpawnReason.CHUNK_LOAD || reason == SpawnReason.COMMAND) {
@ -246,20 +245,12 @@ public class CitizensNPC extends AbstractNPC {
}
getOrAddTrait(CurrentLocation.class).setLocation(at);
entityController.spawn(at, this);
getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));
entityController.spawn(at.clone(), this);
boolean loaded = Util.isLoaded(at);
boolean couldSpawn = !loaded ? false : NMS.addEntityToWorld(getEntity(), CreatureSpawnEvent.SpawnReason.CUSTOM);
// send skin packets, if applicable, before other NMS packets are sent
if (couldSpawn) {
SkinnableEntity skinnable = getEntity() instanceof SkinnableEntity ? ((SkinnableEntity) getEntity()) : null;
if (skinnable != null) {
skinnable.getSkinTracker().onSpawnNPC();
}
} else {
if (!couldSpawn) {
if (Messaging.isDebugging()) {
Messaging.debug("Retrying spawn of", getId(), "later, SpawnReason." + reason + ". Was loaded", loaded,
"is loaded", Util.isLoaded(at));
@ -269,6 +260,12 @@ public class CitizensNPC extends AbstractNPC {
Bukkit.getPluginManager().callEvent(new NPCNeedsRespawnEvent(this, at));
return false;
}
getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true));
// send skin packets, if applicable, before other NMS packets are sent
SkinnableEntity skinnable = getEntity() instanceof SkinnableEntity ? ((SkinnableEntity) getEntity()) : null;
if (skinnable != null) {
skinnable.getSkinTracker().onSpawnNPC();
}
getEntity().teleport(at);
NMS.setHeadYaw(getEntity(), at.getYaw());