mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2025-02-04 14:31:19 +01:00
Add extra spawning debug
This commit is contained in:
parent
13dee3570f
commit
12b796afa3
@ -152,7 +152,9 @@ public class EventListen implements Listener {
|
|||||||
Runnable runnable = new Runnable() {
|
Runnable runnable = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
respawnAllFromCoord(new ChunkCoord(event.getChunk()), event);
|
ChunkCoord coord = new ChunkCoord(event.getChunk());
|
||||||
|
Messaging.debug("Respawning all NPCs at", coord, "due to chunk load");
|
||||||
|
respawnAllFromCoord(coord, event);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if (event instanceof Cancellable) {
|
if (event instanceof Cancellable) {
|
||||||
@ -186,16 +188,13 @@ public class EventListen implements Listener {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
((Cancellable) event).setCancelled(true);
|
((Cancellable) event).setCancelled(true);
|
||||||
if (Messaging.isDebugging()) {
|
Messaging.debug("Cancelled chunk unload at", coord);
|
||||||
Messaging.debug("Cancelled chunk unload at [" + coord.x + "," + coord.z + "]");
|
|
||||||
}
|
|
||||||
respawnAllFromCoord(coord, event);
|
respawnAllFromCoord(coord, event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
toRespawn.put(coord, npc);
|
toRespawn.put(coord, npc);
|
||||||
if (Messaging.isDebugging()) {
|
if (Messaging.isDebugging()) {
|
||||||
Messaging.debug("Despawned id", npc.getId(),
|
Messaging.debug("Despawned id", npc.getId(), "due to chunk unload at", coord);
|
||||||
"due to chunk unload at [" + coord.x + "," + coord.z + "]");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (loadChunk) {
|
if (loadChunk) {
|
||||||
@ -414,10 +413,11 @@ public class EventListen implements Listener {
|
|||||||
public void onNPCDespawn(NPCDespawnEvent event) {
|
public void onNPCDespawn(NPCDespawnEvent event) {
|
||||||
if (event.getReason() == DespawnReason.PLUGIN || event.getReason() == DespawnReason.REMOVAL
|
if (event.getReason() == DespawnReason.PLUGIN || event.getReason() == DespawnReason.REMOVAL
|
||||||
|| event.getReason() == DespawnReason.RELOAD) {
|
|| event.getReason() == DespawnReason.RELOAD) {
|
||||||
Messaging.debug("Preventing further respawns of " + event.getNPC().getId() + " due to DespawnReason."
|
|
||||||
+ event.getReason().name());
|
|
||||||
if (event.getNPC().getStoredLocation() != null) {
|
if (event.getNPC().getStoredLocation() != null) {
|
||||||
toRespawn.remove(new ChunkCoord(event.getNPC().getStoredLocation()), event.getNPC());
|
ChunkCoord coord = new ChunkCoord(event.getNPC().getStoredLocation());
|
||||||
|
Messaging.debug("Preventing further respawns of " + event.getNPC().getId() + " at [" + coord.x + ","
|
||||||
|
+ coord.z + "] due to DespawnReason." + event.getReason());
|
||||||
|
toRespawn.remove(coord, event.getNPC());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Messaging.debug("Removing " + event.getNPC().getId() + " from skin tracker due to DespawnReason."
|
Messaging.debug("Removing " + event.getNPC().getId() + " from skin tracker due to DespawnReason."
|
||||||
@ -639,6 +639,9 @@ public class EventListen implements Listener {
|
|||||||
for (ChunkCoord chunk : toRespawn.keySet()) {
|
for (ChunkCoord chunk : toRespawn.keySet()) {
|
||||||
if (!chunk.worldUUID.equals(event.getWorld().getUID()) || !event.getWorld().isChunkLoaded(chunk.x, chunk.z))
|
if (!chunk.worldUUID.equals(event.getWorld().getUID()) || !event.getWorld().isChunkLoaded(chunk.x, chunk.z))
|
||||||
continue;
|
continue;
|
||||||
|
if (Messaging.isDebugging()) {
|
||||||
|
Messaging.debug("Respawning all NPCs at", chunk, "due to world load");
|
||||||
|
}
|
||||||
respawnAllFromCoord(chunk, event);
|
respawnAllFromCoord(chunk, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -652,6 +655,9 @@ public class EventListen implements Listener {
|
|||||||
if (event.isCancelled() || !despawned) {
|
if (event.isCancelled() || !despawned) {
|
||||||
for (ChunkCoord coord : toRespawn.keySet()) {
|
for (ChunkCoord coord : toRespawn.keySet()) {
|
||||||
if (event.getWorld().getUID().equals(coord.worldUUID)) {
|
if (event.getWorld().getUID().equals(coord.worldUUID)) {
|
||||||
|
if (Messaging.isDebugging()) {
|
||||||
|
Messaging.debug("Respawning all NPCs at", coord, "due to cancelled world unload");
|
||||||
|
}
|
||||||
respawnAllFromCoord(coord, event);
|
respawnAllFromCoord(coord, event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -679,15 +685,14 @@ public class EventListen implements Listener {
|
|||||||
if (npc.isSpawned()) {
|
if (npc.isSpawned()) {
|
||||||
ids.remove(i--);
|
ids.remove(i--);
|
||||||
if (Messaging.isDebugging()) {
|
if (Messaging.isDebugging()) {
|
||||||
Messaging.debug("NPC", npc.getId(), "already spawned");
|
Messaging.debug("Can't respawn NPC", npc.getId(), ": already spawned");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
boolean success = spawn(npc);
|
boolean success = spawn(npc);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
if (Messaging.isDebugging()) {
|
if (Messaging.isDebugging()) {
|
||||||
Messaging.debug("Couldn't respawn id", npc.getId(), "during", event,
|
Messaging.debug("Couldn't respawn id", npc.getId(), "during", event, "at", coord);
|
||||||
"at [" + coord.x + "," + coord.z + "]");
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -696,11 +701,11 @@ public class EventListen implements Listener {
|
|||||||
} catch (IndexOutOfBoundsException ex) {
|
} catch (IndexOutOfBoundsException ex) {
|
||||||
// something caused toRespawn to get modified?
|
// something caused toRespawn to get modified?
|
||||||
Messaging.debug("Some strange chunk loading happened while spawning", npc.getId(),
|
Messaging.debug("Some strange chunk loading happened while spawning", npc.getId(),
|
||||||
" - check all your NPCs in chunk [" + coord.x + "," + coord.z + "] are spawned");
|
" - check all your NPCs in chunk", coord, "are spawned");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (Messaging.isDebugging()) {
|
if (Messaging.isDebugging()) {
|
||||||
Messaging.debug("Spawned id", npc.getId(), "during", event, "at [" + coord.x + "," + coord.z + "]");
|
Messaging.debug("Spawned id", npc.getId(), "during", event, "at", coord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
@Override
|
@Override
|
||||||
public boolean despawn(DespawnReason reason) {
|
public boolean despawn(DespawnReason reason) {
|
||||||
if (!isSpawned() && reason != DespawnReason.DEATH) {
|
if (!isSpawned() && reason != DespawnReason.DEATH) {
|
||||||
Messaging.debug("Tried to despawn", getId(), "while already despawned.");
|
Messaging.debug("Tried to despawn", getId(), "while already despawned, DespawnReason." + reason);
|
||||||
if (reason == DespawnReason.REMOVAL) {
|
if (reason == DespawnReason.REMOVAL) {
|
||||||
Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this, reason));
|
Bukkit.getPluginManager().callEvent(new NPCDespawnEvent(this, reason));
|
||||||
}
|
}
|
||||||
@ -82,7 +82,7 @@ public class CitizensNPC extends AbstractNPC {
|
|||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
if (event.isCancelled() && reason != DespawnReason.DEATH) {
|
if (event.isCancelled() && reason != DespawnReason.DEATH) {
|
||||||
Messaging.debug("Couldn't despawn", getId(), "due to despawn event cancellation. Will load chunk.",
|
Messaging.debug("Couldn't despawn", getId(), "due to despawn event cancellation. Will load chunk.",
|
||||||
getEntity().isValid());
|
getEntity().isValid(), ", DespawnReason." + reason);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
boolean keepSelected = getOrAddTrait(Spawned.class).shouldSpawn();
|
boolean keepSelected = getOrAddTrait(Spawned.class).shouldSpawn();
|
||||||
|
@ -65,5 +65,10 @@ public class ChunkCoord {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "[" + x + "," + z + "]";
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean SUPPORTS_FORCE_LOADED = true;
|
private static boolean SUPPORTS_FORCE_LOADED = true;
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user