Solved Loop through multiple configs in specific folder

Discussion in 'Plugin Development' started by L33m4n123, Sep 16, 2013.

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

    L33m4n123

    Hey!

    One of my plugins stores stats of the user in files.

    They are all stored within
    /path/to/your/plugin/pluginName/players/playerName.cookie

    (basicly a normal txt file but has more style with a plugin specific ending :D)

    Is there a Method within Java or even within Bukkit that allows me to get all of the file names out of one folder so I can go ahaed and get a integer value from one of the paths?

    What I want to do (I describe it here now maybe there is a more easier way)

    I want to make a Leaderboard for the top 10 players. For that I would need to have the specific value from each individual playerfile. So any Input regarding this matter is appreciated.

    Edit: While I sent this in I thought of maybe writing an extra config file that saves all playernames as path and the corresponding value is their score. But I still would like to hear your peoples opinion on it :)

    Edit: While I sent this in I thought of maybe writing an extra config file that saves all playernames as path and the corresponding value is their score. But I still would like to hear your peoples opinion on it :)
     
  2. Offline

    Mitsugaru

    Why not just use the listFiles() method on a File object that points to your "players" directory? Then you can iterate over your files for the info that you want.

    ---

    If your player's directory has a mix of files and you just want the .cookie files, then just pass a FilenameFilter to the same method.

    Code:
    private final FilenameFilter filter = new FilenameFilter() {
        @Override
        public boolean accept(File dir, String name) {
            return name.endsWith(".cookie");
        }
    };
     
  3. Offline

    L33m4n123


    Cheers. Didn't know there was a Method called listFiles() ;-)
     
  4. Offline

    Pizza371

    L33m4n123 I have also been looking for a way to make a leaderboard with per-player yaml files (I would prefer /top <page> but meh, either would do) if you come across a way would you be so kind as to share a little code :3?
    ~Pizza
     
  5. Offline

    chasechocolate

    Pizza371 save all the stats in a HashMap<String, Integer>, and use TreeMaps and comparators to order them. See this thread.
     
Thread Status:
Not open for further replies.

Share This Page