Solved how to get default custom config

Discussion in 'Spigot Plugin Development' started by Peaches_MLG100, 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:
    https://github.com/gronnmann/CoinFl...thub/gronnmann/coinflipper/ConfigManager.java
     
    • Winner Winner x 1
  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?)
    java.lang.NullPointerException
            at java.io.Reader.<init>(Unknown Source) ~[?:1.8.0_152]
            at java.io.InputStreamReader.<init>(Unknown Source) ~[?:1.8.0_152]
            at com.peaches.customenchants.main.ConfigManager.checkMessages(ConfigManager.java:112) ~[?:?]
            at com.peaches.customenchants.main.Main.checkconfig(Main.java:415) ~[?:?]
            at com.peaches.customenchants.main.Main.onEnable(Main.java:80) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.Bukkit.reload(Bukkit.java:535) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_152]
    Code:

    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));
                }
            }
            this.Messages.save(this.mfile);
    and yes i did type Messages.yml correctly
     
  6. Code (Text):
            if (!(new File(this.getDataFolder(), "config.yml").exists())) {
                this.saveDefaultConfig();
            }
    ?
     
  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 :)
     

Share This Page