How to get the number of rows from a StringList and apply?

3

I have a StringList inside a mensagens.txt file, I would like to count how many rows have this StringList contained within that file. For each line of the string 1 code will be run in plugin code.

If StringList has 10 lines the code will execute:

web.setScore(1) para a linha 1
web.setScore(2) para a linha 2.....
web.setScore(10) para a linha 10

The code I created is this:

public class ScoreBoard implements Listener {

    @EventHandler
    public void pj(PlayerJoinEvent e) {
        for (String list : Main.getMensagens().getStringList("Scoreboard")) {;

        Scoreboard scoreboard = Bukkit.getServer().getScoreboardManager().getNewScoreboard();
        Objective obj = scoreboard.registerNewObjective(Main.getMensagens().getString("Titulo"), "dummy");
        obj.setDisplaySlot(DisplaySlot.SIDEBAR);
          Score web = obj.getScore(list);
          web.setScore(1);

        Player p = e.getPlayer();
        p.setScoreboard(scoreboard);
    }
  }
}

My problem is with web.setScore , I need it to take the number of lines StringList and run automatically.

    
asked by anonymous 08.02.2018 / 04:27

1 answer

3

Turn in a for and have control over the index.

public class ScoreBoard implements Listener {
    @EventHandler
    public void pj(PlayerJoinEvent e) {
        /*tipo de retorno do getStringList*/ list = Main.getMensagens().getStringList("Scoreboard");
        for (int i = 0;  i < list.length; i++) {    
             Scoreboard scoreboard = Bukkit.getServer().getScoreboardManager().getNewScoreboard();
             Objective obj = scoreboard.registerNewObjective(Main.getMensagens().getString("Titulo"), "dummy");
             obj.setDisplaySlot(DisplaySlot.SIDEBAR);
             Score web = obj.getScore(list.get(i));
             web.setScore(i);
             Player p = e.getPlayer();
             p.setScoreboard(scoreboard);
        }
    }
}
    
08.02.2018 / 10:58