Skip to content

Commit

Permalink
[Conditions] Fix mistake from past commits not loading true/false val…
Browse files Browse the repository at this point in the history
…ues if not wrapped in ""
  • Loading branch information
NEZNAMY committed Nov 10, 2024
1 parent 07f5dc6 commit 2f00aa7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public Object getObject(@NotNull String path, @NotNull Object defaultValue) {

@Nullable
private <T> T getNullable(@NotNull String path, @NotNull Class<T> clazz) {
return evaluateNullable(map.get(path), path, clazz);
return evaluateNullable(get(path), path, clazz);
}

@Nullable
Expand All @@ -119,7 +119,7 @@ private <T> T evaluateNullable(@Nullable Object value, @NotNull String path, @No

@NotNull
private <T> T getRequired(@NotNull String path, @NotNull T defaultValue, @NotNull Class<T> clazz) {
return evaluateRequired(map.get(path), path, defaultValue, clazz);
return evaluateRequired(get(path), path, defaultValue, clazz);
}

@NotNull
Expand All @@ -137,6 +137,14 @@ private <T> T evaluateRequired(@Nullable Object value, @NotNull String path, @No
return (T) value;
}

@Nullable
private Object get(@NotNull String key) {
for (Map.Entry<Object, Object> entry : map.entrySet()) {
if (key.equalsIgnoreCase(entry.getKey().toString())) return entry.getValue();
}
return null;
}

@NotNull
public Collection<Object> getKeys() {
return map.keySet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ public static ConditionDefinition fromSection(@NotNull ConfigurationSection sect
list = Collections.emptyList();
}
String type = section.getString("type");
String yes = section.getString("true");
Object yes = section.getObject("true");
if (yes == null) yes = "true";
String no = section.getString("false");
Object no = section.getObject("false");
if (no == null) no = "false";
if (list.size() >= 2 && type == null) {
section.startupWarn(String.format("Condition \"%s\" has multiple conditions defined, but is missing \"type\" attribute. Using AND.", name));
}
return new ConditionDefinition(list, !"OR".equals(type), yes, no);
return new ConditionDefinition(list, !"OR".equals(type), yes.toString(), no.toString());
}
}
}

0 comments on commit 2f00aa7

Please sign in to comment.