Plugin Help Checking files in folder [FIGURED-OUT]

Discussion in 'Plugin Help/Development/Requests' started by meowxiik, Oct 26, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    meowxiik

    I have folder like this:

    Code:
    +plugins
    +VoteShop
      -settings.yml
      -playerData.yml
      +shops
       -[1] Shop.yml
       -[2] Shop.yml
    (+ = folders, - = files)

    I want to count them, so I have this:

    Code:java
    1. public int getNumShops(){
    2. int i = 0;
    3. YamlConfiguration test;
    4. test = fm.getConfig("shops" + File.separator + "[" + (i + 1) + "] Shop.yml");
    5. while((fm.getData(test, "shops" + File.separator + "[" + (i) + "] Shop.yml")) != null){
    6. test = fm.getConfig("shops" + File.separator + "[" + (i + 1) + "] Shop.yml");
    7. fm.setData(test, "settings.somethingVeryUseful", true, "[" + (i + 1) + "] Shop.yml");
    8. i++;
    9. }
    10. return i;
    11. }


    FileManager (fm) class:

    Code:java
    1. public class FileManager {
    2.  
    3. VoteShop plugin;
    4. String name = "VoteShop";
    5.  
    6. public FileManager(VoteShop plugin) {
    7. this.plugin = plugin;
    8. }
    9.  
    10. public YamlConfiguration getConfig(String name) {
    11. YamlConfiguration config = YamlConfiguration.loadConfiguration(new File(plugin.getDataFolder().getParentFile()+ File.separator+ this.name+ File.separator + name));
    12. try {
    13. config.save(plugin.getDataFolder().getParentFile() + File.separator+ this.name + File.separator + name);
    14. } catch (IOException e) {
    15. e.printStackTrace();
    16. }
    17. return config;
    18. }
    19.  
    20. public void setData(YamlConfiguration file, String path,Object value, String nameToSave) {
    21. file.set(path, value);
    22. try {
    23. file.save(plugin.getDataFolder().getParentFile()
    24. + File.separator + name + File.separator + nameToSave);
    25. } catch (IOException e) {
    26. plugin.getLogger().info("Error saving yml file");
    27. }
    28. }
    29.  
    30. public Object getData(YamlConfiguration file, String path) {
    31. return file.get(path);
    32. }
    33. }
    34.  


    (I removed few unuseful methods for making it shorter)

    Problem is, even if I have like 5 [x] Shop.yml files, method(getShopsNum()) is still returning 0!!
    Any solution? :/
    P.S.:If I removed something useful, tell me, I'll add it.

    New getNumShops() method, still ain't working

    Code:
        public int getNumShops(){
            int i = 0;
            YamlConfiguration test = fm.getConfig("shops" + File.separator + "[" + (i + 1) + "] Shop.yml");
            fm.setData(test, "settings.somethingVeryUseful", true, "[1] Shop.yml");
            while(fm.getData(fm.getConfig("shops" + File.separator + "[" + (i + 1) + "] Shop.yml"), "settigs.name") != null){
                log("Log message in while loop in getNumShops(), while i = " + i + " : " + fm.getData(fm.getConfig("shops" + File.separator + "[" + (i + 1) + "] Shop.yml"), "settigs.name"));
                i++;
            }
            log("Log message in end of getNumShops(): " + fm.getData(fm.getConfig("shops" + File.separator + "[" + (i + 1) + "] Shop.yml"), "settigs.name"));
            log("i: " + i);
            return i;
        }
    Well, at the ned, I did it like this:
    Code:
        public int getNumFiles(){
            File folder = new File(plugin.getDataFolder() + File.separator + "shops");
            int i = 0;
            File[] files = folder.listFiles();
            i = files.length;
            log("Detected " + i + " shop(s).");
            return i;
        }
    Thanks to nobody! :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
Thread Status:
Not open for further replies.

Share This Page