Skip to content

Commit

Permalink
Add nested action tracking
Browse files Browse the repository at this point in the history
Signed-off-by: TheSilkMiner <thesilkminer@outlook.com>
  • Loading branch information
TheSilkMiner authored and jaredlll08 committed Oct 11, 2022
1 parent f265a79 commit 7c98660
Showing 1 changed file with 18 additions and 3 deletions.
Expand Up @@ -44,11 +44,13 @@ public final class ScriptRunManager implements IScriptRunManager {
});

private final Map<IScriptLoader, RunInfoQueue> previousRunQueues;
private final ThreadLocal<Integer> nestingLevel;
private RunInfo currentRunInfo;

private ScriptRunManager() {

this.previousRunQueues = new HashMap<>();
this.nestingLevel = ThreadLocal.withInitial(() -> 0);
this.currentRunInfo = null;
}

Expand Down Expand Up @@ -186,15 +188,28 @@ private void applyActionInRun(final IAction action) {
return;
}

CraftTweakerAPI.LOGGER.info(this.makeDescription(action));
action.apply();
info.enqueueAction(action, true);
final int nestLevel = this.nestingLevel.get();
try {

this.nestingLevel.set(nestLevel + 1);
CraftTweakerAPI.LOGGER.info(this.makeNestedDescription(action, nestLevel));
action.apply();
info.enqueueAction(action, true);
} finally {

this.nestingLevel.set(nestLevel);
}

} catch(final Exception e) {
CraftTweakerAPI.LOGGER.error("Unable to run action due to an error", e);
}
}

private String makeNestedDescription(final IAction action, final int nestLevel) {

return "-".repeat(nestLevel) + (nestLevel > 0 ? " " : "") + this.makeDescription(action);
}

private String makeDescription(final IAction action) {

final String description = action.describe();
Expand Down

0 comments on commit 7c98660

Please sign in to comment.