Solved how to get an array from config.yml

Discussion in 'Plugin Development' started by Quantico, Nov 20, 2021.

  1. Offline

    Quantico

    Hello.
    It has the following config.yml file:

    Code:
    emerald:
    '1':
    - 695
    - 64
    - 278
    '2':
    - 695
    - 64
    - 279
    iron:
    '1':
    - 694
    - 64
    - 279
    coal:
    '1':
    - 694
    - 64
    - 281
    I check every emerald block that exists in config.yml
    For example, emerald 1 should turn out to be [695, 64, 278]. And so check all the emerald blocks.

    Maybe I'm writing the data in config.yml incorrectly

    My code:
    Code:
    List<String> values = new ArrayList<String>();
    for (String x : getConfig().getConfigurationSection("emerald").getKeys(false))
                {
                    for(String y: getConfig().getConfigurationSection("emerald."+x).getKeys(false))
                    {
                        values.add(y);
                    }
                }
    but, I get an errore:
    Code:
    [22:43:45] [Server thread/ERROR]: Could not pass event BlockBreakEvent to Shaft v1.0
    org.bukkit.event.EventException: null
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:306) ~[server.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[server.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [server.jar:git-Spigot-dcd1643-e60fc34]
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) [server.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerInteractManager.breakBlock(PlayerInteractManager.java:290) [server.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerInteractManager.a(PlayerInteractManager.java:123) [server.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:877) [server.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PacketPlayInBlockDig.a(SourceFile:40) [server.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PacketPlayInBlockDig.a(SourceFile:10) [server.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13) [server.jar:git-Spigot-dcd1643-e60fc34]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
        at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
        at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46) [server.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748) [server.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406) [server.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679) [server.jar:git-Spigot-dcd1643-e60fc34]
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577) [server.jar:git-Spigot-dcd1643-e60fc34]
        at java.lang.Thread.run(Thread.java:831) [?:?]
    Caused by: java.lang.NullPointerException: Cannot invoke "org.bukkit.configuration.ConfigurationSection.getKeys(boolean)" because the return value of "org.bukkit.configuration.file.FileConfiguration.getConfigurationSection(String)" is null
        at net.quantico.shaft.Main.onBlockBreak(Main.java:112) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?]
        at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[?:?]
        at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?]
        at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?]
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:302) ~[server.jar:git-Spigot-dcd1643-e60fc34]
        ... 17 more
    Thank you in advance for your help.
    I appreciate your time.
     
  2. Offline

    pixelrider2000

    You can directly derive a list from a config file of type String or Integer by using 'config.getStringList(PATH)' or 'config.getIntegerList(PATH)'.
     
    Lan3 and Quantico like this.

Share This Page