Looping configs

Discussion in 'Plugin Development' started by MattTheBeast, Jul 24, 2017.

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

    MattTheBeast

    I can seem to find a good way to loop trew configs. Basically I have a player data separator and each player has thier own yml file for stats. I whanted to make leaderboards and to do that I need to loop all configs and store let say kills...

    Any Idea how I can do that, thanks for the help.
     
  2. Offline

    Caderape2

    @MattTheBeast
    You don't have a lot of choice. Get the folder and list the files (file.listFiles[]). Lload each file for get the value.
    But if you have to do it often, you may think about something else.
     
  3. Offline

    Zombie_Striker

    @MattTheBeast
    If you have to do it often, it is better to store the scores for all the players in memory. Go through all the players you want on start up, grab their scores, and add it to a hashmap.
     
    Machine Maker likes this.
  4. Offline

    MattTheBeast

    @Caderape2 @Zombie_Striker What if its only on command ex /baltop

    @Zombie_Striker @Caderape2
    My code does not add anything to my map

    Code:
         private void addToMap(){
              File dataFolder = new File(Main.plugin.getDataFolder(), "player-data");
              for(File file : dataFolder.listFiles()){
                  String p = "";
                  FileReader fr = null;
                  int current = 0;
                    try {
                        fr = new FileReader(file);
                    } catch (FileNotFoundException e) {
                        e.printStackTrace();
                    }
                    if(fr != null){
                      BufferedReader reader = new BufferedReader(fr);
                      @SuppressWarnings("unused")
                        String player = null;
                        try {
                            player = reader.readLine();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    if(p != "" && !map.containsKey(p)){
                        YamlConfiguration config = YamlConfiguration.loadConfiguration(file);
                        if(config.getInt(p + ".coins") >= current){
                            current = config.getInt(p + ".coins");
                            map.put(p, current);
                        }
                    }
              }
         }
    
    Edit: nvm found the mistake, thanks everybody it works now

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

Share This Page