Solved Loop through ArrayList and display on scoreboard

Discussion in 'Plugin Development' started by gradymcd, Aug 3, 2014.

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

    gradymcd

    I have an ArrayList in my plugin and I want to loop through it and display each value on the scoreboard. I have this code.
    Code:java
    1. for(String element : elements){
    2. for(String number : numbers){
    3. objective.getScore(ChatColor.translateAlternateColorCodes("&".charAt(0), element)).setScore(Integer.parseint(number));
    4. }
    5. }

    For some reason, it is putting the lines in a random order. If in that loop, I try
    Code:java
    1. System.out.println(element);
    It prints in the right order. Is this a bug or am I doing something wrong?
     
  2. Offline

    hugokk

    The scores on a scoreboard are always displayed in descending order, there's no way to change it, it's client-side.
     
  3. Offline

    seanw684

    I am having this issue too, can someone please help?
     
  4. Offline

    gradymcd

    No, it is not alphabetical...
     
  5. Offline

    hugokk

    Ofcourse it's not alphabetical, it's displayed with the highest score first, so descending.
     
  6. What's this "numbers" list? Why not just do, e.g.:
    Code:
    for (int i = 0; i < elements.size(); i++) {
        obj.getScore(elements.get(i)).setScore(elements.getSize() - i);
    }
    
    This'll sort the elements in descending order. If ascending, change: elements.getSize() - i
    To: i
     
  7. Offline

    gradymcd

    I figured it out. The numbers list was just a list of random numbers. I had to change to a hashmap with the elements corresponding to the numbers.
     
  8. Ah okay, quite weird though. Imo you should use my way... but anyway, cool. Can you please change your Forum thread prefix to [Solved].
     
Thread Status:
Not open for further replies.

Share This Page