Skip to content

Commit

Permalink
Fix parse expression not working with optional parts (#1222)
Browse files Browse the repository at this point in the history
  • Loading branch information
bensku committed Jan 19, 2019
1 parent 883d524 commit 5e3fa5f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/java/ch/njol/skript/ScriptLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public static ScriptInfo loadScripts(final List<Config> configs) {
else
Skript.debug("Commands changed but not synced to clients (normal on 1.12 and older)");
} else {
Skript.debug("Commands unchanged not syncing them to clients");
Skript.debug("Commands unchanged, not syncing them to clients");
}

// If task was ran asynchronously, returned stats may be wrong
Expand Down
17 changes: 13 additions & 4 deletions src/main/java/ch/njol/skript/expressions/ExprParse.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,19 @@ protected Object[] get(final Event e) {
assert pattern != null && plurals != null;
final ParseResult r = SkriptParser.parse(t, pattern);
if (r != null) {
assert plurals.length == r.exprs.length;
final Object[] os = new Object[r.exprs.length];
for (int i = 0; i < os.length; i++)
os[i] = plurals[i] ? r.exprs[i].getArray(null) : r.exprs[i].getSingle(null);
assert plurals.length == r.exprs.length;
int resultCount = 0;
for (int i = 0; i < r.exprs.length; i++) {
if (r.exprs[i] != null) // Ignore missing optional parts
resultCount++;
}

Object[] os = new Object[resultCount];
for (int i = 0, slot = 0; i < r.exprs.length; i++) {
if (r.exprs[i] != null)
os[slot++] = plurals[i] ? r.exprs[i].getArray(null) : r.exprs[i].getSingle(null);
}

return os;
}
}
Expand Down

0 comments on commit 5e3fa5f

Please sign in to comment.