Solved how to get default custom config

Discussion in 'Spigot Plugin Development' started by Peaches_MLG, Jul 10, 2018.

  1. so i made a custom config and put the config.yml inside my .jar, and i was wondering how to get the default config.yml so i can then compare the current one and add any changes needed
  2. "this.getConfig()"?
    EDIT: "this" if it's in the main class.
  3. ok, first of all that will get the current configuration I want the default configuration.

    Second of all, I am using a custom config (CustomEnchants.yml) and need to get the default one of that.
  4. Code (Java):
    InputStream customClassStream= (plugin main).getClass().getResourceAsStream("/CustomEnchants.yml");
    InputStreamReader strR = new InputStreamReader(customClassStream);
    FileConfiguration defaults = YamlConfiguration.loadConfiguration(strR);
    Just look at this for example implementation:
    • Winner Winner x 2
  5. I tried using that code, however it gives this error:

    Code (Text):
    [13:38:10 ERROR]: Error occurred while enabling CustomEnchants v18.9 (Is it up to date?)
            at<init>(Unknown Source) ~[?:1.8.0_152]
            at<init>(Unknown Source) ~[?:1.8.0_152]
            at com.peaches.customenchants.main.ConfigManager.checkMessages( ~[?:?]
            at com.peaches.customenchants.main.Main.checkconfig( ~[?:?]
            at com.peaches.customenchants.main.Main.onEnable( ~[?:?]
            at ~[1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.Bukkit.reload( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.defaults.ReloadCommand.execute( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A( [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at Source) [?:1.8.0_152]

    Code (Text):
    InputStream customClassStream = getClass().getResourceAsStream("/Messages.yml");
            InputStreamReader strR = new InputStreamReader(customClassStream); //line 112
            FileConfiguration defaults = YamlConfiguration.loadConfiguration(strR);
            for (String path : defaults.getKeys(true)) {
                if (!this.Messages.contains(path)) {
                    this.Messages.set(path, defaults.get(path));
    and yes i did type Messages.yml correctly
  6. Code (Text):
            if (!(new File(this.getDataFolder(), "config.yml").exists())) {
  7. sorry, i fixed this. Turns out i wasnt adding the CustomEnchants.yml into the jar file as i forgot hence it couldnt find it
    • Funny Funny x 1
  8. Haha, it's all good. Happy you got it resolved :)