Skip to content

Commit

Permalink
🐛 Fixed list values return a list instead of an array
Browse files Browse the repository at this point in the history
  • Loading branch information
ItsTheSky committed Nov 16, 2021
1 parent 6a60256 commit bf848c9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'info.itsthesky'
version = '1.1.0'
version = '1.2.1'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;

@Name("Node Value")
Expand Down Expand Up @@ -51,15 +52,16 @@ public class NodeValue extends SimpleExpression<Object> {
NodeValue.class,
Object.class,
ExpressionType.COMBINED,
"[storage] [the] [(1¦default)] value[s] %string% (of|from|in) [the] [(file|shortcut)] %string% [(2¦as (array|list))]",
"[storage] [the] [(file|shortcut)] %string%'[s] [(1¦default)] value[s] %string% [(2¦as (array|list))]"
"[storage] [the] [(1¦default)] value[(3¦s)] %string% (of|from|in) [the] [(file|shortcut)] %string% [(2¦as (array|list))]",
"[storage] [the] [(file|shortcut)] %string%'[s] [(1¦default)] value[(3¦s)] %string% [(2¦as (array|list))]"
);
}

private Expression<String> exprKey;
private Expression<String> exprFile;
private boolean changeDefault;
private boolean forceList;
private boolean list;
private Node node;

@Nullable
Expand All @@ -72,6 +74,9 @@ protected Object[] get(@NotNull Event e) {
final FlatFile data = Utils.parse(path);
if (data == null)
return new Object[0];
final Object entity = data.get(key);
if (entity instanceof List)
return ((List<?>) entity).toArray(new Object[0]);
return new Object[] {data.get(key)};
}

Expand Down Expand Up @@ -133,7 +138,7 @@ public void change(@NotNull Event e, @Nullable Object[] values, Changer.@NotNull

@Override
public boolean isSingle() {
return true;
return !list;
}

@Override
Expand All @@ -152,6 +157,7 @@ public boolean init(Expression<?> @NotNull [] exprs, int matchedPattern, @NotNul
exprFile = (Expression<String>) exprs[1];
changeDefault = (parseResult.mark & 1) != 0;
forceList = (parseResult.mark & 2) != 0;
list = (parseResult.mark & 3) != 0;
node = SkriptLogger.getNode();
return true;
}
Expand Down

0 comments on commit bf848c9

Please sign in to comment.