Set scoreboard from the config

Discussion in 'Spigot Plugin Development' started by Roimeiqui7, Jun 3, 2018.

  1. Hello, im trying to put scoreboard strings from the config:

    Config:
    Code (Text):
    Scoreboard:
      Scores:
      - "&aHola"
      - "&bAdios"
      - "&dQue tal"
      - "&fOMG"
      - "&aHolaa"
      - "&bAdioss"
      - "&dQue tald"
      - "&fOMGdfasd"
      - "&aHolafdasf"
      - "&bAdiosfdadfs"
      - "&dQue fdsatal"
      - "&fOMsadG"
      - "&bAdiosfdadfs"
      - "&dQue fdsatal"
      - "&fOMsadG"
     
     
    This code:

    Code (Text):
    for(String d : ScoreboardFile.scoreFile.getStringList("Scoreboard.Scores")) {
                Score score = o.getScore(color(d));
                for(int i = 1;i<15;i++) {
                    score.setScore(i);
                }
            }
         
            p.setScoreboard(s);
    But all the slots are the same:

    https://imgur.com/a/WFVgmgK[​IMG]
     
  2. Folf

    Folf Previously Checkium

    On your code, you are looping trough all the scoreboard scores that must be set, and then you are setting each score 14 times, leaving them all with a '14' score. The best approach for what you are trying is to create the int variable outside of the loop, then set the score and increment it.
     
    • Agree Agree x 1
  3. This is fairly simple code, as stated above, just iterate through and increase the score by 1 each time. If you want to change the scoreboard then... OOOF good luck with that lol. Scoreboard code can be challenging to create, as you have to manage old lines, new lines, etc.
     
  4. Infoboard gives you great code if you can decompile it. Dont do it without permission though.
     
  5. You can also get the size of the list and decrease it every time you set a line or score.
    Code (Java):
    int size = getConfig().getStringList("Lines").size();
    for (String s : getConfig().getStringList("Lines")) {
        yourObjective.getScore(s).setScore(size);
        size--;
    }