Config manager error

Discussion in 'Spigot Plugin Development' started by Deger, Jun 17, 2016.

  1. Hi why do i get an error?

    Code (Text):
    package me.deger.spawn.manager;

    import java.io.File;
    import java.io.IOException;

    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.PluginDescriptionFile;

    public class Manager {

        private Manager() {
        }

        public static Manager instance = new Manager();

        public static Manager getInstace() {
            return instance;
        }

        File file;
        FileConfiguration fileConfig;
        Plugin p;

        public void Setup(Plugin p) {
            file = new File(p.getDataFolder(), "spawn.yml");

            fileConfig = YamlConfiguration.loadConfiguration(file);



            if(!file.exists()){
                try {
                    file.createNewFile();
                } catch (IOException e) {
                    e.printStackTrace();
                    Bukkit.getServer().getLogger().severe("Could not create spawn.yml");
                    }
                }


           
        }

        public FileConfiguration getData() {
            return fileConfig;
        }

        public void saveData() {
            try {
                fileConfig.save(file);
            } catch (IOException e) {
                Bukkit.getServer().getLogger().severe("Could not save spawn.yml");
            }
        }

        public void reloadData() {
            fileConfig = YamlConfiguration.loadConfiguration(file);
        }

        public PluginDescriptionFile getDesc() {
            return p.getDescription();
        }
    }

    Code (Text):
    [23:02:40 WARN]: java.io.IOException: Det gÕr inte att hitta s÷kvõgen //this is swedish but english it is, "We cant find the serach path"
    [23:02:40 WARN]:        at java.io.WinNTFileSystem.createFileExclusively(Native Method)
    [23:02:40 WARN]:        at java.io.File.createNewFile(File.java:1012)
    [23:02:40 WARN]:        at me.deger.spawn.manager.Manager.Setup(Manager.java:38)
    [23:02:40 WARN]:        at me.deger.spawn.main.Core.onEnable(Core.java:14)
    [23:02:40 WARN]:        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:292)
    [23:02:40 WARN]:        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340)
    [23:02:40 WARN]:        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405)
    [23:02:40 WARN]:        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.loadPlugin(CraftServer.java:361)
    [23:02:40 WARN]:        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.enablePlugins(CraftServer.java:321)
    [23:02:40 WARN]:        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.reload(CraftServer.java:745)
    [23:02:40 WARN]:        at org.bukkit.Bukkit.reload(Bukkit.java:539)
    [23:02:40 WARN]:        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25)
    [23:02:40 WARN]:        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141)
    [23:02:40 WARN]:        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.dispatchCommand(CraftServer.java:645)
    [23:02:40 WARN]:        at org.bukkit.craftbukkit.v1_9_R2.CraftServer.dispatchServerCommand(CraftServer.java:631)
    [23:02:40 WARN]:        at net.minecraft.server.v1_9_R2.DedicatedServer.aL(DedicatedServer.java:437)
    [23:02:40 WARN]:        at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:400)
    [23:02:40 WARN]:        at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665)
    [23:02:40 WARN]:        at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564)
    [23:02:40 WARN]:        at java.lang.Thread.run(Thread.java:745)
    [23:02:40 ERROR]: Could not create spawn.yml

    This is row 38:
    file.createNewFile();

    row 14:
    instance.Setup(this);


    My instance above onEnable;
    Manager instance = Manager.getInstace();

    Thank you!
     
  2. I added this to onenable:
    instance.saveData();

    it is loading a datafolder and spawn.yml but it still throws me a cant find path error
    Same error:/
     
  3. You're trying to load the config before you check if it exists...
     
  4. Thank you!
     
  5. I'm really new so every help i can get i'm truly grateful for!