Solved java.io.File cannot be cast to org.bukkit.configuration.ConfigurationSection

Discussion in 'Spigot Plugin Development' started by Kaneki1337, Jun 25, 2018.

  1. I'm trying to get a yml file from inside of a config.yml file.


    Here's the code.

    Code (Java):
                        Configuration cfg = (Configuration) new File(getDataFolder(), (String)(getConfig().get("supplyDrop.config.defaultYML")));
                        @SuppressWarnings("unchecked")
                        List<ItemStack> list = (List<ItemStack>) cfg.getList("inventory.content");
    Here's the error.

    Code (Text):
    [00:07:08 WARN]: [PyrexMain] Task #21 for PyrexMain v1.0.0 generated an exception
    java.lang.IllegalArgumentException: Name cannot be null
            at org.apache.commons.lang.Validate.notNull(Validate.java:192) ~[spigot.jar:git-PaperSpigot-"8b18730"]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.getWorld(CraftServer.java:1042) ~[spigot.jar:git-PaperSpigot-"8b18730"]
            at org.bukkit.Bukkit.getWorld(Bukkit.java:517) ~[spigot.jar:git-PaperSpigot-"8b18730"]
            at com.faridkamizi.Package.SupplyDrop$1.run(SupplyDrop.java:47) ~[?:?]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:59) ~[spigot.jar:git-PaperSpigot-"8b18730"]
            at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:349) [spigot.jar:git-PaperSpigot-"8b18730"]
            at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:783) [spigot.jar:git-PaperSpigot-"8b18730"]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:378) [spigot.jar:git-PaperSpigot-"8b18730"]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:713) [spigot.jar:git-PaperSpigot-"8b18730"]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:616) [spigot.jar:git-PaperSpigot-"8b18730"]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_162]
     
  2. You need this:
    Code (Java):
    YamlConfiguration Config = YamlConfiguration.loadConfiguration(file);
     
     
    • Like Like x 1