How to get top 10 killers from config?

Discussion in 'Plugin Development' started by Xores, Aug 11, 2018.

  1. Offline

    Xores

    Hello, How to get top 10 killers from config?
     
  2. @Xores
    1. Create an array of "killers". It will contain 10 values/indexes.
    2. Create another array for Integers. This represents the amount of kills each of the top players has.
    3. For loop through all of the killers in the config:
    4. For each killer, check if thier kills are greater than any of the values in the array for #2. If so, for loop through all of the entries, starting at the last entry and going up to the entry of the highest value that is still lower that the checked-killers amount, and move all of the killers and their kill amount to the next index (so if killer[2] has less kills that the current killer, set killer[3] = killer[2] and set killer[2] = <the new killer>)
    5. Once you are done with the loop, the 'killer' array will contain the top 10 players, where the player with the most kills will be at index 0.
     
  3. Offline

    PretMetInternet

    1. Create a HashMap with all the keys and values from the player and their kills.
    2. Create a LinkedList from the above HashMap entries.
    3. Sort the LinkedList using Collections.sort()

    So I would say:
    Code:
    public void sort(){
    Map<String, Integer> map = new HashMap<String, Integer>(); // I am using a String for the player name, not for the Player object.
    // Now, put all the values you want to put in.
    map.put(/*get all the player name here*/,/*Get the player's score here*/
    // Do this put thingy for every score.
    List<Entry<String, Integer>> list = new LinkedList<Entry<String, Integer>>(map.entrySet());
    Collectibles.sort(list, new Comparator<Entry<String, Integer>>(){
         @Override
          public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2){
              return 01.getValue().compareTo(o2.getValue());
         }
    });
    for(Entry<String, Integer> item : list){
       System.out.println(item); //This will print the sorted list
    }
    }
     
    Zombie_Striker likes this.

Share This Page