Skip to content
This repository has been archived by the owner on Apr 12, 2022. It is now read-only.

Commit

Permalink
Improve itemscript error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jun 5, 2018
1 parent 7f84d17 commit d081a5d
Showing 1 changed file with 13 additions and 16 deletions.
Expand Up @@ -83,17 +83,20 @@ public ItemScript(String name, YAMLConfiguration section) {

public final String itemScriptName;

private static final CommandQueue FORCE_TO_STATIC = new CommandQueue(); // Special case recursive static generation helper
private static final CommandQueue FORCE_TO_STATIC; // Special case recursive static generation helper

static {
(FORCE_TO_STATIC = new CommandQueue()).error = (es) -> {
throw new ErrorInducedException(es);
};
}

@Override
public boolean init() {
if (super.init()) {
try {
prepValues();
Action<String> error = (es) -> {
throw new ErrorInducedException(es);
};
if (contents.contains("static") && BooleanTag.getFor(error, contents.getString("static")).getInternal()) {
if (contents.contains("static") && BooleanTag.getFor(FORCE_TO_STATIC.error, contents.getString("static")).getInternal()) {
staticItem = getItemCopy(FORCE_TO_STATIC);
}
}
Expand Down Expand Up @@ -167,18 +170,12 @@ public void prepValues() {
}

public AbstractTagObject parseVal(CommandQueue queue, Argument arg, HashMap<String, AbstractTagObject> varBack) {
Action<String> error = (es) -> {
throw new ErrorInducedException(es);
};
return arg.parse(queue, varBack, getDebugMode(), error);
return arg.parse(queue, varBack, getDebugMode(), queue.error);
}

public ItemStack generateItem(CommandQueue queue) {
Action<String> error = (es) -> {
throw new ErrorInducedException(es);
};
HashMap<String, AbstractTagObject> varBack = new HashMap<>();
ItemTag baseMat = ItemTag.getFor(error, parseVal(queue, material, varBack), queue);
ItemTag baseMat = ItemTag.getFor(queue.error, parseVal(queue, material, varBack), queue);
varBack.put("material", baseMat);
ItemStack.Builder its = ItemStack.builder().from(baseMat.getInternal().copy()).quantity(1);
if (displayName != null) {
Expand Down Expand Up @@ -216,7 +213,7 @@ public ItemStack generateItem(CommandQueue queue) {
flagsMap.getInternal().put(flagVal.one, parseVal(queue, flagVal.two, varBack));
}
}
if (plain == null || !BooleanTag.getFor(error, parseVal(queue, plain, varBack)).getInternal()) {
if (plain == null || !BooleanTag.getFor(queue.error, parseVal(queue, plain, varBack)).getInternal()) {
flagsMap.getInternal().put("_d2_script", new ScriptTag(this));
}
ItemStack toRet = its.build();
Expand All @@ -226,14 +223,14 @@ public ItemStack generateItem(CommandQueue queue) {
if (k == null) {
throw new ErrorInducedException("Key '" + input.one + "' does not seem to exist.");
}
DataKeys.tryApply(toRet, k, parseVal(queue, input.two, varBack), error);
DataKeys.tryApply(toRet, k, parseVal(queue, input.two, varBack), queue.error);
}
}
if (!flagsMap.getInternal().isEmpty()) {
toRet.offer(new FlagMapDataImpl(new FlagMap(flagsMap)));
}
if (queue == FORCE_TO_STATIC && contents.contains("static")
&& BooleanTag.getFor(error, contents.getString("static")).getInternal()) {
&& BooleanTag.getFor(queue.error, contents.getString("static")).getInternal()) {
staticItem = toRet;
}
return toRet;
Expand Down

0 comments on commit d081a5d

Please sign in to comment.