Skip to content

Commit

Permalink
catch self-referential item scripts with a better error message
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Sep 2, 2019
1 parent ca5e0fd commit af9181b
Showing 1 changed file with 10 additions and 0 deletions.
Expand Up @@ -158,9 +158,16 @@ public ItemTag getItemFrom() {
return getItemFrom(null, null);
}

boolean isProcessing = false;

public ItemTag getItemFrom(PlayerTag player, NPCTag npc) {
if (isProcessing) {
Debug.echoError("Item script contains (or chains to) a reference to itself. Cannot process.");
return null;
}
// Try to use this script to make an item.
ItemTag stack = null;
isProcessing = true;
try {
boolean debug = true;
if (contains("DEBUG")) {
Expand Down Expand Up @@ -269,6 +276,9 @@ public ItemTag getItemFrom(PlayerTag player, NPCTag npc) {
Debug.echoError(e);
stack = null;
}
finally {
isProcessing = false;
}

return stack;
}
Expand Down

0 comments on commit af9181b

Please sign in to comment.