Skip to content

Commit

Permalink
fix spawn command on unspawned NPCs
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 13, 2021
1 parent ca58558 commit 4b8237d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
Expand Up @@ -405,7 +405,6 @@ public EntityTag(NPCTag npc) {
}
if (npc != null) {
this.npc = npc;

if (npc.isSpawned()) {
this.entity = npc.getEntity();
this.entity_type = DenizenEntityType.getByName(npc.getEntityType().name());
Expand All @@ -415,7 +414,6 @@ public EntityTag(NPCTag npc) {
else {
Debug.echoError("NPC referenced is null!");
}

}

/////////////////////
Expand Down Expand Up @@ -748,9 +746,18 @@ public void spawnAt(Location location) {
getDenizenNPC().getCitizen().teleport(location, TeleportCause.PLUGIN);
}
else {
getDenizenNPC().getCitizen().spawn(location);
entity = getDenizenNPC().getCitizen().getEntity();
uuid = getDenizenNPC().getCitizen().getEntity().getUniqueId();
if (getDenizenNPC().getCitizen().spawn(location)) {
entity = getDenizenNPC().getCitizen().getEntity();
uuid = getDenizenNPC().getCitizen().getEntity().getUniqueId();
}
else {
if (new LocationTag(location).isChunkLoaded()) {
Debug.echoError("Error spawning NPC - tried to spawn in an unloaded chunk.");
}
else {
Debug.echoError("Error spawning NPC - blocked by plugin");
}
}
}
}
else if (isUnique() && entity != null) {
Expand Down Expand Up @@ -872,7 +879,12 @@ else if (face == BlockFace.SOUTH) {
Debug.echoError("Cannot spawn a null EntityTag!");
}
if (!isUnique()) {
Debug.echoError("Error spawning entity - bad entity type, blocked by another plugin, or tried to spawn in an unloaded chunk?");
if (new LocationTag(location).isChunkLoaded()) {
Debug.echoError("Error spawning entity - tried to spawn in an unloaded chunk.");
}
else {
Debug.echoError("Error spawning entity - bad entity type, blocked by another plugin?");
}
return;
}
for (Mechanism mechanism : mechanisms) {
Expand Down
Expand Up @@ -237,13 +237,13 @@ public boolean canBecome(ObjectTag inp) {
return new EntityTag(((PlayerTag) obj).getPlayerEntity());
}
else if (obj instanceof NPCTag) {
if (!((NPCTag) obj).isSpawned()) {
if (!((NPCTag) obj).isSpawned() && !EntityTag.allowDespawnedNpcs) {
if (context.showErrors()) {
Debug.echoError("NPC '" + obj.debuggable() + "' is unspawned, cannot convert to EntityTag.");
}
return null;
}
return new EntityTag(((NPCTag) obj).getEntity());
return new EntityTag((NPCTag) obj);
}
return EntityTag.valueOf(obj.toString(), context);
});
Expand Down

0 comments on commit 4b8237d

Please sign in to comment.