From d8b3b1c2c047215753da2b0942498ddf048a1b7c Mon Sep 17 00:00:00 2001 From: fullwall Date: Sun, 28 Jun 2020 17:36:24 +0800 Subject: [PATCH] Add event to spawning debug --- .../main/java/net/citizensnpcs/EventListen.java | 17 +++++++++-------- .../java/net/citizensnpcs/npc/CitizensNPC.java | 12 +++++++----- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/main/src/main/java/net/citizensnpcs/EventListen.java b/main/src/main/java/net/citizensnpcs/EventListen.java index af61e30b5..2a0ee13e5 100644 --- a/main/src/main/java/net/citizensnpcs/EventListen.java +++ b/main/src/main/java/net/citizensnpcs/EventListen.java @@ -16,6 +16,7 @@ import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Minecart; import org.bukkit.entity.Player; import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; @@ -150,7 +151,7 @@ public class EventListen implements Listener { Runnable runnable = new Runnable() { @Override public void run() { - respawnAllFromCoord(new ChunkCoord(event.getChunk())); + respawnAllFromCoord(new ChunkCoord(event.getChunk()), event); } }; if (event instanceof Cancellable) { @@ -187,7 +188,7 @@ public class EventListen implements Listener { if (Messaging.isDebugging()) { Messaging.debug("Cancelled chunk unload at [" + coord.x + "," + coord.z + "]"); } - respawnAllFromCoord(coord); + respawnAllFromCoord(coord, event); return; } toRespawn.put(coord, npc); @@ -625,7 +626,7 @@ public class EventListen implements Listener { for (ChunkCoord chunk : toRespawn.keySet()) { if (!chunk.worldUUID.equals(event.getWorld().getUID()) || !event.getWorld().isChunkLoaded(chunk.x, chunk.z)) continue; - respawnAllFromCoord(chunk); + respawnAllFromCoord(chunk, event); } } @@ -638,7 +639,7 @@ public class EventListen implements Listener { if (event.isCancelled() || !despawned) { for (ChunkCoord coord : toRespawn.keySet()) { if (event.getWorld().getUID().equals(coord.worldUUID)) { - respawnAllFromCoord(coord); + respawnAllFromCoord(coord, event); } } event.setCancelled(true); @@ -651,7 +652,7 @@ public class EventListen implements Listener { } } - private void respawnAllFromCoord(ChunkCoord coord) { + private void respawnAllFromCoord(ChunkCoord coord, Event event) { List ids = toRespawn.get(coord); for (int i = 0; i < ids.size(); i++) { NPC npc = ids.get(i); @@ -672,8 +673,8 @@ public class EventListen implements Listener { boolean success = spawn(npc); if (!success) { if (Messaging.isDebugging()) { - Messaging.debug("Couldn't respawn id", npc.getId(), - "during chunk event at [" + coord.x + "," + coord.z + "]"); + Messaging.debug("Couldn't respawn id", npc.getId(), "during", event, + "at [" + coord.x + "," + coord.z + "]"); } continue; } @@ -686,7 +687,7 @@ public class EventListen implements Listener { break; } if (Messaging.isDebugging()) { - Messaging.debug("Spawned id", npc.getId(), "due to chunk event at [" + coord.x + "," + coord.z + "]"); + Messaging.debug("Spawned id", npc.getId(), "during", event, "at [" + coord.x + "," + coord.z + "]"); } } } diff --git a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java index 47d8974a2..8503d5d6f 100644 --- a/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java +++ b/main/src/main/java/net/citizensnpcs/npc/CitizensNPC.java @@ -243,8 +243,8 @@ public class CitizensNPC extends AbstractNPC { getEntity().setMetadata(NPC_METADATA_MARKER, new FixedMetadataValue(CitizensAPI.getPlugin(), true)); - boolean couldSpawn = !Util.isLoaded(at) ? false - : NMS.addEntityToWorld(getEntity(), CreatureSpawnEvent.SpawnReason.CUSTOM); + 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) { @@ -253,9 +253,11 @@ public class CitizensNPC extends AbstractNPC { skinnable.getSkinTracker().onSpawnNPC(); } } else { - Messaging.debug("Retrying spawn of", getId(), "later due to chunk being unloaded.", - Util.isLoaded(at) ? "Util.isLoaded true" : "Util.isLoaded false"); - // we need to wait for a chunk load before trying to spawn + if (Messaging.isDebugging()) { + Messaging.debug("Retrying spawn of", getId(), "later. Was loaded", loaded, "is loaded", + Util.isLoaded(at)); + } + // we need to wait before trying to spawn entityController.remove(); Bukkit.getPluginManager().callEvent(new NPCNeedsRespawnEvent(this, at)); return false;