Will my Util // API work?

Discussion in 'Spigot Plugin Development' started by NaJated, May 24, 2015.

  1. Hey all, I'm trying to create a little API for creating additional YML datafolders along with a config; here's what I have so far.

    Code (Java):
        public void setDataFolder(FileConfiguration fileData, String file, String path, Object... value) {
            if (new File(Main.getInstance().getDataFolder(), file).isFile()) {
                fileData.set(path, value);
            }
        }

        public void saveDataFolder(FileConfiguration f, String fileName) {
            try {
                f.save(new File(Main.getInstance().getDataFolder(), fileName));
            } catch (IOException e) {
                Bukkit.getLogger().info("Failed saving to data.yml: ");
                e.printStackTrace();
            }
        }

        public void createDataFolder(String fileName) {
            FileConfiguration data = null;
            if (new File(Main.getInstance().getDataFolder(), fileName).isFile()) {
                data = YamlConfiguration.loadConfiguration(new File(Main.getInstance().getDataFolder(), fileName));
                Bukkit.getLogger().info("Successfully loaded existing " + fileName + "!");
            } else try {
                new File(Main.getInstance().getDataFolder(), fileName).createNewFile();
                data = YamlConfiguration.loadConfiguration(new File(Main.getInstance().getDataFolder(), fileName));
                data.createSection("users");
                saveDataFolder(data, fileName);
                Bukkit.getLogger().info("Successfully generated a new " + fileName +"!");
            } catch (IOException e) {
                Bukkit.getLogger().info("Failed to generate a new " + fileName + ":");
                e.printStackTrace();
            }
        }
     
  2. Easiest way to figure out if it will work: test it.