mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-27 21:29:14 +01:00
More spawn/despawn debug
This commit is contained in:
parent
dc4fb0a33e
commit
f1917117e6
@ -92,8 +92,8 @@ public class EventListen implements Listener {
|
||||
return;
|
||||
}
|
||||
toRespawn.put(coord, npc.getId());
|
||||
Messaging.debug("Despawned id ", npc.getId(), "due to chunk unload at [" + coord.x + "," + coord.z
|
||||
+ "]");
|
||||
Messaging
|
||||
.debug("Despawned id", npc.getId(), "due to chunk unload at [" + coord.x + "," + coord.z + "]");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -268,22 +268,23 @@ public class EventListen implements Listener {
|
||||
int id = ids.get(i);
|
||||
boolean success = spawn(id);
|
||||
if (!success) {
|
||||
Messaging.debug("Couldn't respawn id " + id + " during chunk event at [" + coord.x + "," + coord.z
|
||||
+ "]");
|
||||
Messaging.debug("Couldn't respawn id", id, "during chunk event at [" + coord.x + "," + coord.z + "]");
|
||||
continue;
|
||||
}
|
||||
ids.remove(i);
|
||||
Messaging.debug("Spawned id ", id, "due to chunk event at [" + coord.x + "," + coord.z + "]");
|
||||
Messaging.debug("Spawned id", id, "due to chunk event at [" + coord.x + "," + coord.z + "]");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean spawn(int id) {
|
||||
NPC npc = npcRegistry.getById(id);
|
||||
if (npc == null)
|
||||
if (npc == null) {
|
||||
Messaging.debug("Couldn't despawn unknown NPC id", id);
|
||||
return false;
|
||||
}
|
||||
Location spawn = npc.getTrait(CurrentLocation.class).getLocation();
|
||||
if (spawn == null) {
|
||||
Messaging.debug("Couldn't find a spawn location for despawned NPC ID: " + id);
|
||||
Messaging.debug("Couldn't find a spawn location for despawned NPC id", id);
|
||||
return false;
|
||||
}
|
||||
return npc.spawn(spawn);
|
||||
|
@ -50,8 +50,10 @@ public class CitizensNPC extends AbstractNPC {
|
||||
|
||||
@Override
|
||||
public boolean despawn(DespawnReason reason) {
|
||||
if (!isSpawned())
|
||||
if (!isSpawned()) {
|
||||
Messaging.debug("Tried to despawn", getId(), "while already despawned.");
|
||||
return false;
|
||||
}
|
||||
|
||||
NPCDespawnEvent event = new NPCDespawnEvent(this, reason);
|
||||
if (reason == DespawnReason.CHUNK_UNLOAD)
|
||||
@ -59,6 +61,7 @@ public class CitizensNPC extends AbstractNPC {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
getBukkitEntity().getLocation().getChunk().load();
|
||||
Messaging.debug("Couldn't despawn", getId(), "due to despawn event cancellation. Force loaded chunk.");
|
||||
return false;
|
||||
}
|
||||
boolean keepSelected = getTrait(Spawned.class).shouldSpawn();
|
||||
@ -190,13 +193,16 @@ public class CitizensNPC extends AbstractNPC {
|
||||
@Override
|
||||
public boolean spawn(Location at) {
|
||||
Preconditions.checkNotNull(at, "location cannot be null");
|
||||
if (isSpawned())
|
||||
if (isSpawned()) {
|
||||
Messaging.debug("Tried to spawn", getId(), "while already spawned.");
|
||||
return false;
|
||||
}
|
||||
|
||||
entityController.spawn(at, this);
|
||||
EntityLiving mcEntity = getHandle();
|
||||
boolean couldSpawn = !Util.isLoaded(at) ? false : mcEntity.world.addEntity(mcEntity, SpawnReason.CUSTOM);
|
||||
if (!couldSpawn) {
|
||||
Messaging.debug("Retrying spawn of", getId(), "later due to chunk being unloaded.");
|
||||
// we need to wait for a chunk load before trying to spawn
|
||||
mcEntity = null;
|
||||
EventListen.addForRespawn(at, getId());
|
||||
@ -207,6 +213,7 @@ public class CitizensNPC extends AbstractNPC {
|
||||
Bukkit.getPluginManager().callEvent(spawnEvent);
|
||||
if (spawnEvent.isCancelled()) {
|
||||
mcEntity = null;
|
||||
Messaging.debug("Couldn't spawn", getId(), "due to event cancellation.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user