Skip to content

Commit

Permalink
Updated ContentsParser with new setList method
Browse files Browse the repository at this point in the history
  • Loading branch information
fulminazzo committed Apr 11, 2024
1 parent 5873d15 commit 1a40150
Showing 1 changed file with 3 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.LinkedList;
import java.util.List;

public class ContentsParser extends YAMLParser<GUIImpl.Contents> {
Expand All @@ -23,16 +22,8 @@ public ContentsParser() {
return (c, s) -> {
ConfigurationSection section = c.getConfigurationSection(s);
if (section == null) return null;
List<GUIContent> contents = new LinkedList<>();
for (String key : section.getKeys())
try {
int i = Integer.parseInt(key);
if (i < 0) throw new NumberFormatException();
while (contents.size() - 1 < i) contents.add(null);
contents.set(i, section.get(String.valueOf(i), GUIContent.class));
} catch (NumberFormatException e) {
throw new IllegalArgumentException(String.format("Invalid key '%s'", key));
}
List<GUIContent> contents = c.getList(s, GUIContent.class);
if (contents == null) return null;
return new GUIImpl.Contents(contents.toArray(new GUIContent[0]));
};
}
Expand All @@ -42,10 +33,7 @@ public ContentsParser() {
return (c, s, g) -> {
c.set(s, null);
if (g == null) return;
ConfigurationSection section = c.createSection(s);
List<GUIContent> contents = g.getContents();
for (int i = 0; i < contents.size(); i++)
section.set(String.valueOf(i), contents.get(i));
c.setList(s, g.getContents());
};
}
}

0 comments on commit 1a40150

Please sign in to comment.