Mwexim / skript-parser

A standalone and improved implementation of the Skript language for use outside of Minecraft servers.
MIT License
49 stars 15 forks source link

Optional List in SectionConfiguration throws NullPointerException #150

Closed TheLimeGlass closed 11 months ago

TheLimeGlass commented 1 year ago
//SkriptEvent
private final SectionConfiguration configuration = new SectionConfiguration.Builder().addOptionalList("aliases").build();
@Override
public List<Statement> loadSection(FileSection section, ParserState parserState, SkriptLogger logger) {
    configuration.loadConfiguration(null, section, parserState, logger);
    Optional.ofNullable(configuration.getStringList("aliases")).ifPresent(list -> Arrays.stream(list).forEach(aliases -> this.aliases.add(aliases)));
    return configuration.getSection("trigger").getItems();
}

Then when calling:

@Override
public List<Statement> loadSection(FileSection section, ParserState parserState, SkriptLogger logger) {
    Optional.ofNullable(configuration.getStringList("aliases"))
            .ifPresent(list -> Arrays.stream(list).forEach(aliases -> this.aliases.add(aliases)));
}
command /test:
    #aliases: no aliases node
    trigger:
        broadcast "testing"

Throws this:

[Server thread/ERROR] #!#! Caused by: java.lang.NullPointerException: Cannot invoke "Object.getClass()" because "result" is null
[Server thread/ERROR] #!#!     at io.github.syst3ms.skriptparser.lang.entries.SectionConfiguration.getValue(SectionConfiguration.java:135)
[Server thread/ERROR] #!#!     at io.github.syst3ms.skriptparser.lang.entries.SectionConfiguration.getStringList(SectionConfiguration.java:145)