Skip to content

Commit

Permalink
fix "spawn npc" showing unhelpful error
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 3, 2021
1 parent 9a3c094 commit 7ec9330
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
Expand Up @@ -25,6 +25,8 @@ public class PlayerItemTakesDamageScriptEvent extends BukkitScriptEvent implemen
//
// @Regex ^on player [^\s]+ takes damage$
//
// @Synonyms item durability changes
//
// @Group Player
//
// @Location true
Expand Down
Expand Up @@ -169,6 +169,8 @@ public static EntityTag valueOf(String string) {
return valueOf(string, null);
}

public static boolean allowDespawnedNpcs = false;

@Fetchable("e")
public static EntityTag valueOf(String string, TagContext context) {
if (string == null) {
Expand Down Expand Up @@ -215,7 +217,7 @@ public static EntityTag valueOf(String string, TagContext context) {
return new EntityTag(npc);
}
else {
if (context != null && context.showErrors()) {
if (!allowDespawnedNpcs && context != null && context.showErrors()) {
Debug.echoDebug(context.entry, "NPC '" + string + "' is not spawned, errors may follow!");
}
return new EntityTag(npc);
Expand Down
Expand Up @@ -76,7 +76,9 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
for (Argument arg : scriptEntry.getProcessedArgs()) {
if (!scriptEntry.hasObject("entities")
&& arg.matchesArgumentList(EntityTag.class)) {
EntityTag.allowDespawnedNpcs = true;
scriptEntry.addObject("entities", arg.asType(ListTag.class).filter(EntityTag.class, scriptEntry));
EntityTag.allowDespawnedNpcs = false;
}
else if (!scriptEntry.hasObject("location")
&& arg.matchesArgumentType(LocationTag.class)) {
Expand Down

0 comments on commit 7ec9330

Please sign in to comment.